OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkBlurMaskFilter.h" | 11 #include "SkBlurMaskFilter.h" |
12 #include "SkCamera.h" | 12 #include "SkCamera.h" |
13 #include "SkColorFilter.h" | 13 #include "SkColorFilter.h" |
14 #include "SkColorPriv.h" | 14 #include "SkColorPriv.h" |
15 #include "SkDevice.h" | 15 #include "SkDevice.h" |
16 #include "SkGradientShader.h" | 16 #include "SkGradientShader.h" |
17 #include "SkImageDecoder.h" | 17 #include "SkImageDecoder.h" |
18 #include "SkInterpolator.h" | 18 #include "SkInterpolator.h" |
19 #include "SkMaskFilter.h" | 19 #include "SkMaskFilter.h" |
20 #include "SkPath.h" | 20 #include "SkPath.h" |
21 #include "SkRegion.h" | 21 #include "SkRegion.h" |
22 #include "SkShader.h" | 22 #include "SkShader.h" |
23 #include "SkTime.h" | 23 #include "SkTime.h" |
24 #include "SkTypeface.h" | 24 #include "SkTypeface.h" |
25 #include "SkUtils.h" | 25 #include "SkUtils.h" |
26 #include "SkKey.h" | 26 #include "SkKey.h" |
27 #include "SkXfermode.h" | 27 #include "SkXfermode.h" |
28 #include "SkDrawFilter.h" | 28 #include "SkDrawFilter.h" |
29 | 29 |
30 static void make_paint(SkPaint* paint) { | 30 static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) { |
31 SkColor colors[] = { 0, SK_ColorWHITE }; | 31 SkColor colors[] = { 0, SK_ColorWHITE }; |
32 SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } }; | 32 SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } }; |
33 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader:
:kClamp_TileMode); | 33 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader:
:kClamp_TileMode, |
| 34 NULL, 0, &localMatrix); |
34 | 35 |
35 paint->setShader(s)->unref(); | 36 paint->setShader(s)->unref(); |
36 paint->setXfermodeMode(SkXfermode::kDstIn_Mode); | 37 paint->setXfermodeMode(SkXfermode::kDstIn_Mode); |
37 } | 38 } |
38 | 39 |
39 static void dump_layers(const char label[], SkCanvas* canvas) { | 40 static void dump_layers(const char label[], SkCanvas* canvas) { |
40 SkDebugf("Dump Layers(%s)\n", label); | 41 SkDebugf("Dump Layers(%s)\n", label); |
41 | 42 |
42 SkCanvas::LayerIter iter(canvas, true); | 43 SkCanvas::LayerIter iter(canvas, true); |
43 int index = 0; | 44 int index = 0; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 p.setColor(SK_ColorRED); | 98 p.setColor(SK_ColorRED); |
98 p.setAntiAlias(true); | 99 p.setAntiAlias(true); |
99 canvas->drawOval(r, p); | 100 canvas->drawOval(r, p); |
100 } | 101 } |
101 | 102 |
102 // return; | 103 // return; |
103 | 104 |
104 dump_layers("outside layer alpha", canvas); | 105 dump_layers("outside layer alpha", canvas); |
105 | 106 |
106 // now apply an effect | 107 // now apply an effect |
| 108 SkMatrix m; |
| 109 m.setScale(SK_Scalar1, -SK_Scalar1); |
| 110 m.postTranslate(0, SkIntToScalar(100)); |
107 | 111 |
108 SkPaint paint; | 112 SkPaint paint; |
109 make_paint(&paint); | 113 make_paint(&paint, m); |
110 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(20)); | 114 r.set(0, 0, SkIntToScalar(100), SkIntToScalar(20)); |
111 // SkDebugf("--------- draw top grad\n"); | 115 // SkDebugf("--------- draw top grad\n"); |
112 canvas->drawRect(r, paint); | 116 canvas->drawRect(r, paint); |
113 | 117 |
114 SkMatrix m; | |
115 SkShader* s = paint.getShader(); | |
116 m.setScale(SK_Scalar1, -SK_Scalar1); | |
117 m.postTranslate(0, SkIntToScalar(100)); | |
118 s->setLocalMatrix(m); | |
119 | |
120 r.fTop = SkIntToScalar(80); | 118 r.fTop = SkIntToScalar(80); |
121 r.fBottom = SkIntToScalar(100); | 119 r.fBottom = SkIntToScalar(100); |
122 // SkDebugf("--------- draw bot grad\n"); | 120 // SkDebugf("--------- draw bot grad\n"); |
123 canvas->drawRect(r, paint); | 121 canvas->drawRect(r, paint); |
124 } | 122 } |
125 | 123 |
126 class RedFilter : public SkDrawFilter { | 124 class RedFilter : public SkDrawFilter { |
127 public: | 125 public: |
128 virtual bool filter(SkPaint* p, SkDrawFilter::Type) SK_OVERRIDE { | 126 virtual bool filter(SkPaint* p, SkDrawFilter::Type) SK_OVERRIDE { |
129 fColor = p->getColor(); | 127 fColor = p->getColor(); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 231 } |
234 | 232 |
235 private: | 233 private: |
236 typedef SkView INHERITED; | 234 typedef SkView INHERITED; |
237 }; | 235 }; |
238 | 236 |
239 ////////////////////////////////////////////////////////////////////////////// | 237 ////////////////////////////////////////////////////////////////////////////// |
240 | 238 |
241 static SkView* MyFactory() { return new LayersView; } | 239 static SkView* MyFactory() { return new LayersView; } |
242 static SkViewRegister reg(MyFactory); | 240 static SkViewRegister reg(MyFactory); |
OLD | NEW |