Index: samplecode/SamplePathEffects.cpp |
diff --git a/samplecode/SamplePathEffects.cpp b/samplecode/SamplePathEffects.cpp |
index 9af0abb59adb20bf597772e767d08c15f198be46..f07cd6ce400b50530adcf72840c18ea394041a01 100644 |
--- a/samplecode/SamplePathEffects.cpp |
+++ b/samplecode/SamplePathEffects.cpp |
@@ -21,13 +21,12 @@ |
#include "SkPixelXorXfermode.h" |
#define CORNER_RADIUS 12 |
-static SkScalar gPhase; |
static const int gXY[] = { |
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4 |
}; |
-static SkPathEffect* make_pe(int flags) { |
+static SkPathEffect* make_pe(int flags, SkScalar phase) { |
if (flags == 1) |
return SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS)); |
@@ -38,7 +37,8 @@ static SkPathEffect* make_pe(int flags) { |
path.close(); |
path.offset(SkIntToScalar(-6), 0); |
- SkPathEffect* outer = SkPath1DPathEffect::Create(path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kRotate_Style); |
+ SkPathEffect* outer = SkPath1DPathEffect::Create(path, 12, phase, |
+ SkPath1DPathEffect::kRotate_Style); |
if (flags == 2) |
return outer; |
@@ -51,7 +51,7 @@ static SkPathEffect* make_pe(int flags) { |
return pe; |
} |
-static SkPathEffect* make_warp_pe() { |
+static SkPathEffect* make_warp_pe(SkScalar phase) { |
SkPath path; |
path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1])); |
for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2) |
@@ -60,7 +60,7 @@ static SkPathEffect* make_warp_pe() { |
path.offset(SkIntToScalar(-6), 0); |
SkPathEffect* outer = SkPath1DPathEffect::Create( |
- path, SkIntToScalar(12), gPhase, SkPath1DPathEffect::kMorph_Style); |
+ path, 12, phase, SkPath1DPathEffect::kMorph_Style); |
SkPathEffect* inner = SkCornerPathEffect::Create(SkIntToScalar(CORNER_RADIUS)); |
SkPathEffect* pe = SkComposePathEffect::Create(outer, inner); |
@@ -80,29 +80,21 @@ public: |
SkPaint paint; |
paint.setAntiAlias(true); |
-#if 0 |
- paint.setStyle(SkPaint::kStroke_Style); |
- paint.setStrokeWidth(SK_Scalar1*4); |
- this->addLayer(paint); |
- |
- paint.setStrokeWidth(SK_Scalar1*1); |
- paint.setXfermode(SkXfermode::kClear_Mode); |
- this->addLayer(paint); |
-#else |
paint.setAlpha(0x66); |
this->addLayer(paint, SkIntToScalar(4), SkIntToScalar(4)); |
paint.setAlpha(0xFF); |
this->addLayer(paint); |
-#endif |
} |
}; |
class PathEffectView : public SampleView { |
SkPath fPath; |
SkPoint fClickPt; |
+ SkScalar fPhase; |
+ |
public: |
- PathEffectView() { |
+ PathEffectView() : fPhase(0) { |
SkRandom rand; |
int steps = 20; |
SkScalar dist = SkIntToScalar(400); |
@@ -134,8 +126,7 @@ public: |
} |
protected: |
- // overrides from SkEventSink |
- virtual bool onQuery(SkEvent* evt) { |
+ bool onQuery(SkEvent* evt) SK_OVERRIDE { |
if (SampleCode::TitleQ(*evt)) { |
SampleCode::TitleR(evt, "PathEffects"); |
return true; |
@@ -143,45 +134,35 @@ protected: |
return this->INHERITED::onQuery(evt); |
} |
- virtual void onDrawContent(SkCanvas* canvas) { |
- gPhase -= SampleCode::GetAnimSecondsDelta() * 40; |
- this->inval(NULL); |
- |
+ void onDrawContent(SkCanvas* canvas) SK_OVERRIDE { |
SkPaint paint; |
-#if 0 |
- paint.setAntiAlias(true); |
- paint.setStyle(SkPaint::kStroke_Style); |
- paint.setStrokeWidth(SkIntToScalar(5)); |
- canvas->drawPath(fPath, paint); |
- paint.setStrokeWidth(0); |
- |
- paint.setColor(SK_ColorWHITE); |
- paint.setPathEffect(make_pe(1))->unref(); |
- canvas->drawPath(fPath, paint); |
-#endif |
- |
- canvas->translate(0, SkIntToScalar(50)); |
+ canvas->translate(0, 50); |
paint.setColor(SK_ColorBLUE); |
- paint.setPathEffect(make_pe(2))->unref(); |
+ paint.setPathEffect(make_pe(2, fPhase))->unref(); |
canvas->drawPath(fPath, paint); |
- canvas->translate(0, SkIntToScalar(50)); |
+ canvas->translate(0, 50); |
paint.setARGB(0xFF, 0, 0xBB, 0); |
- paint.setPathEffect(make_pe(3))->unref(); |
+ paint.setPathEffect(make_pe(3, fPhase))->unref(); |
canvas->drawPath(fPath, paint); |
- canvas->translate(0, SkIntToScalar(50)); |
+ canvas->translate(0, 50); |
paint.setARGB(0xFF, 0, 0, 0); |
- paint.setPathEffect(make_warp_pe())->unref(); |
+ paint.setPathEffect(make_warp_pe(fPhase))->unref(); |
TestRastBuilder testRastBuilder; |
paint.setRasterizer(testRastBuilder.detachRasterizer())->unref(); |
canvas->drawPath(fPath, paint); |
} |
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE { |
+ fPhase -= (curr - prev) * 0.04f; |
+ return true; |
+ } |
+ |
private: |
typedef SampleView INHERITED; |
}; |