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