1 /**
2 A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.
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.node2d;
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.canvasitem;
24 import godot.node;
25 /**
26 A 2D game object, parent of all 2D related nodes. Has a position, rotation, scale and Z-index.
27 
28 A 2D game object, with a position, rotation and scale. All 2D physics nodes and sprites inherit from Node2D. Use Node2D as a parent node to move, scale and rotate children in a 2D project. Also gives control on the node's render order.
29 */
30 @GodotBaseClass struct Node2D
31 {
32 	enum string _GODOT_internal_name = "Node2D";
33 public:
34 @nogc nothrow:
35 	union { godot_object _godot_object; CanvasItem _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct _classBinding
40 	{
41 		__gshared:
42 		@GodotName("set_position") GodotMethod!(void, Vector2) setPosition;
43 		@GodotName("set_rotation") GodotMethod!(void, double) setRotation;
44 		@GodotName("set_rotation_degrees") GodotMethod!(void, double) setRotationDegrees;
45 		@GodotName("set_scale") GodotMethod!(void, Vector2) setScale;
46 		@GodotName("get_position") GodotMethod!(Vector2) getPosition;
47 		@GodotName("get_rotation") GodotMethod!(double) getRotation;
48 		@GodotName("get_rotation_degrees") GodotMethod!(double) getRotationDegrees;
49 		@GodotName("get_scale") GodotMethod!(Vector2) getScale;
50 		@GodotName("rotate") GodotMethod!(void, double) rotate;
51 		@GodotName("move_local_x") GodotMethod!(void, double, bool) moveLocalX;
52 		@GodotName("move_local_y") GodotMethod!(void, double, bool) moveLocalY;
53 		@GodotName("translate") GodotMethod!(void, Vector2) translate;
54 		@GodotName("global_translate") GodotMethod!(void, Vector2) globalTranslate;
55 		@GodotName("apply_scale") GodotMethod!(void, Vector2) applyScale;
56 		@GodotName("set_global_position") GodotMethod!(void, Vector2) setGlobalPosition;
57 		@GodotName("get_global_position") GodotMethod!(Vector2) getGlobalPosition;
58 		@GodotName("set_global_rotation") GodotMethod!(void, double) setGlobalRotation;
59 		@GodotName("get_global_rotation") GodotMethod!(double) getGlobalRotation;
60 		@GodotName("set_global_rotation_degrees") GodotMethod!(void, double) setGlobalRotationDegrees;
61 		@GodotName("get_global_rotation_degrees") GodotMethod!(double) getGlobalRotationDegrees;
62 		@GodotName("set_global_scale") GodotMethod!(void, Vector2) setGlobalScale;
63 		@GodotName("get_global_scale") GodotMethod!(Vector2) getGlobalScale;
64 		@GodotName("set_transform") GodotMethod!(void, Transform2D) setTransform;
65 		@GodotName("set_global_transform") GodotMethod!(void, Transform2D) setGlobalTransform;
66 		@GodotName("look_at") GodotMethod!(void, Vector2) lookAt;
67 		@GodotName("get_angle_to") GodotMethod!(double, Vector2) getAngleTo;
68 		@GodotName("to_local") GodotMethod!(Vector2, Vector2) toLocal;
69 		@GodotName("to_global") GodotMethod!(Vector2, Vector2) toGlobal;
70 		@GodotName("set_z_index") GodotMethod!(void, long) setZIndex;
71 		@GodotName("get_z_index") GodotMethod!(long) getZIndex;
72 		@GodotName("set_z_as_relative") GodotMethod!(void, bool) setZAsRelative;
73 		@GodotName("is_z_relative") GodotMethod!(bool) isZRelative;
74 		@GodotName("get_relative_transform_to_parent") GodotMethod!(Transform2D, GodotObject) getRelativeTransformToParent;
75 	}
76 	bool opEquals(in Node2D other) const { return _godot_object.ptr is other._godot_object.ptr; }
77 	Node2D opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
78 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
79 	mixin baseCasts;
80 	static Node2D _new()
81 	{
82 		static godot_class_constructor constructor;
83 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Node2D");
84 		if(constructor is null) return typeof(this).init;
85 		return cast(Node2D)(constructor());
86 	}
87 	@disable new(size_t s);
88 	/**
89 	
90 	*/
91 	void setPosition(in Vector2 position)
92 	{
93 		checkClassBinding!(typeof(this))();
94 		ptrcall!(void)(_classBinding.setPosition, _godot_object, position);
95 	}
96 	/**
97 	
98 	*/
99 	void setRotation(in double radians)
100 	{
101 		checkClassBinding!(typeof(this))();
102 		ptrcall!(void)(_classBinding.setRotation, _godot_object, radians);
103 	}
104 	/**
105 	
106 	*/
107 	void setRotationDegrees(in double degrees)
108 	{
109 		checkClassBinding!(typeof(this))();
110 		ptrcall!(void)(_classBinding.setRotationDegrees, _godot_object, degrees);
111 	}
112 	/**
113 	
114 	*/
115 	void setScale(in Vector2 scale)
116 	{
117 		checkClassBinding!(typeof(this))();
118 		ptrcall!(void)(_classBinding.setScale, _godot_object, scale);
119 	}
120 	/**
121 	
122 	*/
123 	Vector2 getPosition() const
124 	{
125 		checkClassBinding!(typeof(this))();
126 		return ptrcall!(Vector2)(_classBinding.getPosition, _godot_object);
127 	}
128 	/**
129 	
130 	*/
131 	double getRotation() const
132 	{
133 		checkClassBinding!(typeof(this))();
134 		return ptrcall!(double)(_classBinding.getRotation, _godot_object);
135 	}
136 	/**
137 	
138 	*/
139 	double getRotationDegrees() const
140 	{
141 		checkClassBinding!(typeof(this))();
142 		return ptrcall!(double)(_classBinding.getRotationDegrees, _godot_object);
143 	}
144 	/**
145 	
146 	*/
147 	Vector2 getScale() const
148 	{
149 		checkClassBinding!(typeof(this))();
150 		return ptrcall!(Vector2)(_classBinding.getScale, _godot_object);
151 	}
152 	/**
153 	Applies a rotation to the node, in radians, starting from its current rotation.
154 	*/
155 	void rotate(in double radians)
156 	{
157 		checkClassBinding!(typeof(this))();
158 		ptrcall!(void)(_classBinding.rotate, _godot_object, radians);
159 	}
160 	/**
161 	Applies a local translation on the node's X axis based on the $(D Node._process)'s `delta`. If `scaled` is false, normalizes the movement.
162 	*/
163 	void moveLocalX(in double delta, in bool scaled = false)
164 	{
165 		checkClassBinding!(typeof(this))();
166 		ptrcall!(void)(_classBinding.moveLocalX, _godot_object, delta, scaled);
167 	}
168 	/**
169 	Applies a local translation on the node's Y axis based on the $(D Node._process)'s `delta`. If `scaled` is false, normalizes the movement.
170 	*/
171 	void moveLocalY(in double delta, in bool scaled = false)
172 	{
173 		checkClassBinding!(typeof(this))();
174 		ptrcall!(void)(_classBinding.moveLocalY, _godot_object, delta, scaled);
175 	}
176 	/**
177 	Translates the node by the given `offset` in local coordinates.
178 	*/
179 	void translate(in Vector2 offset)
180 	{
181 		checkClassBinding!(typeof(this))();
182 		ptrcall!(void)(_classBinding.translate, _godot_object, offset);
183 	}
184 	/**
185 	Adds the 'offset' vector to the node's global position.
186 	*/
187 	void globalTranslate(in Vector2 offset)
188 	{
189 		checkClassBinding!(typeof(this))();
190 		ptrcall!(void)(_classBinding.globalTranslate, _godot_object, offset);
191 	}
192 	/**
193 	Multiplies the current scale by the 'ratio' vector.
194 	*/
195 	void applyScale(in Vector2 ratio)
196 	{
197 		checkClassBinding!(typeof(this))();
198 		ptrcall!(void)(_classBinding.applyScale, _godot_object, ratio);
199 	}
200 	/**
201 	
202 	*/
203 	void setGlobalPosition(in Vector2 position)
204 	{
205 		checkClassBinding!(typeof(this))();
206 		ptrcall!(void)(_classBinding.setGlobalPosition, _godot_object, position);
207 	}
208 	/**
209 	
210 	*/
211 	Vector2 getGlobalPosition() const
212 	{
213 		checkClassBinding!(typeof(this))();
214 		return ptrcall!(Vector2)(_classBinding.getGlobalPosition, _godot_object);
215 	}
216 	/**
217 	
218 	*/
219 	void setGlobalRotation(in double radians)
220 	{
221 		checkClassBinding!(typeof(this))();
222 		ptrcall!(void)(_classBinding.setGlobalRotation, _godot_object, radians);
223 	}
224 	/**
225 	
226 	*/
227 	double getGlobalRotation() const
228 	{
229 		checkClassBinding!(typeof(this))();
230 		return ptrcall!(double)(_classBinding.getGlobalRotation, _godot_object);
231 	}
232 	/**
233 	
234 	*/
235 	void setGlobalRotationDegrees(in double degrees)
236 	{
237 		checkClassBinding!(typeof(this))();
238 		ptrcall!(void)(_classBinding.setGlobalRotationDegrees, _godot_object, degrees);
239 	}
240 	/**
241 	
242 	*/
243 	double getGlobalRotationDegrees() const
244 	{
245 		checkClassBinding!(typeof(this))();
246 		return ptrcall!(double)(_classBinding.getGlobalRotationDegrees, _godot_object);
247 	}
248 	/**
249 	
250 	*/
251 	void setGlobalScale(in Vector2 scale)
252 	{
253 		checkClassBinding!(typeof(this))();
254 		ptrcall!(void)(_classBinding.setGlobalScale, _godot_object, scale);
255 	}
256 	/**
257 	
258 	*/
259 	Vector2 getGlobalScale() const
260 	{
261 		checkClassBinding!(typeof(this))();
262 		return ptrcall!(Vector2)(_classBinding.getGlobalScale, _godot_object);
263 	}
264 	/**
265 	
266 	*/
267 	void setTransform(in Transform2D xform)
268 	{
269 		checkClassBinding!(typeof(this))();
270 		ptrcall!(void)(_classBinding.setTransform, _godot_object, xform);
271 	}
272 	/**
273 	
274 	*/
275 	void setGlobalTransform(in Transform2D xform)
276 	{
277 		checkClassBinding!(typeof(this))();
278 		ptrcall!(void)(_classBinding.setGlobalTransform, _godot_object, xform);
279 	}
280 	/**
281 	Rotates the node so it points towards the 'point'.
282 	*/
283 	void lookAt(in Vector2 point)
284 	{
285 		checkClassBinding!(typeof(this))();
286 		ptrcall!(void)(_classBinding.lookAt, _godot_object, point);
287 	}
288 	/**
289 	Returns the angle between the node and the 'point' in radians.
290 	*/
291 	double getAngleTo(in Vector2 point) const
292 	{
293 		checkClassBinding!(typeof(this))();
294 		return ptrcall!(double)(_classBinding.getAngleTo, _godot_object, point);
295 	}
296 	/**
297 	Converts a global point's coordinates to local coordinates.
298 	*/
299 	Vector2 toLocal(in Vector2 global_point) const
300 	{
301 		checkClassBinding!(typeof(this))();
302 		return ptrcall!(Vector2)(_classBinding.toLocal, _godot_object, global_point);
303 	}
304 	/**
305 	Converts a local point's coordinates to global coordinates.
306 	*/
307 	Vector2 toGlobal(in Vector2 local_point) const
308 	{
309 		checkClassBinding!(typeof(this))();
310 		return ptrcall!(Vector2)(_classBinding.toGlobal, _godot_object, local_point);
311 	}
312 	/**
313 	
314 	*/
315 	void setZIndex(in long z_index)
316 	{
317 		checkClassBinding!(typeof(this))();
318 		ptrcall!(void)(_classBinding.setZIndex, _godot_object, z_index);
319 	}
320 	/**
321 	
322 	*/
323 	long getZIndex() const
324 	{
325 		checkClassBinding!(typeof(this))();
326 		return ptrcall!(long)(_classBinding.getZIndex, _godot_object);
327 	}
328 	/**
329 	
330 	*/
331 	void setZAsRelative(in bool enable)
332 	{
333 		checkClassBinding!(typeof(this))();
334 		ptrcall!(void)(_classBinding.setZAsRelative, _godot_object, enable);
335 	}
336 	/**
337 	
338 	*/
339 	bool isZRelative() const
340 	{
341 		checkClassBinding!(typeof(this))();
342 		return ptrcall!(bool)(_classBinding.isZRelative, _godot_object);
343 	}
344 	/**
345 	Returns the $(D Transform2D) relative to this node's parent.
346 	*/
347 	Transform2D getRelativeTransformToParent(GodotObject parent) const
348 	{
349 		checkClassBinding!(typeof(this))();
350 		return ptrcall!(Transform2D)(_classBinding.getRelativeTransformToParent, _godot_object, parent);
351 	}
352 	/**
353 	Position, relative to the node's parent.
354 	*/
355 	@property Vector2 position()
356 	{
357 		return getPosition();
358 	}
359 	/// ditto
360 	@property void position(Vector2 v)
361 	{
362 		setPosition(v);
363 	}
364 	/**
365 	Rotation in radians, relative to the node's parent.
366 	*/
367 	@property double rotation()
368 	{
369 		return getRotation();
370 	}
371 	/// ditto
372 	@property void rotation(double v)
373 	{
374 		setRotation(v);
375 	}
376 	/**
377 	Rotation in degrees, relative to the node's parent.
378 	*/
379 	@property double rotationDegrees()
380 	{
381 		return getRotationDegrees();
382 	}
383 	/// ditto
384 	@property void rotationDegrees(double v)
385 	{
386 		setRotationDegrees(v);
387 	}
388 	/**
389 	The node's scale. Unscaled value: `(1, 1)`
390 	*/
391 	@property Vector2 scale()
392 	{
393 		return getScale();
394 	}
395 	/// ditto
396 	@property void scale(Vector2 v)
397 	{
398 		setScale(v);
399 	}
400 	/**
401 	Local $(D Transform2D).
402 	*/
403 	@property Transform2D transform()
404 	{
405 		return getTransform();
406 	}
407 	/// ditto
408 	@property void transform(Transform2D v)
409 	{
410 		setTransform(v);
411 	}
412 	/**
413 	Global position.
414 	*/
415 	@property Vector2 globalPosition()
416 	{
417 		return getGlobalPosition();
418 	}
419 	/// ditto
420 	@property void globalPosition(Vector2 v)
421 	{
422 		setGlobalPosition(v);
423 	}
424 	/**
425 	Global rotation in radians.
426 	*/
427 	@property double globalRotation()
428 	{
429 		return getGlobalRotation();
430 	}
431 	/// ditto
432 	@property void globalRotation(double v)
433 	{
434 		setGlobalRotation(v);
435 	}
436 	/**
437 	Global rotation in degrees.
438 	*/
439 	@property double globalRotationDegrees()
440 	{
441 		return getGlobalRotationDegrees();
442 	}
443 	/// ditto
444 	@property void globalRotationDegrees(double v)
445 	{
446 		setGlobalRotationDegrees(v);
447 	}
448 	/**
449 	Global scale.
450 	*/
451 	@property Vector2 globalScale()
452 	{
453 		return getGlobalScale();
454 	}
455 	/// ditto
456 	@property void globalScale(Vector2 v)
457 	{
458 		setGlobalScale(v);
459 	}
460 	/**
461 	Global $(D Transform2D).
462 	*/
463 	@property Transform2D globalTransform()
464 	{
465 		return getGlobalTransform();
466 	}
467 	/// ditto
468 	@property void globalTransform(Transform2D v)
469 	{
470 		setGlobalTransform(v);
471 	}
472 	/**
473 	Z-index. Controls the order in which the nodes render. A node with a higher Z-index will display in front of others.
474 	*/
475 	@property long zIndex()
476 	{
477 		return getZIndex();
478 	}
479 	/// ditto
480 	@property void zIndex(long v)
481 	{
482 		setZIndex(v);
483 	}
484 	/**
485 	If `true` the node's Z-index is relative to its parent's Z-index. If this node's Z-index is 2 and its parent's effective Z-index is 3, then this node's effective Z-index will be 2 + 3 = 5.
486 	*/
487 	@property bool zAsRelative()
488 	{
489 		return isZRelative();
490 	}
491 	/// ditto
492 	@property void zAsRelative(bool v)
493 	{
494 		setZAsRelative(v);
495 	}
496 }