blob: de40d1e025fc98ce36c3993991a02c21593e5ddd [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#ifndef SampleCode_DEFINED
2#define SampleCode_DEFINED
3
reed@google.comf2183392011-04-22 14:10:48 +00004#include "SkColor.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00005#include "SkEvent.h"
reed@android.comf2b98d62010-12-20 18:26:13 +00006#include "SkKey.h"
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00007#include "SkView.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00008
9class SampleCode {
10public:
reed@android.comf2b98d62010-12-20 18:26:13 +000011 static bool KeyQ(const SkEvent&, SkKey* outKey);
12 static bool CharQ(const SkEvent&, SkUnichar* outUni);
13
reed@android.com8a1c16f2008-12-17 15:59:43 +000014 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);
reed@android.comf2b98d62010-12-20 18:26:13 +000019
20 static bool FastTextQ(const SkEvent&);
21
reed@android.com44177402009-11-23 21:07:51 +000022 static SkMSec GetAnimTime();
reed@android.comf2b98d62010-12-20 18:26:13 +000023 static SkMSec GetAnimTimeDelta();
24 static SkScalar GetAnimSecondsDelta();
reed@android.com44177402009-11-23 21:07:51 +000025 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000026};
27
28//////////////////////////////////////////////////////////////////////////////
29
reed@android.com8a1c16f2008-12-17 15:59:43 +000030typedef SkView* (*SkViewFactory)();
31
32class SkViewRegister : SkNoncopyable {
33public:
deanm@chromium.org1220e1c2009-06-11 12:26:47 +000034 explicit SkViewRegister(SkViewFactory);
reed@android.com8a1c16f2008-12-17 15:59:43 +000035
36 static const SkViewRegister* Head() { return gHead; }
37
38 SkViewRegister* next() const { return fChain; }
39 SkViewFactory factory() const { return fFact; }
40
41private:
42 SkViewFactory fFact;
43 SkViewRegister* fChain;
44
45 static SkViewRegister* gHead;
46};
47
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000048///////////////////////////////////////////////////////////////////////////////
49
50class SampleView : public SkView {
51public:
reed@google.com0faac1e2011-05-11 05:58:58 +000052 SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) {
53 fUsePipe = false;
54 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000055
reed@google.comf2183392011-04-22 14:10:48 +000056 void setBGColor(SkColor color) { fBGColor = color; }
57
58 static bool SetRepeatDraw(SkView*, int count);
reed@google.com0faac1e2011-05-11 05:58:58 +000059 static bool SetUsePipe(SkView*, bool);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000060
61protected:
62 virtual void onDrawBackground(SkCanvas*);
63 virtual void onDrawContent(SkCanvas*) = 0;
64
65 // overrides
66 virtual bool onEvent(const SkEvent& evt);
67 virtual bool onQuery(SkEvent* evt);
68 virtual void onDraw(SkCanvas*);
69
70private:
71 int fRepeatCount;
reed@google.comf2183392011-04-22 14:10:48 +000072 SkColor fBGColor;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000073
reed@google.com0faac1e2011-05-11 05:58:58 +000074 bool fUsePipe;
75
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000076 typedef SkView INHERITED;
77};
78
reed@android.com8a1c16f2008-12-17 15:59:43 +000079#endif
80