Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: samplecode/SampleCode.h

Issue 894083003: add SkAnimTimer, SPACE = pause/resume, ESP = stop (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9
10 #ifndef SampleCode_DEFINED 8 #ifndef SampleCode_DEFINED
11 #define SampleCode_DEFINED 9 #define SampleCode_DEFINED
12 10
13 #include "SkColor.h" 11 #include "SkColor.h"
14 #include "SkEvent.h" 12 #include "SkEvent.h"
15 #include "SkKey.h" 13 #include "SkKey.h"
16 #include "SkView.h" 14 #include "SkView.h"
17 #include "SkOSMenu.h" 15 #include "SkOSMenu.h"
16
18 class GrContext; 17 class GrContext;
18 class SkAnimTimer;
19 19
20 #define DEF_SAMPLE(code) \ 20 #define DEF_SAMPLE(code) \
21 static SkView* SK_MACRO_APPEND_LINE(F_)() { code } \ 21 static SkView* SK_MACRO_APPEND_LINE(F_)() { code } \
22 static SkViewRegister SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); 22 static SkViewRegister SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_));
23 23
24 24
25 class SampleCode { 25 class SampleCode {
26 public: 26 public:
27 static bool KeyQ(const SkEvent&, SkKey* outKey); 27 static bool KeyQ(const SkEvent&, SkKey* outKey);
28 static bool CharQ(const SkEvent&, SkUnichar* outUni); 28 static bool CharQ(const SkEvent&, SkUnichar* outUni);
29 29
30 static bool TitleQ(const SkEvent&); 30 static bool TitleQ(const SkEvent&);
31 static void TitleR(SkEvent*, const char title[]); 31 static void TitleR(SkEvent*, const char title[]);
32 static bool RequestTitle(SkView* view, SkString* title); 32 static bool RequestTitle(SkView* view, SkString* title);
33 33
34 static bool PrefSizeQ(const SkEvent&); 34 static bool PrefSizeQ(const SkEvent&);
35 static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height); 35 static void PrefSizeR(SkEvent*, SkScalar width, SkScalar height);
36 36
37 static bool FastTextQ(const SkEvent&); 37 static bool FastTextQ(const SkEvent&);
38 38
39 private:
40 static SkMSec GetAnimTime();
41 static SkMSec GetAnimTimeDelta();
42 static SkScalar GetAnimSecondsDelta();
43 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0);
44 // gives a sinusoidal value between 0 and amplitude
45 static SkScalar GetAnimSinScalar(SkScalar amplitude,
46 SkScalar periodInSec,
47 SkScalar phaseInSec = 0);
48
49 friend class SampleWindow; 39 friend class SampleWindow;
50 }; 40 };
51 41
52 ////////////////////////////////////////////////////////////////////////////// 42 //////////////////////////////////////////////////////////////////////////////
53 43
54 // interface that constructs SkViews 44 // interface that constructs SkViews
55 class SkViewFactory : public SkRefCnt { 45 class SkViewFactory : public SkRefCnt {
56 public: 46 public:
57 virtual SkView* operator() () const = 0; 47 virtual SkView* operator() () const = 0;
58 }; 48 };
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 103
114 class SampleView : public SkView { 104 class SampleView : public SkView {
115 public: 105 public:
116 SampleView() 106 SampleView()
117 : fPipeState(SkOSMenu::kOffState) 107 : fPipeState(SkOSMenu::kOffState)
118 , fBGColor(SK_ColorWHITE) 108 , fBGColor(SK_ColorWHITE)
119 , fRepeatCount(1) 109 , fRepeatCount(1)
120 {} 110 {}
121 111
122 void setBGColor(SkColor color) { fBGColor = color; } 112 void setBGColor(SkColor color) { fBGColor = color; }
123 bool animatePulse(SkMSec curr, SkMSec prev) { return this->onAnimatePulse(cu rr, prev); } 113 bool animate(const SkAnimTimer& timer) { return this->onAnimate(timer); }
124 114
125 static bool IsSampleView(SkView*); 115 static bool IsSampleView(SkView*);
126 static bool SetRepeatDraw(SkView*, int count); 116 static bool SetRepeatDraw(SkView*, int count);
127 static bool SetUsePipe(SkView*, SkOSMenu::TriState); 117 static bool SetUsePipe(SkView*, SkOSMenu::TriState);
128 118
129 /** 119 /**
130 * Call this to request menu items from a SampleView. 120 * Call this to request menu items from a SampleView.
131 * Subclassing notes: A subclass of SampleView can overwrite this method 121 * Subclassing notes: A subclass of SampleView can overwrite this method
132 * to add new items of various types to the menu and change its title. 122 * to add new items of various types to the menu and change its title.
133 * The events attached to any new menu items must be handled in its onEvent 123 * The events attached to any new menu items must be handled in its onEvent
134 * method. See SkOSMenu.h for helper functions. 124 * method. See SkOSMenu.h for helper functions.
135 */ 125 */
136 virtual void requestMenu(SkOSMenu* menu) {} 126 virtual void requestMenu(SkOSMenu* menu) {}
137 127
138 virtual void onTileSizeChanged(const SkSize& tileSize) {} 128 virtual void onTileSizeChanged(const SkSize& tileSize) {}
139 129
140 protected: 130 protected:
141 virtual void onDrawBackground(SkCanvas*); 131 virtual void onDrawBackground(SkCanvas*);
142 virtual void onDrawContent(SkCanvas*) = 0; 132 virtual void onDrawContent(SkCanvas*) = 0;
143 virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; } 133 virtual bool onAnimate(const SkAnimTimer&) { return false; }
144 134
145 // overrides 135 // overrides
146 virtual bool onEvent(const SkEvent& evt); 136 virtual bool onEvent(const SkEvent& evt);
147 virtual bool onQuery(SkEvent* evt); 137 virtual bool onQuery(SkEvent* evt);
148 virtual void draw(SkCanvas*); 138 virtual void draw(SkCanvas*);
149 virtual void onDraw(SkCanvas*); 139 virtual void onDraw(SkCanvas*);
150 140
151 SkOSMenu::TriState fPipeState; 141 SkOSMenu::TriState fPipeState;
152 SkColor fBGColor; 142 SkColor fBGColor;
153 143
154 private: 144 private:
155 int fRepeatCount; 145 int fRepeatCount;
156 146
157 typedef SkView INHERITED; 147 typedef SkView INHERITED;
158 }; 148 };
159 149
160 #endif 150 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698