michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkStrokeRec_DEFINED michael@0: #define SkStrokeRec_DEFINED michael@0: michael@0: #include "SkPaint.h" michael@0: michael@0: class SkPath; michael@0: michael@0: class SkStrokeRec { michael@0: public: michael@0: enum InitStyle { michael@0: kHairline_InitStyle, michael@0: kFill_InitStyle michael@0: }; michael@0: SkStrokeRec(InitStyle style); michael@0: michael@0: SkStrokeRec(const SkStrokeRec&); michael@0: explicit SkStrokeRec(const SkPaint&); michael@0: michael@0: enum Style { michael@0: kHairline_Style, michael@0: kFill_Style, michael@0: kStroke_Style, michael@0: kStrokeAndFill_Style michael@0: }; michael@0: michael@0: Style getStyle() const; michael@0: SkScalar getWidth() const { return fWidth; } michael@0: SkScalar getMiter() const { return fMiterLimit; } michael@0: SkPaint::Cap getCap() const { return fCap; } michael@0: SkPaint::Join getJoin() const { return fJoin; } michael@0: michael@0: bool isHairlineStyle() const { michael@0: return kHairline_Style == this->getStyle(); michael@0: } michael@0: michael@0: bool isFillStyle() const { michael@0: return kFill_Style == this->getStyle(); michael@0: } michael@0: michael@0: void setFillStyle(); michael@0: void setHairlineStyle(); michael@0: /** michael@0: * Specify the strokewidth, and optionally if you want stroke + fill. michael@0: * Note, if width==0, then this request is taken to mean: michael@0: * strokeAndFill==true -> new style will be Fill michael@0: * strokeAndFill==false -> new style will be Hairline michael@0: */ michael@0: void setStrokeStyle(SkScalar width, bool strokeAndFill = false); michael@0: michael@0: void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) { michael@0: fCap = cap; michael@0: fJoin = join; michael@0: fMiterLimit = miterLimit; michael@0: } michael@0: michael@0: /** michael@0: * Returns true if this specifes any thick stroking, i.e. applyToPath() michael@0: * will return true. michael@0: */ michael@0: bool needToApply() const { michael@0: Style style = this->getStyle(); michael@0: return (kStroke_Style == style) || (kStrokeAndFill_Style == style); michael@0: } michael@0: michael@0: /** michael@0: * Apply these stroke parameters to the src path, returning the result michael@0: * in dst. michael@0: * michael@0: * If there was no change (i.e. style == hairline or fill) this returns michael@0: * false and dst is unchanged. Otherwise returns true and the result is michael@0: * stored in dst. michael@0: * michael@0: * src and dst may be the same path. michael@0: */ michael@0: bool applyToPath(SkPath* dst, const SkPath& src) const; michael@0: michael@0: bool operator==(const SkStrokeRec& other) const { michael@0: return fWidth == other.fWidth && michael@0: fMiterLimit == other.fMiterLimit && michael@0: fCap == other.fCap && michael@0: fJoin == other.fJoin && michael@0: fStrokeAndFill == other.fStrokeAndFill; michael@0: } michael@0: michael@0: private: michael@0: SkScalar fWidth; michael@0: SkScalar fMiterLimit; michael@0: SkPaint::Cap fCap; michael@0: SkPaint::Join fJoin; michael@0: bool fStrokeAndFill; michael@0: }; michael@0: michael@0: #endif