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 29 matching lines...) Expand all Loading... |
40 public: | 40 public: |
41 FatBits() { | 41 FatBits() { |
42 fAA = false; | 42 fAA = false; |
43 fStyle = kHair_Style; | 43 fStyle = kHair_Style; |
44 fGrid = false; | 44 fGrid = false; |
45 fShowSkeleton = true; | 45 fShowSkeleton = true; |
46 fUseGPU = false; | 46 fUseGPU = false; |
47 fUseClip = false; | 47 fUseClip = false; |
48 fRectAsOval = false; | 48 fRectAsOval = false; |
49 fUseTriangle = false; | 49 fUseTriangle = false; |
| 50 fStrokeCap = SkPaint::kButt_Cap; |
50 | 51 |
51 fClipRect.set(2, 2, 11, 8 ); | 52 fClipRect.set(2, 2, 11, 8 ); |
52 } | 53 } |
53 | 54 |
54 int getZoom() const { return fZoom; } | 55 int getZoom() const { return fZoom; } |
55 | 56 |
56 bool getAA() const { return fAA; } | 57 bool getAA() const { return fAA; } |
57 void setAA(bool aa) { fAA = aa; } | 58 void setAA(bool aa) { fAA = aa; } |
58 | 59 |
59 bool getGrid() const { return fGrid; } | 60 bool getGrid() const { return fGrid; } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 info = info.makeWH(width * zoom, height * zoom); | 96 info = info.makeWH(width * zoom, height * zoom); |
96 fMaxSurface.reset(SkSurface::NewRaster(info)); | 97 fMaxSurface.reset(SkSurface::NewRaster(info)); |
97 } | 98 } |
98 | 99 |
99 void drawBG(SkCanvas*); | 100 void drawBG(SkCanvas*); |
100 void drawFG(SkCanvas*); | 101 void drawFG(SkCanvas*); |
101 void drawLine(SkCanvas*, SkPoint pts[2]); | 102 void drawLine(SkCanvas*, SkPoint pts[2]); |
102 void drawRect(SkCanvas* canvas, SkPoint pts[2]); | 103 void drawRect(SkCanvas* canvas, SkPoint pts[2]); |
103 void drawTriangle(SkCanvas* canvas, SkPoint pts[3]); | 104 void drawTriangle(SkCanvas* canvas, SkPoint pts[3]); |
104 | 105 |
| 106 SkPaint::Cap fStrokeCap; |
| 107 |
105 private: | 108 private: |
106 bool fAA, fGrid, fShowSkeleton, fUseGPU, fUseClip, fRectAsOval, fUseTriangle
; | 109 bool fAA, fGrid, fShowSkeleton, fUseGPU, fUseClip, fRectAsOval, fUseTriangle
; |
107 Style fStyle; | 110 Style fStyle; |
108 int fW, fH, fZoom; | 111 int fW, fH, fZoom; |
109 SkMatrix fMatrix, fInverse; | 112 SkMatrix fMatrix, fInverse; |
110 SkRect fBounds, fClipRect; | 113 SkRect fBounds, fClipRect; |
111 SkAutoTUnref<SkShader> fShader; | 114 SkAutoTUnref<SkShader> fShader; |
112 SkAutoTUnref<SkSurface> fMinSurface; | 115 SkAutoTUnref<SkSurface> fMinSurface; |
113 SkAutoTUnref<SkSurface> fMaxSurface; | 116 SkAutoTUnref<SkSurface> fMaxSurface; |
114 | 117 |
115 void setupPaint(SkPaint* paint) { | 118 void setupPaint(SkPaint* paint) { |
116 bool aa = this->getAA(); | 119 bool aa = this->getAA(); |
| 120 paint->setStrokeCap(fStrokeCap); |
117 switch (fStyle) { | 121 switch (fStyle) { |
118 case kHair_Style: | 122 case kHair_Style: |
119 paint->setStrokeWidth(0); | 123 paint->setStrokeWidth(0); |
120 break; | 124 break; |
121 case kStroke_Style: | 125 case kStroke_Style: |
122 paint->setStrokeWidth(SK_Scalar1); | 126 paint->setStrokeWidth(SK_Scalar1); |
123 break; | 127 break; |
124 } | 128 } |
125 paint->setAntiAlias(aa); | 129 paint->setAntiAlias(aa); |
126 } | 130 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 p.setStrokeWidth(SK_Scalar1 * fZoom); | 243 p.setStrokeWidth(SK_Scalar1 * fZoom); |
240 SkPath dst; | 244 SkPath dst; |
241 p.getFillPath(path, &dst); | 245 p.getFillPath(path, &dst); |
242 path.addPath(dst); | 246 path.addPath(dst); |
243 } | 247 } |
244 break; | 248 break; |
245 case kStroke_Style: { | 249 case kStroke_Style: { |
246 SkPaint p; | 250 SkPaint p; |
247 p.setStyle(SkPaint::kStroke_Style); | 251 p.setStyle(SkPaint::kStroke_Style); |
248 p.setStrokeWidth(SK_Scalar1 * fZoom); | 252 p.setStrokeWidth(SK_Scalar1 * fZoom); |
| 253 p.setStrokeCap(fStrokeCap); |
249 SkPath dst; | 254 SkPath dst; |
250 p.getFillPath(path, &dst); | 255 p.getFillPath(path, &dst); |
251 path = dst; | 256 path = dst; |
252 | 257 |
| 258 path.moveTo(pts[0]); |
| 259 path.lineTo(pts[1]); |
| 260 |
253 if (fUseGPU) { | 261 if (fUseGPU) { |
254 path.moveTo(dst.getPoint(0)); | 262 path.moveTo(dst.getPoint(0)); |
255 path.lineTo(dst.getPoint(2)); | 263 path.lineTo(dst.getPoint(2)); |
256 } | 264 } |
257 } break; | 265 } break; |
258 } | 266 } |
259 max->drawPath(path, paint); | 267 max->drawPath(path, paint); |
260 } | 268 } |
261 | 269 |
262 void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { | 270 void FatBits::drawLine(SkCanvas* canvas, SkPoint pts[]) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 fFB.setGrid(!fFB.getGrid()); | 431 fFB.setGrid(!fFB.getGrid()); |
424 this->inval(nullptr); | 432 this->inval(nullptr); |
425 return true; | 433 return true; |
426 case 's': | 434 case 's': |
427 if (FatBits::kStroke_Style == fFB.getStyle()) { | 435 if (FatBits::kStroke_Style == fFB.getStyle()) { |
428 this->setStyle(FatBits::kHair_Style); | 436 this->setStyle(FatBits::kHair_Style); |
429 } else { | 437 } else { |
430 this->setStyle(FatBits::kStroke_Style); | 438 this->setStyle(FatBits::kStroke_Style); |
431 } | 439 } |
432 return true; | 440 return true; |
| 441 case 'k': { |
| 442 const SkPaint::Cap caps[] = { |
| 443 SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquar
e_Cap, |
| 444 }; |
| 445 fFB.fStrokeCap = caps[(fFB.fStrokeCap + 1) % 3]; |
| 446 this->inval(nullptr); |
| 447 return true; |
| 448 } break; |
433 case 'a': | 449 case 'a': |
434 fFB.setAA(!fFB.getAA()); | 450 fFB.setAA(!fFB.getAA()); |
435 this->inval(nullptr); | 451 this->inval(nullptr); |
436 return true; | 452 return true; |
437 case 'w': | 453 case 'w': |
438 fFB.setShowSkeleton(!fFB.getShowSkeleton()); | 454 fFB.setShowSkeleton(!fFB.getShowSkeleton()); |
439 this->inval(nullptr); | 455 this->inval(nullptr); |
440 return true; | 456 return true; |
441 case 'g': | 457 case 'g': |
442 fFB.setUseGPU(!fFB.getUseGPU()); | 458 fFB.setUseGPU(!fFB.getUseGPU()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 526 |
511 private: | 527 private: |
512 | 528 |
513 typedef SampleView INHERITED; | 529 typedef SampleView INHERITED; |
514 }; | 530 }; |
515 | 531 |
516 ////////////////////////////////////////////////////////////////////////////// | 532 ////////////////////////////////////////////////////////////////////////////// |
517 | 533 |
518 static SkView* MyFactory() { return new DrawLineView; } | 534 static SkView* MyFactory() { return new DrawLineView; } |
519 static SkViewRegister reg(MyFactory); | 535 static SkViewRegister reg(MyFactory); |
OLD | NEW |