reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #ifndef SampleCode_DEFINED |
| 2 | #define SampleCode_DEFINED |
| 3 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 4 | #include "SkColor.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 5 | #include "SkEvent.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 6 | #include "SkKey.h" |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 7 | #include "SkView.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 9 | class GrContext; |
| 10 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 11 | class SampleCode { |
| 12 | public: |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 13 | static bool KeyQ(const SkEvent&, SkKey* outKey); |
| 14 | static bool CharQ(const SkEvent&, SkUnichar* outUni); |
| 15 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | static bool TitleQ(const SkEvent&); |
| 17 | static void TitleR(SkEvent*, const char title[]); |
| 18 | |
| 19 | static bool PrefSizeQ(const SkEvent&); |
| 20 | static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 21 | |
| 22 | static bool FastTextQ(const SkEvent&); |
| 23 | |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 24 | static SkMSec GetAnimTime(); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 25 | static SkMSec GetAnimTimeDelta(); |
| 26 | static SkScalar GetAnimSecondsDelta(); |
reed@android.com | 4417740 | 2009-11-23 21:07:51 +0000 | [diff] [blame] | 27 | static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0); |
reed@google.com | 3cec4d7 | 2011-07-06 13:59:47 +0000 | [diff] [blame] | 28 | |
| 29 | static GrContext* GetGr(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | ////////////////////////////////////////////////////////////////////////////// |
| 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | typedef SkView* (*SkViewFactory)(); |
| 35 | |
| 36 | class SkViewRegister : SkNoncopyable { |
| 37 | public: |
deanm@chromium.org | 1220e1c | 2009-06-11 12:26:47 +0000 | [diff] [blame] | 38 | explicit SkViewRegister(SkViewFactory); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | |
| 40 | static const SkViewRegister* Head() { return gHead; } |
| 41 | |
| 42 | SkViewRegister* next() const { return fChain; } |
| 43 | SkViewFactory factory() const { return fFact; } |
| 44 | |
| 45 | private: |
| 46 | SkViewFactory fFact; |
| 47 | SkViewRegister* fChain; |
| 48 | |
| 49 | static SkViewRegister* gHead; |
| 50 | }; |
| 51 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
| 54 | class SampleView : public SkView { |
| 55 | public: |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 56 | SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) { |
| 57 | fUsePipe = false; |
| 58 | } |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 59 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 60 | void setBGColor(SkColor color) { fBGColor = color; } |
| 61 | |
reed@google.com | a6ff4dc | 2011-05-12 22:08:24 +0000 | [diff] [blame] | 62 | static bool IsSampleView(SkView*); |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 63 | static bool SetRepeatDraw(SkView*, int count); |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 64 | static bool SetUsePipe(SkView*, bool); |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 65 | |
| 66 | protected: |
| 67 | virtual void onDrawBackground(SkCanvas*); |
| 68 | virtual void onDrawContent(SkCanvas*) = 0; |
| 69 | |
| 70 | // overrides |
| 71 | virtual bool onEvent(const SkEvent& evt); |
| 72 | virtual bool onQuery(SkEvent* evt); |
| 73 | virtual void onDraw(SkCanvas*); |
| 74 | |
| 75 | private: |
| 76 | int fRepeatCount; |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 77 | SkColor fBGColor; |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 78 | |
reed@google.com | 0faac1e | 2011-05-11 05:58:58 +0000 | [diff] [blame] | 79 | bool fUsePipe; |
| 80 | |
mike@reedtribe.org | 2eb5952 | 2011-04-22 01:59:09 +0000 | [diff] [blame] | 81 | typedef SkView INHERITED; |
| 82 | }; |
| 83 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 84 | #endif |
| 85 | |