2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #include "SampleCode.h"
14 // Implementation in C++ of Mozilla Canvas2D benchmark Canvas Clock Test
15 // See https://code.google.com/p/skia/issues/detail?id=1626
19 class ClockView : public SampleView {
24 // overrides from SkEventSink
25 bool onQuery(SkEvent* evt) override {
26 if (SampleCode::TitleQ(*evt)) {
27 SampleCode::TitleR(evt, "Clock");
30 return this->INHERITED::onQuery(evt);
33 void onDrawContent(SkCanvas* canvas) override {
39 canvas->translate(150, 150);
40 canvas->scale(0.4f, 0.4f);
41 canvas->rotate(-180.f/2.f);
43 paintFill.setAntiAlias(true);
44 paintFill.setColor(SK_ColorBLACK);
45 paintStroke.setAntiAlias(true);
46 paintStroke.setStyle(SkPaint::kStroke_Style);
47 paintStroke.setColor(SK_ColorBLACK);
48 paintStroke.setStrokeWidth(8);
49 paintStroke.setStrokeCap(SkPaint::kRound_Cap);
54 rect = SkRect::MakeLTRB(200-4, -4, 240+4, 4);
56 SkVector radii[4] = {{4,4}, {4,4}, {4,4}, {4,4}};
57 rrect.setRectRadii(rect, radii);
60 for (int i=0;i<12;i++){
61 canvas->rotate(180.f/6.f);
66 canvas->drawPath(path, paintStroke);
68 canvas->drawRRect(rrect, paintFill);
76 paintStroke.setStrokeWidth(5);
78 rect = SkRect::MakeLTRB(231.5f, -2.5f, 242.5, 2.5f);
79 radii[0] = SkPoint::Make(2.5f,2.5f);
80 radii[1] = SkPoint::Make(2.5f,2.5f);
81 radii[2] = SkPoint::Make(2.5f,2.5f);
82 radii[3] = SkPoint::Make(2.5f,2.5f);
83 rrect.setRectRadii(rect, radii);
85 for (int i=0;i<60;i++){
87 canvas->rotate(180.f/30.f);
94 canvas->drawPath(path, paintStroke);
96 canvas->drawRRect(rrect, paintFill);
98 canvas->rotate(180.f/30.f);
102 SkTime::DateTime time;
103 SkTime::GetDateTime(&time);
104 time.fHour = time.fHour >= 12 ? time.fHour-12 : time.fHour;
105 paintFill.setColor(SK_ColorBLACK);
109 canvas->rotate(time.fHour*(180.f/6.f) + time.fMinute*(180.f/360.f)
110 + time.fSecond*(180.f/21600.f) );
112 paintStroke.setStrokeWidth(14);
116 canvas->drawPath(path, paintStroke);
118 rect = SkRect::MakeLTRB(-20-7, -7, 80+7, 7);
119 radii[0] = SkPoint::Make(7,7);
120 radii[1] = SkPoint::Make(7,7);
121 radii[2] = SkPoint::Make(7,7);
122 radii[3] = SkPoint::Make(7,7);
123 rrect.setRectRadii(rect, radii);
124 canvas->drawRRect(rrect, paintFill);
130 canvas->rotate(time.fMinute*(180.f/30.f)
131 + time.fSecond*(180.f/1800.f) );
133 paintStroke.setStrokeWidth(10);
137 canvas->drawPath(path, paintStroke);
139 rect = SkRect::MakeLTRB(-56-5, -5, 224+5, 5);
140 radii[0] = SkPoint::Make(5,5);
141 radii[1] = SkPoint::Make(5,5);
142 radii[2] = SkPoint::Make(5,5);
143 radii[3] = SkPoint::Make(5,5);
144 rrect.setRectRadii(rect, radii);
145 canvas->drawRRect(rrect, paintFill);
151 canvas->rotate(time.fSecond*(180.f/30.f));
152 paintFill.setColor(0xffd40000);
153 paintStroke.setColor(0xffd40000);
154 paintStroke.setStrokeWidth(6);
159 canvas->drawPath(path, paintStroke);
161 rect = SkRect::MakeLTRB(-60-3, -3, 166+3, 3);
162 radii[0] = SkPoint::Make(3,3);
163 radii[1] = SkPoint::Make(3,3);
164 radii[2] = SkPoint::Make(3,3);
165 radii[3] = SkPoint::Make(3,3);
166 rrect.setRectRadii(rect, radii);
167 canvas->drawRRect(rrect, paintFill);
169 rect = SkRect::MakeLTRB(-20, -20, 20, 20);
172 path.arcTo(rect, 0, 0, false);
173 path.addOval(rect, SkPath::kCCW_Direction);
174 path.arcTo(rect, 360, 0, true);
175 canvas->drawPath(path, paintFill);
177 canvas->drawOval(rect, paintFill);
179 rect = SkRect::MakeLTRB(-20+190, -20, 20+190, 20);
182 path.arcTo(rect, 0, 0, false);
183 path.addOval(rect, SkPath::kCCW_Direction);
184 path.arcTo(rect, 360, 0, true);
185 canvas->drawPath(path, paintStroke);
187 canvas->drawOval(rect, paintStroke);
189 paintFill.setColor(0xff505050);
191 rect = SkRect::MakeLTRB(-6, -6, 6, 6);
192 path.arcTo(rect, 0, 0, false);
193 path.addOval(rect, SkPath::kCCW_Direction);
194 path.arcTo(rect, 360, 0, true);
195 canvas->drawPath(path, paintFill);
197 canvas->drawOval(rect, paintFill);
198 rect = SkRect::MakeLTRB(-6, -6, 6, 6);
199 canvas->drawOval(rect, paintFill);
203 paintStroke.setStrokeWidth(18);
204 paintStroke.setColor(0xff325FA2);
205 rect = SkRect::MakeLTRB(-284, -284, 284, 284);
208 path.arcTo(rect, 0, 0, false);
209 path.addOval(rect, SkPath::kCCW_Direction);
210 path.arcTo(rect, 360, 0, true);
211 canvas->drawPath(path, paintStroke);
213 canvas->drawOval(rect, paintStroke);
223 typedef SampleView INHERITED;
226 //////////////////////////////////////////////////////////////////////////////
228 static SkView* MyFactory() { return new ClockView; }
229 static SkViewRegister reg(MyFactory);