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 "SkRandom.h" | 12 #include "SkRandom.h" |
12 | 13 |
13 class AddArcGM : public skiagm::GM { | 14 class AddArcGM : public skiagm::GM { |
14 public: | 15 public: |
15 AddArcGM() : fRotate(0) {} | 16 AddArcGM() : fRotate(0) {} |
16 | 17 |
17 protected: | 18 protected: |
18 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); } | 19 SkString onShortName() SK_OVERRIDE { return SkString("addarc"); } |
19 | 20 |
20 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); } | 21 SkISize onISize() SK_OVERRIDE { return SkISize::Make(1040, 1040); } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 54 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
54 fRotate = timer.scaled(1, 360); | 55 fRotate = timer.scaled(1, 360); |
55 return true; | 56 return true; |
56 } | 57 } |
57 | 58 |
58 private: | 59 private: |
59 SkScalar fRotate; | 60 SkScalar fRotate; |
60 typedef skiagm::GM INHERITED; | 61 typedef skiagm::GM INHERITED; |
61 }; | 62 }; |
62 DEF_GM( return new AddArcGM; ) | 63 DEF_GM( return new AddArcGM; ) |
| 64 |
| 65 /////////////////////////////////////////////////// |
| 66 |
| 67 #define R 400 |
| 68 |
| 69 class AddArcMeasGM : public skiagm::GM { |
| 70 public: |
| 71 AddArcMeasGM() {} |
| 72 |
| 73 protected: |
| 74 SkString onShortName() SK_OVERRIDE { return SkString("addarc_meas"); } |
| 75 |
| 76 SkISize onISize() SK_OVERRIDE { return SkISize::Make(2*R + 40, 2*R + 40); } |
| 77 |
| 78 void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
| 79 canvas->translate(R + 20, R + 20); |
| 80 |
| 81 SkPaint paint; |
| 82 paint.setAntiAlias(true); |
| 83 paint.setStyle(SkPaint::kStroke_Style); |
| 84 |
| 85 SkPaint measPaint; |
| 86 measPaint.setAntiAlias(true); |
| 87 measPaint.setColor(SK_ColorRED); |
| 88 |
| 89 const SkRect oval = SkRect::MakeLTRB(-R, -R, R, R); |
| 90 canvas->drawOval(oval, paint); |
| 91 |
| 92 for (SkScalar deg = 0; deg < 360; deg += 10) { |
| 93 const SkScalar rad = SkDegreesToRadians(deg); |
| 94 SkScalar rx = SkScalarCos(rad) * R; |
| 95 SkScalar ry = SkScalarSin(rad) * R; |
| 96 |
| 97 canvas->drawLine(0, 0, rx, ry, paint); |
| 98 |
| 99 SkPath path; |
| 100 path.addArc(oval, 0, deg); |
| 101 SkPathMeasure meas(path, false); |
| 102 SkScalar arcLen = rad * R; |
| 103 SkPoint pos; |
| 104 if (meas.getPosTan(arcLen, &pos, NULL)) { |
| 105 canvas->drawLine(0, 0, pos.x(), pos.y(), measPaint); |
| 106 } |
| 107 } |
| 108 } |
| 109 |
| 110 private: |
| 111 typedef skiagm::GM INHERITED; |
| 112 }; |
| 113 DEF_GM( return new AddArcMeasGM; ) |
OLD | NEW |