SkDashPathEffect.h revision 687c57c7d5a17549f63e0b15208db18b220e2a91
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkDashPathEffect_DEFINED
9#define SkDashPathEffect_DEFINED
10
11#include "SkPathEffect.h"
12
13/** \class SkDashPathEffect
14
15    SkDashPathEffect is a subclass of SkPathEffect that implements dashing
16*/
17class SK_API SkDashPathEffect : public SkPathEffect {
18public:
19    /** intervals: array containing an even number of entries (>=2), with
20         the even indices specifying the length of "on" intervals, and the odd
21         indices specifying the length of "off" intervals.
22        count: number of elements in the intervals array
23        phase: offset into the intervals array (mod the sum of all of the
24         intervals).
25
26        For example: if intervals[] = {10, 20}, count = 2, and phase = 25,
27         this will set up a dashed path like so:
28         5 pixels off
29         10 pixels on
30         20 pixels off
31         10 pixels on
32         20 pixels off
33         ...
34        A phase of -5, 25, 55, 85, etc. would all result in the same path,
35         because the sum of all the intervals is 30.
36
37        Note: only affects stroked paths.
38    */
39    SkDashPathEffect(const SkScalar intervals[], int count, SkScalar phase, bool scaleToFit = false);
40    virtual ~SkDashPathEffect();
41
42    virtual bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*) SK_OVERRIDE;
43
44    virtual bool asPoints(PointData* results, const SkPath& src,
45                          const SkStrokeRec&, const SkMatrix&) const SK_OVERRIDE;
46
47    // overrides for SkFlattenable
48    //  This method is not exported to java.
49    virtual Factory getFactory();
50    static SkFlattenable* CreateProc(SkFlattenableReadBuffer&);
51
52protected:
53    SkDashPathEffect(SkFlattenableReadBuffer&);
54    virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
55
56private:
57    SkScalar*   fIntervals;
58    int32_t     fCount;
59    // computed from phase
60    SkScalar    fInitialDashLength;
61    int32_t     fInitialDashIndex;
62    SkScalar    fIntervalLength;
63    bool        fScaleToFit;
64
65    typedef SkPathEffect INHERITED;
66};
67
68#endif
69