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

Side by Side Diff: samplecode/SampleQuadStroker.cpp

Issue 1612543003: replace arcto quads with a conic (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | « no previous file | src/core/SkGeometry.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 default: 70 default:
71 break; 71 break;
72 } 72 }
73 } 73 }
74 if (count > 0) { 74 if (count > 0) {
75 contourCounts->push_back(count); 75 contourCounts->push_back(count);
76 } 76 }
77 } 77 }
78 78
79 static void erase(SkSurface* surface) { 79 static void erase(SkSurface* surface) {
80 surface->getCanvas()->clear(SK_ColorTRANSPARENT); 80 SkCanvas* canvas = surface->getCanvas();
81 if (canvas) {
82 canvas->clear(SK_ColorTRANSPARENT);
83 }
81 } 84 }
82 85
83 struct StrokeTypeButton { 86 struct StrokeTypeButton {
84 SkRect fBounds; 87 SkRect fBounds;
85 char fLabel; 88 char fLabel;
86 bool fEnabled; 89 bool fEnabled;
87 }; 90 };
88 91
89 struct CircleTypeButton : public StrokeTypeButton { 92 struct CircleTypeButton : public StrokeTypeButton {
90 bool fFill; 93 bool fFill;
91 }; 94 };
92 95
93 class QuadStrokerView : public SampleView { 96 class QuadStrokerView : public SampleView {
94 enum { 97 enum {
95 SKELETON_COLOR = 0xFF0000FF, 98 SKELETON_COLOR = 0xFF0000FF,
96 WIREFRAME_COLOR = 0x80FF0000 99 WIREFRAME_COLOR = 0x80FF0000
97 }; 100 };
98 101
99 enum { 102 enum {
100 kCount = 15 103 kCount = 18
101 }; 104 };
102 SkPoint fPts[kCount]; 105 SkPoint fPts[kCount];
103 SkRect fWeightControl; 106 SkRect fWeightControl;
107 SkRect fRadiusControl;
104 SkRect fErrorControl; 108 SkRect fErrorControl;
105 SkRect fWidthControl; 109 SkRect fWidthControl;
106 SkRect fBounds; 110 SkRect fBounds;
107 SkMatrix fMatrix, fInverse; 111 SkMatrix fMatrix, fInverse;
108 SkAutoTUnref<SkShader> fShader; 112 SkAutoTUnref<SkShader> fShader;
109 SkAutoTUnref<SkSurface> fMinSurface; 113 SkAutoTUnref<SkSurface> fMinSurface;
110 SkAutoTUnref<SkSurface> fMaxSurface; 114 SkAutoTUnref<SkSurface> fMaxSurface;
111 StrokeTypeButton fCubicButton; 115 StrokeTypeButton fCubicButton;
112 StrokeTypeButton fConicButton; 116 StrokeTypeButton fConicButton;
113 StrokeTypeButton fQuadButton; 117 StrokeTypeButton fQuadButton;
118 StrokeTypeButton fArcButton;
114 StrokeTypeButton fRRectButton; 119 StrokeTypeButton fRRectButton;
115 CircleTypeButton fCircleButton; 120 CircleTypeButton fCircleButton;
116 StrokeTypeButton fTextButton; 121 StrokeTypeButton fTextButton;
117 SkString fText; 122 SkString fText;
118 SkScalar fTextSize; 123 SkScalar fTextSize;
119 SkScalar fWeight; 124 SkScalar fWeight;
125 SkScalar fRadius;
120 SkScalar fWidth, fDWidth; 126 SkScalar fWidth, fDWidth;
121 SkScalar fWidthScale; 127 SkScalar fWidthScale;
122 int fW, fH, fZoom; 128 int fW, fH, fZoom;
123 bool fAnimate; 129 bool fAnimate;
124 bool fDrawRibs; 130 bool fDrawRibs;
125 bool fDrawTangents; 131 bool fDrawTangents;
126 bool fDrawTDivs; 132 bool fDrawTDivs;
127 #ifdef SK_DEBUG 133 #ifdef SK_DEBUG
128 #define kStrokerErrorMin 0.001f 134 #define kStrokerErrorMin 0.001f
129 #define kStrokerErrorMax 5 135 #define kStrokerErrorMax 5
(...skipping 10 matching lines...) Expand all
140 fPts[3].set(300, 50); 146 fPts[3].set(300, 50);
141 147
142 fPts[4].set(350, 200); // conic 148 fPts[4].set(350, 200); // conic
143 fPts[5].set(350, 100); 149 fPts[5].set(350, 100);
144 fPts[6].set(450, 50); 150 fPts[6].set(450, 50);
145 151
146 fPts[7].set(150, 300); // quad 152 fPts[7].set(150, 300); // quad
147 fPts[8].set(150, 200); 153 fPts[8].set(150, 200);
148 fPts[9].set(250, 150); 154 fPts[9].set(250, 150);
149 155
150 fPts[10].set(200, 200); // rrect 156 fPts[10].set(250, 200); // arc
151 fPts[11].set(400, 400); 157 fPts[11].set(250, 300);
158 fPts[12].set(150, 350);
152 159
153 fPts[12].set(250, 250); // oval 160 fPts[13].set(200, 200); // rrect
154 fPts[13].set(450, 450); 161 fPts[14].set(400, 400);
162
163 fPts[15].set(250, 250); // oval
164 fPts[16].set(450, 450);
155 165
156 fText = "a"; 166 fText = "a";
157 fTextSize = 12; 167 fTextSize = 12;
158 fWidth = 50; 168 fWidth = 50;
159 fDWidth = 0.25f; 169 fDWidth = 0.25f;
160 fWeight = 1; 170 fWeight = 1;
171 fRadius = 150;
161 172
162 fCubicButton.fLabel = 'C'; 173 fCubicButton.fLabel = 'C';
163 fCubicButton.fEnabled = false; 174 fCubicButton.fEnabled = false;
164 fConicButton.fLabel = 'K'; 175 fConicButton.fLabel = 'K';
165 fConicButton.fEnabled = true; 176 fConicButton.fEnabled = false;
166 fQuadButton.fLabel = 'Q'; 177 fQuadButton.fLabel = 'Q';
167 fQuadButton.fEnabled = false; 178 fQuadButton.fEnabled = false;
179 fArcButton.fLabel = 'A';
180 fArcButton.fEnabled = true;
168 fRRectButton.fLabel = 'R'; 181 fRRectButton.fLabel = 'R';
169 fRRectButton.fEnabled = false; 182 fRRectButton.fEnabled = false;
170 fCircleButton.fLabel = 'O'; 183 fCircleButton.fLabel = 'O';
171 fCircleButton.fEnabled = false; 184 fCircleButton.fEnabled = true;
172 fCircleButton.fFill = false; 185 fCircleButton.fFill = true;
173 fTextButton.fLabel = 'T'; 186 fTextButton.fLabel = 'T';
174 fTextButton.fEnabled = false; 187 fTextButton.fEnabled = false;
175 fAnimate = true; 188 fAnimate = false;
176 setAsNeeded(); 189 setAsNeeded();
177 } 190 }
178 191
179 protected: 192 protected:
180 bool onQuery(SkEvent* evt) override { 193 bool onQuery(SkEvent* evt) override {
181 if (SampleCode::TitleQ(*evt)) { 194 if (SampleCode::TitleQ(*evt)) {
182 SampleCode::TitleR(evt, "QuadStroker"); 195 SampleCode::TitleR(evt, "QuadStroker");
183 return true; 196 return true;
184 } 197 }
185 SkUnichar uni; 198 SkUnichar uni;
(...skipping 12 matching lines...) Expand all
198 default: 211 default:
199 fText.appendUnichar(uni); 212 fText.appendUnichar(uni);
200 } 213 }
201 this->inval(nullptr); 214 this->inval(nullptr);
202 return true; 215 return true;
203 } 216 }
204 return this->INHERITED::onQuery(evt); 217 return this->INHERITED::onQuery(evt);
205 } 218 }
206 219
207 void onSizeChange() override { 220 void onSizeChange() override {
221 fRadiusControl.setXYWH(this->width() - 200, 30, 30, 400);
208 fWeightControl.setXYWH(this->width() - 150, 30, 30, 400); 222 fWeightControl.setXYWH(this->width() - 150, 30, 30, 400);
209 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); 223 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400);
210 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); 224 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400);
211 int buttonOffset = 450; 225 int buttonOffset = 450;
212 fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30); 226 fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
213 buttonOffset += 50; 227 buttonOffset += 50;
214 fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30); 228 fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
215 buttonOffset += 50; 229 buttonOffset += 50;
216 fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30); 230 fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30);
217 buttonOffset += 50; 231 buttonOffset += 50;
232 fArcButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffse t), 30, 30);
233 buttonOffset += 50;
218 fRRectButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30); 234 fRRectButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff set), 30, 30);
219 buttonOffset += 50; 235 buttonOffset += 50;
220 fCircleButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOf fset), 30, 30); 236 fCircleButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOf fset), 30, 30);
221 buttonOffset += 50; 237 buttonOffset += 50;
222 fTextButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30); 238 fTextButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs et), 30, 30);
223 this->INHERITED::onSizeChange(); 239 this->INHERITED::onSizeChange();
224 } 240 }
225 241
226 void copyMinToMax() { 242 void copyMinToMax() {
227 erase(fMaxSurface); 243 erase(fMaxSurface);
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 } 528 }
513 529
514 void setForSingles() { 530 void setForSingles() {
515 setForGeometry(); 531 setForGeometry();
516 fDrawTDivs = true; 532 fDrawTDivs = true;
517 } 533 }
518 534
519 void setAsNeeded() { 535 void setAsNeeded() {
520 if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabl ed) { 536 if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabl ed) {
521 setForSingles(); 537 setForSingles();
522 } else if (fRRectButton.fEnabled || fCircleButton.fEnabled) { 538 } else if (fRRectButton.fEnabled || fCircleButton.fEnabled || fArcButton .fEnabled) {
523 setForGeometry(); 539 setForGeometry();
524 } else { 540 } else {
525 setForText(); 541 setForText();
526 } 542 }
527 } 543 }
528 544
545 bool arcCenter(SkPoint* center) {
546 SkPath path;
547 path.moveTo(fPts[10]);
548 path.arcTo(fPts[11], fPts[12], fRadius);
549 SkPath::Iter iter(path, false);
550 SkPoint pts[4];
551 iter.next(pts);
552 if (SkPath::kLine_Verb == iter.next(pts)) {
553 iter.next(pts);
554 }
555 SkVector before = pts[0] - pts[1];
556 SkVector after = pts[1] - pts[2];
557 before.setLength(fRadius);
558 after.setLength(fRadius);
559 SkVector beforeCCW, afterCCW;
560 before.rotateCCW(&beforeCCW);
561 after.rotateCCW(&afterCCW);
562 beforeCCW += pts[0];
563 afterCCW += pts[2];
564 *center = beforeCCW;
565 if (SkScalarNearlyEqual(beforeCCW.fX, afterCCW.fX)
566 && SkScalarNearlyEqual(beforeCCW.fY, afterCCW.fY)) {
567 return true;
568 }
569 SkVector beforeCW, afterCW;
570 before.rotateCW(&beforeCW);
571 after.rotateCW(&afterCW);
572 beforeCW += pts[0];
573 afterCW += pts[2];
574 *center = beforeCW;
575 return SkScalarNearlyEqual(beforeCW.fX, afterCW.fX)
576 && SkScalarNearlyEqual(beforeCCW.fY, afterCW.fY);
577 }
578
529 void onDrawContent(SkCanvas* canvas) override { 579 void onDrawContent(SkCanvas* canvas) override {
530 SkPath path; 580 SkPath path;
531 SkScalar width = fWidth; 581 SkScalar width = fWidth;
532 582
533 if (fCubicButton.fEnabled) { 583 if (fCubicButton.fEnabled) {
534 path.moveTo(fPts[0]); 584 path.moveTo(fPts[0]);
535 path.cubicTo(fPts[1], fPts[2], fPts[3]); 585 path.cubicTo(fPts[1], fPts[2], fPts[3]);
536 setForSingles(); 586 setForSingles();
537 draw_stroke(canvas, path, width, 950, false); 587 draw_stroke(canvas, path, width, 950, false);
538 } 588 }
539 589
540 if (fConicButton.fEnabled) { 590 if (fConicButton.fEnabled) {
541 path.reset(); 591 path.reset();
542 path.moveTo(fPts[4]); 592 path.moveTo(fPts[4]);
543 path.conicTo(fPts[5], fPts[6], fWeight); 593 path.conicTo(fPts[5], fPts[6], fWeight);
544 setForSingles(); 594 setForSingles();
545 draw_stroke(canvas, path, width, 950, false); 595 draw_stroke(canvas, path, width, 950, false);
546 } 596 }
547 597
548 if (fQuadButton.fEnabled) { 598 if (fQuadButton.fEnabled) {
549 path.reset(); 599 path.reset();
550 path.moveTo(fPts[7]); 600 path.moveTo(fPts[7]);
551 path.quadTo(fPts[8], fPts[9]); 601 path.quadTo(fPts[8], fPts[9]);
552 setForSingles(); 602 setForSingles();
553 draw_stroke(canvas, path, width, 950, false); 603 draw_stroke(canvas, path, width, 950, false);
554 } 604 }
555 605
606 if (fArcButton.fEnabled) {
607 path.reset();
608 path.moveTo(fPts[10]);
609 path.arcTo(fPts[11], fPts[12], fRadius);
610 setForGeometry();
611 draw_stroke(canvas, path, width, 950, false);
612 SkPath pathPts;
613 pathPts.moveTo(fPts[10]);
614 pathPts.lineTo(fPts[11]);
615 pathPts.lineTo(fPts[12]);
616 draw_points(canvas, pathPts, SK_ColorDKGRAY, true);
617 }
618
556 if (fRRectButton.fEnabled) { 619 if (fRRectButton.fEnabled) {
557 SkScalar rad = 32; 620 SkScalar rad = 32;
558 SkRect r; 621 SkRect r;
559 r.set(&fPts[10], 2); 622 r.set(&fPts[13], 2);
560 path.reset(); 623 path.reset();
561 SkRRect rr; 624 SkRRect rr;
562 rr.setRectXY(r, rad, rad); 625 rr.setRectXY(r, rad, rad);
563 path.addRRect(rr); 626 path.addRRect(rr);
564 setForGeometry(); 627 setForGeometry();
565 draw_stroke(canvas, path, width, 950, false); 628 draw_stroke(canvas, path, width, 950, false);
566 629
567 path.reset(); 630 path.reset();
568 SkRRect rr2; 631 SkRRect rr2;
569 rr.inset(width/2, width/2, &rr2); 632 rr.inset(width/2, width/2, &rr2);
570 path.addRRect(rr2, SkPath::kCCW_Direction); 633 path.addRRect(rr2, SkPath::kCCW_Direction);
571 rr.inset(-width/2, -width/2, &rr2); 634 rr.inset(-width/2, -width/2, &rr2);
572 path.addRRect(rr2, SkPath::kCW_Direction); 635 path.addRRect(rr2, SkPath::kCW_Direction);
573 SkPaint paint; 636 SkPaint paint;
574 paint.setAntiAlias(true); 637 paint.setAntiAlias(true);
575 paint.setColor(0x40FF8844); 638 paint.setColor(0x40FF8844);
576 canvas->drawPath(path, paint); 639 canvas->drawPath(path, paint);
577 } 640 }
578 641
579 if (fCircleButton.fEnabled) { 642 if (fCircleButton.fEnabled) {
580 path.reset(); 643 path.reset();
581 SkRect r; 644 SkRect r;
582 r.set(&fPts[12], 2); 645 r.set(&fPts[15], 2);
583 path.addOval(r); 646 path.addOval(r);
584 setForGeometry(); 647 setForGeometry();
585 if (fCircleButton.fFill) { 648 if (fCircleButton.fFill) {
649 if (fArcButton.fEnabled) {
650 SkPoint center;
651 if (arcCenter(&center)) {
652 r.set(center.fX - fRadius, center.fY - fRadius, center.f X + fRadius,
653 center.fY + fRadius);
654 }
655 }
586 draw_fill(canvas, r, width); 656 draw_fill(canvas, r, width);
587 } else { 657 } else {
588 draw_stroke(canvas, path, width, 950, false); 658 draw_stroke(canvas, path, width, 950, false);
589 } 659 }
590 } 660 }
591 661
592 if (fTextButton.fEnabled) { 662 if (fTextButton.fEnabled) {
593 path.reset(); 663 path.reset();
594 SkPaint paint; 664 SkPaint paint;
595 paint.setAntiAlias(true); 665 paint.setAntiAlias(true);
596 paint.setTextSize(fTextSize); 666 paint.setTextSize(fTextSize);
597 paint.getTextPath(fText.c_str(), fText.size(), 0, fTextSize, &path); 667 paint.getTextPath(fText.c_str(), fText.size(), 0, fTextSize, &path);
598 setForText(); 668 setForText();
599 draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize , true); 669 draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize , true);
600 } 670 }
601 671
602 if (fAnimate) { 672 if (fAnimate) {
603 fWidth += fDWidth; 673 fWidth += fDWidth;
604 if (fDWidth > 0 && fWidth > kWidthMax) { 674 if (fDWidth > 0 && fWidth > kWidthMax) {
605 fDWidth = -fDWidth; 675 fDWidth = -fDWidth;
606 } else if (fDWidth < 0 && fWidth < kWidthMin) { 676 } else if (fDWidth < 0 && fWidth < kWidthMin) {
607 fDWidth = -fDWidth; 677 fDWidth = -fDWidth;
608 } 678 }
609 } 679 }
610 setAsNeeded(); 680 setAsNeeded();
611 if (fConicButton.fEnabled) { 681 if (fConicButton.fEnabled) {
612 draw_control(canvas, fWeightControl, fWeight, 0, 5, "weight"); 682 draw_control(canvas, fWeightControl, fWeight, 0, 5, "weight");
613 } 683 }
684 if (fArcButton.fEnabled) {
685 draw_control(canvas, fRadiusControl, fRadius, 0, 500, "radius");
686 }
614 #ifdef SK_DEBUG 687 #ifdef SK_DEBUG
615 draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin , kStrokerErrorMax, 688 draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin , kStrokerErrorMax,
616 "error"); 689 "error");
617 #endif 690 #endif
618 draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fW idthScale, 691 draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fW idthScale,
619 kWidthMax * fWidthScale, "width"); 692 kWidthMax * fWidthScale, "width");
620 draw_button(canvas, fQuadButton); 693 draw_button(canvas, fQuadButton);
621 draw_button(canvas, fCubicButton); 694 draw_button(canvas, fCubicButton);
622 draw_button(canvas, fConicButton); 695 draw_button(canvas, fConicButton);
696 draw_button(canvas, fArcButton);
623 draw_button(canvas, fRRectButton); 697 draw_button(canvas, fRRectButton);
624 draw_button(canvas, fCircleButton); 698 draw_button(canvas, fCircleButton);
625 draw_button(canvas, fTextButton); 699 draw_button(canvas, fTextButton);
626 this->inval(nullptr); 700 this->inval(nullptr);
627 } 701 }
628 702
629 class MyClick : public Click { 703 class MyClick : public Click {
630 public: 704 public:
631 int fIndex; 705 int fIndex;
632 MyClick(SkView* target, int index) : Click(target), fIndex(index) {} 706 MyClick(SkView* target, int index) : Click(target), fIndex(index) {}
633 }; 707 };
634 708
635 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, 709 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
636 unsigned modi) override { 710 unsigned modi) override {
637 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) { 711 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) {
638 if (hittest(fPts[i], x, y)) { 712 if (hittest(fPts[i], x, y)) {
639 return new MyClick(this, (int)i); 713 return new MyClick(this, (int)i);
640 } 714 }
641 } 715 }
642 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1); 716 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1);
643 if (fWeightControl.contains(rectPt)) { 717 if (fWeightControl.contains(rectPt)) {
644 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1); 718 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1);
645 } 719 }
720 if (fRadiusControl.contains(rectPt)) {
721 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 2);
722 }
646 #ifdef SK_DEBUG 723 #ifdef SK_DEBUG
647 if (fErrorControl.contains(rectPt)) { 724 if (fErrorControl.contains(rectPt)) {
648 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 2); 725 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 3);
649 } 726 }
650 #endif 727 #endif
651 if (fWidthControl.contains(rectPt)) { 728 if (fWidthControl.contains(rectPt)) {
652 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 3); 729 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 4);
653 } 730 }
654 if (fCubicButton.fBounds.contains(rectPt)) { 731 if (fCubicButton.fBounds.contains(rectPt)) {
655 fCubicButton.fEnabled ^= true; 732 fCubicButton.fEnabled ^= true;
656 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 4); 733 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 5);
657 } 734 }
658 if (fConicButton.fBounds.contains(rectPt)) { 735 if (fConicButton.fBounds.contains(rectPt)) {
659 fConicButton.fEnabled ^= true; 736 fConicButton.fEnabled ^= true;
660 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 5); 737 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6);
661 } 738 }
662 if (fQuadButton.fBounds.contains(rectPt)) { 739 if (fQuadButton.fBounds.contains(rectPt)) {
663 fQuadButton.fEnabled ^= true; 740 fQuadButton.fEnabled ^= true;
664 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6); 741 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 7);
742 }
743 if (fArcButton.fBounds.contains(rectPt)) {
744 fArcButton.fEnabled ^= true;
745 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 8);
665 } 746 }
666 if (fRRectButton.fBounds.contains(rectPt)) { 747 if (fRRectButton.fBounds.contains(rectPt)) {
667 fRRectButton.fEnabled ^= true; 748 fRRectButton.fEnabled ^= true;
668 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 7); 749 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 9);
669 } 750 }
670 if (fCircleButton.fBounds.contains(rectPt)) { 751 if (fCircleButton.fBounds.contains(rectPt)) {
671 bool wasEnabled = fCircleButton.fEnabled; 752 bool wasEnabled = fCircleButton.fEnabled;
672 fCircleButton.fEnabled = !fCircleButton.fFill; 753 fCircleButton.fEnabled = !fCircleButton.fFill;
673 fCircleButton.fFill = wasEnabled && !fCircleButton.fFill; 754 fCircleButton.fFill = wasEnabled && !fCircleButton.fFill;
674 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 8); 755 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 10);
675 } 756 }
676 if (fTextButton.fBounds.contains(rectPt)) { 757 if (fTextButton.fBounds.contains(rectPt)) {
677 fTextButton.fEnabled ^= true; 758 fTextButton.fEnabled ^= true;
678 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 9); 759 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 11);
679 } 760 }
680 return this->INHERITED::onFindClickHandler(x, y, modi); 761 return this->INHERITED::onFindClickHandler(x, y, modi);
681 } 762 }
682 763
683 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min , 764 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min ,
684 SkScalar max) { 765 SkScalar max) {
685 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min ) + min; 766 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min ) + min;
686 } 767 }
687 768
688 bool onClick(Click* click) override { 769 bool onClick(Click* click) override {
689 int index = ((MyClick*)click)->fIndex; 770 int index = ((MyClick*)click)->fIndex;
690 if (index < (int) SK_ARRAY_COUNT(fPts)) { 771 if (index < (int) SK_ARRAY_COUNT(fPts)) {
691 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX ), 772 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX ),
692 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY )); 773 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY ));
693 this->inval(nullptr); 774 this->inval(nullptr);
694 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { 775 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) {
695 fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5); 776 fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5);
777 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) {
778 fRadius = MapScreenYtoValue(click->fICurr.fY, fRadiusControl, 0, 500 );
696 } 779 }
697 #ifdef SK_DEBUG 780 #ifdef SK_DEBUG
698 else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) { 781 else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) {
699 gDebugStrokerError = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fI Curr.fY, 782 gDebugStrokerError = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fI Curr.fY,
700 fErrorControl, kStrokerErrorMin, kStrokerErrorMax)); 783 fErrorControl, kStrokerErrorMin, kStrokerErrorMax));
701 gDebugStrokerErrorSet = true; 784 gDebugStrokerErrorSet = true;
702 } 785 }
703 #endif 786 #endif
704 else if (index == (int) SK_ARRAY_COUNT(fPts) + 3) { 787 else if (index == (int) SK_ARRAY_COUNT(fPts) + 4) {
705 fWidth = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fICurr.fY, fWi dthControl, 788 fWidth = SkTMax(FLT_EPSILON, MapScreenYtoValue(click->fICurr.fY, fWi dthControl,
706 kWidthMin, kWidthMax)); 789 kWidthMin, kWidthMax));
707 fAnimate = fWidth <= kWidthMin; 790 fAnimate = fWidth <= kWidthMin;
708 } 791 }
709 return true; 792 return true;
710 } 793 }
711 794
712 private: 795 private:
713 typedef SkView INHERITED; 796 typedef SkView INHERITED;
714 }; 797 };
715 798
716 /////////////////////////////////////////////////////////////////////////////// 799 ///////////////////////////////////////////////////////////////////////////////
717 800
718 static SkView* F2() { return new QuadStrokerView; } 801 static SkView* F2() { return new QuadStrokerView; }
719 static SkViewRegister gR2(F2); 802 static SkViewRegister gR2(F2);
OLDNEW
« no previous file with comments | « no previous file | src/core/SkGeometry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698