Home | History | Annotate | Download | only in samplecode
      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:
     18     bool fShowSize;
     19     typedef skiagm::GM GM;
     20 
     21 public:
     22     GMSampleView(GM* gm)
     23     : fShowSize(false), fGM(gm) {}
     24 
     25     virtual ~GMSampleView() {
     26         delete fGM;
     27     }
     28 
     29     static SkEvent* NewShowSizeEvt(bool doShowSize) {
     30         SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize"));
     31         evt->setFast32(doShowSize);
     32         return evt;
     33     }
     34 
     35 protected:
     36     virtual bool onQuery(SkEvent* evt) {
     37         if (SampleCode::TitleQ(*evt)) {
     38             SkString name("GM:");
     39             name.append(fGM->getName());
     40             SampleCode::TitleR(evt, name.c_str());
     41             return true;
     42         }
     43         return this->INHERITED::onQuery(evt);
     44     }
     45 
     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     }
     53 
     54     virtual void onDrawContent(SkCanvas* canvas) {
     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         }
     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
     79