Chromium Code Reviews| Index: gm/dashcircle.cpp |
| diff --git a/gm/dashcircle.cpp b/gm/dashcircle.cpp |
| index a02c7d0f7b4cf5e91f95df55d178d1d4d12b8724..7b4ae70c05c9412d6f18e781edd9a1e9f3947ee1 100644 |
| --- a/gm/dashcircle.cpp |
| +++ b/gm/dashcircle.cpp |
| @@ -24,55 +24,84 @@ struct DashExample { |
| { dash4, SK_ARRAY_COUNT(dash4) } |
| }; |
| -DEF_SIMPLE_GM(dashcircle, canvas, 900, 1200) { |
| - SkPaint refPaint; |
| - refPaint.setAntiAlias(true); |
| - refPaint.setColor(0xFFbf3f7f); |
| - refPaint.setStyle(SkPaint::kStroke_Style); |
| - refPaint.setStrokeWidth(1); |
| - const SkScalar radius = 125; |
| - SkRect oval = SkRect::MakeLTRB(-radius - 20, -radius - 20, radius + 20, radius + 20); |
| - SkPath circle; |
| - circle.addCircle(0, 0, radius); |
| - SkScalar circumference = radius * SK_ScalarPI * 2; |
| - int wedges[] = { 6, 12, 36 }; |
| - canvas->translate(radius + 20, radius + 20); |
| - for (int wedge : wedges) { |
| - SkScalar arcLength = 360.f / wedge; |
| - canvas->save(); |
| - for (const DashExample& dashExample : dashExamples) { |
| - SkPath refPath; |
| - int dashUnits = 0; |
| - for (int index = 0; index < dashExample.length; ++index) { |
| - dashUnits += dashExample.pattern[index]; |
| - } |
| - SkScalar unitLength = arcLength / dashUnits; |
| - SkScalar angle = 0; |
| - for (int index = 0; index < wedge; ++index) { |
| - for (int i2 = 0; i2 < dashExample.length; i2 += 2) { |
| - SkScalar span = dashExample.pattern[i2] * unitLength; |
| - refPath.moveTo(0, 0); |
| - refPath.arcTo(oval, angle, span, false); |
| - refPath.close(); |
| - angle += span + (dashExample.pattern[i2 + 1]) * unitLength; |
| + |
| +class DashCircleGM : public skiagm::GM { |
| +public: |
| + DashCircleGM() : fRotation(0) { } |
| + |
| +protected: |
| + SkString onShortName() override { return SkString("dashcircle"); } |
| + |
| + SkISize onISize() override { return SkISize::Make(900, 1200); } |
| + |
| + void onDraw(SkCanvas* canvas) override { |
| + SkPaint refPaint; |
| + refPaint.setAntiAlias(true); |
| + refPaint.setColor(0xFFbf3f7f); |
| + refPaint.setStyle(SkPaint::kStroke_Style); |
| + refPaint.setStrokeWidth(1); |
| + const SkScalar radius = 125; |
| + SkRect oval = SkRect::MakeLTRB(-radius - 20, -radius - 20, radius + 20, radius + 20); |
| + SkPath circle; |
| + circle.addCircle(0, 0, radius); |
| + SkScalar circumference = radius * SK_ScalarPI * 2; |
| + int wedges[] = { 6, 12, 36 }; |
| + canvas->translate(radius+20, radius+20); |
| + for (int wedge : wedges) { |
| + SkScalar arcLength = 360.f / wedge; |
| + canvas->save(); |
| + for (const DashExample& dashExample : dashExamples) { |
| + SkPath refPath; |
| + int dashUnits = 0; |
| + for (int index = 0; index < dashExample.length; ++index) { |
| + dashUnits += dashExample.pattern[index]; |
| } |
| + SkScalar unitLength = arcLength / dashUnits; |
| + SkScalar angle = 0; |
| + for (int index = 0; index < wedge; ++index) { |
| + for (int i2 = 0; i2 < dashExample.length; i2 += 2) { |
| + SkScalar span = dashExample.pattern[i2] * unitLength; |
| + refPath.moveTo(0, 0); |
| + refPath.arcTo(oval, angle, span, false); |
| + refPath.close(); |
| + angle += span + (dashExample.pattern[i2 + 1]) * unitLength; |
| + } |
| + } |
| + canvas->save(); |
| + canvas->rotate(SkIntToScalar(fRotation)); |
| + canvas->drawPath(refPath, refPaint); |
| + canvas->restore(); |
| + SkPaint p; |
| + p.setAntiAlias(true); |
| + p.setStyle(SkPaint::kStroke_Style); |
| + p.setStrokeWidth(10); |
| + SkScalar intervals[4]; |
| + int intervalCount = dashExample.length; |
| + SkScalar dashLength = circumference / wedge / dashUnits; |
| + for (int index = 0; index < dashExample.length; ++index) { |
| + intervals[index] = dashExample.pattern[index] * dashLength; |
| + } |
| + p.setPathEffect(SkDashPathEffect::Make(intervals, intervalCount, 0)); |
| + canvas->save(); |
| + canvas->rotate(SkIntToScalar(fRotation)); |
| + canvas->drawPath(circle, p); |
| + canvas->restore(); |
| + canvas->translate(0, radius * 2 + 50); |
| } |
| - canvas->drawPath(refPath, refPaint); |
| - SkPaint p; |
| - p.setAntiAlias(true); |
| - p.setStyle(SkPaint::kStroke_Style); |
| - p.setStrokeWidth(10); |
| - SkScalar intervals[4]; |
| - int intervalCount = dashExample.length; |
| - SkScalar dashLength = circumference / wedge / dashUnits; |
| - for (int index = 0; index < dashExample.length; ++index) { |
| - intervals[index] = dashExample.pattern[index] * dashLength; |
| - } |
| - p.setPathEffect(SkDashPathEffect::Make(intervals, intervalCount, 0)); |
| - canvas->drawPath(circle, p); |
| - canvas->translate(0, radius * 2 + 50); |
| + canvas->restore(); |
| + canvas->translate(radius * 2 + 50, 0); |
| } |
| - canvas->restore(); |
| - canvas->translate(radius * 2 + 50, 0); |
| } |
| -} |
| + |
| + bool onAnimate(const SkAnimTimer& timer) override { |
| + fRotation = (fRotation + 2) % 360; |
|
jvanverth1
2016/04/08 19:10:56
I suppose it's not a big deal, but the animation s
robertphillips
2016/04/08 20:14:58
Doh - fixed.
|
| + return true; |
| + } |
| + |
| +private: |
| + int fRotation; |
| + |
| + typedef GM INHERITED; |
| +}; |
| + |
| +DEF_GM(return new DashCircleGM; ) |