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