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 | */ |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 7 | #include "SampleCode.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 8 | #include "SkBlurMask.h" |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 9 | #include "SkBlurMaskFilter.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 11 | #include "SkColorMatrixFilter.h" |
| 12 | #include "SkDiscretePathEffect.h" |
Ben Wagner | 339b84e | 2017-11-10 16:24:50 -0500 | [diff] [blame^] | 13 | #include "SkEmbossMaskFilter.h" |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 14 | #include "SkGradientShader.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 15 | #include "SkPaint.h" |
| 16 | #include "SkView.h" |
| 17 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 18 | |
| 19 | //#define COLOR 0xFFFF8844 |
| 20 | #define COLOR 0xFF888888 |
| 21 | |
sugoi@google.com | 93c7ee3 | 2013-03-12 14:36:57 +0000 | [diff] [blame] | 22 | static void paint_proc0(SkPaint*) { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | static void paint_proc1(SkPaint* paint) { |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 26 | paint->setMaskFilter(SkBlurMaskFilter::Make( |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 27 | kNormal_SkBlurStyle, |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 28 | SkBlurMask::ConvertRadiusToSigma(2))); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static void paint_proc2(SkPaint* paint) { |
Ben Wagner | 339b84e | 2017-11-10 16:24:50 -0500 | [diff] [blame^] | 32 | paint->setMaskFilter(SkEmbossMaskFilter::Make( |
| 33 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), |
| 34 | { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 })); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static void paint_proc3(SkPaint* paint) { |
| 38 | SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 39 | SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 40 | paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), |
| 41 | SkShader::kMirror_TileMode)); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | static void paint_proc5(SkPaint* paint) { |
| 45 | paint_proc3(paint); |
| 46 | paint_proc2(paint); |
| 47 | } |
| 48 | |
| 49 | typedef void (*PaintProc)(SkPaint*); |
| 50 | const PaintProc gPaintProcs[] = { |
| 51 | paint_proc0, |
| 52 | paint_proc1, |
| 53 | paint_proc2, |
| 54 | paint_proc3, |
| 55 | paint_proc5, |
| 56 | }; |
| 57 | |
| 58 | /////////////////////////////////////////////////////////////////////////////// |
| 59 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 60 | class EffectsView : public SampleView { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 61 | public: |
| 62 | SkPath fPath; |
| 63 | SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; |
| 64 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | EffectsView() { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 66 | size_t i; |
| 67 | const float pts[] = { |
| 68 | 0, 0, |
| 69 | 10, 0, |
| 70 | 10, 5, |
| 71 | 20, -5, |
| 72 | 10, -15, |
| 73 | 10, -10, |
| 74 | 0, -10 |
| 75 | }; |
| 76 | fPath.moveTo(pts[0], pts[1]); |
| 77 | for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) { |
| 78 | fPath.lineTo(pts[i], pts[i+1]); |
| 79 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 80 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 81 | for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) { |
| 82 | fPaint[i].setAntiAlias(true); |
| 83 | fPaint[i].setColor(COLOR); |
| 84 | gPaintProcs[i](&fPaint[i]); |
| 85 | } |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 86 | |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 87 | SkColorMatrix cm; |
| 88 | cm.setRotate(SkColorMatrix::kG_Axis, 180); |
| 89 | cm.setIdentity(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 90 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 91 | this->setBGColor(0xFFDDDDDD); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 92 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 93 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 94 | protected: |
| 95 | // overrides from SkEventSink |
| 96 | virtual bool onQuery(SkEvent* evt) { |
| 97 | if (SampleCode::TitleQ(*evt)) { |
| 98 | SampleCode::TitleR(evt, "Effects"); |
| 99 | return true; |
| 100 | } |
| 101 | return this->INHERITED::onQuery(evt); |
| 102 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 103 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 104 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 105 | canvas->scale(3, 3); |
| 106 | canvas->translate(10, 30); |
| 107 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { |
| 108 | canvas->drawPath(fPath, fPaint[i]); |
| 109 | canvas->translate(32, 0); |
| 110 | } |
| 111 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 112 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 113 | private: |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 114 | typedef SampleView INHERITED; |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | /////////////////////////////////////////////////////////////////////////////// |
| 118 | |
| 119 | static SkView* MyFactory() { return new EffectsView; } |
| 120 | static SkViewRegister reg(MyFactory); |