blob: 2eb8bef2626a1c803b66a7c60c11b159a374fe98 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#ifndef SampleCode_DEFINED
2#define SampleCode_DEFINED
3
4#include "SkEvent.h"
reed@android.comf2b98d62010-12-20 18:26:13 +00005#include "SkKey.h"
mike@reedtribe.org2eb59522011-04-22 01:59:09 +00006#include "SkView.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +00007
8class SampleCode {
9public:
reed@android.comf2b98d62010-12-20 18:26:13 +000010 static bool KeyQ(const SkEvent&, SkKey* outKey);
11 static bool CharQ(const SkEvent&, SkUnichar* outUni);
12
reed@android.com8a1c16f2008-12-17 15:59:43 +000013 static bool TitleQ(const SkEvent&);
14 static void TitleR(SkEvent*, const char title[]);
15
16 static bool PrefSizeQ(const SkEvent&);
17 static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height);
reed@android.comf2b98d62010-12-20 18:26:13 +000018
19 static bool FastTextQ(const SkEvent&);
20
reed@android.com44177402009-11-23 21:07:51 +000021 static SkMSec GetAnimTime();
reed@android.comf2b98d62010-12-20 18:26:13 +000022 static SkMSec GetAnimTimeDelta();
23 static SkScalar GetAnimSecondsDelta();
reed@android.com44177402009-11-23 21:07:51 +000024 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000025};
26
27//////////////////////////////////////////////////////////////////////////////
28
reed@android.com8a1c16f2008-12-17 15:59:43 +000029typedef SkView* (*SkViewFactory)();
30
31class SkViewRegister : SkNoncopyable {
32public:
deanm@chromium.org1220e1c2009-06-11 12:26:47 +000033 explicit SkViewRegister(SkViewFactory);
reed@android.com8a1c16f2008-12-17 15:59:43 +000034
35 static const SkViewRegister* Head() { return gHead; }
36
37 SkViewRegister* next() const { return fChain; }
38 SkViewFactory factory() const { return fFact; }
39
40private:
41 SkViewFactory fFact;
42 SkViewRegister* fChain;
43
44 static SkViewRegister* gHead;
45};
46
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000047///////////////////////////////////////////////////////////////////////////////
48
49class SampleView : public SkView {
50public:
51 SampleView() : fRepeatCount(1) {}
52
53 static void SetRepeatDraw(SkView*, int count);
54
55protected:
56 virtual void onDrawBackground(SkCanvas*);
57 virtual void onDrawContent(SkCanvas*) = 0;
58
59 // overrides
60 virtual bool onEvent(const SkEvent& evt);
61 virtual bool onQuery(SkEvent* evt);
62 virtual void onDraw(SkCanvas*);
63
64private:
65 int fRepeatCount;
66
67 typedef SkView INHERITED;
68};
69
reed@android.com8a1c16f2008-12-17 15:59:43 +000070#endif
71