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

Side by Side Diff: samplecode/SampleArc.cpp

Issue 716793004: experimental (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove bad start in picture Created 6 years, 1 month 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/SkCanvas.h ('k') | src/core/SkCanvas.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 /* 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 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkRegion.h" 13 #include "SkRegion.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkUtils.h" 15 #include "SkUtils.h"
16 #include "SkComposeShader.h" 16 #include "SkComposeShader.h"
17 #include "Sk1DPathEffect.h" 17 #include "Sk1DPathEffect.h"
18 #include "SkCornerPathEffect.h" 18 #include "SkCornerPathEffect.h"
19 #include "SkPathMeasure.h" 19 #include "SkPathMeasure.h"
20 #include "SkRandom.h" 20 #include "SkRandom.h"
21 #include "SkColorPriv.h" 21 #include "SkColorPriv.h"
22 #include "SkColorFilter.h" 22 #include "SkColorFilter.h"
23 #include "SkLayerRasterizer.h" 23 #include "SkLayerRasterizer.h"
24 24
25 #include "SkCanvasDrawable.h"
26
25 #include "SkParsePath.h" 27 #include "SkParsePath.h"
26 static void testparse() { 28 static void testparse() {
27 SkRect r; 29 SkRect r;
28 r.set(0, 0, 10, 10.5f); 30 r.set(0, 0, 10, 10.5f);
29 SkPath p, p2; 31 SkPath p, p2;
30 SkString str, str2; 32 SkString str, str2;
31 33
32 p.addRect(r); 34 p.addRect(r);
33 SkParsePath::ToSVGString(p, &str); 35 SkParsePath::ToSVGString(p, &str);
34 SkParsePath::FromSVGString(str.c_str(), &p2); 36 SkParsePath::FromSVGString(str.c_str(), &p2);
35 SkParsePath::ToSVGString(p2, &str2); 37 SkParsePath::ToSVGString(p2, &str2);
36 } 38 }
37 39
38 class ArcsView : public SampleView { 40 class ArcsView : public SampleView {
41 class MyDrawable : public SkCanvasDrawable {
42 SkRect fR;
43 SkScalar fSweep;
44 public:
45 MyDrawable(const SkRect& r) : fR(r), fSweep(0) {
46 }
47
48 void setSweep(SkScalar sweep) {
49 if (fSweep != sweep) {
50 fSweep = sweep;
51 this->notifyDrawingChanged();
52 }
53 }
54
55 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
56 SkPaint paint;
57 paint.setAntiAlias(true);
58 paint.setStrokeWidth(SkIntToScalar(2));
59
60 paint.setStyle(SkPaint::kFill_Style);
61 paint.setColor(0x800000FF);
62 canvas->drawArc(fR, 0, fSweep, true, paint);
63
64 paint.setColor(0x800FF000);
65 canvas->drawArc(fR, 0, fSweep, false, paint);
66
67 paint.setStyle(SkPaint::kStroke_Style);
68 paint.setColor(SK_ColorRED);
69 canvas->drawArc(fR, 0, fSweep, true, paint);
70
71 paint.setStrokeWidth(0);
72 paint.setColor(SK_ColorBLUE);
73 canvas->drawArc(fR, 0, fSweep, false, paint);
74 }
75 };
76
39 public: 77 public:
78 SkRect fRect;
79 MyDrawable* fDrawable;
mtklein 2014/11/12 03:34:42 AutoTUnref?
80
40 ArcsView() { 81 ArcsView() {
41 testparse(); 82 testparse();
42 fSweep = SkIntToScalar(100); 83 fSweep = SkIntToScalar(100);
43 this->setBGColor(0xFFDDDDDD); 84 this->setBGColor(0xFFDDDDDD);
85
86 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
87 fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
88 fDrawable = SkNEW_ARGS(MyDrawable, (fRect));
89 }
90
91 virtual ~ArcsView() SK_OVERRIDE {
92 fDrawable->unref();
44 } 93 }
45 94
46 protected: 95 protected:
47 // overrides from SkEventSink 96 // overrides from SkEventSink
48 virtual bool onQuery(SkEvent* evt) { 97 virtual bool onQuery(SkEvent* evt) {
49 if (SampleCode::TitleQ(*evt)) { 98 if (SampleCode::TitleQ(*evt)) {
50 SampleCode::TitleR(evt, "Arcs"); 99 SampleCode::TitleR(evt, "Arcs");
51 return true; 100 return true;
52 } 101 }
53 return this->INHERITED::onQuery(evt); 102 return this->INHERITED::onQuery(evt);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 163
115 draw_label(canvas, r, gAngles[i], gAngles[i+1]); 164 draw_label(canvas, r, gAngles[i], gAngles[i+1]);
116 165
117 canvas->translate(w * 8 / 7, 0); 166 canvas->translate(w * 8 / 7, 0);
118 } 167 }
119 168
120 canvas->restore(); 169 canvas->restore();
121 } 170 }
122 171
123 virtual void onDrawContent(SkCanvas* canvas) { 172 virtual void onDrawContent(SkCanvas* canvas) {
124 fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24, 173 fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
125 SkIntToScalar(360)); 174 SkIntToScalar(360)));
126 // fSweep = 359.99f;
127 175
128 SkRect r;
129 SkPaint paint; 176 SkPaint paint;
130
131 paint.setAntiAlias(true); 177 paint.setAntiAlias(true);
132 paint.setStrokeWidth(SkIntToScalar(2)); 178 paint.setStrokeWidth(SkIntToScalar(2));
133 paint.setStyle(SkPaint::kStroke_Style); 179 paint.setStyle(SkPaint::kStroke_Style);
134 180
135 r.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); 181 drawRectWithLines(canvas, fRect, paint);
136 r.offset(SkIntToScalar(20), SkIntToScalar(20));
137 182
138 if (false) { 183 canvas->EXPERIMENTAL_drawDrawable(fDrawable);
139 const SkScalar d = SkIntToScalar(3);
140 const SkScalar rad[] = { d, d, d, d, d, d, d, d };
141 SkPath path;
142 path.addRoundRect(r, rad);
143 canvas->drawPath(path, paint);
144 return;
145 }
146
147 drawRectWithLines(canvas, r, paint);
148
149 // printf("----- sweep %g %X\n", SkScalarToFloat(fSweep), SkDegreesToRadi ans(fSweep));
150
151
152 paint.setStyle(SkPaint::kFill_Style);
153 paint.setColor(0x800000FF);
154 canvas->drawArc(r, 0, fSweep, true, paint);
155
156 paint.setColor(0x800FF000);
157 canvas->drawArc(r, 0, fSweep, false, paint);
158
159 paint.setStyle(SkPaint::kStroke_Style);
160 paint.setColor(SK_ColorRED);
161 canvas->drawArc(r, 0, fSweep, true, paint);
162
163 paint.setStrokeWidth(0);
164 paint.setColor(SK_ColorBLUE);
165 canvas->drawArc(r, 0, fSweep, false, paint);
166 184
167 drawArcs(canvas); 185 drawArcs(canvas);
168 this->inval(NULL); 186 this->inval(NULL);
169 } 187 }
170 188
171 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, 189 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
172 unsigned modi) { 190 unsigned modi) {
173 // fSweep += SK_Scalar1; 191 // fSweep += SK_Scalar1;
174 this->inval(NULL); 192 this->inval(NULL);
175 return this->INHERITED::onFindClickHandler(x, y, modi); 193 return this->INHERITED::onFindClickHandler(x, y, modi);
176 } 194 }
177 195
178 virtual bool onClick(Click* click) { 196 virtual bool onClick(Click* click) {
179 return this->INHERITED::onClick(click); 197 return this->INHERITED::onClick(click);
180 } 198 }
181 199
182 private: 200 private:
183 SkScalar fSweep; 201 SkScalar fSweep;
184 202
185 typedef SampleView INHERITED; 203 typedef SampleView INHERITED;
186 }; 204 };
187 205
188 ////////////////////////////////////////////////////////////////////////////// 206 //////////////////////////////////////////////////////////////////////////////
189 207
190 static SkView* MyFactory() { return new ArcsView; } 208 static SkView* MyFactory() { return new ArcsView; }
191 static SkViewRegister reg(MyFactory); 209 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkCanvas.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698