diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index 3f57aa1538..cbe9e88598 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -26,6 +26,7 @@ 'sources': [ '../gm/gm.cpp', '../samplecode/GMSampleView.h', + '../samplecode/GMSampleView.cpp', '../samplecode/ClockFaceView.cpp', '../samplecode/OverView.cpp', '../samplecode/OverView.h', diff --git a/samplecode/GMSampleView.cpp b/samplecode/GMSampleView.cpp new file mode 100644 index 0000000000..e74612b248 --- /dev/null +++ b/samplecode/GMSampleView.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GMSampleView.h" + +GMSampleView::GMSampleView(GM* gm) : fShowSize(false), fGM(gm) {} + +GMSampleView::~GMSampleView() { + delete fGM; +} + +SkEvent* GMSampleView::NewShowSizeEvt(bool doShowSize) { + SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize")); + evt->setFast32(doShowSize); + return evt; +} + +bool GMSampleView::onQuery(SkEvent* evt) { + if (SampleCode::TitleQ(*evt)) { + SkString name("GM:"); + name.append(fGM->getName()); + SampleCode::TitleR(evt, name.c_str()); + return true; + } + return this->INHERITED::onQuery(evt); +} + +bool GMSampleView::onEvent(const SkEvent& evt) { + if (evt.isType("GMSampleView::showSize")) { + fShowSize = SkToBool(evt.getFast32()); + return true; + } + return this->INHERITED::onEvent(evt); +} + +void GMSampleView::onDrawContent(SkCanvas* canvas) { + { + SkAutoCanvasRestore acr(canvas, fShowSize); + fGM->drawContent(canvas); + } + if (fShowSize) { + SkISize size = fGM->getISize(); + SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), + SkIntToScalar(size.height())); + SkPaint paint; + paint.setColor(0x40FF8833); + canvas->drawRect(r, paint); + } +} + +void GMSampleView::onDrawBackground(SkCanvas* canvas) { + fGM->drawBackground(canvas); +} + +bool GMSampleView::onAnimate(const SkAnimTimer& timer) { + return fGM->animate(timer); +} + diff --git a/samplecode/GMSampleView.h b/samplecode/GMSampleView.h index adaf23d43f..f97ce92d2b 100644 --- a/samplecode/GMSampleView.h +++ b/samplecode/GMSampleView.h @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -6,7 +5,6 @@ * found in the LICENSE file. */ - #ifndef GMSampleView_DEFINED #define GMSampleView_DEFINED @@ -19,60 +17,17 @@ private: typedef skiagm::GM GM; public: - GMSampleView(GM* gm) - : fShowSize(false), fGM(gm) {} + GMSampleView(GM*); + virtual ~GMSampleView(); - virtual ~GMSampleView() { - delete fGM; - } - - static SkEvent* NewShowSizeEvt(bool doShowSize) { - SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize")); - evt->setFast32(doShowSize); - return evt; - } + static SkEvent* NewShowSizeEvt(bool doShowSize); protected: - virtual bool onQuery(SkEvent* evt) { - if (SampleCode::TitleQ(*evt)) { - SkString name("GM:"); - name.append(fGM->getName()); - SampleCode::TitleR(evt, name.c_str()); - return true; - } - return this->INHERITED::onQuery(evt); - } - - bool onEvent(const SkEvent& evt) SK_OVERRIDE { - if (evt.isType("GMSampleView::showSize")) { - fShowSize = SkToBool(evt.getFast32()); - return true; - } - return this->INHERITED::onEvent(evt); - } - - virtual void onDrawContent(SkCanvas* canvas) { - { - SkAutoCanvasRestore acr(canvas, fShowSize); - fGM->drawContent(canvas); - } - if (fShowSize) { - SkISize size = fGM->getISize(); - SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), - SkIntToScalar(size.height())); - SkPaint paint; - paint.setColor(0x40FF8833); - canvas->drawRect(r, paint); - } - } - - virtual void onDrawBackground(SkCanvas* canvas) { - fGM->drawBackground(canvas); - } - - bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { - return fGM->animate(timer); - } + bool onQuery(SkEvent*) SK_OVERRIDE; + bool onEvent(const SkEvent&) SK_OVERRIDE; + void onDrawContent(SkCanvas*) SK_OVERRIDE; + void onDrawBackground(SkCanvas*) SK_OVERRIDE; + bool onAnimate(const SkAnimTimer&) SK_OVERRIDE; private: GM* fGM;