bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | |
| 10 | #ifndef GMSampleView_DEFINED |
| 11 | #define GMSampleView_DEFINED |
| 12 | |
| 13 | #include "SampleCode.h" |
| 14 | #include "gm.h" |
| 15 | |
| 16 | class GMSampleView : public SampleView { |
| 17 | private: |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 18 | bool fShowSize; |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 19 | typedef skiagm::GM GM; |
| 20 | |
| 21 | public: |
| 22 | GMSampleView(GM* gm) |
tfarina@chromium.org | 2cda387 | 2012-11-20 16:36:20 +0000 | [diff] [blame] | 23 | : fShowSize(false), fGM(gm) {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 25 | virtual ~GMSampleView() { |
| 26 | delete fGM; |
| 27 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 28 | |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 29 | static SkEvent* NewShowSizeEvt(bool doShowSize) { |
| 30 | SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize")); |
| 31 | evt->setFast32(doShowSize); |
| 32 | return evt; |
| 33 | } |
| 34 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 35 | protected: |
| 36 | virtual bool onQuery(SkEvent* evt) { |
| 37 | if (SampleCode::TitleQ(*evt)) { |
bsalomon@google.com | e9f091d | 2011-12-09 19:50:48 +0000 | [diff] [blame] | 38 | SkString name("GM:"); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 39 | name.append(fGM->getName()); |
reed@google.com | ac7aa1b | 2011-11-08 15:06:34 +0000 | [diff] [blame] | 40 | SampleCode::TitleR(evt, name.c_str()); |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 41 | return true; |
| 42 | } |
| 43 | return this->INHERITED::onQuery(evt); |
| 44 | } |
skia.committer@gmail.com | 884e60b | 2012-11-16 02:01:17 +0000 | [diff] [blame] | 45 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 46 | bool onEvent(const SkEvent& evt) SK_OVERRIDE { |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 47 | if (evt.isType("GMSampleView::showSize")) { |
| 48 | fShowSize = SkToBool(evt.getFast32()); |
| 49 | return true; |
| 50 | } |
| 51 | return this->INHERITED::onEvent(evt); |
| 52 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 53 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 54 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 55 | { |
| 56 | SkAutoCanvasRestore acr(canvas, fShowSize); |
| 57 | fGM->drawContent(canvas); |
| 58 | } |
| 59 | if (fShowSize) { |
| 60 | SkISize size = fGM->getISize(); |
| 61 | SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), |
| 62 | SkIntToScalar(size.height())); |
| 63 | SkPaint paint; |
| 64 | paint.setColor(0x40FF8833); |
| 65 | canvas->drawRect(r, paint); |
| 66 | } |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | virtual void onDrawBackground(SkCanvas* canvas) { |
| 70 | fGM->drawBackground(canvas); |
| 71 | } |
| 72 | |
reed | 76113a9 | 2015-02-02 12:55:02 -0800 | [diff] [blame] | 73 | bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
| 74 | return fGM->animate(timer); |
reed | d9adfe6 | 2015-02-01 19:01:04 -0800 | [diff] [blame] | 75 | } |
| 76 | |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [diff] [blame] | 77 | private: |
| 78 | GM* fGM; |
| 79 | typedef SampleView INHERITED; |
| 80 | }; |
| 81 | |
| 82 | #endif |