OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "gm.h" | 7 #include "gm.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 canvas->restore(); | 289 canvas->restore(); |
290 } | 290 } |
291 canvas->restore(); | 291 canvas->restore(); |
292 canvas->restore(); | 292 canvas->restore(); |
293 } | 293 } |
294 | 294 |
295 private: | 295 private: |
296 typedef skiagm::GM INHERITED; | 296 typedef skiagm::GM INHERITED; |
297 }; | 297 }; |
298 | 298 |
| 299 #include "SkGeometry.h" |
| 300 |
| 301 class TrickyStrokeCubicGM : public skiagm::GM { |
| 302 public: |
| 303 TrickyStrokeCubicGM() {} |
| 304 |
| 305 protected: |
| 306 SkString onShortName() { |
| 307 return SkString("strokecubic"); |
| 308 } |
| 309 |
| 310 SkISize onISize() { return SkISize::Make(640, 480); } |
| 311 |
| 312 virtual void onDraw(SkCanvas* canvas) { |
| 313 const SkPoint pts[] = {{10,20}, {0,40}, {10,0}, {50,10}}; |
| 314 SkPath path; |
| 315 |
| 316 path.moveTo(pts[0]); |
| 317 path.cubicTo(pts[1], pts[2], pts[3]); |
| 318 |
| 319 SkRect srcR; |
| 320 // hone in on the interesting part of the cubic |
| 321 srcR.set(6, 23, 9, 27); |
| 322 |
| 323 SkMatrix matrix; |
| 324 matrix.setRectToRect(srcR, SkRect::MakeLTRB(10, 10, 630, 470), |
| 325 SkMatrix::kCenter_ScaleToFit); |
| 326 canvas->concat(matrix); |
| 327 |
| 328 SkPaint paint; |
| 329 paint.setStyle(SkPaint::kStroke_Style); |
| 330 paint.setStrokeWidth(0.15f); |
| 331 SkPath stroke; |
| 332 paint.getFillPath(path, &stroke); |
| 333 |
| 334 paint.setAntiAlias(true); |
| 335 paint.setColor(SK_ColorLTGRAY); |
| 336 canvas->drawPath(path, paint); |
| 337 |
| 338 paint.setStrokeWidth(0); |
| 339 paint.setColor(SK_ColorBLUE); |
| 340 canvas->drawPath(path, paint); |
| 341 |
| 342 paint.setColor(SK_ColorRED); |
| 343 canvas->drawPath(stroke, paint); |
| 344 } |
| 345 |
| 346 private: |
| 347 typedef skiagm::GM INHERITED; |
| 348 }; |
| 349 |
299 ////////////////////////////////////////////////////////////////////////////// | 350 ////////////////////////////////////////////////////////////////////////////// |
300 | 351 |
301 DEF_GM( return new CubicPathGM; ) | 352 DEF_GM( return new CubicPathGM; ) |
302 DEF_GM( return new CubicClosePathGM; ) | 353 DEF_GM( return new CubicClosePathGM; ) |
| 354 DEF_GM( return new TrickyStrokeCubicGM; ) |
303 | 355 |
OLD | NEW |