blob: 7b6191178faf5b015f49d32fea449a7fd34e92b9 [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[] = {
15 { -8.38822452e+21, -7.69721471e+19 },
16 { 1.57645875e+23, 1.44634003e+21 },
17 { 1.61519691e+23, 1.48208059e+21 },
18 { 3.13963584e+23, 2.88057438e+21 }
19 };
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(
42 SkBlurMaskFilter::CreateEmboss(dir, 0.1, 0.05, 1))->unref();
43}
44
45static void paint_proc3(SkPaint* paint) {
46 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
47 SkPoint pts[] = { 3, 0, 7, 5 };
48 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
68class EffectsView : public SkView {
69public:
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();
reed@android.comba974cc2009-05-22 13:48:35 +000099 }
100
101protected:
102 // overrides from SkEventSink
103 virtual bool onQuery(SkEvent* evt) {
104 if (SampleCode::TitleQ(*evt)) {
105 SampleCode::TitleR(evt, "Effects");
106 return true;
107 }
108 return this->INHERITED::onQuery(evt);
109 }
110
111 void drawBG(SkCanvas* canvas) {
112 canvas->drawColor(0xFFDDDDDD);
113 }
114
115 virtual void onDraw(SkCanvas* canvas) {
116 this->drawBG(canvas);
117
118 canvas->scale(3, 3);
119 canvas->translate(10, 30);
120 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
121 canvas->drawPath(fPath, fPaint[i]);
122 canvas->translate(32, 0);
123 }
124 }
125
126private:
127 typedef SkView INHERITED;
128};
129
130///////////////////////////////////////////////////////////////////////////////
131
132static SkView* MyFactory() { return new EffectsView; }
133static SkViewRegister reg(MyFactory);
134