node_2d.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*************************************************************************/
  2. /* node_2d.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. #include "scene/2d/canvas_item.h"
  33. class Node2D : public CanvasItem {
  34. GDCLASS(Node2D, CanvasItem);
  35. Point2 pos;
  36. float angle;
  37. Size2 _scale;
  38. int z;
  39. bool z_relative;
  40. Transform2D _mat;
  41. bool _xform_dirty;
  42. void _update_transform();
  43. // Deprecated, should be removed in a future version.
  44. void _set_rotd(float p_degrees);
  45. float _get_rotd() const;
  46. void _update_xform_values();
  47. protected:
  48. void _notification(int p_what);
  49. static void _bind_methods();
  50. public:
  51. virtual Variant edit_get_state() const;
  52. virtual void edit_set_state(const Variant &p_state);
  53. virtual void edit_set_rect(const Rect2 &p_edit_rect);
  54. virtual void edit_rotate(float p_rot);
  55. virtual void edit_set_pivot(const Point2 &p_pivot);
  56. virtual Point2 edit_get_pivot() const;
  57. virtual bool edit_has_pivot() const;
  58. void set_position(const Point2 &p_pos);
  59. void set_rotation(float p_radians);
  60. void set_rotation_in_degrees(float p_degrees);
  61. void set_scale(const Size2 &p_scale);
  62. void rotate(float p_radians);
  63. void move_x(float p_delta, bool p_scaled = false);
  64. void move_y(float p_delta, bool p_scaled = false);
  65. void translate(const Vector2 &p_amount);
  66. void global_translate(const Vector2 &p_amount);
  67. void apply_scale(const Size2 &p_amount);
  68. Point2 get_position() const;
  69. float get_rotation() const;
  70. float get_rotation_in_degrees() const;
  71. Size2 get_scale() const;
  72. Point2 get_global_position() const;
  73. float get_global_rotation() const;
  74. float get_global_rotation_in_degrees() const;
  75. Size2 get_global_scale() const;
  76. virtual Rect2 get_item_rect() const;
  77. void set_transform(const Transform2D &p_transform);
  78. void set_global_transform(const Transform2D &p_transform);
  79. void set_global_position(const Point2 &p_pos);
  80. void set_global_rotation(float p_radians);
  81. void set_global_rotation_in_degrees(float p_degrees);
  82. void set_global_scale(const Size2 &p_scale);
  83. void set_z(int p_z);
  84. int get_z() const;
  85. void look_at(const Vector2 &p_pos);
  86. float get_angle_to(const Vector2 &p_pos) const;
  87. Point2 to_local(Point2 p_global) const;
  88. Point2 to_global(Point2 p_local) const;
  89. void set_z_as_relative(bool p_enabled);
  90. bool is_z_relative() const;
  91. Transform2D get_relative_transform_to_parent(const Node *p_parent) const;
  92. Transform2D get_transform() const;
  93. Node2D();
  94. };
  95. #endif // NODE2D_H