Flutter Engine
The Flutter Engine
Animator.h
Go to the documentation of this file.
1/*
2 * Copyright 2020 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 SkottieAnimator_DEFINED
9#define SkottieAnimator_DEFINED
10
12
13#include <vector>
14
15struct SkV2;
16
17namespace skjson {
18
19class ObjectValue;
20
21} // namespace skjson
22
23namespace skottie {
24
25class SlotManager;
26
27namespace internal {
28
29class AnimationBuilder;
30class AnimatorBuilder;
31
32class Animator : public SkRefCnt {
33public:
34 using StateChanged = bool;
35 StateChanged seek(float t) { return this->onSeek(t); }
36
37protected:
38 Animator() = default;
39
40 virtual StateChanged onSeek(float t) = 0;
41
42private:
43 Animator(const Animator&) = delete;
44 Animator& operator=(const Animator&) = delete;
45};
46
48public:
49 // This is the workhorse for property binding: depending on whether the property is animated,
50 // it will either apply immediately or instantiate and attach a keyframe animator, scoped to
51 // this container.
52 template <typename T>
54
55 template <typename T>
56 bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
57 return this->bind<T>(abuilder, jobject, &v);
58 }
59
60 // A flavor of bind<Vec2Value> which drives an additional/optional orientation target
61 // (rotation in degrees), when bound to a motion path property.
62 bool bindAutoOrientable(const AnimationBuilder& abuilder,
63 const skjson::ObjectValue* jobject,
64 SkV2* v, float* orientation);
65
66 bool isStatic() const { return fAnimators.empty() && !fHasSlotID; }
67
68protected:
70 virtual void onSync() = 0;
71
72 void shrink_to_fit();
73
75
76private:
77 StateChanged onSeek(float) final;
78
79 bool bindImpl(const AnimationBuilder&, const skjson::ObjectValue*, AnimatorBuilder&);
80
81 std::vector<sk_sp<Animator>> fAnimators;
82 bool fHasSynced = false;
83 bool fHasSlotID = false;
84};
85
86} // namespace internal
87} // namespace skottie
88
89#endif // SkottieAnimator_DEFINED
bool bindAutoOrientable(const AnimationBuilder &abuilder, const skjson::ObjectValue *jobject, SkV2 *v, float *orientation)
void attachDiscardableAdapter(sk_sp< AnimatablePropertyContainer >)
Definition: Animator.cpp:36
bool bind(const AnimationBuilder &abuilder, const skjson::ObjectValue *jobject, T &v)
Definition: Animator.h:56
bool bind(const AnimationBuilder &, const skjson::ObjectValue *, T *)
virtual StateChanged onSeek(float t)=0
StateChanged seek(float t)
Definition: Animator.h:35
#define T
Definition: precompiler.cc:65
Definition: SkM44.h:19