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 | |
| 9 | GM::GM() {} |
| 10 | GM::~GM() {} |
| 11 | |
| 12 | void GM::draw(SkCanvas* canvas) { |
| 13 | this->onDraw(canvas); |
| 14 | } |
| 15 | |
| 16 | // need to explicitly declare this, or we get some weird infinite loop llist |
| 17 | template GMRegistry* GMRegistry::gHead; |
| 18 | |
| 19 | class Iter { |
| 20 | public: |
| 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 | |
| 44 | private: |
| 45 | const GMRegistry* fReg; |
| 46 | }; |
| 47 | |
| 48 | /////////////////////////////////////////////////////////////////////////////// |
| 49 | |
| 50 | class GMView : public SkView { |
| 51 | Iter fIter; |
| 52 | GM* fGM; |
| 53 | public: |
| 54 | GMView() { |
| 55 | fGM = fIter.next(); |
| 56 | } |
| 57 | |
| 58 | protected: |
| 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 | |
| 76 | private: |
| 77 | typedef SkView INHERITED; |
| 78 | }; |
| 79 | |
| 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
| 82 | static SkView* MyFactory() { return new GMView; } |
| 83 | static SkViewRegister reg(MyFactory); |
| 84 | |