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 | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkCornerPathEffect.h" |
| 12 | #include "SkCullPoints.h" |
| 13 | #include "SkGradientShader.h" |
| 14 | #include "SkPath.h" |
| 15 | #include "SkRegion.h" |
| 16 | #include "SkShader.h" |
| 17 | #include "SkUtils.h" |
| 18 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 19 | class FillTypeView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | SkPath fPath; |
| 21 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 22 | FillTypeView() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 23 | const SkScalar radius = SkIntToScalar(45); |
| 24 | fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); |
| 25 | fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 26 | |
| 27 | this->setBGColor(0xFFDDDDDD); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 29 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | protected: |
| 31 | // overrides from SkEventSink |
| 32 | virtual bool onQuery(SkEvent* evt) { |
| 33 | if (SampleCode::TitleQ(*evt)) { |
| 34 | SampleCode::TitleR(evt, "FillType"); |
| 35 | return true; |
| 36 | } |
| 37 | return this->INHERITED::onQuery(evt); |
| 38 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 56 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 67 | |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 68 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 70 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 71 | SkPaint paint; |
| 72 | const SkScalar scale = SkIntToScalar(5)/4; |
| 73 | |
| 74 | paint.setAntiAlias(false); |
reed@android.com | b602b8e | 2009-07-10 15:58:53 +0000 | [diff] [blame] | 75 | paint.setColor(0x8000FF00); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | |
| 77 | showFour(canvas, SK_Scalar1, paint); |
| 78 | canvas->translate(SkIntToScalar(450), 0); |
| 79 | showFour(canvas, scale, paint); |
| 80 | |
| 81 | paint.setAntiAlias(true); |
| 82 | |
| 83 | canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); |
| 84 | showFour(canvas, SK_Scalar1, paint); |
| 85 | canvas->translate(SkIntToScalar(450), 0); |
| 86 | showFour(canvas, scale, paint); |
| 87 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 88 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | private: |
reed@google.com | 961ddb0 | 2011-05-05 14:03:48 +0000 | [diff] [blame] | 90 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | ////////////////////////////////////////////////////////////////////////////// |
| 94 | |
| 95 | static SkView* MyFactory() { return new FillTypeView; } |
| 96 | static SkViewRegister reg(MyFactory); |
| 97 | |