OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "gm.h" | 8 #include "gm.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkPathMeasure.h" | 11 #include "SkPathMeasure.h" |
12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
13 | 13 |
14 class AddArcGM : public skiagm::GM { | 14 class AddArcGM : public skiagm::GM { |
15 public: | 15 public: |
16 AddArcGM() : fRotate(0) {} | 16 AddArcGM() : fRotate(0) {} |
17 | 17 |
18 protected: | 18 protected: |
19 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); } | 19 SkString onShortName() override { return SkString("addarc"); } |
20 | 20 |
21 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); } | 21 SkISize onISize() override { return SkISize::Make(1040, 1040); } |
22 | 22 |
23 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 23 void onDraw(SkCanvas* canvas) override { |
24 canvas->translate(20, 20); | 24 canvas->translate(20, 20); |
25 | 25 |
26 SkRect r = SkRect::MakeWH(1000, 1000); | 26 SkRect r = SkRect::MakeWH(1000, 1000); |
27 | 27 |
28 SkPaint paint; | 28 SkPaint paint; |
29 paint.setAntiAlias(true); | 29 paint.setAntiAlias(true); |
30 paint.setStyle(SkPaint::kStroke_Style); | 30 paint.setStyle(SkPaint::kStroke_Style); |
31 paint.setStrokeWidth(15); | 31 paint.setStrokeWidth(15); |
32 | 32 |
33 const SkScalar inset = paint.getStrokeWidth() + 4; | 33 const SkScalar inset = paint.getStrokeWidth() + 4; |
(...skipping 10 matching lines...) Expand all Loading... |
44 | 44 |
45 SkPath path; | 45 SkPath path; |
46 path.addArc(r, startAngle, sweepAngle); | 46 path.addArc(r, startAngle, sweepAngle); |
47 canvas->drawPath(path, paint); | 47 canvas->drawPath(path, paint); |
48 | 48 |
49 r.inset(inset, inset); | 49 r.inset(inset, inset); |
50 sign = -sign; | 50 sign = -sign; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 54 bool onAnimate(const SkAnimTimer& timer) override { |
55 fRotate = timer.scaled(1, 360); | 55 fRotate = timer.scaled(1, 360); |
56 return true; | 56 return true; |
57 } | 57 } |
58 | 58 |
59 private: | 59 private: |
60 SkScalar fRotate; | 60 SkScalar fRotate; |
61 typedef skiagm::GM INHERITED; | 61 typedef skiagm::GM INHERITED; |
62 }; | 62 }; |
63 DEF_GM( return new AddArcGM; ) | 63 DEF_GM( return new AddArcGM; ) |
64 | 64 |
65 /////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////// |
66 | 66 |
67 #define R 400 | 67 #define R 400 |
68 | 68 |
69 class AddArcMeasGM : public skiagm::GM { | 69 class AddArcMeasGM : public skiagm::GM { |
70 public: | 70 public: |
71 AddArcMeasGM() {} | 71 AddArcMeasGM() {} |
72 | 72 |
73 protected: | 73 protected: |
74 SkString onShortName() SK_OVERRIDE { return SkString("addarc_meas"); } | 74 SkString onShortName() override { return SkString("addarc_meas"); } |
75 | 75 |
76 SkISize onISize() SK_OVERRIDE { return SkISize::Make(2*R + 40, 2*R + 40); } | 76 SkISize onISize() override { return SkISize::Make(2*R + 40, 2*R + 40); } |
77 | 77 |
78 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 78 void onDraw(SkCanvas* canvas) override { |
79 canvas->translate(R + 20, R + 20); | 79 canvas->translate(R + 20, R + 20); |
80 | 80 |
81 SkPaint paint; | 81 SkPaint paint; |
82 paint.setAntiAlias(true); | 82 paint.setAntiAlias(true); |
83 paint.setStyle(SkPaint::kStroke_Style); | 83 paint.setStyle(SkPaint::kStroke_Style); |
84 | 84 |
85 SkPaint measPaint; | 85 SkPaint measPaint; |
86 measPaint.setAntiAlias(true); | 86 measPaint.setAntiAlias(true); |
87 measPaint.setColor(SK_ColorRED); | 87 measPaint.setColor(SK_ColorRED); |
88 | 88 |
(...skipping 26 matching lines...) Expand all Loading... |
115 /////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////// |
116 | 116 |
117 // Emphasize drawing a stroked oval (containing conics) and then scaling the res
ults up, | 117 // Emphasize drawing a stroked oval (containing conics) and then scaling the res
ults up, |
118 // to ensure that we compute the stroke taking the CTM into account | 118 // to ensure that we compute the stroke taking the CTM into account |
119 // | 119 // |
120 class StrokeCircleGM : public skiagm::GM { | 120 class StrokeCircleGM : public skiagm::GM { |
121 public: | 121 public: |
122 StrokeCircleGM() : fRotate(0) {} | 122 StrokeCircleGM() : fRotate(0) {} |
123 | 123 |
124 protected: | 124 protected: |
125 SkString onShortName() SK_OVERRIDE { return SkString("strokecircle"); } | 125 SkString onShortName() override { return SkString("strokecircle"); } |
126 | 126 |
127 SkISize onISize() SK_OVERRIDE { return SkISize::Make(520, 520); } | 127 SkISize onISize() override { return SkISize::Make(520, 520); } |
128 | 128 |
129 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 129 void onDraw(SkCanvas* canvas) override { |
130 canvas->scale(20, 20); | 130 canvas->scale(20, 20); |
131 canvas->translate(13, 13); | 131 canvas->translate(13, 13); |
132 | 132 |
133 SkPaint paint; | 133 SkPaint paint; |
134 paint.setAntiAlias(true); | 134 paint.setAntiAlias(true); |
135 paint.setStyle(SkPaint::kStroke_Style); | 135 paint.setStyle(SkPaint::kStroke_Style); |
136 paint.setStrokeWidth(SK_Scalar1 / 2); | 136 paint.setStrokeWidth(SK_Scalar1 / 2); |
137 | 137 |
138 const SkScalar delta = paint.getStrokeWidth() * 3 / 2; | 138 const SkScalar delta = paint.getStrokeWidth() * 3 / 2; |
139 SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24); | 139 SkRect r = SkRect::MakeXYWH(-12, -12, 24, 24); |
140 SkRandom rand; | 140 SkRandom rand; |
141 | 141 |
142 SkScalar sign = 1; | 142 SkScalar sign = 1; |
143 while (r.width() > paint.getStrokeWidth() * 2) { | 143 while (r.width() > paint.getStrokeWidth() * 2) { |
144 SkAutoCanvasRestore acr(canvas, true); | 144 SkAutoCanvasRestore acr(canvas, true); |
145 canvas->rotate(fRotate * sign); | 145 canvas->rotate(fRotate * sign); |
146 | 146 |
147 paint.setColor(rand.nextU() | (0xFF << 24)); | 147 paint.setColor(rand.nextU() | (0xFF << 24)); |
148 canvas->drawOval(r, paint); | 148 canvas->drawOval(r, paint); |
149 r.inset(delta, delta); | 149 r.inset(delta, delta); |
150 sign = -sign; | 150 sign = -sign; |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 154 bool onAnimate(const SkAnimTimer& timer) override { |
155 fRotate = timer.scaled(60, 360); | 155 fRotate = timer.scaled(60, 360); |
156 return true; | 156 return true; |
157 } | 157 } |
158 | 158 |
159 private: | 159 private: |
160 SkScalar fRotate; | 160 SkScalar fRotate; |
161 | 161 |
162 typedef skiagm::GM INHERITED; | 162 typedef skiagm::GM INHERITED; |
163 }; | 163 }; |
164 DEF_GM( return new StrokeCircleGM; ) | 164 DEF_GM( return new StrokeCircleGM; ) |
165 | 165 |
166 ////////////////////// | 166 ////////////////////// |
167 | 167 |
168 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk
Scalar start, | 168 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk
Scalar start, |
169 SkScalar end, bool ccw) { | 169 SkScalar end, bool ccw) { |
170 SkRect bounds = { x - r, y - r, x + r, y + r }; | 170 SkRect bounds = { x - r, y - r, x + r, y + r }; |
171 SkScalar sweep = ccw ? end - start : start - end; | 171 SkScalar sweep = ccw ? end - start : start - end; |
172 path->arcTo(bounds, start, sweep, false); | 172 path->arcTo(bounds, start, sweep, false); |
173 } | 173 } |
174 | 174 |
175 // Lifted from canvas-arc-circumference-fill-diffs.html | 175 // Lifted from canvas-arc-circumference-fill-diffs.html |
176 class ManyArcsGM : public skiagm::GM { | 176 class ManyArcsGM : public skiagm::GM { |
177 public: | 177 public: |
178 ManyArcsGM() {} | 178 ManyArcsGM() {} |
179 | 179 |
180 protected: | 180 protected: |
181 SkString onShortName() SK_OVERRIDE { return SkString("manyarcs"); } | 181 SkString onShortName() override { return SkString("manyarcs"); } |
182 | 182 |
183 SkISize onISize() SK_OVERRIDE { return SkISize::Make(620, 330); } | 183 SkISize onISize() override { return SkISize::Make(620, 330); } |
184 | 184 |
185 void onDraw(SkCanvas* canvas) SK_OVERRIDE { | 185 void onDraw(SkCanvas* canvas) override { |
186 SkPaint paint; | 186 SkPaint paint; |
187 paint.setAntiAlias(true); | 187 paint.setAntiAlias(true); |
188 paint.setStyle(SkPaint::kStroke_Style); | 188 paint.setStyle(SkPaint::kStroke_Style); |
189 | 189 |
190 canvas->translate(10, 10); | 190 canvas->translate(10, 10); |
191 | 191 |
192 // 20 angles. | 192 // 20 angles. |
193 SkScalar sweepAngles[] = { | 193 SkScalar sweepAngles[] = { |
194 -123.7f, -2.3f, -2, -1, -0.3f, -0.000001f, 0, 0.00000
1f, 0.3f, 0.7f, | 194 -123.7f, -2.3f, -2, -1, -0.3f, -0.000001f, 0, 0.00000
1f, 0.3f, 0.7f, |
195 1, 1.3f, 1.5f, 1.7f, 1.99999f, 2, 2.00001f, 2.3f, 4.3
f, 3934723942837.3f | 195 1, 1.3f, 1.5f, 1.7f, 1.99999f, 2, 2.00001f, 2.3f, 4.3
f, 3934723942837.3f |
(...skipping 28 matching lines...) Expand all Loading... |
224 canvas->restore(); | 224 canvas->restore(); |
225 canvas->translate(0, 40); | 225 canvas->translate(0, 40); |
226 } | 226 } |
227 } | 227 } |
228 | 228 |
229 private: | 229 private: |
230 typedef skiagm::GM INHERITED; | 230 typedef skiagm::GM INHERITED; |
231 }; | 231 }; |
232 DEF_GM( return new ManyArcsGM; ) | 232 DEF_GM( return new ManyArcsGM; ) |
233 | 233 |
OLD | NEW |