blob: dc4af490ce76cd1c86e3aa1640cb1b25005c0a8e [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 Malita97df5dc2018-09-10 15:53:27 -040025 SkPaint makePaint() const;
Florin Malita4aa44412017-12-19 12:21:02 -050026
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 Malita25366fa2018-01-23 13:37:59 -050029 SG_ATTRIBUTE(BlendMode , SkBlendMode , fBlendMode )
Florin Malitafa8d49a2017-12-29 11:52:44 -050030 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
Florin Malita4aa44412017-12-19 12:21:02 -050036protected:
37 PaintNode();
38
Florin Malitafa8d49a2017-12-29 11:52:44 -050039 virtual void onApplyToPaint(SkPaint*) const = 0;
Florin Malita4aa44412017-12-19 12:21:02 -050040
Florin Malitac14f1442018-01-05 11:32:31 -050041 SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
Florin Malita4aa44412017-12-19 12:21:02 -050042
43private:
Florin Malita1586d852018-01-12 14:27:39 -050044 SkScalar fOpacity = 1,
45 fStrokeWidth = 1,
Florin Malitafa8d49a2017-12-29 11:52:44 -050046 fStrokeMiter = 4;
47 bool fAntiAlias = false;
Florin Malita25366fa2018-01-23 13:37:59 -050048 SkBlendMode fBlendMode = SkBlendMode::kSrcOver;
Florin Malitafa8d49a2017-12-29 11:52:44 -050049 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