1 /*************************************************************************/
2 /*  node_2d.h                                                            */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 #ifndef NODE2D_H
31 #define NODE2D_H
32 
33 #include "scene/2d/canvas_item.h"
34 
35 class Node2D : public CanvasItem {
36 
37 	OBJ_TYPE(Node2D, CanvasItem);
38 
39 	Point2 pos;
40 	float angle;
41 	Size2 _scale;
42 	int z;
43 	bool z_relative;
44 
45 	Matrix32 _mat;
46 
47 	bool _xform_dirty;
48 
49 	void _update_transform();
50 
51 	// Deprecated, should be removed in a future version.
52 	void _set_rotd(float p_angle);
53 	float _get_rotd() const;
54 
55 	void _update_xform_values();
56 
57 protected:
58 	void _notification(int p_what);
59 
60 	static void _bind_methods();
61 
62 public:
63 	virtual Variant edit_get_state() const;
64 	virtual void edit_set_state(const Variant &p_state);
65 	virtual void edit_set_rect(const Rect2 &p_edit_rect);
66 	virtual void edit_rotate(float p_rot);
67 	virtual void edit_set_pivot(const Point2 &p_pivot);
68 	virtual Point2 edit_get_pivot() const;
69 	virtual bool edit_has_pivot() const;
70 
71 	void set_pos(const Point2 &p_pos);
72 	void set_rot(float p_radians);
73 	void set_rotd(float p_degrees);
74 	void set_scale(const Size2 &p_scale);
75 
76 	void rotate(float p_radians);
77 	void move_x(float p_delta, bool p_scaled = false);
78 	void move_y(float p_delta, bool p_scaled = false);
79 	void translate(const Vector2 &p_amount);
80 	void global_translate(const Vector2 &p_amount);
81 	void scale(const Size2 &p_amount);
82 
83 	Point2 get_pos() const;
84 	float get_rot() const;
85 	float get_rotd() const;
86 	Size2 get_scale() const;
87 
88 	Point2 get_global_pos() const;
89 	float get_global_rot() const;
90 	float get_global_rotd() const;
91 	Size2 get_global_scale() const;
92 	virtual Rect2 get_item_rect() const;
93 
94 	void set_transform(const Matrix32 &p_transform);
95 	void set_global_transform(const Matrix32 &p_transform);
96 	void set_global_pos(const Point2 &p_pos);
97 	void set_global_rot(float p_radians);
98 	void set_global_rotd(float p_degrees);
99 	void set_global_scale(const Size2 &p_scale);
100 
101 	void set_z(int p_z);
102 	int get_z() const;
103 
104 	void look_at(const Vector2 &p_pos);
105 	float get_angle_to(const Vector2 &p_pos) const;
106 
107 	void set_z_as_relative(bool p_enabled);
108 	bool is_z_relative() const;
109 
110 	Matrix32 get_relative_transform_to_parent(const Node *p_parent) const;
111 
112 	Matrix32 get_transform() const;
113 
114 	Node2D();
115 };
116 
117 #endif // NODE2D_H
118