blob: 98162a72ee056518d24cdc81214d69bf98d3b901 [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
reed@google.com3cec4d72011-07-06 13:59:47 +00009class GrContext;
10
reed@android.com8a1c16f2008-12-17 15:59:43 +000011class SampleCode {
12public:
reed@android.comf2b98d62010-12-20 18:26:13 +000013 static bool KeyQ(const SkEvent&, SkKey* outKey);
14 static bool CharQ(const SkEvent&, SkUnichar* outUni);
15
reed@android.com8a1c16f2008-12-17 15:59:43 +000016 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.comf2b98d62010-12-20 18:26:13 +000021
22 static bool FastTextQ(const SkEvent&);
23
reed@android.com44177402009-11-23 21:07:51 +000024 static SkMSec GetAnimTime();
reed@android.comf2b98d62010-12-20 18:26:13 +000025 static SkMSec GetAnimTimeDelta();
26 static SkScalar GetAnimSecondsDelta();
reed@android.com44177402009-11-23 21:07:51 +000027 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
reed@google.com3cec4d72011-07-06 13:59:47 +000028
29 static GrContext* GetGr();
reed@android.com8a1c16f2008-12-17 15:59:43 +000030};
31
32//////////////////////////////////////////////////////////////////////////////
33
reed@android.com8a1c16f2008-12-17 15:59:43 +000034typedef SkView* (*SkViewFactory)();
35
36class SkViewRegister : SkNoncopyable {
37public:
deanm@chromium.org1220e1c2009-06-11 12:26:47 +000038 explicit SkViewRegister(SkViewFactory);
reed@android.com8a1c16f2008-12-17 15:59:43 +000039
40 static const SkViewRegister* Head() { return gHead; }
41
42 SkViewRegister* next() const { return fChain; }
43 SkViewFactory factory() const { return fFact; }
44
45private:
46 SkViewFactory fFact;
47 SkViewRegister* fChain;
48
49 static SkViewRegister* gHead;
50};
51
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000052///////////////////////////////////////////////////////////////////////////////
53
54class SampleView : public SkView {
55public:
reed@google.com0faac1e2011-05-11 05:58:58 +000056 SampleView() : fRepeatCount(1), fBGColor(SK_ColorWHITE) {
57 fUsePipe = false;
58 }
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000059
reed@google.comf2183392011-04-22 14:10:48 +000060 void setBGColor(SkColor color) { fBGColor = color; }
61
reed@google.coma6ff4dc2011-05-12 22:08:24 +000062 static bool IsSampleView(SkView*);
reed@google.comf2183392011-04-22 14:10:48 +000063 static bool SetRepeatDraw(SkView*, int count);
reed@google.com0faac1e2011-05-11 05:58:58 +000064 static bool SetUsePipe(SkView*, bool);
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000065
66protected:
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
75private:
76 int fRepeatCount;
reed@google.comf2183392011-04-22 14:10:48 +000077 SkColor fBGColor;
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000078
reed@google.com0faac1e2011-05-11 05:58:58 +000079 bool fUsePipe;
80
mike@reedtribe.org2eb59522011-04-22 01:59:09 +000081 typedef SkView INHERITED;
82};
83
reed@android.com8a1c16f2008-12-17 15:59:43 +000084#endif
85