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 
14 
15 namespace impeller {
16 namespace scene {
17 
18 class Node;
19 class AnimationPlayer;
20 
21 class AnimationClip final {
22  public:
23  AnimationClip(std::shared_ptr<Animation> animation, Node* bind_target);
25 
28 
29  bool IsPlaying() const;
30 
31  void SetPlaying(bool playing);
32 
33  void Play();
34 
35  void Pause();
36 
37  void Stop();
38 
39  bool GetLoop() const;
40 
41  void SetLoop(bool looping);
42 
44 
45  /// @brief Sets the animation playback speed. Negative values make the clip
46  /// play in reverse.
47  void SetPlaybackTimeScale(Scalar playback_speed);
48 
49  Scalar GetWeight() const;
50 
51  void SetWeight(Scalar weight);
52 
53  /// @brief Get the current playback time of the animation.
54  SecondsF GetPlaybackTime() const;
55 
56  /// @brief Move the animation to the specified time. The given `time` is
57  /// clamped to the animation's playback range.
58  void Seek(SecondsF time);
59 
60  /// @brief Advance the animation by `delta_time` seconds. Negative
61  /// `delta_time` values do nothing.
62  void Advance(SecondsF delta_time);
63 
64  /// @brief Applies the animation to all binded properties in the scene.
65  void ApplyToBindings(
66  std::unordered_map<Node*, AnimationTransforms>& transform_decomps,
67  Scalar weight_multiplier) const;
68 
69  private:
70  void BindToTarget(Node* node);
71 
72  struct ChannelBinding {
73  const Animation::Channel& channel;
74  Node* node;
75  };
76 
77  std::shared_ptr<Animation> animation_;
78  std::vector<ChannelBinding> bindings_;
79 
80  SecondsF playback_time_;
81  Scalar playback_time_scale_ = 1; // Seconds multiplier, can be negative.
82  Scalar weight_ = 1;
83  bool playing_ = false;
84  bool loop_ = false;
85 
86  AnimationClip(const AnimationClip&) = delete;
87 
88  AnimationClip& operator=(const AnimationClip&) = delete;
89 
90  friend AnimationPlayer;
91 };
92 
93 } // namespace scene
94 } // namespace impeller
95 
96 #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:51
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:21
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:20
impeller::scene::AnimationClip::Pause
void Pause()
Definition: animation_clip.cc:40
impeller::scene::Node
Definition: node.h:26
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_blend_unittests.cc:18
impeller::scene::AnimationClip::operator=
AnimationClip & operator=(AnimationClip &&)
impeller::scene::AnimationClip::Stop
void Stop()
Definition: animation_clip.cc:44