aboutsummaryrefslogtreecommitdiffhomepage
path: root/samplecode/GMSampleView.h
blob: 40d11abce46122c4601973b5b6184a981aef74db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

/*
 * 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:
    bool fShowSize;
    typedef skiagm::GM GM;

public:
    GMSampleView(GM* gm)
    : fShowSize(false), fGM(gm) {}

    virtual ~GMSampleView() {
        delete fGM;
    }

    static SkEvent* NewShowSizeEvt(bool doShowSize) {
        SkEvent* evt = SkNEW_ARGS(SkEvent, ("GMSampleView::showSize"));
        evt->setFast32(doShowSize);
        return evt;
    }

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);
    }

    virtual 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);
    }

private:
    GM* fGM;
    typedef SampleView INHERITED;
};

#endif