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