blob: a63c08d3f54b257372a1e75fae026173a9be12b2 [file] [log] [blame]
reed@android.comba974cc2009-05-22 13:48:35 +00001#include "SampleCode.h"
2#include "SkCanvas.h"
3#include "SkPaint.h"
reed@android.comba974cc2009-05-22 13:48:35 +00004#include "SkView.h"
5
6#include "SkBlurMaskFilter.h"
7#include "SkColorMatrixFilter.h"
8#include "SkDiscretePathEffect.h"
9#include "SkGradientShader.h"
10
reed@android.com7d970c72010-04-22 16:07:49 +000011#include "SkEdgeClipper.h"
12
13static void test_edgeclipper() {
14 SkPoint pts[] = {
reed@google.com261b8e22011-04-14 17:53:24 +000015 { -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.com7d970c72010-04-22 16:07:49 +000019 };
20 SkRect clip = { 0, 0, 300, 200 };
21
22 SkEdgeClipper clipper;
23 clipper.clipCubic(pts, clip);
24}
25
26///////////
27
reed@android.comba974cc2009-05-22 13:48:35 +000028//#define COLOR 0xFFFF8844
29#define COLOR 0xFF888888
30
31static void paint_proc0(SkPaint* paint) {
32}
33
34static void paint_proc1(SkPaint* paint) {
35 paint->setMaskFilter(SkBlurMaskFilter::Create(2,
36 SkBlurMaskFilter::kNormal_BlurStyle))->unref();
37}
38
39static void paint_proc2(SkPaint* paint) {
40 SkScalar dir[3] = { 1, 1, 1};
41 paint->setMaskFilter(
reed@google.com261b8e22011-04-14 17:53:24 +000042 SkBlurMaskFilter::CreateEmboss(dir, 0.1f, 0.05f, 1))->unref();
reed@android.comba974cc2009-05-22 13:48:35 +000043}
44
45static void paint_proc3(SkPaint* paint) {
46 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000047 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed@android.comba974cc2009-05-22 13:48:35 +000048 paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
49 SkShader::kMirror_TileMode))->unref();
50}
51
52static void paint_proc5(SkPaint* paint) {
53 paint_proc3(paint);
54 paint_proc2(paint);
55}
56
57typedef void (*PaintProc)(SkPaint*);
58const PaintProc gPaintProcs[] = {
59 paint_proc0,
60 paint_proc1,
61 paint_proc2,
62 paint_proc3,
63 paint_proc5,
64};
65
66///////////////////////////////////////////////////////////////////////////////
67
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000068class EffectsView : public SampleView {
reed@android.comba974cc2009-05-22 13:48:35 +000069public:
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.com7d970c72010-04-22 16:07:49 +000094
95 test_edgeclipper();
96 SkColorMatrix cm;
97 cm.setRotate(SkColorMatrix::kG_Axis, 180);
98 cm.setIdentity();
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000099
100 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +0000101 }
102
103protected:
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.org5fd92432011-05-05 01:59:48 +0000113 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000114 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
122private:
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000123 typedef SampleView INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000124};
125
126///////////////////////////////////////////////////////////////////////////////
127
128static SkView* MyFactory() { return new EffectsView; }
129static SkViewRegister reg(MyFactory);
130