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 "Sample.h"
8 #include "SkBlurMask.h"
9 #include "SkCanvas.h"
10 #include "SkColorMatrixFilter.h"
11 #include "SkDiscretePathEffect.h"
12 #include "SkEmbossMaskFilter.h"
13 #include "SkGradientShader.h"
14 #include "SkPaint.h"
15
16
17 //#define COLOR 0xFFFF8844
18 #define COLOR 0xFF888888
19
paint_proc0(SkPaint *)20 static void paint_proc0(SkPaint*) {
21 }
22
paint_proc1(SkPaint * paint)23 static void paint_proc1(SkPaint* paint) {
24 paint->setMaskFilter(SkMaskFilter::MakeBlur(
25 kNormal_SkBlurStyle,
26 SkBlurMask::ConvertRadiusToSigma(2)));
27 }
28
paint_proc2(SkPaint * paint)29 static void paint_proc2(SkPaint* paint) {
30 paint->setMaskFilter(SkEmbossMaskFilter::Make(
31 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
32 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
33 }
34
paint_proc3(SkPaint * paint)35 static void paint_proc3(SkPaint* paint) {
36 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
37 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
38 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
39 SkShader::kMirror_TileMode));
40 }
41
paint_proc5(SkPaint * paint)42 static void paint_proc5(SkPaint* paint) {
43 paint_proc3(paint);
44 paint_proc2(paint);
45 }
46
47 typedef void (*PaintProc)(SkPaint*);
48 const PaintProc gPaintProcs[] = {
49 paint_proc0,
50 paint_proc1,
51 paint_proc2,
52 paint_proc3,
53 paint_proc5,
54 };
55
56 ///////////////////////////////////////////////////////////////////////////////
57
58 class EffectsView : public Sample {
59 public:
60 SkPath fPath;
61 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
62
EffectsView()63 EffectsView() {
64 size_t i;
65 const float pts[] = {
66 0, 0,
67 10, 0,
68 10, 5,
69 20, -5,
70 10, -15,
71 10, -10,
72 0, -10
73 };
74 fPath.moveTo(pts[0], pts[1]);
75 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
76 fPath.lineTo(pts[i], pts[i+1]);
77 }
78
79 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
80 fPaint[i].setAntiAlias(true);
81 fPaint[i].setColor(COLOR);
82 gPaintProcs[i](&fPaint[i]);
83 }
84
85 SkColorMatrix cm;
86 cm.setRotate(SkColorMatrix::kG_Axis, 180);
87 cm.setIdentity();
88
89 this->setBGColor(0xFFDDDDDD);
90 }
91
92 protected:
onQuery(Sample::Event * evt)93 virtual bool onQuery(Sample::Event* evt) {
94 if (Sample::TitleQ(*evt)) {
95 Sample::TitleR(evt, "Effects");
96 return true;
97 }
98 return this->INHERITED::onQuery(evt);
99 }
100
onDrawContent(SkCanvas * canvas)101 virtual void onDrawContent(SkCanvas* canvas) {
102 canvas->scale(3, 3);
103 canvas->translate(10, 30);
104 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
105 canvas->drawPath(fPath, fPaint[i]);
106 canvas->translate(32, 0);
107 }
108 }
109
110 private:
111 typedef Sample INHERITED;
112 };
113
114 ///////////////////////////////////////////////////////////////////////////////
115
116 DEF_SAMPLE( return new EffectsView(); )
117