yangsu@google.com | 688823f | 2011-08-30 19:14:13 +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 SimpleApp |
| 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 | @end |