blob: 095dfe68f5419bee5635512b439738d940a270fe [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
9GM::GM() {}
10GM::~GM() {}
11
12void GM::draw(SkCanvas* canvas) {
13 this->onDraw(canvas);
14}
15
16// need to explicitly declare this, or we get some weird infinite loop llist
17template GMRegistry* GMRegistry::gHead;
18
19class Iter {
20public:
21 Iter() {
22 fReg = GMRegistry::Head();
23 }
24
25 GM* next() {
26 if (fReg) {
27 GMRegistry::Factory fact = fReg->factory();
28 fReg = fReg->next();
29 return fact(0);
30 }
31 return NULL;
32 }
33
34 static int Count() {
35 const GMRegistry* reg = GMRegistry::Head();
36 int count = 0;
37 while (reg) {
38 count += 1;
39 reg = reg->next();
40 }
41 return count;
42 }
43
44private:
45 const GMRegistry* fReg;
46};
47
48///////////////////////////////////////////////////////////////////////////////
49
50class GMView : public SkView {
51 Iter fIter;
52 GM* fGM;
53public:
54 GMView() {
55 fGM = fIter.next();
56 }
57
58protected:
59 // overrides from SkEventSink
60 virtual bool onQuery(SkEvent* evt) {
61 if (SampleCode::TitleQ(*evt)) {
62 SampleCode::TitleR(evt, "GM");
63 return true;
64 }
65 return this->INHERITED::onQuery(evt);
66 }
67
68 void drawBG(SkCanvas* canvas) {
69 canvas->drawColor(0xFFDDDDDD);
70 }
71
72 virtual void onDraw(SkCanvas* canvas) {
73 fGM->draw(canvas);
74 }
75
76private:
77 typedef SkView INHERITED;
78};
79
80///////////////////////////////////////////////////////////////////////////////
81
82static SkView* MyFactory() { return new GMView; }
83static SkViewRegister reg(MyFactory);
84