1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkStrokeRec.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Copyright 2012 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkStrokeRec_DEFINED 1.12 +#define SkStrokeRec_DEFINED 1.13 + 1.14 +#include "SkPaint.h" 1.15 + 1.16 +class SkPath; 1.17 + 1.18 +class SkStrokeRec { 1.19 +public: 1.20 + enum InitStyle { 1.21 + kHairline_InitStyle, 1.22 + kFill_InitStyle 1.23 + }; 1.24 + SkStrokeRec(InitStyle style); 1.25 + 1.26 + SkStrokeRec(const SkStrokeRec&); 1.27 + explicit SkStrokeRec(const SkPaint&); 1.28 + 1.29 + enum Style { 1.30 + kHairline_Style, 1.31 + kFill_Style, 1.32 + kStroke_Style, 1.33 + kStrokeAndFill_Style 1.34 + }; 1.35 + 1.36 + Style getStyle() const; 1.37 + SkScalar getWidth() const { return fWidth; } 1.38 + SkScalar getMiter() const { return fMiterLimit; } 1.39 + SkPaint::Cap getCap() const { return fCap; } 1.40 + SkPaint::Join getJoin() const { return fJoin; } 1.41 + 1.42 + bool isHairlineStyle() const { 1.43 + return kHairline_Style == this->getStyle(); 1.44 + } 1.45 + 1.46 + bool isFillStyle() const { 1.47 + return kFill_Style == this->getStyle(); 1.48 + } 1.49 + 1.50 + void setFillStyle(); 1.51 + void setHairlineStyle(); 1.52 + /** 1.53 + * Specify the strokewidth, and optionally if you want stroke + fill. 1.54 + * Note, if width==0, then this request is taken to mean: 1.55 + * strokeAndFill==true -> new style will be Fill 1.56 + * strokeAndFill==false -> new style will be Hairline 1.57 + */ 1.58 + void setStrokeStyle(SkScalar width, bool strokeAndFill = false); 1.59 + 1.60 + void setStrokeParams(SkPaint::Cap cap, SkPaint::Join join, SkScalar miterLimit) { 1.61 + fCap = cap; 1.62 + fJoin = join; 1.63 + fMiterLimit = miterLimit; 1.64 + } 1.65 + 1.66 + /** 1.67 + * Returns true if this specifes any thick stroking, i.e. applyToPath() 1.68 + * will return true. 1.69 + */ 1.70 + bool needToApply() const { 1.71 + Style style = this->getStyle(); 1.72 + return (kStroke_Style == style) || (kStrokeAndFill_Style == style); 1.73 + } 1.74 + 1.75 + /** 1.76 + * Apply these stroke parameters to the src path, returning the result 1.77 + * in dst. 1.78 + * 1.79 + * If there was no change (i.e. style == hairline or fill) this returns 1.80 + * false and dst is unchanged. Otherwise returns true and the result is 1.81 + * stored in dst. 1.82 + * 1.83 + * src and dst may be the same path. 1.84 + */ 1.85 + bool applyToPath(SkPath* dst, const SkPath& src) const; 1.86 + 1.87 + bool operator==(const SkStrokeRec& other) const { 1.88 + return fWidth == other.fWidth && 1.89 + fMiterLimit == other.fMiterLimit && 1.90 + fCap == other.fCap && 1.91 + fJoin == other.fJoin && 1.92 + fStrokeAndFill == other.fStrokeAndFill; 1.93 + } 1.94 + 1.95 +private: 1.96 + SkScalar fWidth; 1.97 + SkScalar fMiterLimit; 1.98 + SkPaint::Cap fCap; 1.99 + SkPaint::Join fJoin; 1.100 + bool fStrokeAndFill; 1.101 +}; 1.102 + 1.103 +#endif