1 /**
2 Smoothly animates a node's properties over time.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.tween;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.classdb;
23 import godot.node;
24 /**
25 Smoothly animates a node's properties over time.
26 
27 Tweens are useful for animations requiring a numerical property to be interpolated over a range of values. The name *tween* comes from *in-betweening*, an animation technique where you specify *keyframes* and the computer interpolates the frames that appear between them.
28 Here is a brief usage example that causes a 2D node to move smoothly between two positions:
29 
30 
31 var tween = get_node("Tween")
32 tween.interpolate_property($Node2D, "position",
33         Vector2(0, 0), Vector2(100, 100), 1,
34         Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
35 tween.start()
36 
37 
38 Many methods require a property name, such as "position" above. You can find the correct property name by hovering over the property in the Inspector.
39 Many of the methods accept `trans_type` and `ease_type`. The first accepts an $(D transitiontype) constant, and refers to the way the timing of the animation is handled (see `http://easings.net/` for some examples). The second accepts an $(D easetype) constant, and controls the where `trans_type` is applied to the interpolation (in the beginning, the end, or both). If you don't know which transition and easing to pick, you can try different $(D transitiontype) constants with `EASE_IN_OUT`, and use the one that looks best.
40 */
41 @GodotBaseClass struct Tween
42 {
43 	enum string _GODOT_internal_name = "Tween";
44 public:
45 @nogc nothrow:
46 	union { godot_object _godot_object; Node _GODOT_base; }
47 	alias _GODOT_base this;
48 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
49 	package(godot) __gshared bool _classBindingInitialized = false;
50 	package(godot) static struct _classBinding
51 	{
52 		__gshared:
53 		@GodotName("is_active") GodotMethod!(bool) isActive;
54 		@GodotName("set_active") GodotMethod!(void, bool) setActive;
55 		@GodotName("is_repeat") GodotMethod!(bool) isRepeat;
56 		@GodotName("set_repeat") GodotMethod!(void, bool) setRepeat;
57 		@GodotName("set_speed_scale") GodotMethod!(void, double) setSpeedScale;
58 		@GodotName("get_speed_scale") GodotMethod!(double) getSpeedScale;
59 		@GodotName("set_tween_process_mode") GodotMethod!(void, long) setTweenProcessMode;
60 		@GodotName("get_tween_process_mode") GodotMethod!(Tween.TweenProcessMode) getTweenProcessMode;
61 		@GodotName("start") GodotMethod!(bool) start;
62 		@GodotName("reset") GodotMethod!(bool, GodotObject, String) reset;
63 		@GodotName("reset_all") GodotMethod!(bool) resetAll;
64 		@GodotName("stop") GodotMethod!(bool, GodotObject, String) stop;
65 		@GodotName("stop_all") GodotMethod!(bool) stopAll;
66 		@GodotName("resume") GodotMethod!(bool, GodotObject, String) resume;
67 		@GodotName("resume_all") GodotMethod!(bool) resumeAll;
68 		@GodotName("remove") GodotMethod!(bool, GodotObject, String) remove;
69 		@GodotName("_remove_by_uid") GodotMethod!(void, long) _removeByUid;
70 		@GodotName("remove_all") GodotMethod!(bool) removeAll;
71 		@GodotName("seek") GodotMethod!(bool, double) seek;
72 		@GodotName("tell") GodotMethod!(double) tell;
73 		@GodotName("get_runtime") GodotMethod!(double) getRuntime;
74 		@GodotName("interpolate_property") GodotMethod!(bool, GodotObject, NodePath, Variant, Variant, double, long, long, double) interpolateProperty;
75 		@GodotName("interpolate_method") GodotMethod!(bool, GodotObject, String, Variant, Variant, double, long, long, double) interpolateMethod;
76 		@GodotName("interpolate_callback") GodotMethod!(bool, GodotObject, double, String, Variant, Variant, Variant, Variant, Variant) interpolateCallback;
77 		@GodotName("interpolate_deferred_callback") GodotMethod!(bool, GodotObject, double, String, Variant, Variant, Variant, Variant, Variant) interpolateDeferredCallback;
78 		@GodotName("follow_property") GodotMethod!(bool, GodotObject, NodePath, Variant, GodotObject, NodePath, double, long, long, double) followProperty;
79 		@GodotName("follow_method") GodotMethod!(bool, GodotObject, String, Variant, GodotObject, String, double, long, long, double) followMethod;
80 		@GodotName("targeting_property") GodotMethod!(bool, GodotObject, NodePath, GodotObject, NodePath, Variant, double, long, long, double) targetingProperty;
81 		@GodotName("targeting_method") GodotMethod!(bool, GodotObject, String, GodotObject, String, Variant, double, long, long, double) targetingMethod;
82 	}
83 	bool opEquals(in Tween other) const { return _godot_object.ptr is other._godot_object.ptr; }
84 	Tween opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
85 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
86 	mixin baseCasts;
87 	static Tween _new()
88 	{
89 		static godot_class_constructor constructor;
90 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Tween");
91 		if(constructor is null) return typeof(this).init;
92 		return cast(Tween)(constructor());
93 	}
94 	@disable new(size_t s);
95 	/// 
96 	enum TransitionType : int
97 	{
98 		/**
99 		The animation is interpolated linearly.
100 		*/
101 		transLinear = 0,
102 		/**
103 		The animation is interpolated using a sine function.
104 		*/
105 		transSine = 1,
106 		/**
107 		The animation is interpolated with a quintic (to the power of 5) function.
108 		*/
109 		transQuint = 2,
110 		/**
111 		The animation is interpolated with a quartic (to the power of 4) function.
112 		*/
113 		transQuart = 3,
114 		/**
115 		The animation is interpolated with a quadratic (to the power of 2) function.
116 		*/
117 		transQuad = 4,
118 		/**
119 		The animation is interpolated with an exponential (to the power of x) function.
120 		*/
121 		transExpo = 5,
122 		/**
123 		The animation is interpolated with elasticity, wiggling around the edges.
124 		*/
125 		transElastic = 6,
126 		/**
127 		The animation is interpolated with a cubic (to the power of 3) function.
128 		*/
129 		transCubic = 7,
130 		/**
131 		The animation is interpolated with a function using square roots.
132 		*/
133 		transCirc = 8,
134 		/**
135 		The animation is interpolated by bouncing at the end.
136 		*/
137 		transBounce = 9,
138 		/**
139 		The animation is interpolated backing out at ends.
140 		*/
141 		transBack = 10,
142 	}
143 	/// 
144 	enum TweenProcessMode : int
145 	{
146 		/**
147 		The tween updates with the `_physics_process` callback.
148 		*/
149 		tweenProcessPhysics = 0,
150 		/**
151 		The tween updates with the `_process` callback.
152 		*/
153 		tweenProcessIdle = 1,
154 	}
155 	/// 
156 	enum EaseType : int
157 	{
158 		/**
159 		The interpolation starts slowly and speeds up towards the end.
160 		*/
161 		easeIn = 0,
162 		/**
163 		The interpolation starts quickly and slows down towards the end.
164 		*/
165 		easeOut = 1,
166 		/**
167 		A combination of EASE_IN and EASE_OUT. The interpolation is slowest at both ends.
168 		*/
169 		easeInOut = 2,
170 		/**
171 		A combination of EASE_IN and EASE_OUT. The interpolation is fastest at both ends.
172 		*/
173 		easeOutIn = 3,
174 	}
175 	/// 
176 	enum Constants : int
177 	{
178 		easeIn = 0,
179 		tweenProcessPhysics = 0,
180 		transLinear = 0,
181 		transSine = 1,
182 		tweenProcessIdle = 1,
183 		easeOut = 1,
184 		easeInOut = 2,
185 		transQuint = 2,
186 		easeOutIn = 3,
187 		transQuart = 3,
188 		transQuad = 4,
189 		transExpo = 5,
190 		transElastic = 6,
191 		transCubic = 7,
192 		transCirc = 8,
193 		transBounce = 9,
194 		transBack = 10,
195 	}
196 	/**
197 	Returns `true` if any tweens are currently running. Note that this method doesn't consider tweens that have ended.
198 	*/
199 	bool isActive() const
200 	{
201 		checkClassBinding!(typeof(this))();
202 		return ptrcall!(bool)(_classBinding.isActive, _godot_object);
203 	}
204 	/**
205 	Activates/deactivates the tween. See also $(D stopAll) and $(D resumeAll).
206 	*/
207 	void setActive(in bool active)
208 	{
209 		checkClassBinding!(typeof(this))();
210 		ptrcall!(void)(_classBinding.setActive, _godot_object, active);
211 	}
212 	/**
213 	
214 	*/
215 	bool isRepeat() const
216 	{
217 		checkClassBinding!(typeof(this))();
218 		return ptrcall!(bool)(_classBinding.isRepeat, _godot_object);
219 	}
220 	/**
221 	
222 	*/
223 	void setRepeat(in bool repeat)
224 	{
225 		checkClassBinding!(typeof(this))();
226 		ptrcall!(void)(_classBinding.setRepeat, _godot_object, repeat);
227 	}
228 	/**
229 	
230 	*/
231 	void setSpeedScale(in double speed)
232 	{
233 		checkClassBinding!(typeof(this))();
234 		ptrcall!(void)(_classBinding.setSpeedScale, _godot_object, speed);
235 	}
236 	/**
237 	
238 	*/
239 	double getSpeedScale() const
240 	{
241 		checkClassBinding!(typeof(this))();
242 		return ptrcall!(double)(_classBinding.getSpeedScale, _godot_object);
243 	}
244 	/**
245 	
246 	*/
247 	void setTweenProcessMode(in long mode)
248 	{
249 		checkClassBinding!(typeof(this))();
250 		ptrcall!(void)(_classBinding.setTweenProcessMode, _godot_object, mode);
251 	}
252 	/**
253 	
254 	*/
255 	Tween.TweenProcessMode getTweenProcessMode() const
256 	{
257 		checkClassBinding!(typeof(this))();
258 		return ptrcall!(Tween.TweenProcessMode)(_classBinding.getTweenProcessMode, _godot_object);
259 	}
260 	/**
261 	Starts the tween. You can define animations both before and after this.
262 	*/
263 	bool start()
264 	{
265 		checkClassBinding!(typeof(this))();
266 		return ptrcall!(bool)(_classBinding.start, _godot_object);
267 	}
268 	/**
269 	Resets a tween to its initial value (the one given, not the one before the tween), given its object and property/method pair. By default, all tweens are removed, unless `key` is specified.
270 	*/
271 	bool reset(StringArg1)(GodotObject object, in StringArg1 key = "")
272 	{
273 		checkClassBinding!(typeof(this))();
274 		return ptrcall!(bool)(_classBinding.reset, _godot_object, object, key);
275 	}
276 	/**
277 	Resets all tweens to their initial values (the ones given, not those before the tween).
278 	*/
279 	bool resetAll()
280 	{
281 		checkClassBinding!(typeof(this))();
282 		return ptrcall!(bool)(_classBinding.resetAll, _godot_object);
283 	}
284 	/**
285 	Stops a tween, given its object and property/method pair. By default, all tweens are stopped, unless `key` is specified.
286 	*/
287 	bool stop(StringArg1)(GodotObject object, in StringArg1 key = "")
288 	{
289 		checkClassBinding!(typeof(this))();
290 		return ptrcall!(bool)(_classBinding.stop, _godot_object, object, key);
291 	}
292 	/**
293 	Stops animating all tweens.
294 	*/
295 	bool stopAll()
296 	{
297 		checkClassBinding!(typeof(this))();
298 		return ptrcall!(bool)(_classBinding.stopAll, _godot_object);
299 	}
300 	/**
301 	Continues animating a stopped tween, given its object and property/method pair. By default, all tweens are resumed, unless `key` is specified.
302 	*/
303 	bool resume(StringArg1)(GodotObject object, in StringArg1 key = "")
304 	{
305 		checkClassBinding!(typeof(this))();
306 		return ptrcall!(bool)(_classBinding.resume, _godot_object, object, key);
307 	}
308 	/**
309 	Continues animating all stopped tweens.
310 	*/
311 	bool resumeAll()
312 	{
313 		checkClassBinding!(typeof(this))();
314 		return ptrcall!(bool)(_classBinding.resumeAll, _godot_object);
315 	}
316 	/**
317 	Stops animation and removes a tween, given its object and property/method pair. By default, all tweens are removed, unless `key` is specified.
318 	*/
319 	bool remove(StringArg1)(GodotObject object, in StringArg1 key = "")
320 	{
321 		checkClassBinding!(typeof(this))();
322 		return ptrcall!(bool)(_classBinding.remove, _godot_object, object, key);
323 	}
324 	/**
325 	
326 	*/
327 	void _removeByUid(in long uid)
328 	{
329 		Array _GODOT_args = Array.empty_array;
330 		_GODOT_args.append(uid);
331 		String _GODOT_method_name = String("_remove_by_uid");
332 		this.callv(_GODOT_method_name, _GODOT_args);
333 	}
334 	/**
335 	Stops animation and removes all tweens.
336 	*/
337 	bool removeAll()
338 	{
339 		checkClassBinding!(typeof(this))();
340 		return ptrcall!(bool)(_classBinding.removeAll, _godot_object);
341 	}
342 	/**
343 	Sets the interpolation to the given `time` in seconds.
344 	*/
345 	bool seek(in double time)
346 	{
347 		checkClassBinding!(typeof(this))();
348 		return ptrcall!(bool)(_classBinding.seek, _godot_object, time);
349 	}
350 	/**
351 	Returns the current time of the tween.
352 	*/
353 	double tell() const
354 	{
355 		checkClassBinding!(typeof(this))();
356 		return ptrcall!(double)(_classBinding.tell, _godot_object);
357 	}
358 	/**
359 	Returns the total time needed for all tweens to end. If you have two tweens, one lasting 10 seconds and the other 20 seconds, it would return 20 seconds, as by that time all tweens would have finished.
360 	*/
361 	double getRuntime() const
362 	{
363 		checkClassBinding!(typeof(this))();
364 		return ptrcall!(double)(_classBinding.getRuntime, _godot_object);
365 	}
366 	/**
367 	Animates `property` of `object` from `initial_val` to `final_val` for `duration` seconds, `delay` seconds later. Setting the initial value to `null` uses the current value of the property.
368 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
369 	*/
370 	bool interpolateProperty(NodePathArg1, VariantArg2, VariantArg3)(GodotObject object, in NodePathArg1 property, in VariantArg2 initial_val, in VariantArg3 final_val, in double duration, in long trans_type, in long ease_type, in double delay = 0)
371 	{
372 		checkClassBinding!(typeof(this))();
373 		return ptrcall!(bool)(_classBinding.interpolateProperty, _godot_object, object, property, initial_val, final_val, duration, trans_type, ease_type, delay);
374 	}
375 	/**
376 	Animates `method` of `object` from `initial_val` to `final_val` for `duration` seconds, `delay` seconds later. Methods are called with consecutive values.
377 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
378 	*/
379 	bool interpolateMethod(StringArg1, VariantArg2, VariantArg3)(GodotObject object, in StringArg1 method, in VariantArg2 initial_val, in VariantArg3 final_val, in double duration, in long trans_type, in long ease_type, in double delay = 0)
380 	{
381 		checkClassBinding!(typeof(this))();
382 		return ptrcall!(bool)(_classBinding.interpolateMethod, _godot_object, object, method, initial_val, final_val, duration, trans_type, ease_type, delay);
383 	}
384 	/**
385 	Calls `callback` of `object` after `duration`. `arg1`-`arg5` are arguments to be passed to the callback.
386 	*/
387 	bool interpolateCallback(StringArg2, VariantArg3, VariantArg4, VariantArg5, VariantArg6, VariantArg7)(GodotObject object, in double duration, in StringArg2 callback, in VariantArg3 arg1 = Variant.nil, in VariantArg4 arg2 = Variant.nil, in VariantArg5 arg3 = Variant.nil, in VariantArg6 arg4 = Variant.nil, in VariantArg7 arg5 = Variant.nil)
388 	{
389 		checkClassBinding!(typeof(this))();
390 		return ptrcall!(bool)(_classBinding.interpolateCallback, _godot_object, object, duration, callback, arg1, arg2, arg3, arg4, arg5);
391 	}
392 	/**
393 	Calls `callback` of `object` after `duration` on the main thread (similar to $(D GodotObject.callDeferred)). `arg1`-`arg5` are arguments to be passed to the callback.
394 	*/
395 	bool interpolateDeferredCallback(StringArg2, VariantArg3, VariantArg4, VariantArg5, VariantArg6, VariantArg7)(GodotObject object, in double duration, in StringArg2 callback, in VariantArg3 arg1 = Variant.nil, in VariantArg4 arg2 = Variant.nil, in VariantArg5 arg3 = Variant.nil, in VariantArg6 arg4 = Variant.nil, in VariantArg7 arg5 = Variant.nil)
396 	{
397 		checkClassBinding!(typeof(this))();
398 		return ptrcall!(bool)(_classBinding.interpolateDeferredCallback, _godot_object, object, duration, callback, arg1, arg2, arg3, arg4, arg5);
399 	}
400 	/**
401 	Follows `property` of `object` and applies it on `target_property` of `target`, beginning from `initial_val` for `duration` seconds, `delay` seconds later.
402 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
403 	*/
404 	bool followProperty(NodePathArg1, VariantArg2, NodePathArg4)(GodotObject object, in NodePathArg1 property, in VariantArg2 initial_val, GodotObject target, in NodePathArg4 target_property, in double duration, in long trans_type, in long ease_type, in double delay = 0)
405 	{
406 		checkClassBinding!(typeof(this))();
407 		return ptrcall!(bool)(_classBinding.followProperty, _godot_object, object, property, initial_val, target, target_property, duration, trans_type, ease_type, delay);
408 	}
409 	/**
410 	Follows `method` of `object` and applies the returned value on `target_method` of `target`, beginning from `initial_val` for `duration` seconds, `delay` later. Methods are called with consecutive values.
411 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
412 	*/
413 	bool followMethod(StringArg1, VariantArg2, StringArg4)(GodotObject object, in StringArg1 method, in VariantArg2 initial_val, GodotObject target, in StringArg4 target_method, in double duration, in long trans_type, in long ease_type, in double delay = 0)
414 	{
415 		checkClassBinding!(typeof(this))();
416 		return ptrcall!(bool)(_classBinding.followMethod, _godot_object, object, method, initial_val, target, target_method, duration, trans_type, ease_type, delay);
417 	}
418 	/**
419 	Animates `property` of `object` from the current value of the `initial_val` property of `initial` to `final_val` for `duration` seconds, `delay` seconds later.
420 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
421 	*/
422 	bool targetingProperty(NodePathArg1, NodePathArg3, VariantArg4)(GodotObject object, in NodePathArg1 property, GodotObject initial, in NodePathArg3 initial_val, in VariantArg4 final_val, in double duration, in long trans_type, in long ease_type, in double delay = 0)
423 	{
424 		checkClassBinding!(typeof(this))();
425 		return ptrcall!(bool)(_classBinding.targetingProperty, _godot_object, object, property, initial, initial_val, final_val, duration, trans_type, ease_type, delay);
426 	}
427 	/**
428 	Animates `method` of `object` from the value returned by `initial_method` to `final_val` for `duration` seconds, `delay` seconds later. Methods are animated by calling them with consecutive values.
429 	Use $(D transitiontype) for `trans_type` and $(D easetype) for `ease_type` parameters. These values control the timing and direction of the interpolation. See the class description for more information
430 	*/
431 	bool targetingMethod(StringArg1, StringArg3, VariantArg4)(GodotObject object, in StringArg1 method, GodotObject initial, in StringArg3 initial_method, in VariantArg4 final_val, in double duration, in long trans_type, in long ease_type, in double delay = 0)
432 	{
433 		checkClassBinding!(typeof(this))();
434 		return ptrcall!(bool)(_classBinding.targetingMethod, _godot_object, object, method, initial, initial_method, final_val, duration, trans_type, ease_type, delay);
435 	}
436 	/**
437 	If `true` the tween loops.
438 	*/
439 	@property bool repeat()
440 	{
441 		return isRepeat();
442 	}
443 	/// ditto
444 	@property void repeat(bool v)
445 	{
446 		setRepeat(v);
447 	}
448 	/**
449 	The tween's animation process thread. See $(D tweenprocessmode). Default value: $(D tweenProcessIdle).
450 	*/
451 	@property Tween.TweenProcessMode playbackProcessMode()
452 	{
453 		return getTweenProcessMode();
454 	}
455 	/// ditto
456 	@property void playbackProcessMode(long v)
457 	{
458 		setTweenProcessMode(v);
459 	}
460 	/**
461 	The tween's speed multiplier. For example, set it to `1.0` for normal speed, `2.0` for two times normal speed, or `0.5` for half of the normal speed. A value of `0` pauses the animation, but see also $(D setActive) or $(D stopAll) for this.
462 	*/
463 	@property double playbackSpeed()
464 	{
465 		return getSpeedScale();
466 	}
467 	/// ditto
468 	@property void playbackSpeed(double v)
469 	{
470 		setSpeedScale(v);
471 	}
472 }