| 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" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 patch->draw(canvas, paint, 10, 10, false, false); | 212 patch->draw(canvas, paint, 10, 10, false, false); |
| 213 canvas->translate(SkIntToScalar(180), 0); | 213 canvas->translate(SkIntToScalar(180), 0); |
| 214 patch->draw(canvas, paint, 10, 10, true, false); | 214 patch->draw(canvas, paint, 10, 10, true, false); |
| 215 canvas->translate(SkIntToScalar(180), 0); | 215 canvas->translate(SkIntToScalar(180), 0); |
| 216 patch->draw(canvas, paint, 10, 10, false, true); | 216 patch->draw(canvas, paint, 10, 10, false, true); |
| 217 canvas->translate(SkIntToScalar(180), 0); | 217 canvas->translate(SkIntToScalar(180), 0); |
| 218 patch->draw(canvas, paint, 10, 10, true, true); | 218 patch->draw(canvas, paint, 10, 10, true, true); |
| 219 } | 219 } |
| 220 | 220 |
| 221 const SkScalar DX = 20; |
| 222 const SkScalar DY = 0; |
| 223 |
| 221 class PatchView : public SampleView { | 224 class PatchView : public SampleView { |
| 222 SkShader* fShader0; | 225 SkShader* fShader0; |
| 223 SkShader* fShader1; | 226 SkShader* fShader1; |
| 224 SkIPoint fSize0, fSize1; | 227 SkIPoint fSize0, fSize1; |
| 225 SkPoint fPts[12]; | 228 SkPoint fPts[12]; |
| 226 | 229 |
| 227 public: | 230 public: |
| 228 PatchView() { | 231 PatchView() { |
| 229 fShader0 = make_shader0(&fSize0); | 232 fShader0 = make_shader0(&fSize0); |
| 230 fSize1 = fSize0; | 233 fSize1 = fSize0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 return true; | 267 return true; |
| 265 } | 268 } |
| 266 return this->INHERITED::onQuery(evt); | 269 return this->INHERITED::onQuery(evt); |
| 267 } | 270 } |
| 268 | 271 |
| 269 virtual void onDrawContent(SkCanvas* canvas) { | 272 virtual void onDrawContent(SkCanvas* canvas) { |
| 270 SkPaint paint; | 273 SkPaint paint; |
| 271 paint.setDither(true); | 274 paint.setDither(true); |
| 272 paint.setFilterLevel(SkPaint::kLow_FilterLevel); | 275 paint.setFilterLevel(SkPaint::kLow_FilterLevel); |
| 273 | 276 |
| 274 canvas->translate(SkIntToScalar(20), 0); | 277 canvas->translate(DX, DY); |
| 275 | 278 |
| 276 Patch patch; | 279 Patch patch; |
| 277 | 280 |
| 278 paint.setShader(fShader0); | 281 paint.setShader(fShader0); |
| 279 if (fSize0.fX == 0) { | 282 if (fSize0.fX == 0) { |
| 280 fSize0.fX = 1; | 283 fSize0.fX = 1; |
| 281 } | 284 } |
| 282 if (fSize0.fY == 0) { | 285 if (fSize0.fY == 0) { |
| 283 fSize0.fY = 1; | 286 fSize0.fY = 1; |
| 284 } | 287 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 int fIndex; | 323 int fIndex; |
| 321 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} | 324 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} |
| 322 }; | 325 }; |
| 323 | 326 |
| 324 static bool hittest(const SkPoint& pt, SkScalar x, SkScalar y) { | 327 static bool hittest(const SkPoint& pt, SkScalar x, SkScalar y) { |
| 325 return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5); | 328 return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5); |
| 326 } | 329 } |
| 327 | 330 |
| 328 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 331 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
| 329 unsigned modi) SK_OVERRIDE { | 332 unsigned modi) SK_OVERRIDE { |
| 333 x -= DX; |
| 334 y -= DY; |
| 330 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) { | 335 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) { |
| 331 if (hittest(fPts[i], x, y)) { | 336 if (hittest(fPts[i], x, y)) { |
| 332 return new PtClick(this, (int)i); | 337 return new PtClick(this, (int)i); |
| 333 } | 338 } |
| 334 } | 339 } |
| 335 return this->INHERITED::onFindClickHandler(x, y, modi); | 340 return this->INHERITED::onFindClickHandler(x, y, modi); |
| 336 } | 341 } |
| 337 | 342 |
| 338 virtual bool onClick(Click* click) { | 343 virtual bool onClick(Click* click) { |
| 339 fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX, click->fCurr.fY); | 344 fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX - DX, click->fCurr.f
Y - DY); |
| 340 this->inval(NULL); | 345 this->inval(NULL); |
| 341 return true; | 346 return true; |
| 342 } | 347 } |
| 343 | 348 |
| 344 private: | 349 private: |
| 345 typedef SampleView INHERITED; | 350 typedef SampleView INHERITED; |
| 346 }; | 351 }; |
| 347 | 352 |
| 348 ////////////////////////////////////////////////////////////////////////////// | 353 ////////////////////////////////////////////////////////////////////////////// |
| 349 | 354 |
| 350 static SkView* MyFactory() { return new PatchView; } | 355 static SkView* MyFactory() { return new PatchView; } |
| 351 static SkViewRegister reg(MyFactory); | 356 static SkViewRegister reg(MyFactory); |
| OLD | NEW |