OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SampleCode.h" | 9 #include "SampleCode.h" |
10 #include "SkAnimTimer.h" | 10 #include "SkAnimTimer.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) { | 188 for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) { |
189 this->drawPath(canvas, fPath[j], gJoins[i]); | 189 this->drawPath(canvas, fPath[j], gJoins[i]); |
190 canvas->translate(200, 0); | 190 canvas->translate(200, 0); |
191 } | 191 } |
192 canvas->restore(); | 192 canvas->restore(); |
193 | 193 |
194 canvas->translate(0, 200); | 194 canvas->translate(0, 200); |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { | 198 bool onAnimate(const SkAnimTimer& timer) override { |
199 SkScalar currSecs = timer.scaled(100); | 199 SkScalar currSecs = timer.scaled(100); |
200 SkScalar delta = currSecs - fPrevSecs; | 200 SkScalar delta = currSecs - fPrevSecs; |
201 fPrevSecs = currSecs; | 201 fPrevSecs = currSecs; |
202 | 202 |
203 fStroke += fDStroke * delta; | 203 fStroke += fDStroke * delta; |
204 if (fStroke > fMaxStroke || fStroke < fMinStroke) { | 204 if (fStroke > fMaxStroke || fStroke < fMinStroke) { |
205 fDStroke = -fDStroke; | 205 fDStroke = -fDStroke; |
206 } | 206 } |
207 return true; | 207 return true; |
208 } | 208 } |
209 | 209 |
210 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
OVERRIDE { | 210 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
211 fShowHairline = !fShowHairline; | 211 fShowHairline = !fShowHairline; |
212 this->inval(NULL); | 212 this->inval(NULL); |
213 return this->INHERITED::onFindClickHandler(x, y, modi); | 213 return this->INHERITED::onFindClickHandler(x, y, modi); |
214 } | 214 } |
215 | 215 |
216 private: | 216 private: |
217 typedef SampleView INHERITED; | 217 typedef SampleView INHERITED; |
218 }; | 218 }; |
219 DEF_SAMPLE( return new PathView; ) | 219 DEF_SAMPLE( return new PathView; ) |
220 | 220 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 fSkeletonPaint.setColor(SK_ColorRED); | 265 fSkeletonPaint.setColor(SK_ColorRED); |
266 } | 266 } |
267 | 267 |
268 void toggle(bool& value) { | 268 void toggle(bool& value) { |
269 value = !value; | 269 value = !value; |
270 this->inval(NULL); | 270 this->inval(NULL); |
271 } | 271 } |
272 | 272 |
273 protected: | 273 protected: |
274 // overrides from SkEventSink | 274 // overrides from SkEventSink |
275 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 275 bool onQuery(SkEvent* evt) override { |
276 if (SampleCode::TitleQ(*evt)) { | 276 if (SampleCode::TitleQ(*evt)) { |
277 SampleCode::TitleR(evt, "ArcTo"); | 277 SampleCode::TitleR(evt, "ArcTo"); |
278 return true; | 278 return true; |
279 } | 279 } |
280 SkUnichar uni; | 280 SkUnichar uni; |
281 if (SampleCode::CharQ(*evt, &uni)) { | 281 if (SampleCode::CharQ(*evt, &uni)) { |
282 switch (uni) { | 282 switch (uni) { |
283 case '1': this->toggle(fDoFrame); return true; | 283 case '1': this->toggle(fDoFrame); return true; |
284 case '2': this->toggle(fDoArcTo); return true; | 284 case '2': this->toggle(fDoArcTo); return true; |
285 case '3': this->toggle(fDoCorner); return true; | 285 case '3': this->toggle(fDoCorner); return true; |
286 case '4': this->toggle(fDoConic); return true; | 286 case '4': this->toggle(fDoConic); return true; |
287 default: break; | 287 default: break; |
288 } | 288 } |
289 } | 289 } |
290 return this->INHERITED::onQuery(evt); | 290 return this->INHERITED::onQuery(evt); |
291 } | 291 } |
292 | 292 |
293 void makePath(SkPath* path) { | 293 void makePath(SkPath* path) { |
294 path->moveTo(fPts[0]); | 294 path->moveTo(fPts[0]); |
295 for (int i = 1; i < N; ++i) { | 295 for (int i = 1; i < N; ++i) { |
296 path->lineTo(fPts[i]); | 296 path->lineTo(fPts[i]); |
297 } | 297 } |
298 if (!fDoFrame) { | 298 if (!fDoFrame) { |
299 path->close(); | 299 path->close(); |
300 } | 300 } |
301 } | 301 } |
302 | 302 |
303 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 303 void onDrawContent(SkCanvas* canvas) override { |
304 canvas->drawPoints(SkCanvas::kPoints_PointMode, N, fPts, fPtsPaint); | 304 canvas->drawPoints(SkCanvas::kPoints_PointMode, N, fPts, fPtsPaint); |
305 | 305 |
306 SkPath path; | 306 SkPath path; |
307 this->makePath(&path); | 307 this->makePath(&path); |
308 | 308 |
309 if (fDoCorner) { | 309 if (fDoCorner) { |
310 canvas->drawPath(path, fCornerPaint); | 310 canvas->drawPath(path, fCornerPaint); |
311 } | 311 } |
312 if (fDoArcTo) { | 312 if (fDoArcTo) { |
313 canvas->drawPath(path, fArcToPaint); | 313 canvas->drawPath(path, fArcToPaint); |
314 } | 314 } |
315 | 315 |
316 canvas->drawPath(path, fSkeletonPaint); | 316 canvas->drawPath(path, fSkeletonPaint); |
317 } | 317 } |
318 | 318 |
319 bool onClick(Click* click) SK_OVERRIDE { | 319 bool onClick(Click* click) override { |
320 int32_t index; | 320 int32_t index; |
321 if (click->fMeta.findS32("index", &index)) { | 321 if (click->fMeta.findS32("index", &index)) { |
322 SkASSERT((unsigned)index < N); | 322 SkASSERT((unsigned)index < N); |
323 fPts[index] = click->fCurr; | 323 fPts[index] = click->fCurr; |
324 this->inval(NULL); | 324 this->inval(NULL); |
325 return true; | 325 return true; |
326 } | 326 } |
327 return false; | 327 return false; |
328 } | 328 } |
329 | 329 |
330 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_
OVERRIDE { | 330 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove
rride { |
331 const SkScalar tol = 4; | 331 const SkScalar tol = 4; |
332 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2); | 332 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2); |
333 for (int i = 0; i < N; ++i) { | 333 for (int i = 0; i < N; ++i) { |
334 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) { | 334 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) { |
335 Click* click = new Click(this); | 335 Click* click = new Click(this); |
336 click->fMeta.setS32("index", i); | 336 click->fMeta.setS32("index", i); |
337 return click; | 337 return click; |
338 } | 338 } |
339 } | 339 } |
340 return this->INHERITED::onFindClickHandler(x, y, modi); | 340 return this->INHERITED::onFindClickHandler(x, y, modi); |
341 } | 341 } |
342 | 342 |
343 private: | 343 private: |
344 typedef SampleView INHERITED; | 344 typedef SampleView INHERITED; |
345 }; | 345 }; |
346 DEF_SAMPLE( return new ArcToView; ) | 346 DEF_SAMPLE( return new ArcToView; ) |
347 | 347 |
OLD | NEW |