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() { |
bsalomon@google.com | 48dd1a2 | 2011-10-31 14:18:20 +0000 | [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 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 29 | return kSkipTiled_Flag; |
| 30 | } |
| 31 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 32 | virtual SkString onShortName() { |
| 33 | return SkString("filltypes"); |
| 34 | } |
| 35 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 36 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 37 | return SkISize::Make(835, 840); |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft, |
| 41 | SkScalar scale, const SkPaint& paint) { |
| 42 | |
| 43 | const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) }; |
| 44 | |
| 45 | canvas->save(); |
| 46 | canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 47 | canvas->clipRect(r); |
| 48 | canvas->drawColor(SK_ColorWHITE); |
| 49 | fPath.setFillType(ft); |
| 50 | canvas->translate(r.centerX(), r.centerY()); |
| 51 | canvas->scale(scale, scale); |
| 52 | canvas->translate(-r.centerX(), -r.centerY()); |
| 53 | canvas->drawPath(fPath, paint); |
| 54 | canvas->restore(); |
| 55 | } |
| 56 | |
| 57 | void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) { |
| 58 | showPath(canvas, 0, 0, SkPath::kWinding_FillType, |
| 59 | scale, paint); |
| 60 | showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType, |
| 61 | scale, paint); |
| 62 | showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType, |
| 63 | scale, paint); |
| 64 | showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType, |
| 65 | scale, paint); |
| 66 | } |
| 67 | |
| 68 | virtual void onDraw(SkCanvas* canvas) { |
reed@google.com | d42e3f6 | 2012-03-30 20:04:21 +0000 | [diff] [blame] | 69 | this->makePath(); |
| 70 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 71 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 72 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 73 | SkPaint paint; |
| 74 | const SkScalar scale = SkIntToScalar(5)/4; |
| 75 | |
| 76 | paint.setAntiAlias(false); |
| 77 | |
| 78 | showFour(canvas, SK_Scalar1, paint); |
| 79 | canvas->translate(SkIntToScalar(450), 0); |
| 80 | showFour(canvas, scale, paint); |
| 81 | |
| 82 | paint.setAntiAlias(true); |
| 83 | |
| 84 | canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); |
| 85 | showFour(canvas, SK_Scalar1, paint); |
| 86 | canvas->translate(SkIntToScalar(450), 0); |
| 87 | showFour(canvas, scale, paint); |
| 88 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 89 | |
reed@android.com | 048522d | 2009-06-23 12:19:41 +0000 | [diff] [blame] | 90 | private: |
| 91 | typedef GM INHERITED; |
| 92 | }; |
| 93 | |
| 94 | ////////////////////////////////////////////////////////////////////////////// |
| 95 | |
| 96 | static GM* MyFactory(void*) { return new FillTypeGM; } |
| 97 | static GMRegistry reg(MyFactory); |
| 98 | |
| 99 | } |