Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: samplecode/SampleQuadStroker.cpp

Issue 932113002: Revive quad approximation stroker (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add macro to suppress uninitialized warning Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/common.gypi ('k') | src/core/SkStroke.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 static void erase(SkSurface* surface) { 78 static void erase(SkSurface* surface) {
79 surface->getCanvas()->clear(SK_ColorTRANSPARENT); 79 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
80 } 80 }
81 81
82 struct StrokeTypeButton { 82 struct StrokeTypeButton {
83 SkRect fBounds; 83 SkRect fBounds;
84 char fLabel; 84 char fLabel;
85 bool fEnabled; 85 bool fEnabled;
86 }; 86 };
87 87
88 struct CircleTypeButton : public StrokeTypeButton {
89 bool fFill;
90 };
91
88 class QuadStrokerView : public SampleView { 92 class QuadStrokerView : public SampleView {
89 enum { 93 enum {
90 SKELETON_COLOR = 0xFF0000FF, 94 SKELETON_COLOR = 0xFF0000FF,
91 WIREFRAME_COLOR = 0x80FF0000 95 WIREFRAME_COLOR = 0x80FF0000
92 }; 96 };
93 97
94 enum { 98 enum {
95 kCount = 10 99 kCount = 15
96 }; 100 };
97 SkPoint fPts[kCount]; 101 SkPoint fPts[kCount];
102 SkRect fWeightControl;
98 SkRect fErrorControl; 103 SkRect fErrorControl;
99 SkRect fWidthControl; 104 SkRect fWidthControl;
100 SkRect fBounds; 105 SkRect fBounds;
101 SkMatrix fMatrix, fInverse; 106 SkMatrix fMatrix, fInverse;
102 SkAutoTUnref<SkShader> fShader; 107 SkAutoTUnref<SkShader> fShader;
103 SkAutoTUnref<SkSurface> fMinSurface; 108 SkAutoTUnref<SkSurface> fMinSurface;
104 SkAutoTUnref<SkSurface> fMaxSurface; 109 SkAutoTUnref<SkSurface> fMaxSurface;
105 StrokeTypeButton fCubicButton; 110 StrokeTypeButton fCubicButton;
111 StrokeTypeButton fConicButton;
106 StrokeTypeButton fQuadButton; 112 StrokeTypeButton fQuadButton;
107 StrokeTypeButton fRRectButton; 113 StrokeTypeButton fRRectButton;
114 CircleTypeButton fCircleButton;
108 StrokeTypeButton fTextButton; 115 StrokeTypeButton fTextButton;
109 SkString fText; 116 SkString fText;
110 SkScalar fTextSize; 117 SkScalar fTextSize;
118 SkScalar fWeight;
111 SkScalar fWidth, fDWidth; 119 SkScalar fWidth, fDWidth;
112 SkScalar fWidthScale; 120 SkScalar fWidthScale;
113 int fW, fH, fZoom; 121 int fW, fH, fZoom;
114 bool fAnimate; 122 bool fAnimate;
115 bool fDrawRibs; 123 bool fDrawRibs;
116 bool fDrawTangents; 124 bool fDrawTangents;
117 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) 125 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
118 #define kStrokerErrorMin 0.001f 126 #define kStrokerErrorMin 0.001f
119 #define kStrokerErrorMax 5 127 #define kStrokerErrorMax 5
120 #endif 128 #endif
121 #define kWidthMin 1 129 #define kWidthMin 1
122 #define kWidthMax 100 130 #define kWidthMax 100
123 public: 131 public:
124 QuadStrokerView() { 132 QuadStrokerView() {
125 this->setBGColor(SK_ColorLTGRAY); 133 this->setBGColor(SK_ColorLTGRAY);
126 134
127 fPts[0].set(50, 200); 135 fPts[0].set(50, 200); // cubic
128 fPts[1].set(50, 100); 136 fPts[1].set(50, 100);
129 fPts[2].set(150, 50); 137 fPts[2].set(150, 50);
130 fPts[3].set(300, 50); 138 fPts[3].set(300, 50);
131 139
132 fPts[4].set(350, 200); 140 fPts[4].set(350, 200); // conic
133 fPts[5].set(350, 100); 141 fPts[5].set(350, 100);
134 fPts[6].set(450, 50); 142 fPts[6].set(450, 50);
135 143
136 fPts[7].set(200, 200); 144 fPts[7].set(150, 300); // quad
137 fPts[8].set(400, 400); 145 fPts[8].set(150, 200);
146 fPts[9].set(250, 150);
138 147
139 fPts[9].set(250, 800); 148 fPts[10].set(200, 200); // rrect
149 fPts[11].set(400, 400);
150
151 fPts[12].set(250, 250); // oval
152 fPts[13].set(450, 450);
153
140 fText = "a"; 154 fText = "a";
141 fTextSize = 12; 155 fTextSize = 12;
142 fWidth = 50; 156 fWidth = 50;
143 fDWidth = 0.25f; 157 fDWidth = 0.25f;
158 fWeight = 1;
144 159
145 fCubicButton.fLabel = 'C'; 160 fCubicButton.fLabel = 'C';
146 fCubicButton.fEnabled = false; 161 fCubicButton.fEnabled = false;
162 fConicButton.fLabel = 'K';
163 fConicButton.fEnabled = true;
147 fQuadButton.fLabel = 'Q'; 164 fQuadButton.fLabel = 'Q';
148 fQuadButton.fEnabled = false; 165 fQuadButton.fEnabled = false;
149 fRRectButton.fLabel = 'R'; 166 fRRectButton.fLabel = 'R';
150 fRRectButton.fEnabled = false; 167 fRRectButton.fEnabled = false;
168 fCircleButton.fLabel = 'O';
169 fCircleButton.fEnabled = false;
170 fCircleButton.fFill = false;
151 fTextButton.fLabel = 'T'; 171 fTextButton.fLabel = 'T';
152 fTextButton.fEnabled = true; 172 fTextButton.fEnabled = false;
153 fAnimate = true; 173 fAnimate = true;
154 setAsNeeded(); 174 setAsNeeded();
155 } 175 }
156 176
157 protected: 177 protected:
158 bool onQuery(SkEvent* evt) SK_OVERRIDE { 178 bool onQuery(SkEvent* evt) SK_OVERRIDE {
159 if (SampleCode::TitleQ(*evt)) { 179 if (SampleCode::TitleQ(*evt)) {
160 SampleCode::TitleR(evt, "QuadStroker"); 180 SampleCode::TitleR(evt, "QuadStroker");
161 return true; 181 return true;
162 } 182 }
(...skipping 13 matching lines...) Expand all
176 default: 196 default:
177 fText.appendUnichar(uni); 197 fText.appendUnichar(uni);
178 } 198 }
179 this->inval(NULL); 199 this->inval(NULL);
180 return true; 200 return true;
181 } 201 }
182 return this->INHERITED::onQuery(evt); 202 return this->INHERITED::onQuery(evt);
183 } 203 }
184 204
185 void onSizeChange() SK_OVERRIDE { 205 void onSizeChange() SK_OVERRIDE {
206 fWeightControl.setXYWH(this->width() - 150, 30, 30, 400);
186 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); 207 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400);
187 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); 208 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400);
188 fCubicButton.fBounds.setXYWH(this->width() - 50, 450, 30, 30); 209 int buttonOffset = 450;
189 fQuadButton.fBounds.setXYWH(this->width() - 50, 500, 30, 30); 210 fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
190 fRRectButton.fBounds.setXYWH(this->width() - 50, 550, 30, 30); 211 buttonOffset += 50;
191 fTextButton.fBounds.setXYWH(this->width() - 50, 600, 30, 30); 212 fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
213 buttonOffset += 50;
214 fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30);
215 buttonOffset += 50;
216 fRRectButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
217 buttonOffset += 50;
218 fCircleButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOf fset), 30, 30);
219 buttonOffset += 50;
220 fTextButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30);
192 this->INHERITED::onSizeChange(); 221 this->INHERITED::onSizeChange();
193 } 222 }
194 223
195 void copyMinToMax() { 224 void copyMinToMax() {
196 erase(fMaxSurface); 225 erase(fMaxSurface);
197 SkCanvas* canvas = fMaxSurface->getCanvas(); 226 SkCanvas* canvas = fMaxSurface->getCanvas();
198 canvas->save(); 227 canvas->save();
199 canvas->concat(fMatrix); 228 canvas->concat(fMatrix);
200 fMinSurface->draw(canvas, 0, 0, NULL); 229 fMinSurface->draw(canvas, 0, 0, NULL);
201 canvas->restore(); 230 canvas->restore();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 for (SkScalar dist = 0; dist <= total; dist += delta) { 295 for (SkScalar dist = 0; dist <= total; dist += delta) {
267 if (meas.getPosTan(dist, &pos, &tan)) { 296 if (meas.getPosTan(dist, &pos, &tan)) {
268 tan.scale(radius); 297 tan.scale(radius);
269 tan.rotateCCW(); 298 tan.rotateCCW();
270 canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(), 299 canvas->drawLine(pos.x() + tan.x(), pos.y() + tan.y(),
271 pos.x() - tan.x(), pos.y() - tan.y(), paint); 300 pos.x() - tan.x(), pos.y() - tan.y(), paint);
272 } 301 }
273 } 302 }
274 } 303 }
275 304
276 void draw_stroke(SkCanvas* canvas, const SkPath& path, SkScalar width, bool drawText) { 305 void draw_stroke(SkCanvas* canvas, const SkPath& path, SkScalar width, SkSca lar scale,
306 bool drawText) {
277 SkRect bounds = path.getBounds(); 307 SkRect bounds = path.getBounds();
278 if (bounds.isEmpty()) { 308 if (bounds.isEmpty()) {
279 return; 309 return;
280 } 310 }
281 this->setWHZ(SkScalarCeilToInt(bounds.right()), SkScalarRoundToInt(fText Size * 3 / 2), 311 this->setWHZ(SkScalarCeilToInt(bounds.right()), drawText
282 SkScalarRoundToInt(950.0f / fTextSize)); 312 ? SkScalarRoundToInt(scale * 3 / 2) : SkScalarRoundToInt(scale),
313 SkScalarRoundToInt(950.0f / scale));
283 erase(fMinSurface); 314 erase(fMinSurface);
284 SkPaint paint; 315 SkPaint paint;
285 paint.setColor(0x1f1f0f0f); 316 paint.setColor(0x1f1f0f0f);
286 fMinSurface->getCanvas()->drawPath(path, paint);
287 paint.setStyle(SkPaint::kStroke_Style); 317 paint.setStyle(SkPaint::kStroke_Style);
288 paint.setStrokeWidth(width * fTextSize * fTextSize); 318 paint.setStrokeWidth(width * scale * scale);
289 paint.setColor(0x3f0f1f3f); 319 paint.setColor(0x3f0f1f3f);
290 fMinSurface->getCanvas()->drawPath(path, paint); 320 if (drawText) {
291 321 fMinSurface->getCanvas()->drawPath(path, paint);
292 this->copyMinToMax(); 322 this->copyMinToMax();
293 fMaxSurface->draw(canvas, 0, 0, NULL); 323 fMaxSurface->draw(canvas, 0, 0, NULL);
294 324 }
295 paint.setAntiAlias(true); 325 paint.setAntiAlias(true);
296 paint.setStyle(SkPaint::kStroke_Style); 326 paint.setStyle(SkPaint::kStroke_Style);
297 paint.setStrokeWidth(1); 327 paint.setStrokeWidth(1);
298 328
299 paint.setColor(SKELETON_COLOR); 329 paint.setColor(SKELETON_COLOR);
300 SkPath scaled; 330 SkPath scaled;
301 SkMatrix matrix; 331 SkMatrix matrix;
302 matrix.reset(); 332 matrix.reset();
303 matrix.setScale(950 / fTextSize, 950 / fTextSize); 333 matrix.setScale(950 / scale, 950 / scale);
304 if (drawText) { 334 if (drawText) {
305 path.transform(matrix, &scaled); 335 path.transform(matrix, &scaled);
306 } else { 336 } else {
307 scaled = path; 337 scaled = path;
308 } 338 }
309 canvas->drawPath(scaled, paint); 339 canvas->drawPath(scaled, paint);
310 draw_points(canvas, scaled, SKELETON_COLOR, true); 340 draw_points(canvas, scaled, SKELETON_COLOR, true);
311 341
312 if (fDrawRibs) { 342 if (fDrawRibs) {
313 draw_ribs(canvas, scaled, width, 0xFF00FF00); 343 draw_ribs(canvas, scaled, width, 0xFF00FF00);
314 } 344 }
315 345
316 SkPath fill; 346 SkPath fill;
317 347
318 SkPaint p; 348 SkPaint p;
319 p.setStyle(SkPaint::kStroke_Style); 349 p.setStyle(SkPaint::kStroke_Style);
320 p.setStrokeWidth(width * fTextSize * fTextSize); 350 if (drawText) {
321 351 p.setStrokeWidth(width * scale * scale);
352 } else {
353 p.setStrokeWidth(width);
354 }
322 p.getFillPath(path, &fill); 355 p.getFillPath(path, &fill);
323 SkPath scaledFill; 356 SkPath scaledFill;
324 if (drawText) { 357 if (drawText) {
325 fill.transform(matrix, &scaledFill); 358 fill.transform(matrix, &scaledFill);
326 } else { 359 } else {
327 scaledFill = fill; 360 scaledFill = fill;
328 } 361 }
329 paint.setColor(WIREFRAME_COLOR); 362 paint.setColor(WIREFRAME_COLOR);
330 canvas->drawPath(scaledFill, paint); 363 canvas->drawPath(scaledFill, paint);
331 draw_points(canvas, scaledFill, WIREFRAME_COLOR, false); 364 draw_points(canvas, scaledFill, WIREFRAME_COLOR, false);
332 } 365 }
333 366
367 void draw_fill(SkCanvas* canvas, const SkRect& rect, SkScalar width) {
368 if (rect.isEmpty()) {
369 return;
370 }
371 SkPaint paint;
372 paint.setColor(0x1f1f0f0f);
373 paint.setStyle(SkPaint::kStroke_Style);
374 paint.setStrokeWidth(width);
375 SkPath path;
376 SkScalar maxSide = SkTMax(rect.width(), rect.height()) / 2;
377 SkPoint center = { rect.fLeft + maxSide, rect.fTop + maxSide };
378 path.addCircle(center.fX, center.fY, maxSide);
379 canvas->drawPath(path, paint);
380 paint.setStyle(SkPaint::kFill_Style);
381 path.reset();
382 path.addCircle(center.fX, center.fY, maxSide - width / 2);
383 paint.setColor(0x3f0f1f3f);
384 canvas->drawPath(path, paint);
385 path.reset();
386 path.setFillType(SkPath::kEvenOdd_FillType);
387 path.addCircle(center.fX, center.fY, maxSide + width / 2);
388 SkRect outside = SkRect::MakeXYWH(center.fX - maxSide - width, center.fY - maxSide - width,
389 (maxSide + width) * 2, (maxSide + width) * 2);
390 path.addRect(outside);
391 canvas->drawPath(path, paint);
392 }
393
334 void draw_button(SkCanvas* canvas, const StrokeTypeButton& button) { 394 void draw_button(SkCanvas* canvas, const StrokeTypeButton& button) {
335 SkPaint paint; 395 SkPaint paint;
336 paint.setAntiAlias(true); 396 paint.setAntiAlias(true);
337 paint.setStyle(SkPaint::kStroke_Style); 397 paint.setStyle(SkPaint::kStroke_Style);
338 paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000); 398 paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
339 canvas->drawRect(button.fBounds, paint); 399 canvas->drawRect(button.fBounds, paint);
340 paint.setTextSize(25.0f); 400 paint.setTextSize(25.0f);
341 paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000); 401 paint.setColor(button.fEnabled ? 0xFF3F0000 : 0x6F3F0000);
342 paint.setTextAlign(SkPaint::kCenter_Align); 402 paint.setTextAlign(SkPaint::kCenter_Align);
343 paint.setStyle(SkPaint::kFill_Style); 403 paint.setStyle(SkPaint::kFill_Style);
(...skipping 26 matching lines...) Expand all
370 fDrawTangents = true; 430 fDrawTangents = true;
371 fWidthScale = 1; 431 fWidthScale = 1;
372 } 432 }
373 433
374 void setForText() { 434 void setForText() {
375 fDrawRibs = fDrawTangents = false; 435 fDrawRibs = fDrawTangents = false;
376 fWidthScale = 0.002f; 436 fWidthScale = 0.002f;
377 } 437 }
378 438
379 void setAsNeeded() { 439 void setAsNeeded() {
380 if (fCubicButton.fEnabled || fQuadButton.fEnabled || fRRectButton.fEnabl ed) { 440 if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabl ed
441 || fRRectButton.fEnabled || fCircleButton.fEnabled) {
381 setForGeometry(); 442 setForGeometry();
382 } else { 443 } else {
383 setForText(); 444 setForText();
384 } 445 }
385 } 446 }
386 447
387 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { 448 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
388 SkPath path; 449 SkPath path;
389 SkScalar width = fWidth; 450 SkScalar width = fWidth;
390 451
391 if (fCubicButton.fEnabled) { 452 if (fCubicButton.fEnabled) {
392 path.moveTo(fPts[0]); 453 path.moveTo(fPts[0]);
393 path.cubicTo(fPts[1], fPts[2], fPts[3]); 454 path.cubicTo(fPts[1], fPts[2], fPts[3]);
394 setForGeometry(); 455 setForGeometry();
395 draw_stroke(canvas, path, width, false); 456 draw_stroke(canvas, path, width, 950, false);
457 }
458
459 if (fConicButton.fEnabled) {
460 path.moveTo(fPts[4]);
461 path.conicTo(fPts[5], fPts[6], fWeight);
462 setForGeometry();
463 draw_stroke(canvas, path, width, 950, false);
396 } 464 }
397 465
398 if (fQuadButton.fEnabled) { 466 if (fQuadButton.fEnabled) {
399 path.reset(); 467 path.reset();
400 path.moveTo(fPts[4]); 468 path.moveTo(fPts[7]);
401 path.quadTo(fPts[5], fPts[6]); 469 path.quadTo(fPts[8], fPts[9]);
402 setForGeometry(); 470 setForGeometry();
403 draw_stroke(canvas, path, width, false); 471 draw_stroke(canvas, path, width, 950, false);
404 } 472 }
405 473
406 if (fRRectButton.fEnabled) { 474 if (fRRectButton.fEnabled) {
407 SkScalar rad = 32; 475 SkScalar rad = 32;
408 SkRect r; 476 SkRect r;
409 r.set(&fPts[7], 2); 477 r.set(&fPts[10], 2);
410 path.reset(); 478 path.reset();
411 SkRRect rr; 479 SkRRect rr;
412 rr.setRectXY(r, rad, rad); 480 rr.setRectXY(r, rad, rad);
413 path.addRRect(rr); 481 path.addRRect(rr);
414 setForGeometry(); 482 setForGeometry();
415 draw_stroke(canvas, path, width, false); 483 draw_stroke(canvas, path, width, 950, false);
416 484
417 path.reset(); 485 path.reset();
418 SkRRect rr2; 486 SkRRect rr2;
419 rr.inset(width/2, width/2, &rr2); 487 rr.inset(width/2, width/2, &rr2);
420 path.addRRect(rr2, SkPath::kCCW_Direction); 488 path.addRRect(rr2, SkPath::kCCW_Direction);
421 rr.inset(-width/2, -width/2, &rr2); 489 rr.inset(-width/2, -width/2, &rr2);
422 path.addRRect(rr2, SkPath::kCW_Direction); 490 path.addRRect(rr2, SkPath::kCW_Direction);
423 SkPaint paint; 491 SkPaint paint;
424 paint.setAntiAlias(true); 492 paint.setAntiAlias(true);
425 paint.setColor(0x40FF8844); 493 paint.setColor(0x40FF8844);
426 canvas->drawPath(path, paint); 494 canvas->drawPath(path, paint);
427 } 495 }
428 496
497 if (fCircleButton.fEnabled) {
498 path.reset();
499 SkRect r;
500 r.set(&fPts[12], 2);
501 path.addOval(r);
502 setForGeometry();
503 if (fCircleButton.fFill) {
504 draw_fill(canvas, r, width);
505 } else {
506 draw_stroke(canvas, path, width, 950, false);
507 }
508 }
509
429 if (fTextButton.fEnabled) { 510 if (fTextButton.fEnabled) {
430 path.reset(); 511 path.reset();
431 SkPaint paint; 512 SkPaint paint;
432 paint.setAntiAlias(true); 513 paint.setAntiAlias(true);
433 paint.setTextSize(fTextSize); 514 paint.setTextSize(fTextSize);
434 paint.getTextPath(fText.c_str(), fText.size(), 0, fTextSize, &path); 515 paint.getTextPath(fText.c_str(), fText.size(), 0, fTextSize, &path);
435 setForText(); 516 setForText();
436 draw_stroke(canvas, path, width * fWidthScale / fTextSize, true); 517 draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize , true);
437 } 518 }
438 519
439 if (fAnimate) { 520 if (fAnimate) {
440 fWidth += fDWidth; 521 fWidth += fDWidth;
441 if (fDWidth > 0 && fWidth > kWidthMax) { 522 if (fDWidth > 0 && fWidth > kWidthMax) {
442 fDWidth = -fDWidth; 523 fDWidth = -fDWidth;
443 } else if (fDWidth < 0 && fWidth < kWidthMin) { 524 } else if (fDWidth < 0 && fWidth < kWidthMin) {
444 fDWidth = -fDWidth; 525 fDWidth = -fDWidth;
445 } 526 }
446 } 527 }
447 setAsNeeded(); 528 setAsNeeded();
529 if (fConicButton.fEnabled) {
530 draw_control(canvas, fWeightControl, fWeight, 0, 5, "weight");
531 }
448 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) 532 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
449 draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin , kStrokerErrorMax, 533 draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin , kStrokerErrorMax,
450 "error"); 534 "error");
451 #endif 535 #endif
452 draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fW idthScale, 536 draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fW idthScale,
453 kWidthMax * fWidthScale, "width"); 537 kWidthMax * fWidthScale, "width");
454 draw_button(canvas, fQuadButton); 538 draw_button(canvas, fQuadButton);
455 draw_button(canvas, fCubicButton); 539 draw_button(canvas, fCubicButton);
540 draw_button(canvas, fConicButton);
456 draw_button(canvas, fRRectButton); 541 draw_button(canvas, fRRectButton);
542 draw_button(canvas, fCircleButton);
457 draw_button(canvas, fTextButton); 543 draw_button(canvas, fTextButton);
458 this->inval(NULL); 544 this->inval(NULL);
459 } 545 }
460 546
461 class MyClick : public Click { 547 class MyClick : public Click {
462 public: 548 public:
463 int fIndex; 549 int fIndex;
464 MyClick(SkView* target, int index) : Click(target), fIndex(index) {} 550 MyClick(SkView* target, int index) : Click(target), fIndex(index) {}
465 }; 551 };
466 552
467 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, 553 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
468 unsigned modi) SK_OVERRIDE { 554 unsigned modi) SK_OVERRIDE {
469 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) { 555 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) {
470 if (hittest(fPts[i], x, y)) { 556 if (hittest(fPts[i], x, y)) {
471 return new MyClick(this, (int)i); 557 return new MyClick(this, (int)i);
472 } 558 }
473 } 559 }
474 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1); 560 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1);
561 if (fWeightControl.contains(rectPt)) {
562 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1);
563 }
475 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) 564 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
476 if (fErrorControl.contains(rectPt)) { 565 if (fErrorControl.contains(rectPt)) {
477 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1); 566 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 2);
478 } 567 }
479 #endif 568 #endif
480 if (fWidthControl.contains(rectPt)) { 569 if (fWidthControl.contains(rectPt)) {
481 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 3); 570 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 3);
482 } 571 }
483 if (fCubicButton.fBounds.contains(rectPt)) { 572 if (fCubicButton.fBounds.contains(rectPt)) {
484 fCubicButton.fEnabled ^= true; 573 fCubicButton.fEnabled ^= true;
485 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 4); 574 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 4);
486 } 575 }
576 if (fConicButton.fBounds.contains(rectPt)) {
577 fConicButton.fEnabled ^= true;
578 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 5);
579 }
487 if (fQuadButton.fBounds.contains(rectPt)) { 580 if (fQuadButton.fBounds.contains(rectPt)) {
488 fQuadButton.fEnabled ^= true; 581 fQuadButton.fEnabled ^= true;
489 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 5); 582 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6);
490 } 583 }
491 if (fRRectButton.fBounds.contains(rectPt)) { 584 if (fRRectButton.fBounds.contains(rectPt)) {
492 fRRectButton.fEnabled ^= true; 585 fRRectButton.fEnabled ^= true;
493 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6); 586 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 7);
587 }
588 if (fCircleButton.fBounds.contains(rectPt)) {
589 bool wasEnabled = fCircleButton.fEnabled;
590 fCircleButton.fEnabled = !fCircleButton.fFill;
591 fCircleButton.fFill = wasEnabled && !fCircleButton.fFill;
592 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 8);
494 } 593 }
495 if (fTextButton.fBounds.contains(rectPt)) { 594 if (fTextButton.fBounds.contains(rectPt)) {
496 fTextButton.fEnabled ^= true; 595 fTextButton.fEnabled ^= true;
497 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 7); 596 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 9);
498 } 597 }
499 return this->INHERITED::onFindClickHandler(x, y, modi); 598 return this->INHERITED::onFindClickHandler(x, y, modi);
500 } 599 }
501 600
502 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min , 601 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min ,
503 SkScalar max) { 602 SkScalar max) {
504 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min ) + min; 603 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min ) + min;
505 } 604 }
506 605
507 bool onClick(Click* click) SK_OVERRIDE { 606 bool onClick(Click* click) SK_OVERRIDE {
508 int index = ((MyClick*)click)->fIndex; 607 int index = ((MyClick*)click)->fIndex;
509 if (index < (int) SK_ARRAY_COUNT(fPts)) { 608 if (index < (int) SK_ARRAY_COUNT(fPts)) {
510 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX ), 609 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX ),
511 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY )); 610 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY ));
512 this->inval(NULL); 611 this->inval(NULL);
612 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) {
613 fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5);
513 } 614 }
514 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) 615 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG)
515 else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { 616 else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) {
516 gDebugStrokerError = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fI Curr.fY, 617 gDebugStrokerError = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fI Curr.fY,
517 fErrorControl, kStrokerErrorMin, kStrokerErrorMax)); 618 fErrorControl, kStrokerErrorMin, kStrokerErrorMax));
518 gDebugStrokerErrorSet = true; 619 gDebugStrokerErrorSet = true;
519 } 620 }
520 #endif 621 #endif
521 else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) { 622 else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) {
522 fWidth = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fICurr.fY, fWi dthControl, 623 fWidth = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fICurr.fY, fWi dthControl,
523 kWidthMin, kWidthMax)); 624 kWidthMin, kWidthMax));
524 fAnimate = fWidth <= kWidthMin; 625 fAnimate = fWidth <= kWidthMin;
525 } 626 }
526 return true; 627 return true;
527 } 628 }
528 629
529 private: 630 private:
530 typedef SkView INHERITED; 631 typedef SkView INHERITED;
531 }; 632 };
532 633
533 /////////////////////////////////////////////////////////////////////////////// 634 ///////////////////////////////////////////////////////////////////////////////
534 635
535 static SkView* F2() { return new QuadStrokerView; } 636 static SkView* F2() { return new QuadStrokerView; }
536 static SkViewRegister gR2(F2); 637 static SkViewRegister gR2(F2);
OLDNEW
« no previous file with comments | « gyp/common.gypi ('k') | src/core/SkStroke.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698