diff options
-rw-r--r-- | experimental/skotty/Skotty.cpp | 11 | ||||
-rw-r--r-- | experimental/skotty/SkottyProperties.cpp | 15 | ||||
-rw-r--r-- | experimental/skotty/SkottyProperties.h | 17 |
3 files changed, 40 insertions, 3 deletions
diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp index d118516d16..8d43d46b45 100644 --- a/experimental/skotty/Skotty.cpp +++ b/experimental/skotty/Skotty.cpp @@ -297,12 +297,17 @@ sk_sp<sksg::Color> AttachColorPaint(const Json::Value& obj, AttachContext* ctx) auto color_node = sksg::Color::Make(SK_ColorBLACK); color_node->setAntiAlias(true); - auto color_attached = BindProperty<VectorValue>(obj["c"], ctx, color_node, - [](sksg::Color* node, const VectorValue& c) { + auto composite = sk_make_sp<CompositeColor>(color_node); + auto color_attached = BindProperty<VectorValue>(obj["c"], ctx, composite, + [](CompositeColor* node, const VectorValue& c) { node->setColor(ValueTraits<VectorValue>::As<SkColor>(c)); }); + auto opacity_attached = BindProperty<ScalarValue>(obj["o"], ctx, composite, + [](CompositeColor* node, const ScalarValue& o) { + node->setOpacity(o); + }); - return color_attached ? color_node : nullptr; + return (color_attached || opacity_attached) ? color_node : nullptr; } sk_sp<sksg::PaintNode> AttachFillPaint(const Json::Value& jfill, AttachContext* ctx) { diff --git a/experimental/skotty/SkottyProperties.cpp b/experimental/skotty/SkottyProperties.cpp index 3bd95d8969..579823b24c 100644 --- a/experimental/skotty/SkottyProperties.cpp +++ b/experimental/skotty/SkottyProperties.cpp @@ -10,6 +10,7 @@ #include "SkColor.h" #include "SkottyPriv.h" #include "SkPath.h" +#include "SkSGColor.h" #include "SkSGPath.h" #include "SkSGRect.h" #include "SkSGTransform.h" @@ -177,6 +178,20 @@ SkPath ValueTraits<ShapeValue>::As<SkPath>(const ShapeValue& path) { return path; } +CompositeColor::CompositeColor(sk_sp<sksg::Color> wrapped_node) + : fColorNode(std::move(wrapped_node)) { + SkASSERT(fColorNode); +} + +void CompositeColor::apply() { + // 'opacity' is [0..100] + const auto a = SkScalarRoundToInt(SkTPin<float>(fOpacity * .01f, 0, 1) * SkColorGetA(fColor)); + fColorNode->setColor(SkColorSetARGB(a, + SkColorGetR(fColor), + SkColorGetG(fColor), + SkColorGetB(fColor))); +} + CompositeRRect::CompositeRRect(sk_sp<sksg::RRect> wrapped_node) : fRRectNode(std::move(wrapped_node)) {} diff --git a/experimental/skotty/SkottyProperties.h b/experimental/skotty/SkottyProperties.h index 4357367b3f..cb64ed748b 100644 --- a/experimental/skotty/SkottyProperties.h +++ b/experimental/skotty/SkottyProperties.h @@ -8,6 +8,7 @@ #ifndef SkottyProperties_DEFINED #define SkottyProperties_DEFINED +#include "SkColor.h" #include "SkPath.h" #include "SkPoint.h" #include "SkSize.h" @@ -20,6 +21,7 @@ #include <vector> namespace sksg { +class Color; class Matrix; class Path; class RRect; @@ -53,6 +55,21 @@ using ShapeValue = SkPath; p_type f##p_name = p_default; \ public: +class CompositeColor final : public SkRefCnt { +public: + explicit CompositeColor(sk_sp<sksg::Color>); + + COMPOSITE_PROPERTY(Color , SkColor , SK_ColorBLACK) + COMPOSITE_PROPERTY(Opacity, SkScalar, 100 ) + +private: + void apply(); + + sk_sp<sksg::Color> fColorNode; + + using INHERITED = SkRefCnt; +}; + class CompositeRRect final : public SkRefCnt { public: explicit CompositeRRect(sk_sp<sksg::RRect>); |