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 | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkDevice.h" |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 12 | #include "SkFlattenableBuffers.h" |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 13 | #include "SkPaint.h" |
| 14 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 15 | #define BG_COLOR 0xFFDDDDDD |
| 16 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 17 | typedef void (*SlideProc)(SkCanvas*); |
| 18 | |
| 19 | /////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | #include "Sk1DPathEffect.h" |
| 22 | #include "Sk2DPathEffect.h" |
| 23 | #include "SkCornerPathEffect.h" |
| 24 | #include "SkDashPathEffect.h" |
| 25 | #include "SkDiscretePathEffect.h" |
| 26 | |
| 27 | static void compose_pe(SkPaint* paint) { |
| 28 | SkPathEffect* pe = paint->getPathEffect(); |
| 29 | SkPathEffect* corner = new SkCornerPathEffect(25); |
| 30 | SkPathEffect* compose; |
| 31 | if (pe) { |
| 32 | compose = new SkComposePathEffect(pe, corner); |
| 33 | corner->unref(); |
| 34 | } else { |
| 35 | compose = corner; |
| 36 | } |
| 37 | paint->setPathEffect(compose)->unref(); |
| 38 | } |
| 39 | |
| 40 | static void hair_pe(SkPaint* paint) { |
| 41 | paint->setStrokeWidth(0); |
| 42 | } |
| 43 | |
| 44 | static void hair2_pe(SkPaint* paint) { |
| 45 | paint->setStrokeWidth(0); |
| 46 | compose_pe(paint); |
| 47 | } |
| 48 | |
| 49 | static void stroke_pe(SkPaint* paint) { |
| 50 | paint->setStrokeWidth(12); |
| 51 | compose_pe(paint); |
| 52 | } |
| 53 | |
| 54 | static void dash_pe(SkPaint* paint) { |
| 55 | SkScalar inter[] = { 20, 10, 10, 10 }; |
| 56 | paint->setStrokeWidth(12); |
| 57 | paint->setPathEffect(new SkDashPathEffect(inter, SK_ARRAY_COUNT(inter), |
| 58 | 0))->unref(); |
| 59 | compose_pe(paint); |
| 60 | } |
| 61 | |
| 62 | static const int gXY[] = { |
| 63 | 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
| 64 | }; |
| 65 | |
| 66 | static void scale(SkPath* path, SkScalar scale) { |
| 67 | SkMatrix m; |
| 68 | m.setScale(scale, scale); |
| 69 | path->transform(m); |
| 70 | } |
| 71 | |
| 72 | static void one_d_pe(SkPaint* paint) { |
| 73 | SkPath path; |
| 74 | path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
| 75 | for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
| 76 | path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1])); |
| 77 | path.close(); |
| 78 | path.offset(SkIntToScalar(-6), 0); |
robertphillips@google.com | c6ce750 | 2012-05-08 13:15:37 +0000 | [diff] [blame] | 79 | scale(&path, SkFloatToScalar(1.5f)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 80 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 81 | paint->setPathEffect(new SkPath1DPathEffect(path, SkIntToScalar(21), 0, |
| 82 | SkPath1DPathEffect::kRotate_Style))->unref(); |
| 83 | compose_pe(paint); |
| 84 | } |
| 85 | |
| 86 | typedef void (*PE_Proc)(SkPaint*); |
| 87 | static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe }; |
| 88 | |
| 89 | static void fill_pe(SkPaint* paint) { |
| 90 | paint->setStyle(SkPaint::kFill_Style); |
| 91 | paint->setPathEffect(NULL); |
| 92 | } |
| 93 | |
| 94 | static void discrete_pe(SkPaint* paint) { |
| 95 | paint->setPathEffect(new SkDiscretePathEffect(10, 4))->unref(); |
| 96 | } |
| 97 | |
reed@google.com | 43e9f20 | 2011-08-09 19:01:50 +0000 | [diff] [blame] | 98 | static SkPathEffect* MakeTileEffect() { |
| 99 | SkMatrix m; |
| 100 | m.setScale(SkIntToScalar(12), SkIntToScalar(12)); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 101 | |
reed@google.com | 43e9f20 | 2011-08-09 19:01:50 +0000 | [diff] [blame] | 102 | SkPath path; |
| 103 | path.addCircle(0, 0, SkIntToScalar(5)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 104 | |
reed@google.com | 43e9f20 | 2011-08-09 19:01:50 +0000 | [diff] [blame] | 105 | return new SkPath2DPathEffect(m, path); |
| 106 | } |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 107 | |
| 108 | static void tile_pe(SkPaint* paint) { |
reed@google.com | 43e9f20 | 2011-08-09 19:01:50 +0000 | [diff] [blame] | 109 | paint->setPathEffect(MakeTileEffect())->unref(); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe }; |
| 113 | |
| 114 | static void patheffect_slide(SkCanvas* canvas) { |
| 115 | SkPaint paint; |
| 116 | paint.setAntiAlias(true); |
| 117 | paint.setStyle(SkPaint::kStroke_Style); |
| 118 | |
| 119 | SkPath path; |
| 120 | path.moveTo(20, 20); |
| 121 | path.lineTo(70, 120); |
| 122 | path.lineTo(120, 30); |
| 123 | path.lineTo(170, 80); |
| 124 | path.lineTo(240, 50); |
| 125 | |
| 126 | size_t i; |
| 127 | canvas->save(); |
| 128 | for (i = 0; i < SK_ARRAY_COUNT(gPE); i++) { |
| 129 | gPE[i](&paint); |
| 130 | canvas->drawPath(path, paint); |
| 131 | canvas->translate(0, 75); |
| 132 | } |
| 133 | canvas->restore(); |
| 134 | |
| 135 | path.reset(); |
| 136 | SkRect r = { 0, 0, 250, 120 }; |
| 137 | path.addOval(r, SkPath::kCW_Direction); |
| 138 | r.inset(50, 50); |
| 139 | path.addRect(r, SkPath::kCCW_Direction); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 140 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 141 | canvas->translate(320, 20); |
| 142 | for (i = 0; i < SK_ARRAY_COUNT(gPE2); i++) { |
| 143 | gPE2[i](&paint); |
| 144 | canvas->drawPath(path, paint); |
| 145 | canvas->translate(0, 160); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /////////////////////////////////////////////////////////////////////////////// |
| 150 | |
| 151 | #include "SkGradientShader.h" |
| 152 | |
| 153 | struct GradData { |
| 154 | int fCount; |
| 155 | const SkColor* fColors; |
| 156 | const SkScalar* fPos; |
| 157 | }; |
| 158 | |
| 159 | static const SkColor gColors[] = { |
| 160 | SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK |
| 161 | }; |
| 162 | static const SkScalar gPos0[] = { 0, SK_Scalar1 }; |
| 163 | static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; |
| 164 | static const SkScalar gPos2[] = { |
| 165 | 0, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1 |
| 166 | }; |
| 167 | |
| 168 | static const GradData gGradData[] = { |
| 169 | { 2, gColors, NULL }, |
| 170 | { 2, gColors, gPos0 }, |
| 171 | { 2, gColors, gPos1 }, |
| 172 | { 5, gColors, NULL }, |
| 173 | { 5, gColors, gPos2 } |
| 174 | }; |
| 175 | |
| 176 | static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
| 177 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 178 | return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
| 179 | data.fCount, tm, mapper); |
| 180 | } |
| 181 | |
| 182 | static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
| 183 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 184 | SkPoint center; |
| 185 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 186 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 187 | return SkGradientShader::CreateRadial(center, center.fX, data.fColors, |
| 188 | data.fPos, data.fCount, tm, mapper); |
| 189 | } |
| 190 | |
| 191 | static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
| 192 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 193 | SkPoint center; |
| 194 | center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 195 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 196 | return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
| 197 | data.fPos, data.fCount, mapper); |
| 198 | } |
| 199 | |
| 200 | static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, |
| 201 | SkShader::TileMode tm, SkUnitMapper* mapper) { |
| 202 | SkPoint center0, center1; |
| 203 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 204 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 205 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 206 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 207 | return SkGradientShader::CreateTwoPointRadial( |
| 208 | center1, (pts[1].fX - pts[0].fX) / 7, |
| 209 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 210 | data.fColors, data.fPos, data.fCount, tm, mapper); |
| 211 | } |
| 212 | |
| 213 | typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
| 214 | SkShader::TileMode tm, SkUnitMapper* mapper); |
| 215 | static const GradMaker gGradMakers[] = { |
| 216 | MakeLinear, MakeRadial, MakeSweep, Make2Radial |
| 217 | }; |
| 218 | |
| 219 | static void gradient_slide(SkCanvas* canvas) { |
| 220 | SkPoint pts[2] = { |
| 221 | { 0, 0 }, |
| 222 | { SkIntToScalar(100), SkIntToScalar(100) } |
| 223 | }; |
| 224 | SkShader::TileMode tm = SkShader::kClamp_TileMode; |
| 225 | SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; |
| 226 | SkPaint paint; |
| 227 | paint.setAntiAlias(true); |
| 228 | paint.setDither(true); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 229 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 230 | canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); |
| 231 | for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { |
| 232 | canvas->save(); |
| 233 | for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { |
| 234 | SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL); |
| 235 | paint.setShader(shader); |
| 236 | canvas->drawRect(r, paint); |
| 237 | shader->unref(); |
| 238 | canvas->translate(0, SkIntToScalar(120)); |
| 239 | } |
| 240 | canvas->restore(); |
| 241 | canvas->translate(SkIntToScalar(120), 0); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /////////////////////////////////////////////////////////////////////////////// |
| 246 | |
| 247 | #include "SkPathMeasure.h" |
| 248 | |
| 249 | static SkScalar getpathlen(const SkPath& path) { |
| 250 | SkPathMeasure meas(path, false); |
| 251 | return meas.getLength(); |
| 252 | } |
| 253 | |
| 254 | static void textonpath_slide(SkCanvas* canvas) { |
| 255 | const char* text = "Displacement"; |
| 256 | size_t len =strlen(text); |
| 257 | SkPath path; |
| 258 | path.moveTo(100, 300); |
| 259 | path.quadTo(300, 100, 500, 300); |
| 260 | path.offset(0, -100); |
| 261 | |
| 262 | SkPaint paint; |
| 263 | paint.setAntiAlias(true); |
| 264 | paint.setTextSize(40); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 265 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 266 | paint.setStyle(SkPaint::kStroke_Style); |
| 267 | canvas->drawPath(path, paint); |
| 268 | paint.setStyle(SkPaint::kFill_Style); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 269 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 270 | SkScalar x = 50; |
| 271 | paint.setColor(0xFF008800); |
| 272 | canvas->drawTextOnPathHV(text, len, path, |
| 273 | x, paint.getTextSize()*2/3, paint); |
| 274 | paint.setColor(SK_ColorRED); |
| 275 | canvas->drawTextOnPathHV(text, len, path, |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 276 | x + 60, 0, paint); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 277 | paint.setColor(SK_ColorBLUE); |
| 278 | canvas->drawTextOnPathHV(text, len, path, |
| 279 | x + 120, -paint.getTextSize()*2/3, paint); |
| 280 | |
| 281 | path.offset(0, 200); |
| 282 | paint.setTextAlign(SkPaint::kRight_Align); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 283 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 284 | text = "Matrices"; |
| 285 | len = strlen(text); |
| 286 | SkScalar pathLen = getpathlen(path); |
| 287 | SkMatrix matrix; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 288 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 289 | paint.setColor(SK_ColorBLACK); |
| 290 | paint.setStyle(SkPaint::kStroke_Style); |
| 291 | canvas->drawPath(path, paint); |
| 292 | paint.setStyle(SkPaint::kFill_Style); |
| 293 | |
| 294 | paint.setTextSize(50); |
| 295 | canvas->drawTextOnPath(text, len, path, NULL, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 296 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 297 | paint.setColor(SK_ColorRED); |
| 298 | matrix.setScale(-SK_Scalar1, SK_Scalar1); |
| 299 | matrix.postTranslate(pathLen, 0); |
| 300 | canvas->drawTextOnPath(text, len, path, &matrix, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 301 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 302 | paint.setColor(SK_ColorBLUE); |
| 303 | matrix.setScale(SK_Scalar1, -SK_Scalar1); |
| 304 | canvas->drawTextOnPath(text, len, path, &matrix, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 305 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 306 | paint.setColor(0xFF008800); |
| 307 | matrix.setScale(-SK_Scalar1, -SK_Scalar1); |
| 308 | matrix.postTranslate(pathLen, 0); |
| 309 | canvas->drawTextOnPath(text, len, path, &matrix, paint); |
| 310 | } |
| 311 | |
| 312 | /////////////////////////////////////////////////////////////////////////////// |
| 313 | |
| 314 | #include "SkImageDecoder.h" |
| 315 | #include "SkOSFile.h" |
| 316 | #include "SkRandom.h" |
| 317 | #include "SkStream.h" |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 318 | |
| 319 | static SkShader* make_shader0(SkIPoint* size) { |
| 320 | SkBitmap bm; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 321 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 322 | SkImageDecoder::DecodeFile("/skimages/logo.gif", &bm); |
| 323 | size->set(bm.width(), bm.height()); |
| 324 | return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, |
| 325 | SkShader::kClamp_TileMode); |
| 326 | } |
| 327 | |
| 328 | static SkShader* make_shader1(const SkIPoint& size) { |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 329 | SkPoint pts[] = { { 0, 0 }, |
| 330 | { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 331 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }; |
| 332 | return SkGradientShader::CreateLinear(pts, colors, NULL, |
| 333 | SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode, NULL); |
| 334 | } |
| 335 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 336 | class Rec { |
| 337 | public: |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 338 | SkCanvas::VertexMode fMode; |
| 339 | int fCount; |
| 340 | SkPoint* fVerts; |
| 341 | SkPoint* fTexs; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 342 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 343 | Rec() : fCount(0), fVerts(NULL), fTexs(NULL) {} |
| 344 | ~Rec() { delete[] fVerts; delete[] fTexs; } |
| 345 | }; |
| 346 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 347 | static void make_tris(Rec* rec) { |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 348 | int n = 10; |
| 349 | SkRandom rand; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 350 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 351 | rec->fMode = SkCanvas::kTriangles_VertexMode; |
| 352 | rec->fCount = n * 3; |
| 353 | rec->fVerts = new SkPoint[rec->fCount]; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 354 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 355 | for (int i = 0; i < n; i++) { |
| 356 | SkPoint* v = &rec->fVerts[i*3]; |
| 357 | for (int j = 0; j < 3; j++) { |
| 358 | v[j].set(rand.nextUScalar1() * 250, rand.nextUScalar1() * 250); |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 363 | static void make_fan(Rec* rec, int texWidth, int texHeight) { |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 364 | const SkScalar tx = SkIntToScalar(texWidth); |
| 365 | const SkScalar ty = SkIntToScalar(texHeight); |
| 366 | const int n = 24; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 367 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 368 | rec->fMode = SkCanvas::kTriangleFan_VertexMode; |
| 369 | rec->fCount = n + 2; |
| 370 | rec->fVerts = new SkPoint[rec->fCount]; |
| 371 | rec->fTexs = new SkPoint[rec->fCount]; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 372 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 373 | SkPoint* v = rec->fVerts; |
| 374 | SkPoint* t = rec->fTexs; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 375 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 376 | v[0].set(0, 0); |
| 377 | t[0].set(0, 0); |
| 378 | for (int i = 0; i < n; i++) { |
| 379 | SkScalar cos; |
| 380 | SkScalar sin = SkScalarSinCos(SK_ScalarPI * 2 * i / n, &cos); |
| 381 | v[i+1].set(cos, sin); |
| 382 | t[i+1].set(i*tx/n, ty); |
| 383 | } |
| 384 | v[n+1] = v[1]; |
| 385 | t[n+1].set(tx, ty); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 386 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 387 | SkMatrix m; |
| 388 | m.setScale(SkIntToScalar(100), SkIntToScalar(100)); |
| 389 | m.postTranslate(SkIntToScalar(110), SkIntToScalar(110)); |
| 390 | m.mapPoints(v, rec->fCount); |
| 391 | } |
| 392 | |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 393 | static void make_strip(Rec* rec, int texWidth, int texHeight) { |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 394 | const SkScalar tx = SkIntToScalar(texWidth); |
| 395 | const SkScalar ty = SkIntToScalar(texHeight); |
| 396 | const int n = 24; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 397 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 398 | rec->fMode = SkCanvas::kTriangleStrip_VertexMode; |
| 399 | rec->fCount = 2 * (n + 1); |
| 400 | rec->fVerts = new SkPoint[rec->fCount]; |
| 401 | rec->fTexs = new SkPoint[rec->fCount]; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 402 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 403 | SkPoint* v = rec->fVerts; |
| 404 | SkPoint* t = rec->fTexs; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 405 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 406 | for (int i = 0; i < n; i++) { |
| 407 | SkScalar cos; |
| 408 | SkScalar sin = SkScalarSinCos(SK_ScalarPI * 2 * i / n, &cos); |
| 409 | v[i*2 + 0].set(cos/2, sin/2); |
| 410 | v[i*2 + 1].set(cos, sin); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 411 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 412 | t[i*2 + 0].set(tx * i / n, ty); |
| 413 | t[i*2 + 1].set(tx * i / n, 0); |
| 414 | } |
| 415 | v[2*n + 0] = v[0]; |
| 416 | v[2*n + 1] = v[1]; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 417 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 418 | t[2*n + 0].set(tx, ty); |
| 419 | t[2*n + 1].set(tx, 0); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 420 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 421 | SkMatrix m; |
| 422 | m.setScale(SkIntToScalar(100), SkIntToScalar(100)); |
| 423 | m.postTranslate(SkIntToScalar(110), SkIntToScalar(110)); |
| 424 | m.mapPoints(v, rec->fCount); |
| 425 | } |
| 426 | |
| 427 | static void mesh_slide(SkCanvas* canvas) { |
| 428 | Rec fRecs[3]; |
| 429 | SkIPoint size; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 430 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 431 | SkShader* fShader0 = make_shader0(&size); |
| 432 | SkShader* fShader1 = make_shader1(size); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 433 | |
| 434 | SkAutoUnref aur0(fShader0); |
| 435 | SkAutoUnref aur1(fShader1); |
| 436 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 437 | make_strip(&fRecs[0], size.fX, size.fY); |
| 438 | make_fan(&fRecs[1], size.fX, size.fY); |
| 439 | make_tris(&fRecs[2]); |
| 440 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 441 | SkPaint paint; |
| 442 | paint.setDither(true); |
| 443 | paint.setFilterBitmap(true); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 444 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 445 | for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) { |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 446 | canvas->save(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 447 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 448 | paint.setShader(NULL); |
| 449 | canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount, |
| 450 | fRecs[i].fVerts, fRecs[i].fTexs, |
| 451 | NULL, NULL, NULL, 0, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 452 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 453 | canvas->translate(SkIntToScalar(210), 0); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 454 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 455 | paint.setShader(fShader0); |
| 456 | canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount, |
| 457 | fRecs[i].fVerts, fRecs[i].fTexs, |
| 458 | NULL, NULL, NULL, 0, paint); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 459 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 460 | canvas->translate(SkIntToScalar(210), 0); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 461 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 462 | paint.setShader(fShader1); |
| 463 | canvas->drawVertices(fRecs[i].fMode, fRecs[i].fCount, |
| 464 | fRecs[i].fVerts, fRecs[i].fTexs, |
| 465 | NULL, NULL, NULL, 0, paint); |
| 466 | canvas->restore(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 467 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 468 | canvas->translate(0, SkIntToScalar(250)); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /////////////////////////////////////////////////////////////////////////////// |
| 473 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 474 | #include "SkGradientShader.h" |
| 475 | #include "SkLayerRasterizer.h" |
| 476 | #include "SkBlurMaskFilter.h" |
| 477 | |
| 478 | static void r0(SkLayerRasterizer* rast, SkPaint& p) |
| 479 | { |
| 480 | p.setMaskFilter(SkBlurMaskFilter::Create(SkIntToScalar(3), |
| 481 | SkBlurMaskFilter::kNormal_BlurStyle))->unref(); |
| 482 | rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 483 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 484 | p.setMaskFilter(NULL); |
| 485 | p.setStyle(SkPaint::kStroke_Style); |
| 486 | p.setStrokeWidth(SK_Scalar1); |
| 487 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 488 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 489 | p.setAlpha(0x11); |
| 490 | p.setStyle(SkPaint::kFill_Style); |
| 491 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 492 | rast->addLayer(p); |
| 493 | } |
| 494 | |
| 495 | static void r1(SkLayerRasterizer* rast, SkPaint& p) |
| 496 | { |
| 497 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 498 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 499 | p.setAlpha(0x40); |
| 500 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 501 | p.setStyle(SkPaint::kStroke_Style); |
| 502 | p.setStrokeWidth(SK_Scalar1*2); |
| 503 | rast->addLayer(p); |
| 504 | } |
| 505 | |
| 506 | static void r2(SkLayerRasterizer* rast, SkPaint& p) |
| 507 | { |
| 508 | p.setStyle(SkPaint::kStrokeAndFill_Style); |
| 509 | p.setStrokeWidth(SK_Scalar1*4); |
| 510 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 511 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 512 | p.setStyle(SkPaint::kStroke_Style); |
| 513 | p.setStrokeWidth(SK_Scalar1*3/2); |
| 514 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 515 | rast->addLayer(p); |
| 516 | } |
| 517 | |
| 518 | static void r3(SkLayerRasterizer* rast, SkPaint& p) |
| 519 | { |
| 520 | p.setStyle(SkPaint::kStroke_Style); |
| 521 | p.setStrokeWidth(SK_Scalar1*3); |
| 522 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 523 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 524 | p.setAlpha(0x20); |
| 525 | p.setStyle(SkPaint::kFill_Style); |
| 526 | p.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 527 | rast->addLayer(p); |
| 528 | } |
| 529 | |
| 530 | static void r4(SkLayerRasterizer* rast, SkPaint& p) |
| 531 | { |
| 532 | p.setAlpha(0x60); |
| 533 | rast->addLayer(p, SkIntToScalar(3), SkIntToScalar(3)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 534 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 535 | p.setAlpha(0xFF); |
| 536 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 537 | rast->addLayer(p, SK_Scalar1*3/2, SK_Scalar1*3/2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 538 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 539 | p.setXfermode(NULL); |
| 540 | rast->addLayer(p); |
| 541 | } |
| 542 | |
| 543 | #include "SkDiscretePathEffect.h" |
| 544 | |
| 545 | static void r5(SkLayerRasterizer* rast, SkPaint& p) |
| 546 | { |
| 547 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 548 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 549 | p.setPathEffect(new SkDiscretePathEffect(SK_Scalar1*4, SK_Scalar1*3))->unref(); |
| 550 | p.setXfermodeMode(SkXfermode::kSrcOut_Mode); |
| 551 | rast->addLayer(p); |
| 552 | } |
| 553 | |
| 554 | static void r6(SkLayerRasterizer* rast, SkPaint& p) |
| 555 | { |
| 556 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 557 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 558 | p.setAntiAlias(false); |
| 559 | SkLayerRasterizer* rast2 = new SkLayerRasterizer; |
| 560 | r5(rast2, p); |
| 561 | p.setRasterizer(rast2)->unref(); |
| 562 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 563 | rast->addLayer(p); |
| 564 | } |
| 565 | |
| 566 | #include "Sk2DPathEffect.h" |
| 567 | |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 568 | static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) { |
| 569 | SkPath path; |
| 570 | path.addCircle(0, 0, radius); |
| 571 | return new SkPath2DPathEffect(matrix, path); |
| 572 | } |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 573 | |
| 574 | static void r7(SkLayerRasterizer* rast, SkPaint& p) |
| 575 | { |
| 576 | SkMatrix lattice; |
| 577 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 578 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 579 | p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref(); |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 580 | rast->addLayer(p); |
| 581 | } |
| 582 | |
| 583 | static void r8(SkLayerRasterizer* rast, SkPaint& p) |
| 584 | { |
| 585 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 586 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 587 | SkMatrix lattice; |
| 588 | lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0); |
| 589 | lattice.postSkew(SK_Scalar1/3, 0, 0, 0); |
reed@google.com | 18dc477 | 2011-08-09 18:47:40 +0000 | [diff] [blame] | 590 | p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref(); |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 591 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 592 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 593 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 594 | p.setPathEffect(NULL); |
| 595 | p.setXfermode(NULL); |
| 596 | p.setStyle(SkPaint::kStroke_Style); |
| 597 | p.setStrokeWidth(SK_Scalar1); |
| 598 | rast->addLayer(p); |
| 599 | } |
| 600 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 601 | static void r9(SkLayerRasterizer* rast, SkPaint& p) |
| 602 | { |
| 603 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 604 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 605 | SkMatrix lattice; |
| 606 | lattice.setScale(SK_Scalar1, SK_Scalar1*6, 0, 0); |
| 607 | lattice.postRotate(SkIntToScalar(30), 0, 0); |
scroggo@google.com | d8a6cc8 | 2012-09-12 18:53:49 +0000 | [diff] [blame] | 608 | p.setPathEffect(new SkLine2DPathEffect(SK_Scalar1*2, lattice))->unref(); |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 609 | p.setXfermodeMode(SkXfermode::kClear_Mode); |
| 610 | rast->addLayer(p); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 611 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 612 | p.setPathEffect(NULL); |
| 613 | p.setXfermode(NULL); |
| 614 | p.setStyle(SkPaint::kStroke_Style); |
| 615 | p.setStrokeWidth(SK_Scalar1); |
| 616 | rast->addLayer(p); |
| 617 | } |
| 618 | |
| 619 | typedef void (*raster_proc)(SkLayerRasterizer*, SkPaint&); |
| 620 | |
| 621 | static const raster_proc gRastProcs[] = { |
| 622 | r0, r1, r2, r3, r4, r5, r6, r7, r8, r9 |
| 623 | }; |
| 624 | |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 625 | static void apply_shader(SkPaint* paint, int index) { |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 626 | raster_proc proc = gRastProcs[index]; |
| 627 | SkPaint p; |
| 628 | SkLayerRasterizer* rast = new SkLayerRasterizer; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 629 | |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 630 | p.setAntiAlias(true); |
| 631 | proc(rast, p); |
| 632 | paint->setRasterizer(rast)->unref(); |
| 633 | paint->setColor(SK_ColorBLUE); |
| 634 | } |
| 635 | |
| 636 | #include "SkTypeface.h" |
| 637 | |
| 638 | static void texteffect_slide(SkCanvas* canvas) { |
| 639 | const char* str = "Google"; |
| 640 | size_t len = strlen(str); |
| 641 | SkScalar x = 20; |
| 642 | SkScalar y = 80; |
| 643 | SkPaint paint; |
| 644 | paint.setTypeface(SkTypeface::CreateFromName("Georgia", SkTypeface::kItalic)); |
| 645 | paint.setTextSize(75); |
| 646 | paint.setAntiAlias(true); |
| 647 | paint.setColor(SK_ColorBLUE); |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 648 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRastProcs); i++) { |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 649 | apply_shader(&paint, i); |
| 650 | canvas->drawText(str, len, x, y, paint); |
| 651 | y += 80; |
| 652 | if (i == 4) { |
| 653 | x += 320; |
| 654 | y = 80; |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | /////////////////////////////////////////////////////////////////////////////// |
| 660 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 661 | #include "SkImageEncoder.h" |
| 662 | |
| 663 | static const SlideProc gProc[] = { |
| 664 | patheffect_slide, |
| 665 | gradient_slide, |
| 666 | textonpath_slide, |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 667 | mesh_slide, |
| 668 | texteffect_slide |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 669 | }; |
| 670 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 671 | class SlideView : public SampleView { |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 672 | int fIndex; |
reed@google.com | 7b18590 | 2012-03-12 21:13:48 +0000 | [diff] [blame] | 673 | bool fOnce; |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 674 | public: |
| 675 | SlideView() { |
reed@google.com | 7b18590 | 2012-03-12 21:13:48 +0000 | [diff] [blame] | 676 | fOnce = false; |
| 677 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 678 | |
reed@google.com | 7b18590 | 2012-03-12 21:13:48 +0000 | [diff] [blame] | 679 | void init() { |
| 680 | if (fOnce) { |
| 681 | return; |
| 682 | } |
| 683 | fOnce = true; |
| 684 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 685 | fIndex = 0; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 686 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 687 | SkBitmap bm; |
| 688 | bm.setConfig(SkBitmap::kARGB_8888_Config, 1024, 768); |
| 689 | bm.allocPixels(); |
| 690 | SkCanvas canvas(bm); |
| 691 | SkScalar s = SkIntToScalar(1024) / 640; |
| 692 | canvas.scale(s, s); |
| 693 | for (size_t i = 0; i < SK_ARRAY_COUNT(gProc); i++) { |
| 694 | canvas.save(); |
reed@android.com | 8af9602 | 2009-10-12 17:02:22 +0000 | [diff] [blame] | 695 | canvas.drawColor(BG_COLOR); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 696 | gProc[i](&canvas); |
| 697 | canvas.restore(); |
| 698 | SkString str; |
senorblanco@chromium.org | 3a67a66 | 2012-07-09 18:22:08 +0000 | [diff] [blame] | 699 | str.printf("/skimages/slide_" SK_SIZE_T_SPECIFIER ".png", i); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 700 | SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type, 100); |
| 701 | } |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 702 | this->setBGColor(BG_COLOR); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 703 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 704 | |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 705 | protected: |
| 706 | // overrides from SkEventSink |
| 707 | virtual bool onQuery(SkEvent* evt) { |
| 708 | if (SampleCode::TitleQ(*evt)) { |
| 709 | SampleCode::TitleR(evt, "Slides"); |
| 710 | return true; |
| 711 | } |
| 712 | return this->INHERITED::onQuery(evt); |
| 713 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 714 | |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 715 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@google.com | 7b18590 | 2012-03-12 21:13:48 +0000 | [diff] [blame] | 716 | this->init(); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 717 | gProc[fIndex](canvas); |
| 718 | } |
| 719 | |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 720 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE { |
reed@google.com | 7b18590 | 2012-03-12 21:13:48 +0000 | [diff] [blame] | 721 | this->init(); |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 722 | fIndex = (fIndex + 1) % SK_ARRAY_COUNT(gProc); |
| 723 | this->inval(NULL); |
| 724 | return NULL; |
| 725 | } |
| 726 | |
| 727 | private: |
reed@google.com | 81e3d7f | 2011-06-01 12:42:36 +0000 | [diff] [blame] | 728 | typedef SampleView INHERITED; |
reed@android.com | 63e34c6 | 2009-10-06 21:19:18 +0000 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | ////////////////////////////////////////////////////////////////////////////// |
| 732 | |
| 733 | static SkView* MyFactory() { return new SlideView; } |
| 734 | static SkViewRegister reg(MyFactory); |