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