1/*
2 * Copyright 2012 Google Inc.
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 SkStrokeRec_DEFINED
9#define SkStrokeRec_DEFINED
10
11#include "SkPaint.h"
12
13class SkPath;
14
15class SkStrokeRec {
16public:
17    enum InitStyle {
18        kHairline_InitStyle,
19        kFill_InitStyle
20    };
21    SkStrokeRec(InitStyle style);
22
23    SkStrokeRec(const SkStrokeRec&);
24    SkStrokeRec(const SkPaint&, SkPaint::Style);
25    explicit SkStrokeRec(const SkPaint&);
26
27    enum Style {
28        kHairline_Style,
29        kFill_Style,
30        kStroke_Style,
31        kStrokeAndFill_Style
32    };
33
34    Style getStyle() const;
35    SkScalar getWidth() const { return fWidth; }
36    SkScalar getMiter() const { return fMiterLimit; }
37    SkPaint::Cap getCap() const { return fCap; }
38    SkPaint::Join getJoin() const { return fJoin; }
39
40    bool isHairlineStyle() const {
41        return kHairline_Style == this->getStyle();
42    }
43
44    bool isFillStyle() const {
45        return kFill_Style == this->getStyle();
46    }
47
48    void setFillStyle();
49    void setHairlineStyle();
50    /**
51     *  Specify the strokewidth, and optionally if you want stroke + fill.
52     *  Note, if width==0, then this request is taken to mean:
53     *      strokeAndFill==true -> new style will be Fill
54     *      strokeAndFill==false -> new style will be Hairline
55     */
56    void setStrokeStyle(SkScalar width, bool strokeAndFill = false);
57
58    void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) {
59        fCap = cap;
60        fJoin = join;
61        fMiterLimit = miterLimit;
62    }
63
64    /**
65     *  Returns true if this specifes any thick stroking, i.e. applyToPath()
66     *  will return true.
67     */
68    bool needToApply() const {
69        Style style = this->getStyle();
70        return (kStroke_Style == style) || (kStrokeAndFill_Style == style);
71    }
72
73    /**
74     *  Apply these stroke parameters to the src path, returning the result
75     *  in dst.
76     *
77     *  If there was no change (i.e. style == hairline or fill) this returns
78     *  false and dst is unchanged. Otherwise returns true and the result is
79     *  stored in dst.
80     *
81     *  src and dst may be the same path.
82     */
83    bool applyToPath(SkPath* dst, const SkPath& src) const;
84
85    bool operator==(const SkStrokeRec& other) const {
86            return fWidth == other.fWidth &&
87                   fMiterLimit == other.fMiterLimit &&
88                   fCap == other.fCap &&
89                   fJoin == other.fJoin &&
90                   fStrokeAndFill == other.fStrokeAndFill;
91    }
92
93private:
94    void init(const SkPaint& paint, SkPaint::Style style);
95
96
97    SkScalar        fWidth;
98    SkScalar        fMiterLimit;
99    SkPaint::Cap    fCap;
100    SkPaint::Join   fJoin;
101    bool            fStrokeAndFill;
102};
103
104#endif
105