blob: 922177e3aae188f59255938597aaec54dce36fc7 [file] [log] [blame]
yangsu@google.com69f2e052011-08-30 17:08:08 +00001#import "SkCanvas.h"
2#import "SkPaint.h"
3#import "SkWindow.h"
4#include "SkGraphics.h"
5#include "SkCGUtils.h"
6class SkSampleView : public SkView {
7public:
8 SkSampleView() {
9 this->setVisibleP(true);
10 this->setClipToBounds(false);
11 };
12protected:
13 virtual void onDraw(SkCanvas* canvas) {
14 canvas->drawColor(0xFFFFFFFF);
15 SkPaint p;
16 p.setTextSize(20);
17 p.setAntiAlias(true);
18 canvas->drawText("Hello World!", 13, 50, 30, p);
19 SkRect r = {50, 50, 80, 80};
20 p.setColor(0xAA11EEAA);
21 canvas->drawRect(r, p);
22 }
23private:
24 typedef SkView INHERITED;
25};
26
27void application_init() {
28 SkGraphics::Init();
29 SkEvent::Init();
30}
31
32void application_term() {
33 SkGraphics::Term();
34 SkEvent::Term();
35}
36
37class FillLayout : public SkView::Layout {
38protected:
39 virtual void onLayoutChildren(SkView* parent) {
40 SkView* view = SkView::F2BIter(parent).next();
41 view->setSize(parent->width(), parent->height());
42 }
43};
44
45#import "SimpleApp.h"
46@implementation SimpleNSView
47
48- (id)initWithDefaults {
49 if (self = [super initWithDefaults]) {
50 fWind = new SkOSWindow(self);
51 fWind->setLayout(new FillLayout, false);
52 fWind->attachChildToFront(new SkSampleView)->unref();
53 }
54 return self;
55}
56
57- (void)drawRect:(NSRect)dirtyRect {
58 CGContextRef ctx = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
59 SkCGDrawBitmap(ctx, fWind->getBitmap(), 0, 0);
60}
61
62@end