epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 8 | #include "gm.h" |
| 9 | |
| 10 | namespace skiagm { |
| 11 | |
| 12 | class FillTypeGM : public GM { |
| 13 | SkPath fPath; |
| 14 | public: |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 15 | FillTypeGM() { |
caryclark | 0bdb08b | 2015-06-15 05:28:00 -0700 | [diff] [blame^] | 16 | this->setBGColor(0xFFDDDDDD); |
reed@google.com | d42e3f6 | 2012-03-30 20:04:21 +0000 | [diff] [blame] | 17 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 18 | |
reed@google.com | d42e3f6 | 2012-03-30 20:04:21 +0000 | [diff] [blame] | 19 | void makePath() { |
| 20 | if (fPath.isEmpty()) { |
| 21 | const SkScalar radius = SkIntToScalar(45); |
| 22 | fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); |
| 23 | fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); |
| 24 | } |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 25 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 26 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 27 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | SkString onShortName() override { |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 30 | return SkString("filltypes"); |
| 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | SkISize onISize() override { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 34 | return SkISize::Make(835, 840); |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft, |
| 38 | SkScalar scale, const SkPaint& paint) { |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 39 | const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) }; |
| 40 | |
| 41 | canvas->save(); |
| 42 | canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 43 | canvas->clipRect(r); |
| 44 | canvas->drawColor(SK_ColorWHITE); |
| 45 | fPath.setFillType(ft); |
| 46 | canvas->translate(r.centerX(), r.centerY()); |
| 47 | canvas->scale(scale, scale); |
| 48 | canvas->translate(-r.centerX(), -r.centerY()); |
| 49 | canvas->drawPath(fPath, paint); |
| 50 | canvas->restore(); |
| 51 | } |
| 52 | |
| 53 | void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) { |
| 54 | showPath(canvas, 0, 0, SkPath::kWinding_FillType, |
| 55 | scale, paint); |
| 56 | showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType, |
| 57 | scale, paint); |
| 58 | showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType, |
| 59 | scale, paint); |
| 60 | showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType, |
| 61 | scale, paint); |
| 62 | } |
| 63 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 64 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | d42e3f6 | 2012-03-30 20:04:21 +0000 | [diff] [blame] | 65 | this->makePath(); |
| 66 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 67 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 68 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 69 | SkPaint paint; |
| 70 | const SkScalar scale = SkIntToScalar(5)/4; |
| 71 | |
| 72 | paint.setAntiAlias(false); |
| 73 | |
| 74 | showFour(canvas, SK_Scalar1, paint); |
| 75 | canvas->translate(SkIntToScalar(450), 0); |
| 76 | showFour(canvas, scale, paint); |
| 77 | |
| 78 | paint.setAntiAlias(true); |
| 79 | |
| 80 | canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); |
| 81 | showFour(canvas, SK_Scalar1, paint); |
| 82 | canvas->translate(SkIntToScalar(450), 0); |
| 83 | showFour(canvas, scale, paint); |
| 84 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 85 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 86 | private: |
| 87 | typedef GM INHERITED; |
| 88 | }; |
| 89 | |
| 90 | ////////////////////////////////////////////////////////////////////////////// |
| 91 | |
| 92 | static GM* MyFactory(void*) { return new FillTypeGM; } |
| 93 | static GMRegistry reg(MyFactory); |
| 94 | |
| 95 | } |