Skia
2DGraphicsLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkStrokeRec.h
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 
13 class SkPath;
14 
15 SK_BEGIN_REQUIRE_DENSE
16 class SkStrokeRec {
17 public:
18  enum InitStyle {
19  kHairline_InitStyle,
20  kFill_InitStyle
21  };
22  SkStrokeRec(InitStyle style);
23  SkStrokeRec(const SkPaint&, SkPaint::Style, SkScalar resScale = 1);
24  explicit SkStrokeRec(const SkPaint&, SkScalar resScale = 1);
25 
26  enum Style {
27  kHairline_Style,
28  kFill_Style,
29  kStroke_Style,
30  kStrokeAndFill_Style
31  };
32  enum {
33  kStyleCount = kStrokeAndFill_Style + 1
34  };
35 
36  Style getStyle() const;
37  SkScalar getWidth() const { return fWidth; }
38  SkScalar getMiter() const { return fMiterLimit; }
39  SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; }
40  SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; }
41 
42  bool isHairlineStyle() const {
43  return kHairline_Style == this->getStyle();
44  }
45 
46  bool isFillStyle() const {
47  return kFill_Style == this->getStyle();
48  }
49 
50  void setFillStyle();
51  void setHairlineStyle();
58  void setStrokeStyle(SkScalar width, bool strokeAndFill = false);
59 
60  void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) {
61  fCap = cap;
62  fJoin = join;
63  fMiterLimit = miterLimit;
64  }
65 
66  SkScalar getResScale() const {
67  return fResScale;
68  }
69 
70  void setResScale(SkScalar rs) {
71  SkASSERT(rs > 0 && SkScalarIsFinite(rs));
72  fResScale = rs;
73  }
74 
79  bool needToApply() const {
80  Style style = this->getStyle();
81  return (kStroke_Style == style) || (kStrokeAndFill_Style == style);
82  }
83 
94  bool applyToPath(SkPath* dst, const SkPath& src) const;
95 
99  void applyToPaint(SkPaint* paint) const;
100 
106  SkScalar getInflationRadius() const;
107 
115  static SkScalar GetInflationRadius(const SkPaint&, SkPaint::Style);
116 
122  bool hasEqualEffect(const SkStrokeRec& other) const {
123  if (!this->needToApply()) {
124  return this->getStyle() == other.getStyle();
125  }
126  return fWidth == other.fWidth &&
127  fMiterLimit == other.fMiterLimit &&
128  fCap == other.fCap &&
129  fJoin == other.fJoin &&
130  fStrokeAndFill == other.fStrokeAndFill;
131  }
132 
133 private:
134  void init(const SkPaint&, SkPaint::Style, SkScalar resScale);
135 
136  SkScalar fResScale;
137  SkScalar fWidth;
138  SkScalar fMiterLimit;
139  // The following three members are packed together into a single u32.
140  // This is to avoid unnecessary padding and ensure binary equality for
141  // hashing (because the padded areas might contain garbage values).
142  //
143  // fCap and fJoin are larger than needed to avoid having to initialize
144  // any pad values
145  uint32_t fCap : 16; // SkPaint::Cap
146  uint32_t fJoin : 15; // SkPaint::Join
147  uint32_t fStrokeAndFill : 1; // bool
148 };
149 SK_END_REQUIRE_DENSE
150 
151 #endif
The SkPath class encapsulates compound (multiple contour) geometric paths consisting of straight line...
Definition: SkPath.h:25
Definition: SkStrokeRec.h:16
Cap
Cap enum specifies the settings for the paint's strokecap.
Definition: SkPaint.h:392
The SkPaint class holds the style and color information about how to draw geometries, text and bitmaps.
Definition: SkPaint.h:45
bool applyToPath(SkPath *dst, const SkPath &src) const
Apply these stroke parameters to the src path, returning the result in dst.
Join
Join enum specifies the settings for the paint's strokejoin.
Definition: SkPaint.h:405
void setStrokeStyle(SkScalar width, bool strokeAndFill=false)
Specify the strokewidth, and optionally if you want stroke + fill.
bool needToApply() const
Returns true if this specifes any thick stroking, i.e.
Definition: SkStrokeRec.h:79
static SkScalar GetInflationRadius(const SkPaint &, SkPaint::Style)
Equivalent to: SkStrokeRec rec(paint, style); rec.getInflationRadius(); This does not account for oth...
Style
Styles apply to rect, oval, path, and text.
Definition: SkPaint.h:289
SkScalar getInflationRadius() const
Gives a conservative value for the outset that should applied to a geometries bounds to account for a...
void applyToPaint(SkPaint *paint) const
Apply these stroke parameters to a paint.
bool hasEqualEffect(const SkStrokeRec &other) const
Compare if two SkStrokeRecs have an equal effect on a path.
Definition: SkStrokeRec.h:122