blob: 0c706ee3d1474efcf77bddf6f3aaf6f72c5eb104 [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.comf2183392011-04-22 14:10:48 +000052 SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) {}
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000053
reed@google.comf2183392011-04-22 14:10:48 +000054 void setBGColor(SkColor color) { fBGColor = color; }
55
56 static bool SetRepeatDraw(SkView*, int count);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000057
58protected:
59 virtual void onDrawBackground(SkCanvas*);
60 virtual void onDrawContent(SkCanvas*) = 0;
61
62 // overrides
63 virtual bool onEvent(const SkEvent& evt);
64 virtual bool onQuery(SkEvent* evt);
65 virtual void onDraw(SkCanvas*);
66
67private:
68 int fRepeatCount;
reed@google.comf2183392011-04-22 14:10:48 +000069 SkColor fBGColor;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000070
71 typedef SkView INHERITED;
72};
73
reed@android.com8a1c16f2008-12-17 15:59:43 +000074#endif
75