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