Sk1DPathEffect.h revision 9797272edfc73f18b4807751377518317991b880
1
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10#ifndef Sk1DPathEffect_DEFINED
11#define Sk1DPathEffect_DEFINED
12
13#include "SkPathEffect.h"
14#include "SkPath.h"
15
16class SkPathMeasure;
17
18//  This class is not exported to java.
19class Sk1DPathEffect : public SkPathEffect {
20public:
21    virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
22
23protected:
24    /** Called at the start of each contour, returns the initial offset
25        into that contour.
26    */
27    virtual SkScalar begin(SkScalar contourLength) = 0;
28    /** Called with the current distance along the path, with the current matrix
29        for the point/tangent at the specified distance.
30        Return the distance to travel for the next call. If return <= 0, then that
31        contour is done.
32    */
33    virtual SkScalar next(SkPath* dst, SkScalar distance, SkPathMeasure&) = 0;
34
35private:
36    typedef SkPathEffect INHERITED;
37};
38
39class SkPath1DPathEffect : public Sk1DPathEffect {
40public:
41    enum Style {
42        kTranslate_Style,   // translate the shape to each position
43        kRotate_Style,      // rotate the shape about its center
44        kMorph_Style,       // transform each point, and turn lines into curves
45
46        kStyleCount
47    };
48
49    /** Dash by replicating the specified path.
50        @param path The path to replicate (dash)
51        @param advance The space between instances of path
52        @param phase distance (mod advance) along path for its initial position
53        @param style how to transform path at each point (based on the current
54                     position and tangent)
55    */
56    SkPath1DPathEffect(const SkPath& path, SkScalar advance, SkScalar phase, Style);
57
58    virtual bool filterPath(SkPath*, const SkPath&, SkStrokeRec*) SK_OVERRIDE;
59
60    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPath1DPathEffect)
61
62protected:
63    SkPath1DPathEffect(SkFlattenableReadBuffer& buffer);
64    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
65
66    // overrides from Sk1DPathEffect
67    virtual SkScalar begin(SkScalar contourLength) SK_OVERRIDE;
68    virtual SkScalar next(SkPath*, SkScalar distance, SkPathMeasure&) SK_OVERRIDE;
69
70private:
71    SkPath      fPath;          // copied from constructor
72    SkScalar    fAdvance;       // copied from constructor
73    SkScalar    fInitialOffset; // computed from phase
74    Style       fStyle;         // copied from constructor
75
76    typedef Sk1DPathEffect INHERITED;
77};
78
79
80#endif
81