epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkPath.h" |
| 13 | #include "SkRegion.h" |
| 14 | #include "SkShader.h" |
| 15 | #include "SkUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkColorPriv.h" |
| 17 | #include "SkColorFilter.h" |
| 18 | #include "SkTypeface.h" |
| 19 | #include "SkAvoidXfermode.h" |
| 20 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 21 | static inline SkPMColor rgb2gray(SkPMColor c) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | unsigned r = SkGetPackedR32(c); |
| 23 | unsigned g = SkGetPackedG32(c); |
| 24 | unsigned b = SkGetPackedB32(c); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 25 | |
reed@google.com | 261b8e2 | 2011-04-14 17:53:24 +0000 | [diff] [blame] | 26 | unsigned x = (r * 5 + g * 7 + b * 4) >> 4; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 27 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | return SkPackARGB32(0, x, x, x) | (c & (SK_A32_MASK << SK_A32_SHIFT)); |
| 29 | } |
| 30 | |
| 31 | class SkGrayScaleColorFilter : public SkColorFilter { |
| 32 | public: |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 33 | virtual void filterSpan(const SkPMColor src[], int count, |
| 34 | SkPMColor result[]) { |
| 35 | for (int i = 0; i < count; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 36 | result[i] = rgb2gray(src[i]); |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 37 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | } |
| 39 | }; |
| 40 | |
| 41 | class SkChannelMaskColorFilter : public SkColorFilter { |
| 42 | public: |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 43 | SkChannelMaskColorFilter(U8CPU redMask, U8CPU greenMask, U8CPU blueMask) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | fMask = SkPackARGB32(0xFF, redMask, greenMask, blueMask); |
| 45 | } |
| 46 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 47 | virtual void filterSpan(const SkPMColor src[], int count, |
| 48 | SkPMColor result[]) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 49 | SkPMColor mask = fMask; |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 50 | for (int i = 0; i < count; i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 51 | result[i] = src[i] & mask; |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 52 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | private: |
| 56 | SkPMColor fMask; |
| 57 | }; |
| 58 | |
| 59 | /////////////////////////////////////////////////////////// |
| 60 | |
| 61 | #include "SkGradientShader.h" |
| 62 | #include "SkLayerRasterizer.h" |
| 63 | #include "SkBlurMaskFilter.h" |
| 64 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 65 | static void r0(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | p.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3), |
| 67 | SkBlurMaskFilter::kNormal_BlurStyle))->unref(); |
| 68 | rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
| 69 | |
| 70 | p.setMaskFilter(NULL); |
| 71 | p.setStyle(SkPaint::kStroke_Style); |
| 72 | p.setStrokeWidth(SK_Scalar1); |
| 73 | rast->addLayer(p); |
| 74 | |
| 75 | p.setAlpha(0x11); |
| 76 | p.setStyle(SkPaint::kFill_Style); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 77 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | rast->addLayer(p); |
| 79 | } |
| 80 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 81 | static void r1(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 82 | rast->addLayer(p); |
| 83 | |
| 84 | p.setAlpha(0x40); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 85 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 86 | p.setStyle(SkPaint::kStroke_Style); |
| 87 | p.setStrokeWidth(SK_Scalar1*2); |
| 88 | rast->addLayer(p); |
| 89 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 90 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 91 | static void r2(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 93 | p.setStrokeWidth(SK_Scalar1*4); |
| 94 | rast->addLayer(p); |
| 95 | |
| 96 | p.setStyle(SkPaint::kStroke_Style); |
| 97 | p.setStrokeWidth(SK_Scalar1*3/2); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 98 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 99 | rast->addLayer(p); |
| 100 | } |
| 101 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 102 | static void r3(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | p.setStyle(SkPaint::kStroke_Style); |
| 104 | p.setStrokeWidth(SK_Scalar1*3); |
| 105 | rast->addLayer(p); |
| 106 | |
| 107 | p.setAlpha(0x20); |
| 108 | p.setStyle(SkPaint::kFill_Style); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 109 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 110 | rast->addLayer(p); |
| 111 | } |
| 112 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 113 | static void r4(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | p.setAlpha(0x60); |
| 115 | rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
| 116 | |
| 117 | p.setAlpha(0xFF); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 118 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 119 | rast->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); |
| 120 | |
| 121 | p.setXfermode(NULL); |
| 122 | rast->addLayer(p); |
| 123 | } |
| 124 | |
| 125 | #include "SkDiscretePathEffect.h" |
| 126 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 127 | static void r5(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 128 | rast->addLayer(p); |
| 129 | |
| 130 | p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref(); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 131 | p.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 132 | rast->addLayer(p); |
| 133 | } |
| 134 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 135 | static void r6(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 136 | rast->addLayer(p); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 137 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 138 | p.setAntiAlias(false); |
| 139 | SkLayerRasterizer* rast2 = new SkLayerRasterizer; |
| 140 | r5(rast2, p); |
| 141 | p.setRasterizer(rast2)->unref(); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 142 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | rast->addLayer(p); |
| 144 | } |
| 145 | |
| 146 | #include "Sk2DPathEffect.h" |
| 147 | |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 148 | static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) { |
| 149 | SkPath path; |
| 150 | path.addCircle(0, 0, radius); |
| 151 | return new SkPath2DPathEffect(matrix, path); |
| 152 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 154 | static void r7(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 155 | SkMatrix lattice; |
| 156 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 157 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 158 | p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 159 | rast->addLayer(p); |
| 160 | } |
| 161 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 162 | static void r8(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 163 | rast->addLayer(p); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 164 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 165 | SkMatrix lattice; |
| 166 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 167 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 168 | p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref(); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 169 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 170 | rast->addLayer(p); |
| 171 | |
| 172 | p.setPathEffect(NULL); |
| 173 | p.setXfermode(NULL); |
| 174 | p.setStyle(SkPaint::kStroke_Style); |
| 175 | p.setStrokeWidth(SK_Scalar1); |
| 176 | rast->addLayer(p); |
| 177 | } |
| 178 | |
| 179 | class Line2DPathEffect : public Sk2DPathEffect { |
| 180 | public: |
| 181 | Line2DPathEffect(SkScalar width, const SkMatrix& matrix) |
| 182 | : Sk2DPathEffect(matrix), fWidth(width) {} |
| 183 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 184 | virtual bool filterPath(SkPath* dst, const SkPath& src, SkScalar* width) { |
| 185 | if (this->INHERITED::filterPath(dst, src, width)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | *width = fWidth; |
| 187 | return true; |
| 188 | } |
| 189 | return false; |
| 190 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 191 | |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 192 | SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Line2DPathEffect) |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 193 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 194 | protected: |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 195 | virtual void nextSpan(int u, int v, int ucount, SkPath* dst) { |
| 196 | if (ucount > 1) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 197 | SkPoint src[2], dstP[2]; |
| 198 | |
| 199 | src[0].set(SkIntToScalar(u) + SK_ScalarHalf, |
| 200 | SkIntToScalar(v) + SK_ScalarHalf); |
| 201 | src[1].set(SkIntToScalar(u+ucount) + SK_ScalarHalf, |
| 202 | SkIntToScalar(v) + SK_ScalarHalf); |
| 203 | this->getMatrix().mapPoints(dstP, src, 2); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 204 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 205 | dst->moveTo(dstP[0]); |
| 206 | dst->lineTo(dstP[1]); |
| 207 | } |
| 208 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 209 | |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 210 | Line2DPathEffect(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | fWidth = buffer.readScalar(); |
| 212 | } |
djsollen@google.com | 5492424 | 2012-03-29 15:18:04 +0000 | [diff] [blame] | 213 | virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE { |
| 214 | this->INHERITED::flatten(buffer); |
| 215 | buffer.writeScalar(fWidth); |
| 216 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 217 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 218 | private: |
| 219 | SkScalar fWidth; |
| 220 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 221 | typedef Sk2DPathEffect INHERITED; |
| 222 | }; |
| 223 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 224 | static void r9(SkLayerRasterizer* rast, SkPaint& p) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 225 | rast->addLayer(p); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 226 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 227 | SkMatrix lattice; |
| 228 | lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
| 229 | lattice.postRotate(SkIntToScalar(30), 0, 0); |
| 230 | p.setPathEffect(new Line2DPathEffect(SK_Scalar1*2, lattice))->unref(); |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 231 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 232 | rast->addLayer(p); |
| 233 | |
| 234 | p.setPathEffect(NULL); |
| 235 | p.setXfermode(NULL); |
| 236 | p.setStyle(SkPaint::kStroke_Style); |
| 237 | p.setStrokeWidth(SK_Scalar1); |
| 238 | rast->addLayer(p); |
| 239 | } |
| 240 | |
| 241 | typedef void (*raster_proc)(SkLayerRasterizer*, SkPaint&); |
| 242 | |
| 243 | static const raster_proc gRastProcs[] = { |
| 244 | r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 |
| 245 | }; |
| 246 | |
| 247 | static const struct { |
| 248 | SkColor fMul, fAdd; |
| 249 | } gLightingColors[] = { |
| 250 | { 0x808080, 0x800000 }, // general case |
| 251 | { 0x707070, 0x707070 }, // no-pin case |
| 252 | { 0xFFFFFF, 0x800000 }, // just-add case |
| 253 | { 0x808080, 0x000000 }, // just-mul case |
| 254 | { 0xFFFFFF, 0x000000 } // identity case |
| 255 | }; |
| 256 | |
| 257 | #include "SkXfermode.h" |
| 258 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 259 | static void apply_shader(SkPaint* paint, int index) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 260 | raster_proc proc = gRastProcs[index]; |
| 261 | if (proc) |
| 262 | { |
| 263 | SkPaint p; |
| 264 | SkLayerRasterizer* rast = new SkLayerRasterizer; |
| 265 | |
| 266 | p.setAntiAlias(true); |
| 267 | proc(rast, p); |
| 268 | paint->setRasterizer(rast)->unref(); |
| 269 | } |
| 270 | |
| 271 | #if 0 |
| 272 | SkScalar dir[] = { SK_Scalar1, SK_Scalar1, SK_Scalar1 }; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 273 | paint->setMaskFilter(SkBlurMaskFilter::CreateEmboss(dir, SK_Scalar1/4, SkIntToScalar(4), SkIntToScalar(3)))->unref(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 274 | #endif |
| 275 | paint->setColor(SK_ColorBLUE); |
| 276 | } |
| 277 | |
| 278 | static int gRastIndex; |
| 279 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 280 | class TextEffectView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 281 | SkTypeface* fFace; |
| 282 | public: |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 283 | TextEffectView() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 284 | fFace = SkTypeface::CreateFromFile("/Users/reed/Downloads/p052024l.pfb"); |
| 285 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 286 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 287 | virtual ~TextEffectView() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 288 | SkSafeUnref(fFace); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | protected: |
| 292 | // overrides from SkEventSink |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 293 | virtual bool onQuery(SkEvent* evt) { |
| 294 | if (SampleCode::TitleQ(*evt)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 295 | SampleCode::TitleR(evt, "Text Effects"); |
| 296 | return true; |
| 297 | } |
| 298 | return this->INHERITED::onQuery(evt); |
| 299 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 300 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 301 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 302 | canvas->save(); |
| 303 | // canvas->scale(SK_Scalar1*2, SK_Scalar1*2, 0, 0); |
| 304 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 305 | SkPaint paint; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 306 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 307 | paint.setAntiAlias(true); |
reed@android.com | 0bb6d06 | 2010-05-17 14:50:04 +0000 | [diff] [blame] | 308 | paint.setTextSize(SkIntToScalar(56)); |
reed@android.com | 069b827 | 2009-03-04 15:31:48 +0000 | [diff] [blame] | 309 | paint.setTypeface(SkTypeface::CreateFromName("sans-serif", |
| 310 | SkTypeface::kBold)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 311 | |
reed@android.com | 0bb6d06 | 2010-05-17 14:50:04 +0000 | [diff] [blame] | 312 | SkScalar x = SkIntToScalar(20); |
| 313 | SkScalar y = paint.getTextSize(); |
| 314 | |
| 315 | SkString str("TextEffects"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 316 | |
| 317 | paint.setTypeface(fFace); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 318 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 319 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 320 | apply_shader(&paint, i); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 321 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | // paint.setMaskFilter(NULL); |
| 323 | // paint.setColor(SK_ColorBLACK); |
| 324 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 325 | #if 1 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 326 | int index = i % SK_ARRAY_COUNT(gLightingColors); |
| 327 | paint.setColorFilter(SkColorFilter::CreateLightingFilter( |
| 328 | gLightingColors[index].fMul, |
| 329 | gLightingColors[index].fAdd))->unref(); |
| 330 | #endif |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 331 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 332 | canvas->drawText(str.c_str(), str.size(), x, y, paint); |
| 333 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 334 | y += paint.getFontSpacing(); |
| 335 | } |
| 336 | |
| 337 | canvas->restore(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 339 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 340 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | gRastIndex = (gRastIndex + 1) % SK_ARRAY_COUNT(gRastProcs); |
| 342 | this->inval(NULL); |
| 343 | |
| 344 | return this->INHERITED::onFindClickHandler(x, y); |
| 345 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 346 | |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 347 | virtual bool onClick(Click* click) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 348 | return this->INHERITED::onClick(click); |
| 349 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 350 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 351 | private: |
reed@google.com | f218339 | 2011-04-22 14:10:48 +0000 | [diff] [blame] | 352 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | ////////////////////////////////////////////////////////////////////////////// |
| 356 | |
| 357 | static SkView* MyFactory() { return new TextEffectView; } |
| 358 | static SkViewRegister reg(MyFactory); |
| 359 | |