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 "include/core/SkCanvas.h"
8 #include "include/core/SkPaint.h"
9 #include "include/effects/SkColorMatrixFilter.h"
10 #include "include/effects/SkDiscretePathEffect.h"
11 #include "include/effects/SkGradientShader.h"
12 #include "samplecode/Sample.h"
13 #include "src/core/SkBlurMask.h"
14 #include "src/effects/SkEmbossMaskFilter.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 SkTileMode::kMirror));
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:
name()93 virtual SkString name() { return SkString("Effects"); }
94
onDrawContent(SkCanvas * canvas)95 virtual void onDrawContent(SkCanvas* canvas) {
96 canvas->scale(3, 3);
97 canvas->translate(10, 30);
98 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
99 canvas->drawPath(fPath, fPaint[i]);
100 canvas->translate(32, 0);
101 }
102 }
103
104 private:
105 typedef Sample INHERITED;
106 };
107
108 ///////////////////////////////////////////////////////////////////////////////
109
110 DEF_SAMPLE( return new EffectsView(); )
111