blob: 507f72722846bf20e46d0b173a249a7c01f5a2cc [file] [log] [blame]
reed@android.comba974cc2009-05-22 13:48:35 +00001#include "SampleCode.h"
2#include "SkCanvas.h"
3#include "SkPaint.h"
4#include "SkPorterDuff.h"
5#include "SkView.h"
6
7#include "SkBlurMaskFilter.h"
8#include "SkColorMatrixFilter.h"
9#include "SkDiscretePathEffect.h"
10#include "SkGradientShader.h"
11
12//#define COLOR 0xFFFF8844
13#define COLOR 0xFF888888
14
15static void paint_proc0(SkPaint* paint) {
16}
17
18static void paint_proc1(SkPaint* paint) {
19 paint->setMaskFilter(SkBlurMaskFilter::Create(2,
20 SkBlurMaskFilter::kNormal_BlurStyle))->unref();
21}
22
23static void paint_proc2(SkPaint* paint) {
24 SkScalar dir[3] = { 1, 1, 1};
25 paint->setMaskFilter(
26 SkBlurMaskFilter::CreateEmboss(dir, 0.1, 0.05, 1))->unref();
27}
28
29static void paint_proc3(SkPaint* paint) {
30 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
31 SkPoint pts[] = { 3, 0, 7, 5 };
32 paint->setShader(SkGradientShader::CreateLinear(pts, colors, NULL, SK_ARRAY_COUNT(colors),
33 SkShader::kMirror_TileMode))->unref();
34}
35
36static void paint_proc5(SkPaint* paint) {
37 paint_proc3(paint);
38 paint_proc2(paint);
39}
40
41typedef void (*PaintProc)(SkPaint*);
42const PaintProc gPaintProcs[] = {
43 paint_proc0,
44 paint_proc1,
45 paint_proc2,
46 paint_proc3,
47 paint_proc5,
48};
49
50///////////////////////////////////////////////////////////////////////////////
51
52class EffectsView : public SkView {
53public:
54 SkPath fPath;
55 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
56
57 EffectsView() {
58 size_t i;
59 const float pts[] = {
60 0, 0,
61 10, 0,
62 10, 5,
63 20, -5,
64 10, -15,
65 10, -10,
66 0, -10
67 };
68 fPath.moveTo(pts[0], pts[1]);
69 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
70 fPath.lineTo(pts[i], pts[i+1]);
71 }
72
73 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
74 fPaint[i].setAntiAlias(true);
75 fPaint[i].setColor(COLOR);
76 gPaintProcs[i](&fPaint[i]);
77 }
78 }
79
80protected:
81 // overrides from SkEventSink
82 virtual bool onQuery(SkEvent* evt) {
83 if (SampleCode::TitleQ(*evt)) {
84 SampleCode::TitleR(evt, "Effects");
85 return true;
86 }
87 return this->INHERITED::onQuery(evt);
88 }
89
90 void drawBG(SkCanvas* canvas) {
91 canvas->drawColor(0xFFDDDDDD);
92 }
93
94 virtual void onDraw(SkCanvas* canvas) {
95 this->drawBG(canvas);
96
97 canvas->scale(3, 3);
98 canvas->translate(10, 30);
99 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
100 canvas->drawPath(fPath, fPaint[i]);
101 canvas->translate(32, 0);
102 }
103 }
104
105private:
106 typedef SkView INHERITED;
107};
108
109///////////////////////////////////////////////////////////////////////////////
110
111static SkView* MyFactory() { return new EffectsView; }
112static SkViewRegister reg(MyFactory);
113