reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | |
| 5 | #include "gm.h" |
| 6 | |
| 7 | using namespace skiagm; |
| 8 | |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 9 | // need to explicitly declare this, or we get some weird infinite loop llist |
| 10 | template GMRegistry* GMRegistry::gHead; |
| 11 | |
| 12 | class Iter { |
| 13 | public: |
| 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 | |
| 37 | private: |
| 38 | const GMRegistry* fReg; |
| 39 | }; |
| 40 | |
| 41 | /////////////////////////////////////////////////////////////////////////////// |
| 42 | |
| 43 | class GMView : public SkView { |
| 44 | Iter fIter; |
| 45 | GM* fGM; |
| 46 | public: |
| 47 | GMView() { |
| 48 | fGM = fIter.next(); |
| 49 | } |
| 50 | |
| 51 | protected: |
| 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 | |
| 69 | private: |
| 70 | typedef SkView INHERITED; |
| 71 | }; |
| 72 | |
| 73 | /////////////////////////////////////////////////////////////////////////////// |
| 74 | |
| 75 | static SkView* MyFactory() { return new GMView; } |
| 76 | static SkViewRegister reg(MyFactory); |
| 77 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 78 | /////////////////////////////////////////////////////////////////////////////// |
| 79 | |
| 80 | using namespace skiagm; |
| 81 | |
| 82 | GM::GM() {} |
| 83 | GM::~GM() {} |
| 84 | |
| 85 | void GM::draw(SkCanvas* canvas) { |
| 86 | this->onDraw(canvas); |
| 87 | } |
| 88 | |
| 89 | |