OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
11 #include "SkDashPathEffect.h" | 11 #include "SkDashPathEffect.h" |
12 | 12 |
13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint, | 13 static void drawline(SkCanvas* canvas, int on, int off, const SkPaint& paint, |
14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI
ntToScalar(0), | 14 SkScalar finalX = SkIntToScalar(600), SkScalar finalY = SkI
ntToScalar(0), |
15 SkScalar phase = SkIntToScalar(0), | 15 SkScalar phase = SkIntToScalar(0), |
16 SkScalar startX = SkIntToScalar(0), SkScalar startY = SkInt
ToScalar(0)) { | 16 SkScalar startX = SkIntToScalar(0), SkScalar startY = SkInt
ToScalar(0)) { |
17 SkPaint p(paint); | 17 SkPaint p(paint); |
18 | 18 |
19 const SkScalar intervals[] = { | 19 const SkScalar intervals[] = { |
20 SkIntToScalar(on), | 20 SkIntToScalar(on), |
21 SkIntToScalar(off), | 21 SkIntToScalar(off), |
22 }; | 22 }; |
23 | 23 |
24 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); | 24 p.setPathEffect(SkDashPathEffect::Make(intervals, 2, phase)); |
25 canvas->drawLine(startX, startY, finalX, finalY, p); | 25 canvas->drawLine(startX, startY, finalX, finalY, p); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 446 |
447 canvas->concat(rot); | 447 canvas->concat(rot); |
448 | 448 |
449 int sign; // used to toggle the direction of the lines | 449 int sign; // used to toggle the direction of the lines |
450 int phase = 0; | 450 int phase = 0; |
451 | 451 |
452 for (int x = 0; x < 200; x += 10) { | 452 for (int x = 0; x < 200; x += 10) { |
453 paint.setStrokeWidth(SkIntToScalar(phase+1)); | 453 paint.setStrokeWidth(SkIntToScalar(phase+1)); |
454 paint.setColor(gColors[phase]); | 454 paint.setColor(gColors[phase]); |
455 sign = (x % 20) ? 1 : -1; | 455 sign = (x % 20) ? 1 : -1; |
456 drawline(canvas, kOn, kOff, paint, | 456 drawline(canvas, kOn, kOff, paint, |
457 SkIntToScalar(x), -sign * SkIntToScalar(10003), | 457 SkIntToScalar(x), -sign * SkIntToScalar(10003), |
458 SkIntToScalar(phase), | 458 SkIntToScalar(phase), |
459 SkIntToScalar(x), sign * SkIntToScalar(10003)); | 459 SkIntToScalar(x), sign * SkIntToScalar(10003)); |
460 phase = (phase + 1) % kIntervalLength; | 460 phase = (phase + 1) % kIntervalLength; |
461 } | 461 } |
462 | 462 |
463 for (int y = -400; y < 0; y += 10) { | 463 for (int y = -400; y < 0; y += 10) { |
464 paint.setStrokeWidth(SkIntToScalar(phase+1)); | 464 paint.setStrokeWidth(SkIntToScalar(phase+1)); |
465 paint.setColor(gColors[phase]); | 465 paint.setColor(gColors[phase]); |
466 sign = (y % 20) ? 1 : -1; | 466 sign = (y % 20) ? 1 : -1; |
467 drawline(canvas, kOn, kOff, paint, | 467 drawline(canvas, kOn, kOff, paint, |
468 -sign * SkIntToScalar(10003), SkIntToScalar(y), | 468 -sign * SkIntToScalar(10003), SkIntToScalar(y), |
469 SkIntToScalar(phase), | 469 SkIntToScalar(phase), |
470 sign * SkIntToScalar(10003), SkIntToScalar(y)); | 470 sign * SkIntToScalar(10003), SkIntToScalar(y)); |
471 phase = (phase + 1) % kIntervalLength; | 471 phase = (phase + 1) % kIntervalLength; |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 private: | 475 private: |
476 bool fDoAA; | 476 bool fDoAA; |
477 }; | 477 }; |
478 | 478 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 } | 545 } |
546 | 546 |
547 ////////////////////////////////////////////////////////////////////////////// | 547 ////////////////////////////////////////////////////////////////////////////// |
548 | 548 |
549 DEF_GM(return new DashingGM;) | 549 DEF_GM(return new DashingGM;) |
550 DEF_GM(return new Dashing2GM;) | 550 DEF_GM(return new Dashing2GM;) |
551 DEF_GM(return new Dashing3GM;) | 551 DEF_GM(return new Dashing3GM;) |
552 DEF_GM(return new Dashing4GM;) | 552 DEF_GM(return new Dashing4GM;) |
553 DEF_GM(return new Dashing5GM(true);) | 553 DEF_GM(return new Dashing5GM(true);) |
554 DEF_GM(return new Dashing5GM(false);) | 554 DEF_GM(return new Dashing5GM(false);) |
OLD | NEW |