node_2d.h
1 /*************************************************************************/
2 /* node_2d.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 NODE2D_H
30 #define NODE2D_H
31 
32 #include "scene/2d/canvas_item.h"
33 
34 class Node2D : public CanvasItem {
35 
36  OBJ_TYPE(Node2D, CanvasItem );
37 
38  Point2 pos;
39  float angle;
40  Size2 _scale;
41  int z;
42  bool z_relative;
43 
44  Matrix32 _mat;
45 
46  bool _xform_dirty;
47 
48  void _update_transform();
49 
50  // Deprecated, should be removed in a future version.
51  void _set_rotd(float p_angle);
52  float _get_rotd() const;
53 
54  void _update_xform_values();
55 
56 protected:
57 
58 
59  void _notification(int p_what);
60 
61  static void _bind_methods();
62 public:
63 
64  virtual Variant edit_get_state() const;
65  virtual void edit_set_state(const Variant& p_state);
66  virtual void edit_set_rect(const Rect2& p_edit_rect);
67  virtual void edit_rotate(float p_rot);
68  virtual void edit_set_pivot(const Point2& p_pivot);
69  virtual Point2 edit_get_pivot() const;
70  virtual bool edit_has_pivot() const;
71 
72  void set_pos(const Point2& p_pos);
73  void set_rot(float p_radians);
74  void set_rotd(float p_degrees);
75  void set_scale(const Size2& p_scale);
76 
77  void rotate(float p_radians);
78  void move_x(float p_delta,bool p_scaled=false);
79  void move_y(float p_delta,bool p_scaled=false);
80  void translate(const Vector2& p_amount);
81  void global_translate(const Vector2& p_amount);
82  void scale(const Vector2& p_amount);
83 
84  Point2 get_pos() const;
85  float get_rot() const;
86  float get_rotd() const;
87  Size2 get_scale() const;
88 
89  Point2 get_global_pos() const;
90  virtual Rect2 get_item_rect() const;
91 
92  void set_transform(const Matrix32& p_transform);
93  void set_global_transform(const Matrix32& p_transform);
94  void set_global_pos(const Point2& p_pos);
95 
96  void set_z(int p_z);
97  int get_z() const;
98 
99  void look_at(const Vector2& p_pos);
100  float get_angle_to(const Vector2& p_pos) const;
101 
102  void set_z_as_relative(bool p_enabled);
103  bool is_z_relative() const;
104 
105  Matrix32 get_relative_transform_to_parent(const Node *p_parent) const;
106 
107 
108 
109  Matrix32 get_transform() const;
110 
111  Node2D();
112 };
113 
114 #endif // NODE2D_H
Definition: variant.h:74
Definition: node.h:42
Definition: math_2d.h:204
Definition: canvas_item.h:87
Definition: math_2d.h:65
Definition: math_2d.h:554
Definition: node_2d.h:34