aboutsummaryrefslogtreecommitdiffstats
path: root/samplecode/SampleTextEffects.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'samplecode/SampleTextEffects.cpp')
-rw-r--r--samplecode/SampleTextEffects.cpp45
1 files changed, 14 insertions, 31 deletions
diff --git a/samplecode/SampleTextEffects.cpp b/samplecode/SampleTextEffects.cpp
index f256b2e..6eadffd 100644
--- a/samplecode/SampleTextEffects.cpp
+++ b/samplecode/SampleTextEffects.cpp
@@ -1,3 +1,10 @@
+
+/*
+ * Copyright 2011 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"
@@ -138,41 +145,17 @@ static void r6(SkLayerRasterizer* rast, SkPaint& p) {
#include "Sk2DPathEffect.h"
-class Dot2DPathEffect : public Sk2DPathEffect {
-public:
- Dot2DPathEffect(SkScalar radius, const SkMatrix& matrix)
- : Sk2DPathEffect(matrix), fRadius(radius) {}
-
- virtual void flatten(SkFlattenableWriteBuffer& buffer) {
- this->INHERITED::flatten(buffer);
-
- buffer.writeScalar(fRadius);
- }
- virtual Factory getFactory() { return CreateProc; }
-
-protected:
- virtual void next(const SkPoint& loc, int u, int v, SkPath* dst) {
- dst->addCircle(loc.fX, loc.fY, fRadius);
- }
-
- Dot2DPathEffect(SkFlattenableReadBuffer& buffer) : Sk2DPathEffect(buffer) {
- fRadius = buffer.readScalar();
- }
-private:
- SkScalar fRadius;
-
- static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
- return new Dot2DPathEffect(buffer);
- }
-
- typedef Sk2DPathEffect INHERITED;
-};
+static SkPathEffect* MakeDotEffect(SkScalar radius, const SkMatrix& matrix) {
+ SkPath path;
+ path.addCircle(0, 0, radius);
+ return new SkPath2DPathEffect(matrix, path);
+}
static void r7(SkLayerRasterizer* rast, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*4, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*4, lattice))->unref();
rast->addLayer(p);
}
@@ -182,7 +165,7 @@ static void r8(SkLayerRasterizer* rast, SkPaint& p) {
SkMatrix lattice;
lattice.setScale(SK_Scalar1*6, SK_Scalar1*6, 0, 0);
lattice.postSkew(SK_Scalar1/3, 0, 0, 0);
- p.setPathEffect(new Dot2DPathEffect(SK_Scalar1*2, lattice))->unref();
+ p.setPathEffect(MakeDotEffect(SK_Scalar1*2, lattice))->unref();
p.setXfermodeMode(SkXfermode::kClear_Mode);
rast->addLayer(p);