blob: 1085e27c0fe61b0b31f8e60de7e1aa35f5783aa3 [file] [log] [blame]
Florin Malita4aa44412017-12-19 12:21:02 -05001/*
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
15namespace 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 */
23class PaintNode : public Node {
24public:
Florin Malita4aa44412017-12-19 12:21:02 -050025 const SkPaint& makePaint();
26
Florin Malitafa8d49a2017-12-29 11:52:44 -050027 SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
Florin Malita1586d852018-01-12 14:27:39 -050028 SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
Florin Malitafa8d49a2017-12-29 11:52:44 -050029 SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
30 SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
31 SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
32 SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
33 SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
34
Florin Malita4aa44412017-12-19 12:21:02 -050035protected:
36 PaintNode();
37
Florin Malitafa8d49a2017-12-29 11:52:44 -050038 virtual void onApplyToPaint(SkPaint*) const = 0;
Florin Malita4aa44412017-12-19 12:21:02 -050039
Florin Malitac14f1442018-01-05 11:32:31 -050040 SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
Florin Malita4aa44412017-12-19 12:21:02 -050041
42private:
Florin Malitafa8d49a2017-12-29 11:52:44 -050043 SkPaint fPaint;
44
Florin Malita1586d852018-01-12 14:27:39 -050045 SkScalar fOpacity = 1,
46 fStrokeWidth = 1,
Florin Malitafa8d49a2017-12-29 11:52:44 -050047 fStrokeMiter = 4;
48 bool fAntiAlias = false;
49 SkPaint::Style fStyle = SkPaint::kFill_Style;
50 SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
51 SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
Florin Malita4aa44412017-12-19 12:21:02 -050052
53 typedef Node INHERITED;
54};
55
56} // namespace sksg
57
58#endif // SkSGGeometryNode_DEFINED