| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "sk_tool_utils.h" | 8 #include "sk_tool_utils.h" |
| 9 #include "SampleCode.h" | 9 #include "SampleCode.h" |
| 10 #include "SkView.h" | 10 #include "SkView.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 max->drawPath(path, paint); | 158 max->drawPath(path, paint); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void copyMinToMax() { | 161 void copyMinToMax() { |
| 162 erase(fMaxSurface); | 162 erase(fMaxSurface); |
| 163 SkCanvas* canvas = fMaxSurface->getCanvas(); | 163 SkCanvas* canvas = fMaxSurface->getCanvas(); |
| 164 canvas->save(); | 164 canvas->save(); |
| 165 canvas->concat(fMatrix); | 165 canvas->concat(fMatrix); |
| 166 fMinSurface->draw(canvas, 0, 0, NULL); | 166 fMinSurface->draw(canvas, 0, 0, nullptr); |
| 167 canvas->restore(); | 167 canvas->restore(); |
| 168 | 168 |
| 169 SkPaint paint; | 169 SkPaint paint; |
| 170 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 170 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
| 171 for (int iy = 1; iy < fH; ++iy) { | 171 for (int iy = 1; iy < fH; ++iy) { |
| 172 SkScalar y = SkIntToScalar(iy * fZoom); | 172 SkScalar y = SkIntToScalar(iy * fZoom); |
| 173 canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint
); | 173 canvas->drawLine(0, y - SK_ScalarHalf, 999, y - SK_ScalarHalf, paint
); |
| 174 } | 174 } |
| 175 for (int ix = 1; ix < fW; ++ix) { | 175 for (int ix = 1; ix < fW; ++ix) { |
| 176 SkScalar x = SkIntToScalar(ix * fZoom); | 176 SkScalar x = SkIntToScalar(ix * fZoom); |
| 177 canvas->drawLine(x - SK_ScalarHalf, 0, x - SK_ScalarHalf, 999, paint
); | 177 canvas->drawLine(x - SK_ScalarHalf, 0, x - SK_ScalarHalf, 999, paint
); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 void FatBits::drawBG(SkCanvas* canvas) { | 182 void FatBits::drawBG(SkCanvas* canvas) { |
| 183 SkPaint paint; | 183 SkPaint paint; |
| 184 | 184 |
| 185 paint.setShader(fShader); | 185 paint.setShader(fShader); |
| 186 canvas->drawRect(fBounds, paint); | 186 canvas->drawRect(fBounds, paint); |
| 187 paint.setShader(NULL); | 187 paint.setShader(nullptr); |
| 188 } | 188 } |
| 189 | 189 |
| 190 void FatBits::drawFG(SkCanvas* canvas) { | 190 void FatBits::drawFG(SkCanvas* canvas) { |
| 191 SkPaint inner, outer; | 191 SkPaint inner, outer; |
| 192 | 192 |
| 193 inner.setAntiAlias(true); | 193 inner.setAntiAlias(true); |
| 194 inner.setColor(SK_ColorBLACK); | 194 inner.setColor(SK_ColorBLACK); |
| 195 inner.setStrokeWidth(PIXEL_CENTER_SIZE); | 195 inner.setStrokeWidth(PIXEL_CENTER_SIZE); |
| 196 | 196 |
| 197 outer.setAntiAlias(true); | 197 outer.setAntiAlias(true); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (fUseClip) { | 281 if (fUseClip) { |
| 282 fMinSurface->getCanvas()->restore(); | 282 fMinSurface->getCanvas()->restore(); |
| 283 } | 283 } |
| 284 this->copyMinToMax(); | 284 this->copyMinToMax(); |
| 285 | 285 |
| 286 SkCanvas* max = fMaxSurface->getCanvas(); | 286 SkCanvas* max = fMaxSurface->getCanvas(); |
| 287 | 287 |
| 288 fMatrix.mapPoints(pts, 2); | 288 fMatrix.mapPoints(pts, 2); |
| 289 this->drawLineSkeleton(max, pts); | 289 this->drawLineSkeleton(max, pts); |
| 290 | 290 |
| 291 fMaxSurface->draw(canvas, 0, 0, NULL); | 291 fMaxSurface->draw(canvas, 0, 0, nullptr); |
| 292 } | 292 } |
| 293 | 293 |
| 294 void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) { | 294 void FatBits::drawRect(SkCanvas* canvas, SkPoint pts[2]) { |
| 295 SkPaint paint; | 295 SkPaint paint; |
| 296 | 296 |
| 297 fInverse.mapPoints(pts, 2); | 297 fInverse.mapPoints(pts, 2); |
| 298 | 298 |
| 299 if (fGrid) { | 299 if (fGrid) { |
| 300 apply_grid(pts, 2); | 300 apply_grid(pts, 2); |
| 301 } | 301 } |
| 302 | 302 |
| 303 SkRect r; | 303 SkRect r; |
| 304 r.set(pts, 2); | 304 r.set(pts, 2); |
| 305 | 305 |
| 306 erase(fMinSurface); | 306 erase(fMinSurface); |
| 307 this->setupPaint(&paint); | 307 this->setupPaint(&paint); |
| 308 paint.setColor(FAT_PIXEL_COLOR); | 308 paint.setColor(FAT_PIXEL_COLOR); |
| 309 { | 309 { |
| 310 SkCanvas* c = fMinSurface->getCanvas(); | 310 SkCanvas* c = fMinSurface->getCanvas(); |
| 311 fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint); | 311 fRectAsOval ? c->drawOval(r, paint) : c->drawRect(r, paint); |
| 312 } | 312 } |
| 313 this->copyMinToMax(); | 313 this->copyMinToMax(); |
| 314 | 314 |
| 315 SkCanvas* max = fMaxSurface->getCanvas(); | 315 SkCanvas* max = fMaxSurface->getCanvas(); |
| 316 | 316 |
| 317 fMatrix.mapPoints(pts, 2); | 317 fMatrix.mapPoints(pts, 2); |
| 318 r.set(pts, 2); | 318 r.set(pts, 2); |
| 319 this->drawRectSkeleton(max, r); | 319 this->drawRectSkeleton(max, r); |
| 320 | 320 |
| 321 fMaxSurface->draw(canvas, 0, 0, NULL); | 321 fMaxSurface->draw(canvas, 0, 0, nullptr); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void FatBits::drawTriangleSkeleton(SkCanvas* max, const SkPoint pts[]) { | 324 void FatBits::drawTriangleSkeleton(SkCanvas* max, const SkPoint pts[]) { |
| 325 SkPaint paint; | 325 SkPaint paint; |
| 326 this->setupSkeletonPaint(&paint); | 326 this->setupSkeletonPaint(&paint); |
| 327 | 327 |
| 328 SkPath path; | 328 SkPath path; |
| 329 path.moveTo(pts[0]); | 329 path.moveTo(pts[0]); |
| 330 path.lineTo(pts[1]); | 330 path.lineTo(pts[1]); |
| 331 path.lineTo(pts[2]); | 331 path.lineTo(pts[2]); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 353 this->setupPaint(&paint); | 353 this->setupPaint(&paint); |
| 354 paint.setColor(FAT_PIXEL_COLOR); | 354 paint.setColor(FAT_PIXEL_COLOR); |
| 355 fMinSurface->getCanvas()->drawPath(path, paint); | 355 fMinSurface->getCanvas()->drawPath(path, paint); |
| 356 this->copyMinToMax(); | 356 this->copyMinToMax(); |
| 357 | 357 |
| 358 SkCanvas* max = fMaxSurface->getCanvas(); | 358 SkCanvas* max = fMaxSurface->getCanvas(); |
| 359 | 359 |
| 360 fMatrix.mapPoints(pts, 3); | 360 fMatrix.mapPoints(pts, 3); |
| 361 this->drawTriangleSkeleton(max, pts); | 361 this->drawTriangleSkeleton(max, pts); |
| 362 | 362 |
| 363 fMaxSurface->draw(canvas, 0, 0, NULL); | 363 fMaxSurface->draw(canvas, 0, 0, nullptr); |
| 364 } | 364 } |
| 365 | 365 |
| 366 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 366 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 367 | 367 |
| 368 class IndexClick : public SkView::Click { | 368 class IndexClick : public SkView::Click { |
| 369 int fIndex; | 369 int fIndex; |
| 370 public: | 370 public: |
| 371 IndexClick(SkView* v, int index) : SkView::Click(v), fIndex(index) {} | 371 IndexClick(SkView* v, int index) : SkView::Click(v), fIndex(index) {} |
| 372 | 372 |
| 373 static int GetIndex(SkView::Click* click) { | 373 static int GetIndex(SkView::Click* click) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 388 fFB.setWHZ(24, 16, kZoom); | 388 fFB.setWHZ(24, 16, kZoom); |
| 389 fPts[0].set(1, 1); | 389 fPts[0].set(1, 1); |
| 390 fPts[1].set(5, 4); | 390 fPts[1].set(5, 4); |
| 391 fPts[2].set(2, 6); | 391 fPts[2].set(2, 6); |
| 392 SkMatrix::MakeScale(kZoom, kZoom).mapPoints(fPts, 3); | 392 SkMatrix::MakeScale(kZoom, kZoom).mapPoints(fPts, 3); |
| 393 fIsRect = false; | 393 fIsRect = false; |
| 394 } | 394 } |
| 395 | 395 |
| 396 void setStyle(FatBits::Style s) { | 396 void setStyle(FatBits::Style s) { |
| 397 fFB.setStyle(s); | 397 fFB.setStyle(s); |
| 398 this->inval(NULL); | 398 this->inval(nullptr); |
| 399 } | 399 } |
| 400 | 400 |
| 401 protected: | 401 protected: |
| 402 bool onQuery(SkEvent* evt) override { | 402 bool onQuery(SkEvent* evt) override { |
| 403 if (SampleCode::TitleQ(*evt)) { | 403 if (SampleCode::TitleQ(*evt)) { |
| 404 SampleCode::TitleR(evt, "FatBits"); | 404 SampleCode::TitleR(evt, "FatBits"); |
| 405 return true; | 405 return true; |
| 406 } | 406 } |
| 407 SkUnichar uni; | 407 SkUnichar uni; |
| 408 if (SampleCode::CharQ(*evt, &uni)) { | 408 if (SampleCode::CharQ(*evt, &uni)) { |
| 409 switch (uni) { | 409 switch (uni) { |
| 410 case 'c': | 410 case 'c': |
| 411 fFB.setUseClip(!fFB.getUseClip()); | 411 fFB.setUseClip(!fFB.getUseClip()); |
| 412 this->inval(NULL); | 412 this->inval(nullptr); |
| 413 return true; | 413 return true; |
| 414 case 'r': | 414 case 'r': |
| 415 fIsRect = !fIsRect; | 415 fIsRect = !fIsRect; |
| 416 this->inval(NULL); | 416 this->inval(nullptr); |
| 417 return true; | 417 return true; |
| 418 case 'o': | 418 case 'o': |
| 419 fFB.toggleRectAsOval(); | 419 fFB.toggleRectAsOval(); |
| 420 this->inval(NULL); | 420 this->inval(nullptr); |
| 421 return true; | 421 return true; |
| 422 case 'x': | 422 case 'x': |
| 423 fFB.setGrid(!fFB.getGrid()); | 423 fFB.setGrid(!fFB.getGrid()); |
| 424 this->inval(NULL); | 424 this->inval(nullptr); |
| 425 return true; | 425 return true; |
| 426 case 's': | 426 case 's': |
| 427 if (FatBits::kStroke_Style == fFB.getStyle()) { | 427 if (FatBits::kStroke_Style == fFB.getStyle()) { |
| 428 this->setStyle(FatBits::kHair_Style); | 428 this->setStyle(FatBits::kHair_Style); |
| 429 } else { | 429 } else { |
| 430 this->setStyle(FatBits::kStroke_Style); | 430 this->setStyle(FatBits::kStroke_Style); |
| 431 } | 431 } |
| 432 return true; | 432 return true; |
| 433 case 'a': | 433 case 'a': |
| 434 fFB.setAA(!fFB.getAA()); | 434 fFB.setAA(!fFB.getAA()); |
| 435 this->inval(NULL); | 435 this->inval(nullptr); |
| 436 return true; | 436 return true; |
| 437 case 'w': | 437 case 'w': |
| 438 fFB.setShowSkeleton(!fFB.getShowSkeleton()); | 438 fFB.setShowSkeleton(!fFB.getShowSkeleton()); |
| 439 this->inval(NULL); | 439 this->inval(nullptr); |
| 440 return true; | 440 return true; |
| 441 case 'g': | 441 case 'g': |
| 442 fFB.setUseGPU(!fFB.getUseGPU()); | 442 fFB.setUseGPU(!fFB.getUseGPU()); |
| 443 this->inval(NULL); | 443 this->inval(nullptr); |
| 444 return true; | 444 return true; |
| 445 case 't': | 445 case 't': |
| 446 fFB.setTriangle(!fFB.getTriangle()); | 446 fFB.setTriangle(!fFB.getTriangle()); |
| 447 this->inval(NULL); | 447 this->inval(nullptr); |
| 448 return true; | 448 return true; |
| 449 } | 449 } |
| 450 } | 450 } |
| 451 return this->INHERITED::onQuery(evt); | 451 return this->INHERITED::onQuery(evt); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void onDrawContent(SkCanvas* canvas) override { | 454 void onDrawContent(SkCanvas* canvas) override { |
| 455 fFB.drawBG(canvas); | 455 fFB.drawBG(canvas); |
| 456 if (fFB.getTriangle()) { | 456 if (fFB.getTriangle()) { |
| 457 fFB.drawTriangle(canvas, fPts); | 457 fFB.drawTriangle(canvas, fPts); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 int index = IndexClick::GetIndex(click); | 497 int index = IndexClick::GetIndex(click); |
| 498 if (index >= 0 && index <= 2) { | 498 if (index >= 0 && index <= 2) { |
| 499 fPts[index] = click->fCurr; | 499 fPts[index] = click->fCurr; |
| 500 } else { | 500 } else { |
| 501 SkScalar dx = click->fCurr.fX - click->fPrev.fX; | 501 SkScalar dx = click->fCurr.fX - click->fPrev.fX; |
| 502 SkScalar dy = click->fCurr.fY - click->fPrev.fY; | 502 SkScalar dy = click->fCurr.fY - click->fPrev.fY; |
| 503 fPts[0].offset(dx, dy); | 503 fPts[0].offset(dx, dy); |
| 504 fPts[1].offset(dx, dy); | 504 fPts[1].offset(dx, dy); |
| 505 fPts[2].offset(dx, dy); | 505 fPts[2].offset(dx, dy); |
| 506 } | 506 } |
| 507 this->inval(NULL); | 507 this->inval(nullptr); |
| 508 return true; | 508 return true; |
| 509 } | 509 } |
| 510 | 510 |
| 511 private: | 511 private: |
| 512 | 512 |
| 513 typedef SampleView INHERITED; | 513 typedef SampleView INHERITED; |
| 514 }; | 514 }; |
| 515 | 515 |
| 516 ////////////////////////////////////////////////////////////////////////////// | 516 ////////////////////////////////////////////////////////////////////////////// |
| 517 | 517 |
| 518 static SkView* MyFactory() { return new DrawLineView; } | 518 static SkView* MyFactory() { return new DrawLineView; } |
| 519 static SkViewRegister reg(MyFactory); | 519 static SkViewRegister reg(MyFactory); |
| OLD | NEW |