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

Side by Side Diff: samplecode/SampleArc.cpp

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

Powered by Google App Engine
This is Rietveld 408576698