Source/Gorgon/Animation.h

Tue, 06 Jul 2021 10:22:49 +0300

author
cemkalyoncu
date
Tue, 06 Jul 2021 10:22:49 +0300
branch
4.x-dev
changeset 1701
b168349a931d
parent 1545
094af4a5b0db
permissions
-rwxr-xr-x

* Image/Bitmap rotate

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 /// @file
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2 /// contains animation system
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4 #pragma once
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include <stdexcept>
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
7 #include <iostream>
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
8
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9 #include "Event.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10 #include "Containers/Collection.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
11
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
12 namespace Gorgon {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
13 /// This namespace contains animation related functionality.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
14 namespace Animation {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
16 class Base;
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
17 class ControllerBase;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
18
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
19 /**
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
20 * This class governs the progress of animations. There might be multiple governors.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
21 * There is always an active governor. Unless overridden, active governor will progress
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
22 * the animations by the deltatime of the current frame. A governor that is destroyed
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
23 * will move its controllers to the currently active governor. If this governor is
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
24 * active, it will automatically activate the default governor.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
25 */
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
26 class Governor {
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
27 friend class ControllerBase;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
28 public:
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
29
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
30 /// Destroys this governor. If it is the active governor, default governor will be activated.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
31 virtual ~Governor();
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
32
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
33 /// Activates this governor, replacing current one.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
34 virtual void Activate() {
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
35 active = this;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
36 }
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
37
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
38 /// Animates the animations within this governor. This function for the animator is called
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
39 /// every frame by the main system. Thus calling it second time within the same frame will
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
40 /// cause animations to progress twice.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
41 virtual void Animate() const;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
42
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
43 /// Returns the default governor.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
44 static Governor &Default() {
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
45 static Governor def;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
46
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
47 return def;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
48 }
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
49
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
50 /// Returns the current governor. If there is no current active governor, default governor
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
51 /// will be returned.
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
52 static Governor &Active() {
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
53 if(active)
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
54 return *active;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
55 else
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
56 return Default();
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
57 }
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
58
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
59 private:
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
60 static Governor *active;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
61 Containers::Collection<ControllerBase> controllers;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
62 };
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
63
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
64 /// Controllers are required to progress animations
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
65 class ControllerBase {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
66 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
67 /// Default constructor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
68 ControllerBase();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
69
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
70 ///
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
71 explicit ControllerBase(Governor &governor);
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
72
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
73 /// Destructor
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
74 virtual ~ControllerBase();
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
75
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
76 /// Progresses this timer by moving the timer timepassed milliseconds forwards
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
77 virtual void Progress(unsigned timepassed) = 0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
78
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
79 /// This function attaches the given animation to this controller
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80 virtual void Add(Base &animation);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
81
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
82 /// Removes the given animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83 virtual void Remove(Base &animation);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
84
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
85 /// Deletes the given animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
86 virtual void Delete(Base &animation);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
87
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
88 /// Returns the current progress of the timer
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
89 virtual unsigned GetProgress() const = 0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
90
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
91 /// This method allows clients to determine if the progress is controlled. If the progress
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
92 /// is not controlled, there is no way to force the animation to stop. Therefore, animations
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
93 /// with looping capabilities should wrap around to start over. However, if the timer is a
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
94 /// controller then the best strategy will be to stop at the end, and return the leftover time.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
95 /// This way, controller can decide what to do next.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
96 virtual bool IsControlled() const = 0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
98 /// Set a flag that will automatically destroy this controller whenever it has no animations left
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
99 /// to control
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
100 void AutoDestruct() { collectable=true; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
101
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
102 /// Resets the flag that will automatically destroy this controller whenever it has no animations left
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
103 /// to control
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
104 void Keep() { collectable=false; }
1186
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
105
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
106 /// Resets the animation to the start. Animation controllers that do not support this request should
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
107 /// silently ignore it.
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
108 virtual void Reset() = 0;
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
109
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
110 /// Changes the governor of this controller
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
111 virtual void SetGovernor(Governor &governor);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
112
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
113 protected:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
114 /// Whether this controller should be collected by the garbage collector when its task is finished
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
115 bool collectable = false;
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
116
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1186
diff changeset
117 Governor *governor = nullptr;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
118
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
119 /// List of animations this controller holds
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
120 Containers::Collection<Base> animations;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
121 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
122
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
123 /// This class is the most basic controller and does not support any operations. It linearly progresses
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
124 /// animation and never stops. Most animations are expected loop under these circumstances. See Controller
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
125 /// for additional functionality.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
126 class Timer : public ControllerBase {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
127 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
128
785
56d21a921789 * Animation saving
cemkalyoncu
parents: 784
diff changeset
129 virtual ~Timer() { }
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
130
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
131 /// Progresses this timer by moving the timer timepassed milliseconds forwards
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
132 virtual void Progress(unsigned timepassed) override final;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
133
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
134 /// Resets the timer, basically starting the animation from the start.
1186
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
135 virtual void Reset() override {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
136 progress=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
137 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
138
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
139 /// Sets the progress of the timer to the given value.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
140 virtual void SetProgress(unsigned progress) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
141 this->progress=progress;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
142 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
143
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
144 /// Returns the current progress of the timer
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
145 virtual unsigned GetProgress() const override final {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
146 return progress;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
147 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
148
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
149 /// This method allows clients to determine if the progress is controlled. If the progress
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
150 /// is not controlled, there is no way to force the animation to stop. Therefore, animations
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
151 /// with looping capabilities should wrap around to start over. However, if the timer is a
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
152 /// controller then the best strategy will be to stop at the end, and return the leftover time.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
153 /// This way, controller can decide what to do next.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
154 virtual bool IsControlled() const override final {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
155 return false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
156 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
157
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
158 protected:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
159 /// Amount of time passed since the start of the animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
160 unsigned progress = 0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
161 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
162
1195
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
163 /**
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
164 * This class allows finer control for the animations, allowing loop, stopping at the end, events,
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
165 * speed and direction control. Use SetLength to control the length of the animation. Otherwise, if
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
166 * the first controlled animation exists, its length is used. Best used with a single animation or
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
167 * animations that have the same duration.
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
168 */
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
169 class Controller : public ControllerBase {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
170 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
171
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
172 /// Default constructor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
173 Controller(double progress = 0.0);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
174
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
175 virtual ~Controller() {}
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
176
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
177 /// @name Progress modification functions
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
178 /// @{
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
179
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
180 /// Progresses this controller by the given time
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
181 virtual void Progress(unsigned timepassed) override final;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
182
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
183 /// Sets the current progress of the controller
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
184 virtual void SetProgress(unsigned progress) { this->progress=progress; }
1543
48b279ef6609 * More label styles
cemkalyoncu
parents: 1314
diff changeset
185
48b279ef6609 * More label styles
cemkalyoncu
parents: 1314
diff changeset
186 virtual unsigned GetProgress() const override {
1545
094af4a5b0db * Listbox selection bug
cemkalyoncu
parents: 1543
diff changeset
187 return (unsigned)progress;
1543
48b279ef6609 * More label styles
cemkalyoncu
parents: 1314
diff changeset
188 }
48b279ef6609 * More label styles
cemkalyoncu
parents: 1314
diff changeset
189
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
190
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
191 /// Sets the current progress of the controller. If the progress is a negative value, it will be
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
192 /// subtracted from the animation length. If the animation length is 0, then the controller will
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
193 /// immediately stop and sets the progress to 0.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
194 void SetProgress(double progress) { this->progress=progress; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
195
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
196 /// Resets the controller to start from the beginning. Also resets finished and paused status and
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
197 /// modifies the speed to be 1.
1186
8eb9de7efa24 * A bug related with UI state switching is fixed
cemkalyoncu
parents: 1184
diff changeset
198 virtual void Reset() override;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
199 /// @}
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
200
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
201 /// @name Progress control functions
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
202 /// @{
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
203
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
204 /// Starts this controller to run once. If the controller is marked as finished, this method will
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
205 /// set the progress to 0 or length depending on the direction of the controller. If length is 0
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
206 /// and the speed is negative this method will not start playing finished controller. If the animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
207 /// is paused, this function works like Resume except that this function sets controller to run once mode.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
208 virtual void Play();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
209
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
210 /// Starts this controller in looping mode. Looping will not work when the length is 0 and the speed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
211 /// is set to a negative value (animation is running in reverse). If the animation is paused, this
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
212 /// function works like Resume except that this function sets controller to looping mode
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
213 virtual void Loop() { Play(); islooping=true; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
214
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
215 /// Pauses the controller, until a Resume or Reset is issued.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
216 virtual void Pause();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
217
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
218 /// Resumes the controller. This method will not have any effect if the animation is finished.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
219 virtual void Resume() { ispaused=false; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
220
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
221 /// Changes the speed of the controller. Speed can be negative to run animations backwards. Setting
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
222 /// speed 0 effectively pauses the controller, however, when the speed is 0 controller will **not** report
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
223 /// that its paused.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
224 virtual void SetSpeed(float speed) { this->speed=speed; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
225
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
226 /// Reverses the animation direction by negating the speed.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
227 virtual void Reverse() { speed=-speed; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
228
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
229 /// Informs controller about the length of the animations its controlling. This allows Controller to seek
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
230 /// to the end of the animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
231 virtual void SetLength(unsigned length) { this->length=length; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
232 /// @}
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
233
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
234 /// @name Information functions
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
235 /// @{
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
236
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
237 /// Returns the current speed of the controller
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
238 virtual float GetSpeed() { return speed; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
239
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
240 /// Returns whether the controller is paused. Does not check if the speed is 0 or not, setting speed to 0
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
241 /// will effectively pause the animation without changing paused status.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
242 bool IsPaused() const { return ispaused; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
243
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
244 /// Whether the controller is finished either by reaching to the end while the speed is positive or reaching to
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
245 /// 0 while the speed is negative
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
246 bool IsFinished() const { return isfinished; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
247
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
248 /// Returns whether the controller is playing its animations right now. This method does not take speed being
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
249 /// 0 into account.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
250 bool IsPlaying() const { return !ispaused && !isfinished; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
251
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
252 /// Checks whether the controller is in loop mode. It also checks the length if the speed is negative and makes
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
253 /// sure that the controller can actually loop
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
254 bool IsLooping() const { return (speed>=0 ? islooping : islooping && length!=0); }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
255
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
256 virtual bool IsControlled() const override final { return true; }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
257 /// @}
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
258
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
259 /// @name Events
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
260 /// @{
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
261
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
262 /// Will be fired when the controller reaches the finished state. controller is finished either by reaching to
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
263 /// the end while the speed is positive or reaching to 0 while the speed is negative
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
264 Event<Controller> FinishedEvent;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
265 /// @}
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
266
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
267 protected:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
268 /// Paused state
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
269 bool ispaused = false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
270
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
271 /// Looping state
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
272 bool islooping = false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
273
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
274 /// Current speed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
275 float speed = 1.0f;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
276
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
277 /// Whether the controller is finished
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
278 bool isfinished = false;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
279
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
280 /// Floating point progress to avoid precision loss due to speed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
281 double progress = 0.0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
282
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
283 /// Length of the animations controlled by this controller
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
284 unsigned length=0;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
285 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
286
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
287 /// This interface marks a class as animation provider
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
288 class Provider {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
289 public:
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
290 using AnimationType = Base;
1000
df96e886e422 * Refactoring to allow animation provider to move themselves out
cemkalyoncu
parents: 991
diff changeset
291
1297
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
292
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
293 /// Virtual destructor
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
294 virtual ~Provider() { }
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
295
1000
df96e886e422 * Refactoring to allow animation provider to move themselves out
cemkalyoncu
parents: 991
diff changeset
296 /// This function moves this animation provider into a new provider. Ownership of this new object belongs
df96e886e422 * Refactoring to allow animation provider to move themselves out
cemkalyoncu
parents: 991
diff changeset
297 /// to the caller and this object could be destroyed safely.
df96e886e422 * Refactoring to allow animation provider to move themselves out
cemkalyoncu
parents: 991
diff changeset
298 virtual Provider &MoveOutProvider() = 0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
299
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
300 /// This function should create a new animation with the given controller
991
9a65be2159ee * Masked line
cemkalyoncu
parents: 972
diff changeset
301 virtual Base &CreateAnimation(ControllerBase &timer) const = 0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
302
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
303 /// This function should create an animation and depending on the create parameter,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
304 /// it should create a timer for it. Timer creation is handled by Base class therefore
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
305 /// only passing this parameter to the constructor is enough.
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
306 virtual Base &CreateAnimation(bool create=true) const = 0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
307 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
308
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
309 /// This is the base class for all animations. It handles some common tasks and defines
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
310 /// the animation interface.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
311 class Base {
1193
e0ba674154f1 * Animation controller garbage collection is now in place
cemkalyoncu
parents: 1192
diff changeset
312 friend class ControllerBase;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
313 public:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
314 /// Sets the controller for this animation to the given controller.
961
887a854567c5 * Design for Graphics::ImageAnimation
cemkalyoncu
parents: 785
diff changeset
315 explicit Base(ControllerBase &controller) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
316 SetController(controller);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
317 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
318
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
319 /// Copies the animation
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
320 Base(const Base &base) {
1251
b0655bf8d5c7 * Automatic UI generation framework
cemkalyoncu
parents: 1195
diff changeset
321 if(base.HasController())
b0655bf8d5c7 * Automatic UI generation framework
cemkalyoncu
parents: 1195
diff changeset
322 SetController(base.GetController());
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
323 }
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
324
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
325 /// This constructor creates a new controller depending on the create parameter. Animation has the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
326 /// right to decline to create a new timer. Animations that does not use timers should ignore create
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
327 /// request without any errors or side effects. If create parameter is true, the controller created
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
328 /// for this object will have dynamic life time. This means, if all animations it has is removed from
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
329 /// it, it will be destroyed.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
330 explicit Base(bool create=false) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
331 if(create) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
332 auto timer = new Timer;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
333 timer->AutoDestruct();
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
334 SetController(*timer);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
335 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
336 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
337
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
338 /// Sets the controller to the given controller.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
339 virtual void SetController(ControllerBase &controller) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
340 if(&controller==this->controller) return;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
341 if(this->controller) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
342 this->controller->Remove(*this);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
343 }
784
0fe865b9e032 * Animations are now working
cemkalyoncu
parents: 764
diff changeset
344 this->controller=&controller;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
345 controller.Add(*this);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
346 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
347
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
348 /// Returns whether this animation has a controller
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
349 virtual bool HasController() const { return controller!=nullptr; }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
350
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
351 /// Returns the controller of this animation
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
352 virtual ControllerBase &GetController() const {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
353 #ifndef NDEBUG
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
354 if(!controller) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
355 throw std::runtime_error("Animation does not have a controller");
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
356 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
357 #endif
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
358 return *controller;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
359 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
360
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
361 /// Removes the controller of this animation.
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
362 virtual void RemoveController() {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
363 if(controller) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
364 controller->Remove(*this);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
365 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
366 controller=nullptr;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
367 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
368
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
369 /// This function should progress the animation. Notice that this function is called internally.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
370 /// Unless a change to the controller has been made and instant update of the animation is required
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
371 /// there is no need to call this function. Returning true from this function denotes that the further
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
372 /// progress is possible. If progress should end, leftover parameter should be set to the amount of
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
373 /// time that cannot be progressed. Progress function should also mind uncontrollable controllers.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
374 virtual bool Progress(unsigned &leftover) = 0;
1195
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
375
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
376 /// Returns the duration of the animation if it is a known apriori. If the animation can be progressed
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
377 /// infinitely, if it is possible to derive optimal duration, it should be returned. In case when it
1314
07c5ba456e0e * KeyRepeater class design #22
cemkalyoncu
parents: 1297
diff changeset
378 /// is impossible to determine the duration, return 0.
1195
d4fb5fca97b0 * Controlled timer is finished, requires testing
cemkalyoncu
parents: 1194
diff changeset
379 virtual int GetDuration() const = 0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
380
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
381 /// Deletes this animation. Please note that some animations are also the animation provider. In these
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
382 /// cases trying to delete the animation will delete the provider as well. This function should be called
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
383 /// instead of delete operator to ensure no such problem occurs.
972
40b12ffaea3e * Animation storage system to unify image, animation, and pointer
cemkalyoncu
parents: 961
diff changeset
384 virtual void DeleteAnimation() const {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
385 delete this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
386 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
387
1297
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
388 protected:
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
389 /// Virtual destructor
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
390 virtual ~Base();
ece08b33403a * Label has now more options to set an icon
cemkalyoncu
parents: 1251
diff changeset
391
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
392 /// Controller of this animation
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
393 ControllerBase *controller = nullptr;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
394 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
395 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
396 }

mercurial