diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-22 20:53:59 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-22 20:53:59 +0000 |
commit | b56370930867d157ee49a6a9f2f5f58fe5145559 (patch) | |
tree | 8b2aa3d7d4e3a84a1e67bed1c710cdfc709a8e4e | |
parent | b89a03c890668f98d9f8b269b6ad00824409435b (diff) |
add test for large strokes on circles
git-svn-id: http://skia.googlecode.com/svn/trunk@6932 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | samplecode/SampleRotateCircles.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/samplecode/SampleRotateCircles.cpp b/samplecode/SampleRotateCircles.cpp new file mode 100644 index 0000000000..739900de62 --- /dev/null +++ b/samplecode/SampleRotateCircles.cpp @@ -0,0 +1,87 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SampleCode.h" +#include "SkView.h" +#include "SkCanvas.h" +#include "SkRandom.h" + +static void rotateAbout(SkCanvas* canvas, SkScalar degrees, + SkScalar cx, SkScalar cy) { + canvas->translate(cx, cy); + canvas->rotate(degrees); + canvas->translate(-cx, -cy); +} + +class RotateCirclesView : public SampleView { +public: + RotateCirclesView() { + this->setBGColor(SK_ColorLTGRAY); + + fAngle = 0; + } + +protected: + // overrides from SkEventSink + virtual bool onQuery(SkEvent* evt) { + if (SampleCode::TitleQ(*evt)) { + SampleCode::TitleR(evt, "RotateCircles"); + return true; + } + return this->INHERITED::onQuery(evt); + } + + virtual void onDrawContent(SkCanvas* canvas) { + SkRandom rand; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStrokeWidth(20); + + SkScalar cx = 240; + SkScalar cy = 240; + SkScalar DX = 240 * 2; + SkColor color = 0; + + float scale = 1; + float sign = 0.3f; + for (SkScalar rad = 200; rad >= 20; rad -= 15) { + sign = -sign; + scale += 0.2f; + + paint.setColor(rand.nextU()); + paint.setAlpha(0xFF); + color = ~color; + + paint.setStyle(SkPaint::kFill_Style); + + canvas->save(); + rotateAbout(canvas, fAngle * scale * sign, cx, cy); + canvas->drawCircle(cx, cy, rad, paint); + canvas->restore(); + + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(rad*2); + + canvas->save(); + rotateAbout(canvas, fAngle * scale * sign, cx + DX, cy); + canvas->drawCircle(cx + DX, cy, 10, paint); + canvas->restore(); + + } + + fAngle = (fAngle + 1) % 360; + this->inval(NULL); + } + +private: + int fAngle; + typedef SkView INHERITED; +}; + +static SkView* F0() { return new RotateCirclesView; } +static SkViewRegister gR0(F0); + |