2018-09-24 21:24:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkottieProperty_DEFINED
|
|
|
|
#define SkottieProperty_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2022-03-10 14:32:29 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
2019-07-31 00:52:35 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/utils/SkTextUtils.h"
|
|
|
|
#include "modules/skottie/src/text/SkottieShaper.h"
|
2018-09-24 21:24:59 +00:00
|
|
|
|
2020-05-11 15:51:33 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2018-09-24 21:24:59 +00:00
|
|
|
class SkMatrix;
|
|
|
|
|
|
|
|
namespace sksg {
|
|
|
|
|
|
|
|
class Color;
|
|
|
|
class OpacityEffect;
|
|
|
|
|
|
|
|
} // namespace sksg
|
|
|
|
|
|
|
|
namespace skottie {
|
|
|
|
|
2018-11-28 16:39:39 +00:00
|
|
|
using ColorPropertyValue = SkColor;
|
|
|
|
using OpacityPropertyValue = float;
|
|
|
|
|
2020-07-10 13:58:48 +00:00
|
|
|
enum class TextPaintOrder : uint8_t {
|
|
|
|
kFillStroke,
|
|
|
|
kStrokeFill,
|
|
|
|
};
|
|
|
|
|
2019-07-31 00:52:35 +00:00
|
|
|
struct TextPropertyValue {
|
2020-10-02 18:15:50 +00:00
|
|
|
sk_sp<SkTypeface> fTypeface;
|
|
|
|
SkString fText;
|
2021-09-03 13:45:53 +00:00
|
|
|
float fTextSize = 0,
|
|
|
|
fMinTextSize = 0, // when auto-sizing
|
|
|
|
fMaxTextSize = std::numeric_limits<float>::max(), // when auto-sizing
|
|
|
|
fStrokeWidth = 0,
|
|
|
|
fLineHeight = 0,
|
|
|
|
fLineShift = 0,
|
|
|
|
fAscent = 0;
|
2022-03-09 19:46:52 +00:00
|
|
|
size_t fMaxLines = 0; // when auto-sizing
|
2021-09-03 13:45:53 +00:00
|
|
|
SkTextUtils::Align fHAlign = SkTextUtils::kLeft_Align;
|
|
|
|
Shaper::VAlign fVAlign = Shaper::VAlign::kTop;
|
|
|
|
Shaper::ResizePolicy fResize = Shaper::ResizePolicy::kNone;
|
|
|
|
Shaper::LinebreakPolicy fLineBreak = Shaper::LinebreakPolicy::kExplicit;
|
|
|
|
Shaper::Direction fDirection = Shaper::Direction::kLTR;
|
|
|
|
Shaper::Capitalization fCapitalization = Shaper::Capitalization::kNone;
|
|
|
|
SkRect fBox = SkRect::MakeEmpty();
|
|
|
|
SkColor fFillColor = SK_ColorTRANSPARENT,
|
|
|
|
fStrokeColor = SK_ColorTRANSPARENT;
|
|
|
|
TextPaintOrder fPaintOrder = TextPaintOrder::kFillStroke;
|
2022-03-10 14:32:29 +00:00
|
|
|
SkPaint::Join fStrokeJoin = SkPaint::Join::kMiter_Join;
|
2021-09-03 13:45:53 +00:00
|
|
|
bool fHasFill = false,
|
|
|
|
fHasStroke = false;
|
2019-07-31 00:52:35 +00:00
|
|
|
|
|
|
|
bool operator==(const TextPropertyValue& other) const;
|
|
|
|
bool operator!=(const TextPropertyValue& other) const;
|
|
|
|
};
|
|
|
|
|
2018-11-28 16:39:39 +00:00
|
|
|
struct TransformPropertyValue {
|
|
|
|
SkPoint fAnchorPoint,
|
|
|
|
fPosition;
|
|
|
|
SkVector fScale;
|
|
|
|
SkScalar fRotation,
|
|
|
|
fSkew,
|
|
|
|
fSkewAxis;
|
|
|
|
|
|
|
|
bool operator==(const TransformPropertyValue& other) const;
|
|
|
|
bool operator!=(const TransformPropertyValue& other) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace internal { class AnimationBuilder; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Property handles are adapters between user-facing AE model/values
|
|
|
|
* and the internal scene-graph representation.
|
|
|
|
*/
|
|
|
|
template <typename ValueT, typename NodeT>
|
|
|
|
class SK_API PropertyHandle final {
|
|
|
|
public:
|
2019-07-25 18:27:03 +00:00
|
|
|
explicit PropertyHandle(sk_sp<NodeT> node) : fNode(std::move(node)) {}
|
2018-11-28 16:39:39 +00:00
|
|
|
~PropertyHandle();
|
|
|
|
|
|
|
|
ValueT get() const;
|
|
|
|
void set(const ValueT&);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const sk_sp<NodeT> fNode;
|
|
|
|
};
|
|
|
|
|
2020-01-06 17:17:27 +00:00
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class TextAdapter;
|
2019-01-02 15:34:49 +00:00
|
|
|
class TransformAdapter2D;
|
2018-11-28 16:39:39 +00:00
|
|
|
|
2020-01-06 17:17:27 +00:00
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
using ColorPropertyHandle = PropertyHandle<ColorPropertyValue,
|
|
|
|
sksg::Color>;
|
|
|
|
using OpacityPropertyHandle = PropertyHandle<OpacityPropertyValue,
|
|
|
|
sksg::OpacityEffect>;
|
|
|
|
using TextPropertyHandle = PropertyHandle<TextPropertyValue,
|
|
|
|
internal::TextAdapter>;
|
|
|
|
using TransformPropertyHandle = PropertyHandle<TransformPropertyValue,
|
|
|
|
internal::TransformAdapter2D>;
|
2018-09-24 21:24:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A PropertyObserver can be used to track and manipulate certain properties of "interesting"
|
|
|
|
* Lottie nodes.
|
|
|
|
*
|
|
|
|
* When registered with an animation builder, PropertyObserver receives notifications for
|
|
|
|
* various properties of layer and shape nodes. The |node_name| argument corresponds to the
|
|
|
|
* name ("nm") node property.
|
|
|
|
*/
|
2018-11-28 16:39:39 +00:00
|
|
|
class SK_API PropertyObserver : public SkRefCnt {
|
2018-09-24 21:24:59 +00:00
|
|
|
public:
|
2021-06-09 21:12:46 +00:00
|
|
|
enum class NodeType {COMPOSITION, LAYER, EFFECT, OTHER};
|
|
|
|
|
2018-09-24 21:24:59 +00:00
|
|
|
template <typename T>
|
2020-05-11 15:51:33 +00:00
|
|
|
using LazyHandle = std::function<std::unique_ptr<T>()>;
|
2018-09-24 21:24:59 +00:00
|
|
|
|
|
|
|
virtual void onColorProperty (const char node_name[],
|
|
|
|
const LazyHandle<ColorPropertyHandle>&);
|
|
|
|
virtual void onOpacityProperty (const char node_name[],
|
|
|
|
const LazyHandle<OpacityPropertyHandle>&);
|
2019-08-06 01:30:25 +00:00
|
|
|
virtual void onTextProperty (const char node_name[],
|
|
|
|
const LazyHandle<TextPropertyHandle>&);
|
2018-09-24 21:24:59 +00:00
|
|
|
virtual void onTransformProperty(const char node_name[],
|
|
|
|
const LazyHandle<TransformPropertyHandle>&);
|
2021-06-09 21:12:46 +00:00
|
|
|
virtual void onEnterNode(const char node_name[], NodeType node_type);
|
|
|
|
virtual void onLeavingNode(const char node_name[], NodeType node_type);
|
2018-09-24 21:24:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace skottie
|
|
|
|
|
|
|
|
#endif // SkottieProperty_DEFINED
|