• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 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 SkSGPaintNode_DEFINED
9 #define SkSGPaintNode_DEFINED
10 
11 #include "SkSGNode.h"
12 
13 #include "SkPaint.h"
14 
15 namespace sksg {
16 
17 /**
18  * Base class for nodes which provide a 'paint' (as opposed to geometry) for
19  * drawing (e.g. colors, gradients, patterns).
20  *
21  * Roughly equivalent to Skia's SkPaint.
22  */
23 class PaintNode : public Node {
24 public:
25     const SkPaint& makePaint();
26 
27     SG_ATTRIBUTE(AntiAlias  , bool          , fAntiAlias  )
28     SG_ATTRIBUTE(Opacity    , SkScalar      , fOpacity    )
29     SG_ATTRIBUTE(BlendMode  , SkBlendMode   , fBlendMode  )
30     SG_ATTRIBUTE(StrokeWidth, SkScalar      , fStrokeWidth)
31     SG_ATTRIBUTE(StrokeMiter, SkScalar      , fStrokeMiter)
32     SG_ATTRIBUTE(Style      , SkPaint::Style, fStyle      )
33     SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
34     SG_ATTRIBUTE(StrokeCap  , SkPaint::Cap  , fStrokeCap  )
35 
36 protected:
37     PaintNode();
38 
39     virtual void onApplyToPaint(SkPaint*) const = 0;
40 
41     SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
42 
43 private:
44     SkPaint        fPaint;
45 
46     SkScalar       fOpacity     = 1,
47                    fStrokeWidth = 1,
48                    fStrokeMiter = 4;
49     bool           fAntiAlias   = false;
50     SkBlendMode    fBlendMode   = SkBlendMode::kSrcOver;
51     SkPaint::Style fStyle       = SkPaint::kFill_Style;
52     SkPaint::Join  fStrokeJoin  = SkPaint::kMiter_Join;
53     SkPaint::Cap   fStrokeCap   = SkPaint::kButt_Cap;
54 
55     typedef Node INHERITED;
56 };
57 
58 } // namespace sksg
59 
60 #endif // SkSGGeometryNode_DEFINED
61