OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SampleCode.h" | 7 #include "SampleCode.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 | 9 |
10 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014 | 10 // Reproduces https://code.google.com/p/chromium/issues/detail?id=279014 |
11 | 11 |
12 // Renders a string art shape. | 12 // Renders a string art shape. |
13 // The particular shape rendered can be controlled by clicking horizontally, the
reby | 13 // The particular shape rendered can be controlled by clicking horizontally, the
reby |
14 // generating an angle from 0 to 1. | 14 // generating an angle from 0 to 1. |
15 | 15 |
16 class StringArtView : public SampleView { | 16 class StringArtView : public SampleView { |
17 public: | 17 public: |
18 StringArtView() : fAngle(0.305f) {} | 18 StringArtView() : fAngle(0.305f) {} |
19 | 19 |
20 protected: | 20 protected: |
21 // overrides from SkEventSink | 21 // overrides from SkEventSink |
22 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 22 bool onQuery(SkEvent* evt) override { |
23 if (SampleCode::TitleQ(*evt)) { | 23 if (SampleCode::TitleQ(*evt)) { |
24 SampleCode::TitleR(evt, "StringArt"); | 24 SampleCode::TitleR(evt, "StringArt"); |
25 return true; | 25 return true; |
26 } | 26 } |
27 return this->INHERITED::onQuery(evt); | 27 return this->INHERITED::onQuery(evt); |
28 } | 28 } |
29 | 29 |
30 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 30 void onDrawContent(SkCanvas* canvas) override { |
31 SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI); | 31 SkScalar angle = fAngle*SK_ScalarPI + SkScalarHalf(SK_ScalarPI); |
32 | 32 |
33 SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf
(this->height())); | 33 SkPoint center = SkPoint::Make(SkScalarHalf(this->width()), SkScalarHalf
(this->height())); |
34 SkScalar length = 5; | 34 SkScalar length = 5; |
35 SkScalar step = angle; | 35 SkScalar step = angle; |
36 | 36 |
37 SkPath path; | 37 SkPath path; |
38 path.moveTo(center); | 38 path.moveTo(center); |
39 | 39 |
40 while (length < (SkScalarHalf(SkMinScalar(this->width(), this->height())
) - 10.f)) | 40 while (length < (SkScalarHalf(SkMinScalar(this->width(), this->height())
) - 10.f)) |
41 { | 41 { |
42 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX, | 42 SkPoint rp = SkPoint::Make(length*SkScalarCos(step) + center.fX, |
43 length*SkScalarSin(step) + center.fY); | 43 length*SkScalarSin(step) + center.fY); |
44 path.lineTo(rp); | 44 path.lineTo(rp); |
45 length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI)); | 45 length += SkScalarDiv(angle, SkScalarHalf(SK_ScalarPI)); |
46 step += angle; | 46 step += angle; |
47 } | 47 } |
48 path.close(); | 48 path.close(); |
49 | 49 |
50 SkPaint paint; | 50 SkPaint paint; |
51 paint.setAntiAlias(true); | 51 paint.setAntiAlias(true); |
52 paint.setStyle(SkPaint::kStroke_Style); | 52 paint.setStyle(SkPaint::kStroke_Style); |
53 paint.setColor(0xFF007700); | 53 paint.setColor(0xFF007700); |
54 | 54 |
55 canvas->drawPath(path, paint); | 55 canvas->drawPath(path, paint); |
56 } | 56 } |
57 | 57 |
58 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERR
IDE { | 58 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) override
{ |
59 fAngle = x/width(); | 59 fAngle = x/width(); |
60 this->inval(NULL); | 60 this->inval(NULL); |
61 return NULL; | 61 return NULL; |
62 } | 62 } |
63 private: | 63 private: |
64 | 64 |
65 SkScalar fAngle; | 65 SkScalar fAngle; |
66 typedef SampleView INHERITED; | 66 typedef SampleView INHERITED; |
67 }; | 67 }; |
68 | 68 |
69 ////////////////////////////////////////////////////////////////////////////// | 69 ////////////////////////////////////////////////////////////////////////////// |
70 | 70 |
71 static SkView* MyFactory() { return new StringArtView; } | 71 static SkView* MyFactory() { return new StringArtView; } |
72 static SkViewRegister reg(MyFactory); | 72 static SkViewRegister reg(MyFactory); |
OLD | NEW |