| Flutter Impeller |

animation_clip.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_SCENE_ANIMATION_ANIMATION_CLIP_H_
6 #define FLUTTER_IMPELLER_SCENE_ANIMATION_ANIMATION_CLIP_H_
7
8 #include <memory>
9 #include <unordered_map>
10 #include <vector>
11
12 #include "flutter/fml/macros.h"
13 #include "impeller/scene/animation/animation.h"
14 #include "impeller/scene/animation/animation_transforms.h"
15
16 namespace impeller {
17 namespace scene {
18
19 class Node;
20 class AnimationPlayer;
21
22 class AnimationClip final {
23 public:
24 AnimationClip(std::shared_ptr<Animation> animation, Node* bind_target);
25 ~AnimationClip();
26
27 AnimationClip(AnimationClip&&);
28 AnimationClip& operator=(AnimationClip&&);
29
30 bool IsPlaying() const;
31
32 void SetPlaying(bool playing);
33
34 void Play();
35
36 void Pause();
37
38 void Stop();
39
40 bool GetLoop() const;
41
42 void SetLoop(bool looping);
43
44 Scalar GetPlaybackTimeScale() const;
45
46 /// @brief Sets the animation playback speed. Negative values make the clip
47 /// play in reverse.
48 void SetPlaybackTimeScale(Scalar playback_speed);
49
50 Scalar GetWeight() const;
51
52 void SetWeight(Scalar weight);
53
54 /// @brief Get the current playback time of the animation.
55 SecondsF GetPlaybackTime() const;
56
57 /// @brief Move the animation to the specified time. The given `time` is
58 /// clamped to the animation's playback range.
59 void Seek(SecondsF time);
60
61 /// @brief Advance the animation by `delta_time` seconds. Negative
62 /// `delta_time` values do nothing.
63 void Advance(SecondsF delta_time);
64
65 /// @brief Applies the animation to all binded properties in the scene.
66 void ApplyToBindings(
67 std::unordered_map<Node*, AnimationTransforms>& transform_decomps,
68 Scalar weight_multiplier) const;
69
70 private:
71 void BindToTarget(Node* node);
72
73 struct ChannelBinding {
74 const Animation::Channel& channel;
75 Node* node;
76 };
77
78 std::shared_ptr<Animation> animation_;
79 std::vector<ChannelBinding> bindings_;
80
81 SecondsF playback_time_;
82 Scalar playback_time_scale_ = 1; // Seconds multiplier, can be negative.
83 Scalar weight_ = 1;
84 bool playing_ = false;
85 bool loop_ = false;
86
87 AnimationClip(const AnimationClip&) = delete;
88
89 AnimationClip& operator=(const AnimationClip&) = delete;
90
91 friend AnimationPlayer;
92 };
93
94 } // namespace scene
95 } // namespace impeller
96
97 #endif // FLUTTER_IMPELLER_SCENE_ANIMATION_ANIMATION_CLIP_H_
animation.h
impeller::Scalar
float Scalar
Definition: scalar.h:18
impeller::scene::Animation::Channel
Definition: animation.h:55
impeller::scene::AnimationClip::SetPlaybackTimeScale
void SetPlaybackTimeScale(Scalar playback_speed)
Sets the animation playback speed. Negative values make the clip play in reverse.
Definition: animation_clip.cc:61
impeller::scene::AnimationClip::GetLoop
bool GetLoop() const
Definition: animation_clip.cc:49
impeller::scene::AnimationClip::SetLoop
void SetLoop(bool looping)
Definition: animation_clip.cc:53
impeller::scene::AnimationClip::GetWeight
Scalar GetWeight() const
Definition: animation_clip.cc:65
impeller::scene::AnimationClip::Play
void Play()
Definition: animation_clip.cc:36
impeller::scene::AnimationClip::ApplyToBindings
void ApplyToBindings(std::unordered_map< Node *, AnimationTransforms > &transform_decomps, Scalar weight_multiplier) const
Applies the animation to all binded properties in the scene.
Definition: animation_clip.cc:113
impeller::scene::AnimationClip
Definition: animation_clip.h:22
impeller::SecondsF
std::chrono::duration< float > SecondsF
Definition: timing.h:13
impeller::scene::AnimationClip::GetPlaybackTime
SecondsF GetPlaybackTime() const
Get the current playback time of the animation.
Definition: animation_clip.cc:73
impeller::scene::AnimationClip::IsPlaying
bool IsPlaying() const
Definition: animation_clip.cc:28
animation_transforms.h
impeller::scene::AnimationClip::Advance
void Advance(SecondsF delta_time)
Advance the animation by delta_time seconds. Negative delta_time values do nothing.
Definition: animation_clip.cc:81
impeller::scene::AnimationClip::GetPlaybackTimeScale
Scalar GetPlaybackTimeScale() const
Definition: animation_clip.cc:57
impeller::scene::AnimationClip::SetWeight
void SetWeight(Scalar weight)
Definition: animation_clip.cc:69
impeller::scene::AnimationPlayer
Definition: animation_player.h:26
impeller::scene::AnimationClip::Pause
void Pause()
Definition: animation_clip.cc:40
impeller::scene::Node
Definition: node.h:30
impeller::scene::AnimationClip::Seek
void Seek(SecondsF time)
Move the animation to the specified time. The given time is clamped to the animation's playback range...
Definition: animation_clip.cc:77
impeller::scene::AnimationClip::~AnimationClip
~AnimationClip()
impeller::scene::AnimationClip::SetPlaying
void SetPlaying(bool playing)
Definition: animation_clip.cc:32
impeller::scene::AnimationClip::AnimationClip
AnimationClip(std::shared_ptr< Animation > animation, Node *bind_target)
Definition: animation_clip.cc:17
impeller
Definition: aiks_context.cc:10
impeller::scene::AnimationClip::operator=
AnimationClip & operator=(AnimationClip &&)
impeller::scene::AnimationClip::Stop
void Stop()
Definition: animation_clip.cc:44