blob: adaf23d43f54f5c597ae0675dfe4a42cf253494d [file] [log] [blame]
bsalomon@google.com48dd1a22011-10-31 14:18:20 +00001
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
16class GMSampleView : public SampleView {
17private:
reed@google.coma4f81372012-11-15 15:56:38 +000018 bool fShowSize;
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000019 typedef skiagm::GM GM;
20
21public:
22 GMSampleView(GM* gm)
tfarina@chromium.org2cda3872012-11-20 16:36:20 +000023 : fShowSize(false), fGM(gm) {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000024
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000025 virtual ~GMSampleView() {
26 delete fGM;
27 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000028
reed@google.coma4f81372012-11-15 15:56:38 +000029 static SkEvent* NewShowSizeEvt(bool doShowSize) {
30 SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize"));
31 evt->setFast32(doShowSize);
32 return evt;
33 }
34
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000035protected:
36 virtual bool onQuery(SkEvent* evt) {
37 if (SampleCode::TitleQ(*evt)) {
bsalomon@google.come9f091d2011-12-09 19:50:48 +000038 SkString name("GM:");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000039 name.append(fGM->getName());
reed@google.comac7aa1b2011-11-08 15:06:34 +000040 SampleCode::TitleR(evt, name.c_str());
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000041 return true;
42 }
43 return this->INHERITED::onQuery(evt);
44 }
skia.committer@gmail.com884e60b2012-11-16 02:01:17 +000045
mtklein72c9faa2015-01-09 10:06:39 -080046 bool onEvent(const SkEvent& evt) SK_OVERRIDE {
reed@google.coma4f81372012-11-15 15:56:38 +000047 if (evt.isType("GMSampleView::showSize")) {
48 fShowSize = SkToBool(evt.getFast32());
49 return true;
50 }
51 return this->INHERITED::onEvent(evt);
52 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000054 virtual void onDrawContent(SkCanvas* canvas) {
reed@google.coma4f81372012-11-15 15:56:38 +000055 {
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.com48dd1a22011-10-31 14:18:20 +000067 }
68
69 virtual void onDrawBackground(SkCanvas* canvas) {
70 fGM->drawBackground(canvas);
71 }
72
reed76113a92015-02-02 12:55:02 -080073 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
74 return fGM->animate(timer);
reedd9adfe62015-02-01 19:01:04 -080075 }
76
bsalomon@google.com48dd1a22011-10-31 14:18:20 +000077private:
78 GM* fGM;
79 typedef SampleView INHERITED;
80};
81
82#endif