OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkView.h" | 10 #include "SkView.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkDrawable.h" |
12 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
13 #include "SkPath.h" | 14 #include "SkPath.h" |
14 #include "SkRegion.h" | 15 #include "SkRegion.h" |
15 #include "SkShader.h" | 16 #include "SkShader.h" |
16 #include "SkUtils.h" | 17 #include "SkUtils.h" |
17 #include "SkComposeShader.h" | 18 #include "SkComposeShader.h" |
18 #include "Sk1DPathEffect.h" | 19 #include "Sk1DPathEffect.h" |
19 #include "SkCornerPathEffect.h" | 20 #include "SkCornerPathEffect.h" |
20 #include "SkPathMeasure.h" | 21 #include "SkPathMeasure.h" |
21 #include "SkPictureRecorder.h" | 22 #include "SkPictureRecorder.h" |
22 #include "SkRandom.h" | 23 #include "SkRandom.h" |
23 #include "SkColorPriv.h" | 24 #include "SkColorPriv.h" |
24 #include "SkColorFilter.h" | 25 #include "SkColorFilter.h" |
25 #include "SkLayerRasterizer.h" | 26 #include "SkLayerRasterizer.h" |
26 | 27 |
27 #include "SkCanvasDrawable.h" | |
28 | |
29 #include "SkParsePath.h" | 28 #include "SkParsePath.h" |
30 static void testparse() { | 29 static void testparse() { |
31 SkRect r; | 30 SkRect r; |
32 r.set(0, 0, 10, 10.5f); | 31 r.set(0, 0, 10, 10.5f); |
33 SkPath p, p2; | 32 SkPath p, p2; |
34 SkString str, str2; | 33 SkString str, str2; |
35 | 34 |
36 p.addRect(r); | 35 p.addRect(r); |
37 SkParsePath::ToSVGString(p, &str); | 36 SkParsePath::ToSVGString(p, &str); |
38 SkParsePath::FromSVGString(str.c_str(), &p2); | 37 SkParsePath::FromSVGString(str.c_str(), &p2); |
39 SkParsePath::ToSVGString(p2, &str2); | 38 SkParsePath::ToSVGString(p2, &str2); |
40 } | 39 } |
41 | 40 |
42 class ArcsView : public SampleView { | 41 class ArcsView : public SampleView { |
43 class MyDrawable : public SkCanvasDrawable { | 42 class MyDrawable : public SkDrawable { |
44 SkRect fR; | 43 SkRect fR; |
45 SkScalar fSweep; | 44 SkScalar fSweep; |
46 public: | 45 public: |
47 MyDrawable(const SkRect& r) : fR(r), fSweep(0) {} | 46 MyDrawable(const SkRect& r) : fR(r), fSweep(0) {} |
48 | 47 |
49 void setSweep(SkScalar sweep) { | 48 void setSweep(SkScalar sweep) { |
50 if (fSweep != sweep) { | 49 if (fSweep != sweep) { |
51 fSweep = sweep; | 50 fSweep = sweep; |
52 this->notifyDrawingChanged(); | 51 this->notifyDrawingChanged(); |
53 } | 52 } |
(...skipping 23 matching lines...) Expand all Loading... |
77 SkRect onGetBounds() SK_OVERRIDE { | 76 SkRect onGetBounds() SK_OVERRIDE { |
78 SkRect r(fR); | 77 SkRect r(fR); |
79 r.outset(2, 2); | 78 r.outset(2, 2); |
80 return r; | 79 return r; |
81 } | 80 } |
82 }; | 81 }; |
83 | 82 |
84 public: | 83 public: |
85 SkRect fRect; | 84 SkRect fRect; |
86 MyDrawable* fAnimatingDrawable; | 85 MyDrawable* fAnimatingDrawable; |
87 SkCanvasDrawable* fRootDrawable; | 86 SkDrawable* fRootDrawable; |
88 | 87 |
89 ArcsView() { | 88 ArcsView() { |
90 testparse(); | 89 testparse(); |
91 fSweep = SkIntToScalar(100); | 90 fSweep = SkIntToScalar(100); |
92 this->setBGColor(0xFFDDDDDD); | 91 this->setBGColor(0xFFDDDDDD); |
93 | 92 |
94 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); | 93 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); |
95 fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); | 94 fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); |
96 fAnimatingDrawable = SkNEW_ARGS(MyDrawable, (fRect)); | 95 fAnimatingDrawable = SkNEW_ARGS(MyDrawable, (fRect)); |
97 | 96 |
98 SkPictureRecorder recorder; | 97 SkPictureRecorder recorder; |
99 this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500))); | 98 this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500))); |
100 fRootDrawable = recorder.EXPERIMENTAL_endRecordingAsDrawable(); | 99 fRootDrawable = recorder.endRecordingAsDrawable(); |
101 } | 100 } |
102 | 101 |
103 ~ArcsView() SK_OVERRIDE { | 102 ~ArcsView() SK_OVERRIDE { |
104 fAnimatingDrawable->unref(); | 103 fAnimatingDrawable->unref(); |
105 fRootDrawable->unref(); | 104 fRootDrawable->unref(); |
106 } | 105 } |
107 | 106 |
108 protected: | 107 protected: |
109 // overrides from SkEventSink | 108 // overrides from SkEventSink |
110 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 109 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 } | 182 } |
184 | 183 |
185 void drawRoot(SkCanvas* canvas) { | 184 void drawRoot(SkCanvas* canvas) { |
186 SkPaint paint; | 185 SkPaint paint; |
187 paint.setAntiAlias(true); | 186 paint.setAntiAlias(true); |
188 paint.setStrokeWidth(SkIntToScalar(2)); | 187 paint.setStrokeWidth(SkIntToScalar(2)); |
189 paint.setStyle(SkPaint::kStroke_Style); | 188 paint.setStyle(SkPaint::kStroke_Style); |
190 | 189 |
191 DrawRectWithLines(canvas, fRect, paint); | 190 DrawRectWithLines(canvas, fRect, paint); |
192 | 191 |
193 canvas->EXPERIMENTAL_drawDrawable(fAnimatingDrawable); | 192 canvas->drawDrawable(fAnimatingDrawable); |
194 | 193 |
195 DrawArcs(canvas); | 194 DrawArcs(canvas); |
196 } | 195 } |
197 | 196 |
198 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 197 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
199 canvas->EXPERIMENTAL_drawDrawable(fRootDrawable); | 198 canvas->drawDrawable(fRootDrawable); |
200 } | 199 } |
201 | 200 |
202 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 201 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
203 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); | 202 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); |
204 fAnimatingDrawable->setSweep(angle); | 203 fAnimatingDrawable->setSweep(angle); |
205 return true; | 204 return true; |
206 } | 205 } |
207 | 206 |
208 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
OVERRIDE { | 207 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
OVERRIDE { |
209 // fSweep += SK_Scalar1; | 208 // fSweep += SK_Scalar1; |
210 this->inval(NULL); | 209 this->inval(NULL); |
211 return this->INHERITED::onFindClickHandler(x, y, modi); | 210 return this->INHERITED::onFindClickHandler(x, y, modi); |
212 } | 211 } |
213 | 212 |
214 private: | 213 private: |
215 SkScalar fSweep; | 214 SkScalar fSweep; |
216 | 215 |
217 typedef SampleView INHERITED; | 216 typedef SampleView INHERITED; |
218 }; | 217 }; |
219 | 218 |
220 ////////////////////////////////////////////////////////////////////////////// | 219 ////////////////////////////////////////////////////////////////////////////// |
221 | 220 |
222 static SkView* MyFactory() { return new ArcsView; } | 221 static SkView* MyFactory() { return new ArcsView; } |
223 static SkViewRegister reg(MyFactory); | 222 static SkViewRegister reg(MyFactory); |
OLD | NEW |