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