• 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     SkPaint makePaint() const;
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     SkScalar       fOpacity     = 1,
45                    fStrokeWidth = 1,
46                    fStrokeMiter = 4;
47     bool           fAntiAlias   = false;
48     SkBlendMode    fBlendMode   = SkBlendMode::kSrcOver;
49     SkPaint::Style fStyle       = SkPaint::kFill_Style;
50     SkPaint::Join  fStrokeJoin  = SkPaint::kMiter_Join;
51     SkPaint::Cap   fStrokeCap   = SkPaint::kButt_Cap;
52 
53     typedef Node INHERITED;
54 };
55 
56 } // namespace sksg
57 
58 #endif // SkSGGeometryNode_DEFINED
59