blob: d85cad122716b32d579e59c8541a9cd868b216e9 [file] [log] [blame]
reed@android.comc4cae852009-09-23 15:06:10 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4
5#include "gm.h"
6
7using namespace skiagm;
8
reed@android.comc4cae852009-09-23 15:06:10 +00009// need to explicitly declare this, or we get some weird infinite loop llist
10template GMRegistry* GMRegistry::gHead;
11
12class Iter {
13public:
14 Iter() {
15 fReg = GMRegistry::Head();
16 }
17
18 GM* next() {
19 if (fReg) {
20 GMRegistry::Factory fact = fReg->factory();
21 fReg = fReg->next();
22 return fact(0);
23 }
24 return NULL;
25 }
26
27 static int Count() {
28 const GMRegistry* reg = GMRegistry::Head();
29 int count = 0;
30 while (reg) {
31 count += 1;
32 reg = reg->next();
33 }
34 return count;
35 }
36
37private:
38 const GMRegistry* fReg;
39};
40
41///////////////////////////////////////////////////////////////////////////////
42
43class GMView : public SkView {
44 Iter fIter;
45 GM* fGM;
46public:
47 GMView() {
48 fGM = fIter.next();
49 }
50
51protected:
52 // overrides from SkEventSink
53 virtual bool onQuery(SkEvent* evt) {
54 if (SampleCode::TitleQ(*evt)) {
55 SampleCode::TitleR(evt, "GM");
56 return true;
57 }
58 return this->INHERITED::onQuery(evt);
59 }
60
61 void drawBG(SkCanvas* canvas) {
62 canvas->drawColor(0xFFDDDDDD);
63 }
64
65 virtual void onDraw(SkCanvas* canvas) {
66 fGM->draw(canvas);
67 }
68
69private:
70 typedef SkView INHERITED;
71};
72
73///////////////////////////////////////////////////////////////////////////////
74
75static SkView* MyFactory() { return new GMView; }
76static SkViewRegister reg(MyFactory);
77
reed@android.comf2b98d62010-12-20 18:26:13 +000078///////////////////////////////////////////////////////////////////////////////
79
80using namespace skiagm;
81
82GM::GM() {}
83GM::~GM() {}
84
85void GM::draw(SkCanvas* canvas) {
86 this->onDraw(canvas);
87}
88
89