2017-12-19 17:21:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-01 17:40:58 +00:00
|
|
|
#ifndef SkSGPaint_DEFINED
|
|
|
|
#define SkSGPaint_DEFINED
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "modules/sksg/include/SkSGNode.h"
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
2019-04-01 17:40:58 +00:00
|
|
|
class Shader;
|
|
|
|
|
2017-12-19 17:21:02 +00:00
|
|
|
/**
|
|
|
|
* Base class for nodes which provide a 'paint' (as opposed to geometry) for
|
|
|
|
* drawing (e.g. colors, gradients, patterns).
|
|
|
|
*
|
|
|
|
* Roughly equivalent to Skia's SkPaint.
|
|
|
|
*/
|
|
|
|
class PaintNode : public Node {
|
|
|
|
public:
|
2018-09-10 19:53:27 +00:00
|
|
|
SkPaint makePaint() const;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2017-12-29 16:52:44 +00:00
|
|
|
SG_ATTRIBUTE(AntiAlias , bool , fAntiAlias )
|
2018-01-12 19:27:39 +00:00
|
|
|
SG_ATTRIBUTE(Opacity , SkScalar , fOpacity )
|
2018-01-23 18:37:59 +00:00
|
|
|
SG_ATTRIBUTE(BlendMode , SkBlendMode , fBlendMode )
|
2017-12-29 16:52:44 +00:00
|
|
|
SG_ATTRIBUTE(StrokeWidth, SkScalar , fStrokeWidth)
|
|
|
|
SG_ATTRIBUTE(StrokeMiter, SkScalar , fStrokeMiter)
|
|
|
|
SG_ATTRIBUTE(Style , SkPaint::Style, fStyle )
|
|
|
|
SG_ATTRIBUTE(StrokeJoin , SkPaint::Join , fStrokeJoin )
|
|
|
|
SG_ATTRIBUTE(StrokeCap , SkPaint::Cap , fStrokeCap )
|
|
|
|
|
2017-12-19 17:21:02 +00:00
|
|
|
protected:
|
|
|
|
PaintNode();
|
|
|
|
|
2017-12-29 16:52:44 +00:00
|
|
|
virtual void onApplyToPaint(SkPaint*) const = 0;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
|
|
|
private:
|
2018-01-12 19:27:39 +00:00
|
|
|
SkScalar fOpacity = 1,
|
|
|
|
fStrokeWidth = 1,
|
2017-12-29 16:52:44 +00:00
|
|
|
fStrokeMiter = 4;
|
|
|
|
bool fAntiAlias = false;
|
2018-01-23 18:37:59 +00:00
|
|
|
SkBlendMode fBlendMode = SkBlendMode::kSrcOver;
|
2017-12-29 16:52:44 +00:00
|
|
|
SkPaint::Style fStyle = SkPaint::kFill_Style;
|
|
|
|
SkPaint::Join fStrokeJoin = SkPaint::kMiter_Join;
|
|
|
|
SkPaint::Cap fStrokeCap = SkPaint::kButt_Cap;
|
2017-12-19 17:21:02 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Node;
|
2017-12-19 17:21:02 +00:00
|
|
|
};
|
|
|
|
|
2019-04-01 17:40:58 +00:00
|
|
|
/**
|
|
|
|
* Concrete Paint node, wrapping an SkColor.
|
|
|
|
*/
|
|
|
|
class Color : public PaintNode {
|
|
|
|
public:
|
|
|
|
static sk_sp<Color> Make(SkColor c);
|
|
|
|
|
|
|
|
SG_ATTRIBUTE(Color, SkColor, fColor)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
|
|
|
|
void onApplyToPaint(SkPaint*) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit Color(SkColor);
|
|
|
|
|
|
|
|
SkColor fColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shader-based paint.
|
|
|
|
*/
|
|
|
|
class ShaderPaint final : public PaintNode {
|
|
|
|
public:
|
|
|
|
~ShaderPaint() override;
|
|
|
|
|
|
|
|
static sk_sp<ShaderPaint> Make(sk_sp<Shader>);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkRect onRevalidate(InvalidationController*, const SkMatrix&) override;
|
|
|
|
|
|
|
|
void onApplyToPaint(SkPaint*) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit ShaderPaint(sk_sp<Shader>);
|
|
|
|
|
|
|
|
const sk_sp<Shader> fShader;
|
|
|
|
|
|
|
|
using INHERITED = PaintNode;
|
|
|
|
};
|
|
|
|
|
2017-12-19 17:21:02 +00:00
|
|
|
} // namespace sksg
|
|
|
|
|
2019-04-01 17:40:58 +00:00
|
|
|
#endif // SkSGPaint_DEFINED
|