yangsu@google.com | 69f2e05 | 2011-08-30 17:08:08 +0000 | [diff] [blame] | 1 | #import "SkCanvas.h" |
| 2 | #import "SkPaint.h" |
| 3 | #import "SkWindow.h" |
| 4 | #include "SkGraphics.h" |
| 5 | #include "SkCGUtils.h" |
| 6 | class SkSampleView : public SkView { |
| 7 | public: |
| 8 | SkSampleView() { |
| 9 | this->setVisibleP(true); |
| 10 | this->setClipToBounds(false); |
| 11 | }; |
| 12 | protected: |
| 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 | } |
| 23 | private: |
| 24 | typedef SkView INHERITED; |
| 25 | }; |
| 26 | |
| 27 | void application_init() { |
| 28 | SkGraphics::Init(); |
| 29 | SkEvent::Init(); |
| 30 | } |
| 31 | |
| 32 | void application_term() { |
| 33 | SkGraphics::Term(); |
| 34 | SkEvent::Term(); |
| 35 | } |
| 36 | |
| 37 | class FillLayout : public SkView::Layout { |
| 38 | protected: |
| 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 |