tween.h
1 /*************************************************************************/
2 /* tween.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef TWEEN_H
30 #define TWEEN_H
31 
32 #include "scene/main/node.h"
33 
34 
35 class Tween : public Node {
36 
37  OBJ_TYPE( Tween, Node );
38 
39 public:
40  enum TweenProcessMode {
41  TWEEN_PROCESS_FIXED,
42  TWEEN_PROCESS_IDLE,
43  };
44 
45  enum TransitionType {
46  TRANS_LINEAR,
47  TRANS_SINE,
48  TRANS_QUINT,
49  TRANS_QUART,
50  TRANS_QUAD,
51  TRANS_EXPO,
52  TRANS_ELASTIC,
53  TRANS_CUBIC,
54  TRANS_CIRC,
55  TRANS_BOUNCE,
56  TRANS_BACK,
57 
58  TRANS_COUNT,
59  };
60 
61  enum EaseType {
62  EASE_IN,
63  EASE_OUT,
64  EASE_IN_OUT,
65  EASE_OUT_IN,
66 
67  EASE_COUNT,
68  };
69 
70 private:
71  enum InterpolateType {
72 
73  INTER_PROPERTY,
74  INTER_METHOD,
75  FOLLOW_PROPERTY,
76  FOLLOW_METHOD,
77  TARGETING_PROPERTY,
78  TARGETING_METHOD,
79  INTER_CALLBACK,
80  };
81 
82  struct InterpolateData {
83  bool active;
84  InterpolateType type;
85  bool finish;
86  bool call_deferred;
87  real_t elapsed;
88  ObjectID id;
89  StringName key;
90  Variant initial_val;
91  Variant delta_val;
92  Variant final_val;
93  ObjectID target_id;
94  StringName target_key;
95  real_t times_in_sec;
96  TransitionType trans_type;
97  EaseType ease_type;
98  real_t delay;
99  int args;
100  Variant arg[5];
101  };
102 
103  String autoplay;
104  TweenProcessMode tween_process_mode;
105  bool processing;
106  bool active;
107  bool repeat;
108  float speed_scale;
109  mutable int pending_update;
110 
111  List<InterpolateData> interpolates;
112 
113  struct PendingCommand {
114  StringName key;
115  int args;
116  Variant arg[10];
117  };
118  List<PendingCommand> pending_commands;
119 
120  void _add_pending_command(StringName p_key
121  ,const Variant& p_arg1=Variant()
122  ,const Variant& p_arg2=Variant()
123  ,const Variant& p_arg3=Variant()
124  ,const Variant& p_arg4=Variant()
125  ,const Variant& p_arg5=Variant()
126  ,const Variant& p_arg6=Variant()
127  ,const Variant& p_arg7=Variant()
128  ,const Variant& p_arg8=Variant()
129  ,const Variant& p_arg9=Variant()
130  ,const Variant& p_arg10=Variant()
131  );
132  void _process_pending_commands();
133 
134  typedef real_t (*interpolater)(real_t t, real_t b, real_t c, real_t d);
135  static interpolater interpolaters[TRANS_COUNT][EASE_COUNT];
136 
137  real_t _run_equation(TransitionType p_trans_type, EaseType p_ease_type, real_t t, real_t b, real_t c, real_t d);
138  Variant& _get_delta_val(InterpolateData& p_data);
139  Variant& _get_initial_val(InterpolateData& p_data);
140  Variant _run_equation(InterpolateData& p_data);
141  bool _calc_delta_val(const Variant& p_initial_val, const Variant& p_final_val, Variant& p_delta_val);
142  bool _apply_tween_value(InterpolateData& p_data, Variant& value);
143 
144  void _tween_process(float p_delta);
145  void _set_process(bool p_process,bool p_force=false);
146 
147 protected:
148 
149  bool _set(const StringName& p_name, const Variant& p_value);
150  bool _get(const StringName& p_name,Variant &r_ret) const;
151  void _get_property_list(List<PropertyInfo> *p_list) const;
152  void _notification(int p_what);
153 
154  static void _bind_methods();
155 
156 public:
157 
158  bool is_active() const;
159  void set_active(bool p_active);
160 
161  bool is_repeat() const;
162  void set_repeat(bool p_repeat);
163 
164  void set_tween_process_mode(TweenProcessMode p_mode);
165  TweenProcessMode get_tween_process_mode() const;
166 
167  void set_speed(float p_speed);
168  float get_speed() const;
169 
170  bool start();
171  bool reset(Object *p_node, String p_key);
172  bool reset_all();
173  bool stop(Object *p_node, String p_key);
174  bool stop_all();
175  bool resume(Object *p_node, String p_key);
176  bool resume_all();
177  bool remove(Object *p_node, String p_key);
178  bool remove_all();
179 
180  bool seek(real_t p_time);
181  real_t tell() const;
182  real_t get_runtime() const;
183 
184  bool interpolate_property(Object *p_node
185  , String p_property
186  , Variant p_initial_val
187  , Variant p_final_val
188  , real_t p_times_in_sec
189  , TransitionType p_trans_type
190  , EaseType p_ease_type
191  , real_t p_delay = 0
192  );
193 
194  bool interpolate_method(Object *p_node
195  , String p_method
196  , Variant p_initial_val
197  , Variant p_final_val
198  , real_t p_times_in_sec
199  , TransitionType p_trans_type
200  , EaseType p_ease_type
201  , real_t p_delay = 0
202  );
203 
204  bool interpolate_callback(Object *p_object
205  , real_t p_times_in_sec
206  , String p_callback
207  , VARIANT_ARG_DECLARE
208  );
209 
210  bool interpolate_deferred_callback(Object *p_object
211  , real_t p_times_in_sec
212  , String p_callback
213  , VARIANT_ARG_DECLARE
214  );
215 
216  bool follow_property(Object *p_node
217  , String p_property
218  , Variant p_initial_val
219  , Object *p_target
220  , String p_target_property
221  , real_t p_times_in_sec
222  , TransitionType p_trans_type
223  , EaseType p_ease_type
224  , real_t p_delay = 0
225  );
226 
227  bool follow_method(Object *p_node
228  , String p_method
229  , Variant p_initial_val
230  , Object *p_target
231  , String p_target_method
232  , real_t p_times_in_sec
233  , TransitionType p_trans_type
234  , EaseType p_ease_type
235  , real_t p_delay = 0
236  );
237 
238  bool targeting_property(Object *p_node
239  , String p_property
240  , Object *p_initial
241  , String p_initial_property
242  , Variant p_final_val
243  , real_t p_times_in_sec
244  , TransitionType p_trans_type
245  , EaseType p_ease_type
246  , real_t p_delay = 0
247  );
248 
249  bool targeting_method(Object *p_node
250  , String p_method
251  , Object *p_initial
252  , String p_initial_method
253  , Variant p_final_val
254  , real_t p_times_in_sec
255  , TransitionType p_trans_type
256  , EaseType p_ease_type
257  , real_t p_delay = 0
258  );
259 
260  Tween();
261  ~Tween();
262 };
263 
264 VARIANT_ENUM_CAST( Tween::TweenProcessMode );
265 VARIANT_ENUM_CAST( Tween::TransitionType );
266 VARIANT_ENUM_CAST( Tween::EaseType );
267 
268 #endif
269 
Definition: variant.h:74
Definition: node.h:42
Definition: string_db.h:48
Definition: tween.h:35
Definition: ustring.h:64
Definition: object.h:317