| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 SkImageDecoder::DecodeFile("/skimages/logo.png", &bm); | 35 SkImageDecoder::DecodeFile("/skimages/logo.png", &bm); |
| 36 size->set(bm.width(), bm.height()); | 36 size->set(bm.width(), bm.height()); |
| 37 return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, | 37 return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, |
| 38 SkShader::kClamp_TileMode); | 38 SkShader::kClamp_TileMode); |
| 39 } | 39 } |
| 40 | 40 |
| 41 static SkShader* make_shader1(const SkIPoint& size) { | 41 static SkShader* make_shader1(const SkIPoint& size) { |
| 42 SkPoint pts[] = { { 0, 0, }, | 42 SkPoint pts[] = { { 0, 0, }, |
| 43 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; | 43 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; |
| 44 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }
; | 44 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }
; |
| 45 return SkGradientShader::CreateLinear(pts, colors, NULL, | 45 return SkGradientShader::CreateLinear(pts, colors, nullptr, |
| 46 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode); | 46 SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
| 50 | 50 |
| 51 class Patch { | 51 class Patch { |
| 52 public: | 52 public: |
| 53 Patch() { sk_bzero(fPts, sizeof(fPts)); } | 53 Patch() { sk_bzero(fPts, sizeof(fPts)); } |
| 54 ~Patch() {} | 54 ~Patch() {} |
| 55 | 55 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 int fW, fH; | 67 int fW, fH; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 static void eval_patch_edge(const SkPoint cubic[], SkPoint samples[], int segs)
{ | 70 static void eval_patch_edge(const SkPoint cubic[], SkPoint samples[], int segs)
{ |
| 71 SkScalar t = 0; | 71 SkScalar t = 0; |
| 72 SkScalar dt = SK_Scalar1 / segs; | 72 SkScalar dt = SK_Scalar1 / segs; |
| 73 | 73 |
| 74 samples[0] = cubic[0]; | 74 samples[0] = cubic[0]; |
| 75 for (int i = 1; i < segs; i++) { | 75 for (int i = 1; i < segs; i++) { |
| 76 t += dt; | 76 t += dt; |
| 77 SkEvalCubicAt(cubic, t, &samples[i], NULL, NULL); | 77 SkEvalCubicAt(cubic, t, &samples[i], nullptr, nullptr); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 static void eval_sheet(const SkPoint edge[], int nu, int nv, int iu, int iv, | 81 static void eval_sheet(const SkPoint edge[], int nu, int nv, int iu, int iv, |
| 82 SkPoint* pt) { | 82 SkPoint* pt) { |
| 83 const int TL = 0; | 83 const int TL = 0; |
| 84 const int TR = nu; | 84 const int TR = nu; |
| 85 const int BR = TR + nv; | 85 const int BR = TR + nv; |
| 86 const int BL = BR + nu; | 86 const int BL = BR + nu; |
| 87 | 87 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 strip[i*2 + 0] = *upper++; | 192 strip[i*2 + 0] = *upper++; |
| 193 strip[i*2 + 1] = *lower++; | 193 strip[i*2 + 1] = *lower++; |
| 194 tex[i*2 + 0].set(s, t); | 194 tex[i*2 + 0].set(s, t); |
| 195 tex[i*2 + 1].set(s, t + dt); | 195 tex[i*2 + 1].set(s, t + dt); |
| 196 colors[i*2 + 0] = make_color(s/fW, t/fH); | 196 colors[i*2 + 0] = make_color(s/fW, t/fH); |
| 197 colors[i*2 + 1] = make_color(s/fW, (t + dt)/fH); | 197 colors[i*2 + 1] = make_color(s/fW, (t + dt)/fH); |
| 198 s += ds; | 198 s += ds; |
| 199 } | 199 } |
| 200 t += dt; | 200 t += dt; |
| 201 canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount, | 201 canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount, |
| 202 strip, doTextures ? tex : NULL, | 202 strip, doTextures ? tex : nullptr, |
| 203 doColors ? colors : NULL, NULL, | 203 doColors ? colors : nullptr, nullptr, |
| 204 NULL, 0, paint); | 204 nullptr, 0, paint); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, | 208 static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, |
| 209 Patch* patch) { | 209 Patch* patch) { |
| 210 SkAutoCanvasRestore ar(canvas, true); | 210 SkAutoCanvasRestore ar(canvas, true); |
| 211 | 211 |
| 212 patch->draw(canvas, paint, nu, nv, false, false); | 212 patch->draw(canvas, paint, nu, nv, false, false); |
| 213 canvas->translate(SkIntToScalar(180), 0); | 213 canvas->translate(SkIntToScalar(180), 0); |
| 214 patch->draw(canvas, paint, nu, nv, true, false); | 214 patch->draw(canvas, paint, nu, nv, true, false); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 fSize0.fX = 1; | 287 fSize0.fX = 1; |
| 288 } | 288 } |
| 289 if (fSize0.fY == 0) { | 289 if (fSize0.fY == 0) { |
| 290 fSize0.fY = 1; | 290 fSize0.fY = 1; |
| 291 } | 291 } |
| 292 patch.setBounds(fSize0.fX, fSize0.fY); | 292 patch.setBounds(fSize0.fX, fSize0.fY); |
| 293 | 293 |
| 294 patch.setPatch(fPts); | 294 patch.setPatch(fPts); |
| 295 drawpatches(canvas, paint, nu, nv, &patch); | 295 drawpatches(canvas, paint, nu, nv, &patch); |
| 296 | 296 |
| 297 paint.setShader(NULL); | 297 paint.setShader(nullptr); |
| 298 paint.setAntiAlias(true); | 298 paint.setAntiAlias(true); |
| 299 paint.setStrokeWidth(SkIntToScalar(5)); | 299 paint.setStrokeWidth(SkIntToScalar(5)); |
| 300 canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fP
ts, paint); | 300 canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fP
ts, paint); |
| 301 | 301 |
| 302 canvas->translate(0, SkIntToScalar(300)); | 302 canvas->translate(0, SkIntToScalar(300)); |
| 303 | 303 |
| 304 paint.setAntiAlias(false); | 304 paint.setAntiAlias(false); |
| 305 paint.setShader(fShader1); | 305 paint.setShader(fShader1); |
| 306 if (true) { | 306 if (true) { |
| 307 SkMatrix m; | 307 SkMatrix m; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) { | 340 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) { |
| 341 if (hittest(fPts[i], x, y)) { | 341 if (hittest(fPts[i], x, y)) { |
| 342 return new PtClick(this, (int)i); | 342 return new PtClick(this, (int)i); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 return this->INHERITED::onFindClickHandler(x, y, modi); | 345 return this->INHERITED::onFindClickHandler(x, y, modi); |
| 346 } | 346 } |
| 347 | 347 |
| 348 bool onClick(Click* click) override { | 348 bool onClick(Click* click) override { |
| 349 fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX - DX, click->fCurr.f
Y - DY); | 349 fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX - DX, click->fCurr.f
Y - DY); |
| 350 this->inval(NULL); | 350 this->inval(nullptr); |
| 351 return true; | 351 return true; |
| 352 } | 352 } |
| 353 | 353 |
| 354 private: | 354 private: |
| 355 typedef SampleView INHERITED; | 355 typedef SampleView INHERITED; |
| 356 }; | 356 }; |
| 357 | 357 |
| 358 ////////////////////////////////////////////////////////////////////////////// | 358 ////////////////////////////////////////////////////////////////////////////// |
| 359 | 359 |
| 360 static SkView* MyFactory() { return new PatchView; } | 360 static SkView* MyFactory() { return new PatchView; } |
| 361 static SkViewRegister reg(MyFactory); | 361 static SkViewRegister reg(MyFactory); |
| OLD | NEW |