Antkeeper  0.0.1
animation.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
21 
23  looped(false),
24  loop_count(0),
25  paused(false),
26  stopped(true),
27  position(0.0),
28  speed(1.0),
29  start_callback(nullptr),
30  end_callback(nullptr),
31  loop_callback(nullptr)
32 {}
33 
34 void animation_base::seek(float t)
35 {
36  position = t;
37 }
38 
40 {
41  seek(0.0);
42 }
43 
44 void animation_base::loop(bool enabled)
45 {
46  looped = enabled;
47 }
48 
50 {
51  paused = true;
52 }
53 
55 {
56  if (stopped)
57  {
58  stopped = false;
59 
60  if (start_callback)
61  {
63  }
64  }
65 
66  paused = false;
67 }
68 
70 {
71  rewind();
72  stopped = true;
73  paused = false;
74  loop_count = 0;
75 }
76 
77 void animation_base::set_speed(float speed)
78 {
79  this->speed = speed;
80 }
81 
82 void animation_base::set_start_callback(std::function<void()> callback)
83 {
84  start_callback = callback;
85 }
86 
87 void animation_base::set_end_callback(std::function<void()> callback)
88 {
89  end_callback = callback;
90 }
91 
92 void animation_base::set_loop_callback(std::function<void(int)> callback)
93 {
94  loop_callback = callback;
95 }
void seek(float t)
Sets the animation position to t.
Definition: animation.cpp:34
void pause()
Pauses the animation.
Definition: animation.cpp:49
void set_loop_callback(std::function< void(int)> callback)
Sets the callback that's executed when the animation loops.
Definition: animation.cpp:92
std::function< void()> start_callback
Definition: animation.hpp:112
void set_end_callback(std::function< void()> callback)
Sets the callback that's executed when a non-looped animation has finished.
Definition: animation.cpp:87
void loop(bool enabled)
Enables or disables looping of the animation.
Definition: animation.cpp:44
void set_speed(float speed)
Sets the speed of the animation.
Definition: animation.cpp:77
void rewind()
Sets the animation position to 0.0.
Definition: animation.cpp:39
void play()
Plays the animation.
Definition: animation.cpp:54
void set_start_callback(std::function< void()> callback)
Sets the callback that's executed when the animation is started from a stopped state.
Definition: animation.cpp:82
std::function< void(int)> loop_callback
Definition: animation.hpp:114
void stop()
Stops the animation, rewinds it, and resets the loop count.
Definition: animation.cpp:69
std::function< void()> end_callback
Definition: animation.hpp:113