2011-10-31 14:18:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GMSampleView_DEFINED
|
|
|
|
#define GMSampleView_DEFINED
|
|
|
|
|
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
class GMSampleView : public SampleView {
|
|
|
|
private:
|
2012-11-15 15:56:38 +00:00
|
|
|
bool fShowSize;
|
2011-10-31 14:18:20 +00:00
|
|
|
typedef skiagm::GM GM;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GMSampleView(GM* gm)
|
2012-11-20 16:36:20 +00:00
|
|
|
: fShowSize(false), fGM(gm) {}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
virtual ~GMSampleView() {
|
|
|
|
delete fGM;
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2012-11-15 15:56:38 +00:00
|
|
|
static SkEvent* NewShowSizeEvt(bool doShowSize) {
|
|
|
|
SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize"));
|
|
|
|
evt->setFast32(doShowSize);
|
|
|
|
return evt;
|
|
|
|
}
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
protected:
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
2011-12-09 19:50:48 +00:00
|
|
|
SkString name("GM:");
|
2014-02-26 23:01:57 +00:00
|
|
|
name.append(fGM->getName());
|
2011-11-08 15:06:34 +00:00
|
|
|
SampleCode::TitleR(evt, name.c_str());
|
2011-10-31 14:18:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-11-16 02:01:17 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
bool onEvent(const SkEvent& evt) SK_OVERRIDE {
|
2012-11-15 15:56:38 +00:00
|
|
|
if (evt.isType("GMSampleView::showSize")) {
|
|
|
|
fShowSize = SkToBool(evt.getFast32());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
2012-11-15 15:56:38 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2011-10-31 14:18:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void onDrawBackground(SkCanvas* canvas) {
|
|
|
|
fGM->drawBackground(canvas);
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE {
|
|
|
|
return fGM->animate(timer);
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
private:
|
|
|
|
GM* fGM;
|
|
|
|
typedef SampleView INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|