a85f3a138c
Introduce a PropertyObserver to receive property notifications for layer and shape nodes. Properties are communicated using strongly-typed "handles", which act as impedance adapters between the AE/BM model and the internal Skottie model. Reviewed-by: Mike Reed <reed@google.com> Change-Id: Id155076faa8595f6b4d81672559f01c2e0c7455a TBR= Reviewed-on: https://skia-review.googlesource.com/156626 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
122 lines
2.8 KiB
C++
122 lines
2.8 KiB
C++
/*
|
|
* 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
|
|
|
|
#include "SkColor.h"
|
|
#include "SkPoint.h"
|
|
#include "SkRefCnt.h"
|
|
|
|
#include <functional>
|
|
|
|
class SkMatrix;
|
|
|
|
namespace sksg {
|
|
|
|
class Color;
|
|
class OpacityEffect;
|
|
|
|
} // namespace sksg
|
|
|
|
namespace skottie {
|
|
|
|
class ColorPropertyHandle;
|
|
class OpacityPropertyHandle;
|
|
class TransformPropertyHandle;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
class PropertyObserver : public SkRefCnt {
|
|
public:
|
|
template <typename T>
|
|
using LazyHandle = std::function<std::unique_ptr<T>()>;
|
|
|
|
virtual void onColorProperty (const char node_name[],
|
|
const LazyHandle<ColorPropertyHandle>&);
|
|
virtual void onOpacityProperty (const char node_name[],
|
|
const LazyHandle<OpacityPropertyHandle>&);
|
|
virtual void onTransformProperty(const char node_name[],
|
|
const LazyHandle<TransformPropertyHandle>&);
|
|
};
|
|
|
|
namespace internal { class AnimationBuilder; }
|
|
|
|
class ColorPropertyHandle final {
|
|
public:
|
|
~ColorPropertyHandle();
|
|
|
|
SkColor getColor() const;
|
|
void setColor(SkColor);
|
|
|
|
private:
|
|
explicit ColorPropertyHandle(sk_sp<sksg::Color>);
|
|
|
|
friend class skottie::internal::AnimationBuilder;
|
|
|
|
const sk_sp<sksg::Color> fColor;
|
|
};
|
|
|
|
class OpacityPropertyHandle final {
|
|
public:
|
|
~OpacityPropertyHandle();
|
|
|
|
float getOpacity() const;
|
|
void setOpacity(float);
|
|
|
|
private:
|
|
explicit OpacityPropertyHandle(sk_sp<sksg::OpacityEffect>);
|
|
|
|
friend class skottie::internal::AnimationBuilder;
|
|
|
|
const sk_sp<sksg::OpacityEffect> fOpacity;
|
|
};
|
|
|
|
class TransformAdapter;
|
|
|
|
class TransformPropertyHandle final {
|
|
public:
|
|
~TransformPropertyHandle();
|
|
|
|
SkPoint getAnchorPoint() const;
|
|
void setAnchorPoint(const SkPoint&);
|
|
|
|
SkPoint getPosition() const;
|
|
void setPosition(const SkPoint&);
|
|
|
|
SkVector getScale() const;
|
|
void setScale(const SkVector&);
|
|
|
|
SkScalar getRotation() const;
|
|
void setRotation(SkScalar);
|
|
|
|
SkScalar getSkew() const;
|
|
void setSkew(SkScalar);
|
|
|
|
SkScalar getSkewAxis() const;
|
|
void setSkewAxis(SkScalar);
|
|
|
|
SkMatrix getTotalMatrix() const;
|
|
|
|
private:
|
|
explicit TransformPropertyHandle(sk_sp<TransformAdapter>);
|
|
|
|
friend class skottie::internal::AnimationBuilder;
|
|
|
|
const sk_sp<TransformAdapter> fTransform;
|
|
};
|
|
|
|
} // namespace skottie
|
|
|
|
#endif // SkottieProperty_DEFINED
|