reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkCanvas.h" |
| 3 | #include "SkPaint.h" |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 4 | #include "SkView.h" |
| 5 | |
| 6 | #include "SkBlurMaskFilter.h" |
| 7 | #include "SkColorMatrixFilter.h" |
| 8 | #include "SkDiscretePathEffect.h" |
| 9 | #include "SkGradientShader.h" |
| 10 | |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 11 | #include "SkEdgeClipper.h" |
| 12 | |
| 13 | static void test_edgeclipper() { |
| 14 | SkPoint pts[] = { |
reed@google.com | 261b8e2 | 2011-04-14 17:53:24 +0000 | [diff] [blame] | 15 | { -8.38822452e+21f, -7.69721471e+19f }, |
| 16 | { 1.57645875e+23f, 1.44634003e+21f }, |
| 17 | { 1.61519691e+23f, 1.48208059e+21f }, |
| 18 | { 3.13963584e+23f, 2.88057438e+21f } |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 19 | }; |
| 20 | SkRect clip = { 0, 0, 300, 200 }; |
| 21 | |
| 22 | SkEdgeClipper clipper; |
| 23 | clipper.clipCubic(pts, clip); |
| 24 | } |
| 25 | |
| 26 | /////////// |
| 27 | |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 28 | //#define COLOR 0xFFFF8844 |
| 29 | #define COLOR 0xFF888888 |
| 30 | |
| 31 | static void paint_proc0(SkPaint* paint) { |
| 32 | } |
| 33 | |
| 34 | static void paint_proc1(SkPaint* paint) { |
| 35 | paint->setMaskFilter(SkBlurMaskFilter::Create(2, |
| 36 | SkBlurMaskFilter::kNormal_BlurStyle))->unref(); |
| 37 | } |
| 38 | |
| 39 | static void paint_proc2(SkPaint* paint) { |
| 40 | SkScalar dir[3] = { 1, 1, 1}; |
| 41 | paint->setMaskFilter( |
reed@google.com | 261b8e2 | 2011-04-14 17:53:24 +0000 | [diff] [blame] | 42 | SkBlurMaskFilter::CreateEmboss(dir, 0.1f, 0.05f, 1))->unref(); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static void paint_proc3(SkPaint* paint) { |
| 46 | SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame^] | 47 | SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 48 | paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors), |
| 49 | SkShader::kMirror_TileMode))->unref(); |
| 50 | } |
| 51 | |
| 52 | static void paint_proc5(SkPaint* paint) { |
| 53 | paint_proc3(paint); |
| 54 | paint_proc2(paint); |
| 55 | } |
| 56 | |
| 57 | typedef void (*PaintProc)(SkPaint*); |
| 58 | const PaintProc gPaintProcs[] = { |
| 59 | paint_proc0, |
| 60 | paint_proc1, |
| 61 | paint_proc2, |
| 62 | paint_proc3, |
| 63 | paint_proc5, |
| 64 | }; |
| 65 | |
| 66 | /////////////////////////////////////////////////////////////////////////////// |
| 67 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 68 | class EffectsView : public SampleView { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 69 | public: |
| 70 | SkPath fPath; |
| 71 | SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; |
| 72 | |
| 73 | EffectsView() { |
| 74 | size_t i; |
| 75 | const float pts[] = { |
| 76 | 0, 0, |
| 77 | 10, 0, |
| 78 | 10, 5, |
| 79 | 20, -5, |
| 80 | 10, -15, |
| 81 | 10, -10, |
| 82 | 0, -10 |
| 83 | }; |
| 84 | fPath.moveTo(pts[0], pts[1]); |
| 85 | for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) { |
| 86 | fPath.lineTo(pts[i], pts[i+1]); |
| 87 | } |
| 88 | |
| 89 | for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) { |
| 90 | fPaint[i].setAntiAlias(true); |
| 91 | fPaint[i].setColor(COLOR); |
| 92 | gPaintProcs[i](&fPaint[i]); |
| 93 | } |
reed@android.com | 7d970c7 | 2010-04-22 16:07:49 +0000 | [diff] [blame] | 94 | |
| 95 | test_edgeclipper(); |
| 96 | SkColorMatrix cm; |
| 97 | cm.setRotate(SkColorMatrix::kG_Axis, 180); |
| 98 | cm.setIdentity(); |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 99 | |
| 100 | this->setBGColor(0xFFDDDDDD); |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | protected: |
| 104 | // overrides from SkEventSink |
| 105 | virtual bool onQuery(SkEvent* evt) { |
| 106 | if (SampleCode::TitleQ(*evt)) { |
| 107 | SampleCode::TitleR(evt, "Effects"); |
| 108 | return true; |
| 109 | } |
| 110 | return this->INHERITED::onQuery(evt); |
| 111 | } |
| 112 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 113 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 114 | canvas->scale(3, 3); |
| 115 | canvas->translate(10, 30); |
| 116 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { |
| 117 | canvas->drawPath(fPath, fPaint[i]); |
| 118 | canvas->translate(32, 0); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | private: |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 123 | typedef SampleView INHERITED; |
reed@android.com | ba974cc | 2009-05-22 13:48:35 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | /////////////////////////////////////////////////////////////////////////////// |
| 127 | |
| 128 | static SkView* MyFactory() { return new EffectsView; } |
| 129 | static SkViewRegister reg(MyFactory); |
| 130 | |