blob: 5c9563b3a6fbae336f306e6a19f908fd17eb697d [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 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 Malitafa8d49a2017-12-29 11:52:44 -050044 SkPaint fPaint;
45
Florin Malita1586d852018-01-12 14:27:39 -050046 SkScalar fOpacity = 1,
47 fStrokeWidth = 1,
Florin Malitafa8d49a2017-12-29 11:52:44 -050048 fStrokeMiter = 4;
49 bool fAntiAlias = false;
Florin Malita25366fa2018-01-23 13:37:59 -050050 SkBlendMode fBlendMode = SkBlendMode::kSrcOver;
Florin Malitafa8d49a2017-12-29 11:52:44 -050051 SkPaint::Style fStyle = SkPaint::kFill_Style;
52 SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
53 SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
Florin Malita4aa44412017-12-19 12:21:02 -050054
55 typedef Node INHERITED;
56};
57
58} // namespace sksg
59
60#endif // SkSGGeometryNode_DEFINED