diff options
author | reed <reed@google.com> | 2014-11-11 19:36:09 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-11 19:36:10 -0800 |
commit | 6a070dc06af4e9f305f9d08a69e34d18ade473cb (patch) | |
tree | 48723d46a9e7ba7246445e98b960add2c7eabce3 /samplecode/SampleArc.cpp | |
parent | ad8aa1dcf36d64ddf849b914281713b901a01f49 (diff) |
experimental
BUG=skia:
Review URL: https://codereview.chromium.org/716793004
Diffstat (limited to 'samplecode/SampleArc.cpp')
-rw-r--r-- | samplecode/SampleArc.cpp | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index 8209c3b764..c9310d6dd6 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; + 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); |