| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 fCircleButton.fLabel = 'O'; | 168 fCircleButton.fLabel = 'O'; |
| 169 fCircleButton.fEnabled = false; | 169 fCircleButton.fEnabled = false; |
| 170 fCircleButton.fFill = false; | 170 fCircleButton.fFill = false; |
| 171 fTextButton.fLabel = 'T'; | 171 fTextButton.fLabel = 'T'; |
| 172 fTextButton.fEnabled = false; | 172 fTextButton.fEnabled = false; |
| 173 fAnimate = true; | 173 fAnimate = true; |
| 174 setAsNeeded(); | 174 setAsNeeded(); |
| 175 } | 175 } |
| 176 | 176 |
| 177 protected: | 177 protected: |
| 178 bool onQuery(SkEvent* evt) SK_OVERRIDE { | 178 bool onQuery(SkEvent* evt) override { |
| 179 if (SampleCode::TitleQ(*evt)) { | 179 if (SampleCode::TitleQ(*evt)) { |
| 180 SampleCode::TitleR(evt, "QuadStroker"); | 180 SampleCode::TitleR(evt, "QuadStroker"); |
| 181 return true; | 181 return true; |
| 182 } | 182 } |
| 183 SkUnichar uni; | 183 SkUnichar uni; |
| 184 if (fTextButton.fEnabled && SampleCode::CharQ(*evt, &uni)) { | 184 if (fTextButton.fEnabled && SampleCode::CharQ(*evt, &uni)) { |
| 185 switch (uni) { | 185 switch (uni) { |
| 186 case ' ': | 186 case ' ': |
| 187 fText = ""; | 187 fText = ""; |
| 188 break; | 188 break; |
| 189 case '-': | 189 case '-': |
| 190 fTextSize = SkTMax(1.0f, fTextSize - 1); | 190 fTextSize = SkTMax(1.0f, fTextSize - 1); |
| 191 break; | 191 break; |
| 192 case '+': | 192 case '+': |
| 193 case '=': | 193 case '=': |
| 194 fTextSize += 1; | 194 fTextSize += 1; |
| 195 break; | 195 break; |
| 196 default: | 196 default: |
| 197 fText.appendUnichar(uni); | 197 fText.appendUnichar(uni); |
| 198 } | 198 } |
| 199 this->inval(NULL); | 199 this->inval(NULL); |
| 200 return true; | 200 return true; |
| 201 } | 201 } |
| 202 return this->INHERITED::onQuery(evt); | 202 return this->INHERITED::onQuery(evt); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void onSizeChange() SK_OVERRIDE { | 205 void onSizeChange() override { |
| 206 fWeightControl.setXYWH(this->width() - 150, 30, 30, 400); | 206 fWeightControl.setXYWH(this->width() - 150, 30, 30, 400); |
| 207 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); | 207 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); |
| 208 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); | 208 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); |
| 209 int buttonOffset = 450; | 209 int buttonOffset = 450; |
| 210 fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff
set), 30, 30); | 210 fCubicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff
set), 30, 30); |
| 211 buttonOffset += 50; | 211 buttonOffset += 50; |
| 212 fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff
set), 30, 30); | 212 fConicButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOff
set), 30, 30); |
| 213 buttonOffset += 50; | 213 buttonOffset += 50; |
| 214 fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs
et), 30, 30); | 214 fQuadButton.fBounds.setXYWH(this->width() - 50, SkIntToScalar(buttonOffs
et), 30, 30); |
| 215 buttonOffset += 50; | 215 buttonOffset += 50; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 | 438 |
| 439 void setAsNeeded() { | 439 void setAsNeeded() { |
| 440 if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabl
ed | 440 if (fConicButton.fEnabled || fCubicButton.fEnabled || fQuadButton.fEnabl
ed |
| 441 || fRRectButton.fEnabled || fCircleButton.fEnabled) { | 441 || fRRectButton.fEnabled || fCircleButton.fEnabled) { |
| 442 setForGeometry(); | 442 setForGeometry(); |
| 443 } else { | 443 } else { |
| 444 setForText(); | 444 setForText(); |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 448 void onDrawContent(SkCanvas* canvas) override { |
| 449 SkPath path; | 449 SkPath path; |
| 450 SkScalar width = fWidth; | 450 SkScalar width = fWidth; |
| 451 | 451 |
| 452 if (fCubicButton.fEnabled) { | 452 if (fCubicButton.fEnabled) { |
| 453 path.moveTo(fPts[0]); | 453 path.moveTo(fPts[0]); |
| 454 path.cubicTo(fPts[1], fPts[2], fPts[3]); | 454 path.cubicTo(fPts[1], fPts[2], fPts[3]); |
| 455 setForGeometry(); | 455 setForGeometry(); |
| 456 draw_stroke(canvas, path, width, 950, false); | 456 draw_stroke(canvas, path, width, 950, false); |
| 457 } | 457 } |
| 458 | 458 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 this->inval(NULL); | 544 this->inval(NULL); |
| 545 } | 545 } |
| 546 | 546 |
| 547 class MyClick : public Click { | 547 class MyClick : public Click { |
| 548 public: | 548 public: |
| 549 int fIndex; | 549 int fIndex; |
| 550 MyClick(SkView* target, int index) : Click(target), fIndex(index) {} | 550 MyClick(SkView* target, int index) : Click(target), fIndex(index) {} |
| 551 }; | 551 }; |
| 552 | 552 |
| 553 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, | 553 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
| 554 unsigned modi) SK_OVERRIDE { | 554 unsigned modi) override { |
| 555 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) { | 555 for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) { |
| 556 if (hittest(fPts[i], x, y)) { | 556 if (hittest(fPts[i], x, y)) { |
| 557 return new MyClick(this, (int)i); | 557 return new MyClick(this, (int)i); |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1); | 560 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1); |
| 561 if (fWeightControl.contains(rectPt)) { | 561 if (fWeightControl.contains(rectPt)) { |
| 562 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1); | 562 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 1); |
| 563 } | 563 } |
| 564 #if !defined SK_LEGACY_STROKE_CURVES && defined(SK_DEBUG) | 564 #if !defined SK_LEGACY_STROKE_CURVES && defined(SK_DEBUG) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 9); | 596 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 9); |
| 597 } | 597 } |
| 598 return this->INHERITED::onFindClickHandler(x, y, modi); | 598 return this->INHERITED::onFindClickHandler(x, y, modi); |
| 599 } | 599 } |
| 600 | 600 |
| 601 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min
, | 601 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min
, |
| 602 SkScalar max) { | 602 SkScalar max) { |
| 603 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min
) + min; | 603 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min
) + min; |
| 604 } | 604 } |
| 605 | 605 |
| 606 bool onClick(Click* click) SK_OVERRIDE { | 606 bool onClick(Click* click) override { |
| 607 int index = ((MyClick*)click)->fIndex; | 607 int index = ((MyClick*)click)->fIndex; |
| 608 if (index < (int) SK_ARRAY_COUNT(fPts)) { | 608 if (index < (int) SK_ARRAY_COUNT(fPts)) { |
| 609 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX
), | 609 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX
), |
| 610 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY
)); | 610 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY
)); |
| 611 this->inval(NULL); | 611 this->inval(NULL); |
| 612 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { | 612 } else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { |
| 613 fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5); | 613 fWeight = MapScreenYtoValue(click->fICurr.fY, fWeightControl, 0, 5); |
| 614 } | 614 } |
| 615 #if !defined SK_LEGACY_STROKE_CURVES && defined(SK_DEBUG) | 615 #if !defined SK_LEGACY_STROKE_CURVES && defined(SK_DEBUG) |
| 616 else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) { | 616 else if (index == (int) SK_ARRAY_COUNT(fPts) + 2) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 628 } | 628 } |
| 629 | 629 |
| 630 private: | 630 private: |
| 631 typedef SkView INHERITED; | 631 typedef SkView INHERITED; |
| 632 }; | 632 }; |
| 633 | 633 |
| 634 /////////////////////////////////////////////////////////////////////////////// | 634 /////////////////////////////////////////////////////////////////////////////// |
| 635 | 635 |
| 636 static SkView* F2() { return new QuadStrokerView; } | 636 static SkView* F2() { return new QuadStrokerView; } |
| 637 static SkViewRegister gR2(F2); | 637 static SkViewRegister gR2(F2); |
| OLD | NEW |