blob: a2fbada065bdee8d1ba5734370828971c0cf9e5e [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 )
28 SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
29 SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
30 SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
31 SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
32 SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
33
Florin Malita4aa44412017-12-19 12:21:02 -050034protected:
35 PaintNode();
36
Florin Malitafa8d49a2017-12-29 11:52:44 -050037 virtual void onApplyToPaint(SkPaint*) const = 0;
Florin Malita4aa44412017-12-19 12:21:02 -050038
Florin Malitac14f1442018-01-05 11:32:31 -050039 SkRect onRevalidate(InvalidationController*, const SkMatrix&) final;
Florin Malita4aa44412017-12-19 12:21:02 -050040
41private:
Florin Malitafa8d49a2017-12-29 11:52:44 -050042 SkPaint fPaint;
43
44 SkScalar fStrokeWidth = 1,
45 fStrokeMiter = 4;
46 bool fAntiAlias = false;
47 SkPaint::Style fStyle = SkPaint::kFill_Style;
48 SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
49 SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
Florin Malita4aa44412017-12-19 12:21:02 -050050
51 typedef Node INHERITED;
52};
53
54} // namespace sksg
55
56#endif // SkSGGeometryNode_DEFINED