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:"); |
reed@google.com | ac7aa1b | 2011-11-08 15:06:34 +0000 | [diff] [blame] | 39 | name.append(fGM->shortName()); |
| 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 | |
reed@google.com | a4f8137 | 2012-11-15 15:56:38 +0000 | [diff] [blame] | 46 | virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE { |
| 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 | |
| 73 | private: |
| 74 | GM* fGM; |
| 75 | typedef SampleView INHERITED; |
| 76 | }; |
| 77 | |
| 78 | #endif |