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

Unified Diff: samplecode/SampleArc.cpp

Issue 716793004: experimental (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove bad start in picture Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkCanvas.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleArc.cpp
diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp
index 8209c3b76489b2352726fe86381c15300e85eca6..c9310d6dd64b1fae55b1349bba10f102cd7489d4 100644
--- a/samplecode/SampleArc.cpp
+++ b/samplecode/SampleArc.cpp
@@ -22,6 +22,8 @@
#include "SkColorFilter.h"
#include "SkLayerRasterizer.h"
+#include "SkCanvasDrawable.h"
+
#include "SkParsePath.h"
static void testparse() {
SkRect r;
@@ -36,11 +38,58 @@ static void testparse() {
}
class ArcsView : public SampleView {
+ class MyDrawable : public SkCanvasDrawable {
+ SkRect fR;
+ SkScalar fSweep;
+ public:
+ MyDrawable(const SkRect& r) : fR(r), fSweep(0) {
+ }
+
+ void setSweep(SkScalar sweep) {
+ if (fSweep != sweep) {
+ fSweep = sweep;
+ this->notifyDrawingChanged();
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStrokeWidth(SkIntToScalar(2));
+
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setColor(0x800000FF);
+ canvas->drawArc(fR, 0, fSweep, true, paint);
+
+ paint.setColor(0x800FF000);
+ canvas->drawArc(fR, 0, fSweep, false, paint);
+
+ paint.setStyle(SkPaint::kStroke_Style);
+ paint.setColor(SK_ColorRED);
+ canvas->drawArc(fR, 0, fSweep, true, paint);
+
+ paint.setStrokeWidth(0);
+ paint.setColor(SK_ColorBLUE);
+ canvas->drawArc(fR, 0, fSweep, false, paint);
+ }
+ };
+
public:
+ SkRect fRect;
+ MyDrawable* fDrawable;
mtklein 2014/11/12 03:34:42 AutoTUnref?
+
ArcsView() {
testparse();
fSweep = SkIntToScalar(100);
this->setBGColor(0xFFDDDDDD);
+
+ fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
+ fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
+ fDrawable = SkNEW_ARGS(MyDrawable, (fRect));
+ }
+
+ virtual ~ArcsView() SK_OVERRIDE {
+ fDrawable->unref();
}
protected:
@@ -121,48 +170,17 @@ protected:
}
virtual void onDrawContent(SkCanvas* canvas) {
- fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
- SkIntToScalar(360));
-// fSweep = 359.99f;
+ fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
+ SkIntToScalar(360)));
- SkRect r;
SkPaint paint;
-
paint.setAntiAlias(true);
paint.setStrokeWidth(SkIntToScalar(2));
paint.setStyle(SkPaint::kStroke_Style);
- r.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
- r.offset(SkIntToScalar(20), SkIntToScalar(20));
-
- if (false) {
- const SkScalar d = SkIntToScalar(3);
- const SkScalar rad[] = { d, d, d, d, d, d, d, d };
- SkPath path;
- path.addRoundRect(r, rad);
- canvas->drawPath(path, paint);
- return;
- }
-
- drawRectWithLines(canvas, r, paint);
-
- // printf("----- sweep %g %X\n", SkScalarToFloat(fSweep), SkDegreesToRadians(fSweep));
-
-
- paint.setStyle(SkPaint::kFill_Style);
- paint.setColor(0x800000FF);
- canvas->drawArc(r, 0, fSweep, true, paint);
-
- paint.setColor(0x800FF000);
- canvas->drawArc(r, 0, fSweep, false, paint);
-
- paint.setStyle(SkPaint::kStroke_Style);
- paint.setColor(SK_ColorRED);
- canvas->drawArc(r, 0, fSweep, true, paint);
+ drawRectWithLines(canvas, fRect, paint);
- paint.setStrokeWidth(0);
- paint.setColor(SK_ColorBLUE);
- canvas->drawArc(r, 0, fSweep, false, paint);
+ canvas->EXPERIMENTAL_drawDrawable(fDrawable);
drawArcs(canvas);
this->inval(NULL);
« no previous file with comments | « include/core/SkCanvas.h ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698