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 "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkView.h" | 9 #include "SkView.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 int fAngle; | 89 int fAngle; |
90 typedef SkView INHERITED; | 90 typedef SkView INHERITED; |
91 }; | 91 }; |
92 | 92 |
93 class TestCirclesView : public SampleView { | 93 class TestCirclesView : public SampleView { |
94 public: | 94 public: |
95 TestCirclesView() { | 95 TestCirclesView() { |
96 } | 96 } |
97 | 97 |
98 protected: | 98 protected: |
99 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 99 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
100 if (SampleCode::TitleQ(*evt)) { | 100 if (SampleCode::TitleQ(*evt)) { |
101 SampleCode::TitleR(evt, "RotateCircles2"); | 101 SampleCode::TitleR(evt, "RotateCircles2"); |
102 return true; | 102 return true; |
103 } | 103 } |
104 return this->INHERITED::onQuery(evt); | 104 return this->INHERITED::onQuery(evt); |
105 } | 105 } |
106 | 106 |
107 void draw_real_circle(SkCanvas* canvas, SkScalar radius) { | 107 void draw_real_circle(SkCanvas* canvas, SkScalar radius) { |
108 int w = SkScalarCeilToInt(radius * 2); | 108 int w = SkScalarCeilToInt(radius * 2); |
109 int h = w; | 109 int h = w; |
(...skipping 11 matching lines...) Expand all Loading... |
121 float d = sqrtf((x - cx)*(x - cx) + (y - cy)*(y - cy)); | 121 float d = sqrtf((x - cx)*(x - cx) + (y - cy)*(y - cy)); |
122 if (d <= radius) { | 122 if (d <= radius) { |
123 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0, 0, 0); | 123 *bm.getAddr32(x, y) = SkPackARGB32(0xFF, 0, 0, 0); |
124 } | 124 } |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 canvas->drawBitmap(bm, 0, 0, NULL); | 128 canvas->drawBitmap(bm, 0, 0, NULL); |
129 } | 129 } |
130 | 130 |
131 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 131 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
132 SkScalar radius = 256; | 132 SkScalar radius = 256; |
133 canvas->translate(10, 10); | 133 canvas->translate(10, 10); |
134 | 134 |
135 draw_real_circle(canvas, radius); | 135 draw_real_circle(canvas, radius); |
136 | 136 |
137 SkPaint paint; | 137 SkPaint paint; |
138 paint.setAntiAlias(true); | 138 paint.setAntiAlias(true); |
139 | 139 |
140 paint.setColor(0x80FF0000); | 140 paint.setColor(0x80FF0000); |
141 canvas->drawCircle(radius, radius, radius, paint); | 141 canvas->drawCircle(radius, radius, radius, paint); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 fCubicButton.fLabel = 'C'; | 229 fCubicButton.fLabel = 'C'; |
230 fCubicButton.fEnabled = true; | 230 fCubicButton.fEnabled = true; |
231 fQuadButton.fLabel = 'Q'; | 231 fQuadButton.fLabel = 'Q'; |
232 fQuadButton.fEnabled = true; | 232 fQuadButton.fEnabled = true; |
233 fRRectButton.fLabel = 'R'; | 233 fRRectButton.fLabel = 'R'; |
234 fRRectButton.fEnabled = true; | 234 fRRectButton.fEnabled = true; |
235 fAnimate = true; | 235 fAnimate = true; |
236 } | 236 } |
237 | 237 |
238 protected: | 238 protected: |
239 virtual bool onQuery(SkEvent* evt) SK_OVERRIDE { | 239 bool onQuery(SkEvent* evt) SK_OVERRIDE { |
240 if (SampleCode::TitleQ(*evt)) { | 240 if (SampleCode::TitleQ(*evt)) { |
241 SampleCode::TitleR(evt, "RotateCircles3"); | 241 SampleCode::TitleR(evt, "RotateCircles3"); |
242 return true; | 242 return true; |
243 } | 243 } |
244 return this->INHERITED::onQuery(evt); | 244 return this->INHERITED::onQuery(evt); |
245 } | 245 } |
246 | 246 |
247 virtual void onSizeChange() SK_OVERRIDE { | 247 void onSizeChange() SK_OVERRIDE { |
248 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); | 248 fErrorControl.setXYWH(this->width() - 100, 30, 30, 400); |
249 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); | 249 fWidthControl.setXYWH(this->width() - 50, 30, 30, 400); |
250 fCubicButton.fBounds.setXYWH(this->width() - 50, 450, 30, 30); | 250 fCubicButton.fBounds.setXYWH(this->width() - 50, 450, 30, 30); |
251 fQuadButton.fBounds.setXYWH(this->width() - 50, 500, 30, 30); | 251 fQuadButton.fBounds.setXYWH(this->width() - 50, 500, 30, 30); |
252 fRRectButton.fBounds.setXYWH(this->width() - 50, 550, 30, 30); | 252 fRRectButton.fBounds.setXYWH(this->width() - 50, 550, 30, 30); |
253 this->INHERITED::onSizeChange(); | 253 this->INHERITED::onSizeChange(); |
254 } | 254 } |
255 | 255 |
256 void draw_points(SkCanvas* canvas, const SkPath& path, SkColor color, | 256 void draw_points(SkCanvas* canvas, const SkPath& path, SkColor color, |
257 bool show_lines) { | 257 bool show_lines) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 SkString label; | 343 SkString label; |
344 label.printf("%0.3g", value); | 344 label.printf("%0.3g", value); |
345 paint.setColor(0xFF000000); | 345 paint.setColor(0xFF000000); |
346 paint.setTextSize(11.0f); | 346 paint.setTextSize(11.0f); |
347 paint.setStyle(SkPaint::kFill_Style); | 347 paint.setStyle(SkPaint::kFill_Style); |
348 canvas->drawText(label.c_str(), label.size(), bounds.fLeft + 5, yPos - 5
, paint); | 348 canvas->drawText(label.c_str(), label.size(), bounds.fLeft + 5, yPos - 5
, paint); |
349 paint.setTextSize(13.0f); | 349 paint.setTextSize(13.0f); |
350 canvas->drawText(name, strlen(name), bounds.fLeft, bounds.bottom() + 11,
paint); | 350 canvas->drawText(name, strlen(name), bounds.fLeft, bounds.bottom() + 11,
paint); |
351 } | 351 } |
352 | 352 |
353 virtual void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { | 353 void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
354 SkPath path; | 354 SkPath path; |
355 SkScalar width = fWidth; | 355 SkScalar width = fWidth; |
356 | 356 |
357 if (fCubicButton.fEnabled) { | 357 if (fCubicButton.fEnabled) { |
358 path.moveTo(fPts[0]); | 358 path.moveTo(fPts[0]); |
359 path.cubicTo(fPts[1], fPts[2], fPts[3]); | 359 path.cubicTo(fPts[1], fPts[2], fPts[3]); |
360 draw_stroke(canvas, path, width); | 360 draw_stroke(canvas, path, width); |
361 } | 361 } |
362 | 362 |
363 if (fQuadButton.fEnabled) { | 363 if (fQuadButton.fEnabled) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6); | 443 return new MyClick(this, (int) SK_ARRAY_COUNT(fPts) + 6); |
444 } | 444 } |
445 return this->INHERITED::onFindClickHandler(x, y, modi); | 445 return this->INHERITED::onFindClickHandler(x, y, modi); |
446 } | 446 } |
447 | 447 |
448 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min
, | 448 static SkScalar MapScreenYtoValue(int y, const SkRect& control, SkScalar min
, |
449 SkScalar max) { | 449 SkScalar max) { |
450 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min
) + min; | 450 return (SkIntToScalar(y) - control.fTop) / control.height() * (max - min
) + min; |
451 } | 451 } |
452 | 452 |
453 virtual bool onClick(Click* click) SK_OVERRIDE { | 453 bool onClick(Click* click) SK_OVERRIDE { |
454 int index = ((MyClick*)click)->fIndex; | 454 int index = ((MyClick*)click)->fIndex; |
455 if (index < (int) SK_ARRAY_COUNT(fPts)) { | 455 if (index < (int) SK_ARRAY_COUNT(fPts)) { |
456 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX
), | 456 fPts[index].offset(SkIntToScalar(click->fICurr.fX - click->fIPrev.fX
), |
457 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY
)); | 457 SkIntToScalar(click->fICurr.fY - click->fIPrev.fY
)); |
458 this->inval(NULL); | 458 this->inval(NULL); |
459 } | 459 } |
460 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) | 460 #if QUAD_STROKE_APPROXIMATION && defined(SK_DEBUG) |
461 else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { | 461 else if (index == (int) SK_ARRAY_COUNT(fPts) + 1) { |
462 gDebugStrokerError = MapScreenYtoValue(click->fICurr.fY, fErrorContr
ol, | 462 gDebugStrokerError = MapScreenYtoValue(click->fICurr.fY, fErrorContr
ol, |
463 kStrokerErrorMin, kStrokerErrorMax); | 463 kStrokerErrorMin, kStrokerErrorMax); |
(...skipping 12 matching lines...) Expand all Loading... |
476 }; | 476 }; |
477 | 477 |
478 /////////////////////////////////////////////////////////////////////////////// | 478 /////////////////////////////////////////////////////////////////////////////// |
479 | 479 |
480 static SkView* F0() { return new RotateCirclesView; } | 480 static SkView* F0() { return new RotateCirclesView; } |
481 static SkViewRegister gR0(F0); | 481 static SkViewRegister gR0(F0); |
482 static SkView* F1() { return new TestCirclesView; } | 482 static SkView* F1() { return new TestCirclesView; } |
483 static SkViewRegister gR1(F1); | 483 static SkViewRegister gR1(F1); |
484 static SkView* F2() { return new TestStrokeView; } | 484 static SkView* F2() { return new TestStrokeView; } |
485 static SkViewRegister gR2(F2); | 485 static SkViewRegister gR2(F2); |
OLD | NEW |