mtklein | fe81e2d | 2015-09-09 07:35:42 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 8 | #include "SkApplication.h" |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 9 | #import "SkCanvas.h" |
| 10 | #import "SkPaint.h" |
| 11 | #import "SkWindow.h" |
| 12 | #include "SkGraphics.h" |
| 13 | #include "SkCGUtils.h" |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 14 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 15 | void dummy_main(int , char *[]) { |
| 16 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 17 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 18 | class SkSampleView : public SkView { |
| 19 | public: |
| 20 | SkSampleView() { |
| 21 | this->setVisibleP(true); |
| 22 | this->setClipToBounds(false); |
| 23 | }; |
| 24 | protected: |
| 25 | virtual void onDraw(SkCanvas* canvas) { |
| 26 | canvas->drawColor(0xFFFFFFFF); |
| 27 | SkPaint p; |
| 28 | p.setTextSize(20); |
| 29 | p.setAntiAlias(true); |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 30 | canvas->drawText("finished", 13, 50, 30, p); |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 31 | SkRect r = {50, 50, 80, 80}; |
| 32 | p.setColor(0xAA11EEAA); |
| 33 | canvas->drawRect(r, p); |
| 34 | } |
| 35 | private: |
mtklein | fe81e2d | 2015-09-09 07:35:42 -0700 | [diff] [blame] | 36 | typedef SkView INHERITED; |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | void application_init() { |
| 40 | SkGraphics::Init(); |
| 41 | SkEvent::Init(); |
| 42 | } |
| 43 | |
| 44 | void application_term() { |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 45 | SkEvent::Term(); |
| 46 | } |
| 47 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 48 | int saved_argc; |
| 49 | char** saved_argv; |
| 50 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 51 | IOS_launch_type set_cmd_line_args(int argc, char *argv[], const char* ) { |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 52 | saved_argc = argc; |
| 53 | saved_argv = argv; |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 54 | return kTool_iOSLaunchType; |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 55 | } |
| 56 | |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 57 | class FillLayout : public SkView::Layout { |
| 58 | protected: |
| 59 | virtual void onLayoutChildren(SkView* parent) { |
| 60 | SkView* view = SkView::F2BIter(parent).next(); |
| 61 | view->setSize(parent->width(), parent->height()); |
| 62 | } |
| 63 | }; |
| 64 | |
| 65 | #import "SimpleApp.h" |
| 66 | @implementation SimpleApp |
| 67 | |
| 68 | - (id)initWithDefaults { |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 69 | dummy_main(saved_argc, saved_argv); |
yangsu@google.com | 688823f | 2011-08-30 19:14:13 +0000 | [diff] [blame] | 70 | if (self = [super initWithDefaults]) { |
| 71 | fWind = new SkOSWindow(self); |
| 72 | fWind->setLayout(new FillLayout, false); |
| 73 | fWind->attachChildToFront(new SkSampleView)->unref(); |
| 74 | } |
| 75 | return self; |
| 76 | } |
| 77 | |
| 78 | @end |