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 "gm.h" | 8 #include "gm.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
11 #include "SkDashPathEffect.h" | 11 #include "SkDashPathEffect.h" |
12 #include "SkParsePath.h" | 12 #include "SkParsePath.h" |
13 #include "sk_tool_utils.h" | |
13 | 14 |
14 #define W 400 | 15 #define W 400 |
15 #define H 400 | 16 #define H 400 |
16 #define N 50 | 17 #define N 50 |
17 | 18 |
18 static const SkScalar SW = SkIntToScalar(W); | 19 static const SkScalar SW = SkIntToScalar(W); |
19 static const SkScalar SH = SkIntToScalar(H); | 20 static const SkScalar SH = SkIntToScalar(H); |
20 | 21 |
21 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { | 22 static void rnd_rect(SkRect* r, SkPaint* paint, SkRandom& rand) { |
22 SkScalar x = rand.nextUScalar1() * W; | 23 SkScalar x = rand.nextUScalar1() * W; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 | 284 |
284 | 285 |
285 SkString onShortName() override { | 286 SkString onShortName() override { |
286 return SkString("strokes_poly"); | 287 return SkString("strokes_poly"); |
287 } | 288 } |
288 | 289 |
289 SkISize onISize() override { | 290 SkISize onISize() override { |
290 return SkISize::Make(W, H*2); | 291 return SkISize::Make(W, H*2); |
291 } | 292 } |
292 | 293 |
293 static void rotate(SkScalar angle, SkScalar px, SkScalar py, SkCanvas* canva s) { | |
294 SkMatrix matrix; | |
295 matrix.setRotate(angle, px, py); | |
296 canvas->concat(matrix); | |
bungeman-skia
2016/07/12 15:47:11
With floats the order of operations matters. This
| |
297 } | |
298 | |
299 void onDraw(SkCanvas* canvas) override { | 294 void onDraw(SkCanvas* canvas) override { |
300 canvas->drawColor(SK_ColorWHITE); | 295 canvas->drawColor(SK_ColorWHITE); |
301 | 296 |
302 SkPaint paint; | 297 SkPaint paint; |
303 paint.setStyle(SkPaint::kStroke_Style); | 298 paint.setStyle(SkPaint::kStroke_Style); |
304 paint.setStrokeWidth(SkIntToScalar(9)/2); | 299 paint.setStrokeWidth(SkIntToScalar(9)/2); |
305 | 300 |
306 for (int y = 0; y < 2; y++) { | 301 for (int y = 0; y < 2; y++) { |
307 paint.setAntiAlias(!!y); | 302 paint.setAntiAlias(!!y); |
308 SkAutoCanvasRestore acr(canvas, true); | 303 SkAutoCanvasRestore acr(canvas, true); |
309 canvas->translate(0, SH * y); | 304 canvas->translate(0, SH * y); |
310 canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2), | 305 canvas->clipRect(SkRect::MakeLTRB(SkIntToScalar(2), |
311 SkIntToScalar(2), | 306 SkIntToScalar(2), |
312 SW - SkIntToScalar(2), | 307 SW - SkIntToScalar(2), |
313 SH - SkIntToScalar(2))); | 308 SH - SkIntToScalar(2))); |
314 | 309 |
315 SkRandom rand; | 310 SkRandom rand; |
316 for (int i = 0; i < N/2; i++) { | 311 for (int i = 0; i < N/2; i++) { |
317 SkRect r; | 312 SkRect r; |
318 rnd_rect(&r, &paint, rand); | 313 rnd_rect(&r, &paint, rand); |
319 rotate(SkIntToScalar(15), SW/2, SH/2, canvas); | 314 sk_tool_utils::rotate_about(canvas, SkIntToScalar(15), SW/2, SH/ 2); |
320 canvas->drawPath(fPath, paint); | 315 canvas->drawPath(fPath, paint); |
321 } | 316 } |
322 } | 317 } |
323 } | 318 } |
324 | 319 |
325 private: | 320 private: |
326 typedef skiagm::GM INHERITED; | 321 typedef skiagm::GM INHERITED; |
327 }; | 322 }; |
328 | 323 |
329 ////////////////////////////////////////////////////////////////////////////// | 324 ////////////////////////////////////////////////////////////////////////////// |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 ////////////////////////////////////////////////////////////////////////////// | 511 ////////////////////////////////////////////////////////////////////////////// |
517 | 512 |
518 DEF_GM( return new StrokesGM; ) | 513 DEF_GM( return new StrokesGM; ) |
519 DEF_GM( return new Strokes2GM; ) | 514 DEF_GM( return new Strokes2GM; ) |
520 DEF_GM( return new Strokes3GM; ) | 515 DEF_GM( return new Strokes3GM; ) |
521 DEF_GM( return new Strokes4GM; ) | 516 DEF_GM( return new Strokes4GM; ) |
522 DEF_GM( return new Strokes5GM; ) | 517 DEF_GM( return new Strokes5GM; ) |
523 | 518 |
524 DEF_GM( return new ZeroLenStrokesGM; ) | 519 DEF_GM( return new ZeroLenStrokesGM; ) |
525 DEF_GM( return new TeenyStrokesGM; ) | 520 DEF_GM( return new TeenyStrokesGM; ) |
OLD | NEW |