Flutter Engine
The Flutter Engine
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
15namespace impeller {
16namespace scene {
17
18class Node;
19class AnimationPlayer;
20
21class 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.
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_
void SetPlaybackTimeScale(Scalar playback_speed)
Sets the animation playback speed. Negative values make the clip play in reverse.
void SetWeight(Scalar weight)
void ApplyToBindings(std::unordered_map< Node *, AnimationTransforms > &transform_decomps, Scalar weight_multiplier) const
Applies the animation to all binded properties in the scene.
AnimationClip(std::shared_ptr< Animation > animation, Node *bind_target)
SecondsF GetPlaybackTime() const
Get the current playback time of the animation.
void Advance(SecondsF delta_time)
Advance the animation by delta_time seconds. Negative delta_time values do nothing.
AnimationClip & operator=(AnimationClip &&)
AnimationClip(AnimationClip &&)
void Seek(SecondsF time)
Move the animation to the specified time. The given time is clamped to the animation's playback range...
Definition: dart.idl:29
float Scalar
Definition: scalar.h:18
std::chrono::duration< float > SecondsF
Definition: timing.h:13
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394