1 /*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SampleCode.h"
8 #include "SkBlurMask.h"
9 #include "SkBlurMaskFilter.h"
10 #include "SkCanvas.h"
11 #include "SkColorMatrixFilter.h"
12 #include "SkDiscretePathEffect.h"
13 #include "SkGradientShader.h"
14 #include "SkPaint.h"
15 #include "SkView.h"
16
17
18 //#define COLOR 0xFFFF8844
19 #define COLOR 0xFF888888
20
paint_proc0(SkPaint *)21 static void paint_proc0(SkPaint*) {
22 }
23
paint_proc1(SkPaint * paint)24 static void paint_proc1(SkPaint* paint) {
25 paint->setMaskFilter(SkBlurMaskFilter::Make(
26 kNormal_SkBlurStyle,
27 SkBlurMask::ConvertRadiusToSigma(2)));
28 }
29
paint_proc2(SkPaint * paint)30 static void paint_proc2(SkPaint* paint) {
31 #ifdef SK_SUPPORT_LEGACY_EMBOSSMASKFILTER
32 SkScalar dir[3] = { 1, 1, 1};
33 paint->setMaskFilter(
34 SkBlurMaskFilter::MakeEmboss(SkBlurMask::ConvertRadiusToSigma(1), dir, 0.1f, 0.05f));
35 #endif
36 }
37
paint_proc3(SkPaint * paint)38 static void paint_proc3(SkPaint* paint) {
39 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
40 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
41 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
42 SkShader::kMirror_TileMode));
43 }
44
paint_proc5(SkPaint * paint)45 static void paint_proc5(SkPaint* paint) {
46 paint_proc3(paint);
47 paint_proc2(paint);
48 }
49
50 typedef void (*PaintProc)(SkPaint*);
51 const PaintProc gPaintProcs[] = {
52 paint_proc0,
53 paint_proc1,
54 paint_proc2,
55 paint_proc3,
56 paint_proc5,
57 };
58
59 ///////////////////////////////////////////////////////////////////////////////
60
61 class EffectsView : public SampleView {
62 public:
63 SkPath fPath;
64 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
65
EffectsView()66 EffectsView() {
67 size_t i;
68 const float pts[] = {
69 0, 0,
70 10, 0,
71 10, 5,
72 20, -5,
73 10, -15,
74 10, -10,
75 0, -10
76 };
77 fPath.moveTo(pts[0], pts[1]);
78 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
79 fPath.lineTo(pts[i], pts[i+1]);
80 }
81
82 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
83 fPaint[i].setAntiAlias(true);
84 fPaint[i].setColor(COLOR);
85 gPaintProcs[i](&fPaint[i]);
86 }
87
88 SkColorMatrix cm;
89 cm.setRotate(SkColorMatrix::kG_Axis, 180);
90 cm.setIdentity();
91
92 this->setBGColor(0xFFDDDDDD);
93 }
94
95 protected:
96 // overrides from SkEventSink
onQuery(SkEvent * evt)97 virtual bool onQuery(SkEvent* evt) {
98 if (SampleCode::TitleQ(*evt)) {
99 SampleCode::TitleR(evt, "Effects");
100 return true;
101 }
102 return this->INHERITED::onQuery(evt);
103 }
104
onDrawContent(SkCanvas * canvas)105 virtual void onDrawContent(SkCanvas* canvas) {
106 canvas->scale(3, 3);
107 canvas->translate(10, 30);
108 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
109 canvas->drawPath(fPath, fPaint[i]);
110 canvas->translate(32, 0);
111 }
112 }
113
114 private:
115 typedef SampleView INHERITED;
116 };
117
118 ///////////////////////////////////////////////////////////////////////////////
119
MyFactory()120 static SkView* MyFactory() { return new EffectsView; }
121 static SkViewRegister reg(MyFactory);
122