OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SampleCode_DEFINED | 10 #ifndef SampleCode_DEFINED |
(...skipping 18 matching lines...) Expand all Loading... |
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: |
39 static SkMSec GetAnimTime(); | 40 static SkMSec GetAnimTime(); |
40 static SkMSec GetAnimTimeDelta(); | 41 static SkMSec GetAnimTimeDelta(); |
41 static SkScalar GetAnimSecondsDelta(); | 42 static SkScalar GetAnimSecondsDelta(); |
42 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0); | 43 static SkScalar GetAnimScalar(SkScalar speedPerSec, SkScalar period = 0); |
43 // gives a sinusoidal value between 0 and amplitude | 44 // gives a sinusoidal value between 0 and amplitude |
44 static SkScalar GetAnimSinScalar(SkScalar amplitude, | 45 static SkScalar GetAnimSinScalar(SkScalar amplitude, |
45 SkScalar periodInSec, | 46 SkScalar periodInSec, |
46 SkScalar phaseInSec = 0); | 47 SkScalar phaseInSec = 0); |
| 48 |
| 49 friend class SampleWindow; |
47 }; | 50 }; |
48 | 51 |
49 ////////////////////////////////////////////////////////////////////////////// | 52 ////////////////////////////////////////////////////////////////////////////// |
50 | 53 |
51 // interface that constructs SkViews | 54 // interface that constructs SkViews |
52 class SkViewFactory : public SkRefCnt { | 55 class SkViewFactory : public SkRefCnt { |
53 public: | 56 public: |
54 virtual SkView* operator() () const = 0; | 57 virtual SkView* operator() () const = 0; |
55 }; | 58 }; |
56 | 59 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 113 |
111 class SampleView : public SkView { | 114 class SampleView : public SkView { |
112 public: | 115 public: |
113 SampleView() | 116 SampleView() |
114 : fPipeState(SkOSMenu::kOffState) | 117 : fPipeState(SkOSMenu::kOffState) |
115 , fBGColor(SK_ColorWHITE) | 118 , fBGColor(SK_ColorWHITE) |
116 , fRepeatCount(1) | 119 , fRepeatCount(1) |
117 {} | 120 {} |
118 | 121 |
119 void setBGColor(SkColor color) { fBGColor = color; } | 122 void setBGColor(SkColor color) { fBGColor = color; } |
| 123 bool animatePulse(SkMSec curr, SkMSec prev) { return this->onAnimatePulse(cu
rr, prev); } |
120 | 124 |
121 static bool IsSampleView(SkView*); | 125 static bool IsSampleView(SkView*); |
122 static bool SetRepeatDraw(SkView*, int count); | 126 static bool SetRepeatDraw(SkView*, int count); |
123 static bool SetUsePipe(SkView*, SkOSMenu::TriState); | 127 static bool SetUsePipe(SkView*, SkOSMenu::TriState); |
124 | 128 |
125 /** | 129 /** |
126 * Call this to request menu items from a SampleView. | 130 * Call this to request menu items from a SampleView. |
127 * Subclassing notes: A subclass of SampleView can overwrite this method | 131 * Subclassing notes: A subclass of SampleView can overwrite this method |
128 * to add new items of various types to the menu and change its title. | 132 * to add new items of various types to the menu and change its title. |
129 * The events attached to any new menu items must be handled in its onEvent | 133 * The events attached to any new menu items must be handled in its onEvent |
130 * method. See SkOSMenu.h for helper functions. | 134 * method. See SkOSMenu.h for helper functions. |
131 */ | 135 */ |
132 virtual void requestMenu(SkOSMenu* menu) {} | 136 virtual void requestMenu(SkOSMenu* menu) {} |
133 | 137 |
134 virtual void onTileSizeChanged(const SkSize& tileSize) {} | 138 virtual void onTileSizeChanged(const SkSize& tileSize) {} |
135 | 139 |
136 protected: | 140 protected: |
137 virtual void onDrawBackground(SkCanvas*); | 141 virtual void onDrawBackground(SkCanvas*); |
138 virtual void onDrawContent(SkCanvas*) = 0; | 142 virtual void onDrawContent(SkCanvas*) = 0; |
| 143 virtual bool onAnimatePulse(SkMSec curr, SkMSec prev) { return false; } |
139 | 144 |
140 // overrides | 145 // overrides |
141 virtual bool onEvent(const SkEvent& evt); | 146 virtual bool onEvent(const SkEvent& evt); |
142 virtual bool onQuery(SkEvent* evt); | 147 virtual bool onQuery(SkEvent* evt); |
143 virtual void draw(SkCanvas*); | 148 virtual void draw(SkCanvas*); |
144 virtual void onDraw(SkCanvas*); | 149 virtual void onDraw(SkCanvas*); |
145 | 150 |
146 SkOSMenu::TriState fPipeState; | 151 SkOSMenu::TriState fPipeState; |
147 SkColor fBGColor; | 152 SkColor fBGColor; |
148 | 153 |
149 private: | 154 private: |
150 int fRepeatCount; | 155 int fRepeatCount; |
151 | 156 |
152 typedef SkView INHERITED; | 157 typedef SkView INHERITED; |
153 }; | 158 }; |
154 | 159 |
155 #endif | 160 #endif |
OLD | NEW |