| 1 | /**************************************************************************/ |
| 2 | /* node_2d.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 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 | |
| 31 | #ifndef NODE_2D_H |
| 32 | #define NODE_2D_H |
| 33 | |
| 34 | #include "scene/main/canvas_item.h" |
| 35 | |
| 36 | class Node2D : public CanvasItem { |
| 37 | GDCLASS(Node2D, CanvasItem); |
| 38 | |
| 39 | mutable MTFlag xform_dirty; |
| 40 | mutable Point2 position; |
| 41 | mutable real_t rotation = 0.0; |
| 42 | mutable Size2 scale = Vector2(1, 1); |
| 43 | mutable real_t skew = 0.0; |
| 44 | |
| 45 | Transform2D transform; |
| 46 | |
| 47 | _FORCE_INLINE_ bool _is_xform_dirty() const { return is_group_processing() ? xform_dirty.mt.is_set() : xform_dirty.st; } |
| 48 | void _set_xform_dirty(bool p_dirty) const; |
| 49 | |
| 50 | void _update_transform(); |
| 51 | |
| 52 | void _update_xform_values() const; |
| 53 | |
| 54 | protected: |
| 55 | void _notification(int p_notification); |
| 56 | static void _bind_methods(); |
| 57 | |
| 58 | public: |
| 59 | #ifdef TOOLS_ENABLED |
| 60 | virtual Dictionary _edit_get_state() const override; |
| 61 | virtual void _edit_set_state(const Dictionary &p_state) override; |
| 62 | |
| 63 | virtual void _edit_set_position(const Point2 &p_position) override; |
| 64 | virtual Point2 _edit_get_position() const override; |
| 65 | |
| 66 | virtual void _edit_set_scale(const Size2 &p_scale) override; |
| 67 | virtual Size2 _edit_get_scale() const override; |
| 68 | |
| 69 | virtual void _edit_set_rotation(real_t p_rotation) override; |
| 70 | virtual real_t _edit_get_rotation() const override; |
| 71 | virtual bool _edit_use_rotation() const override; |
| 72 | |
| 73 | virtual void _edit_set_rect(const Rect2 &p_edit_rect) override; |
| 74 | #endif |
| 75 | virtual void reparent(Node *p_parent, bool p_keep_global_transform = true) override; |
| 76 | |
| 77 | void set_position(const Point2 &p_pos); |
| 78 | void set_rotation(real_t p_radians); |
| 79 | void set_rotation_degrees(real_t p_degrees); |
| 80 | void set_skew(real_t p_radians); |
| 81 | void set_scale(const Size2 &p_scale); |
| 82 | |
| 83 | void rotate(real_t p_radians); |
| 84 | void move_x(real_t p_delta, bool p_scaled = false); |
| 85 | void move_y(real_t p_delta, bool p_scaled = false); |
| 86 | void translate(const Vector2 &p_amount); |
| 87 | void global_translate(const Vector2 &p_amount); |
| 88 | void apply_scale(const Size2 &p_amount); |
| 89 | |
| 90 | Point2 get_position() const; |
| 91 | real_t get_rotation() const; |
| 92 | real_t get_rotation_degrees() const; |
| 93 | real_t get_skew() const; |
| 94 | Size2 get_scale() const; |
| 95 | |
| 96 | Point2 get_global_position() const; |
| 97 | real_t get_global_rotation() const; |
| 98 | real_t get_global_rotation_degrees() const; |
| 99 | real_t get_global_skew() const; |
| 100 | Size2 get_global_scale() const; |
| 101 | |
| 102 | void set_transform(const Transform2D &p_transform); |
| 103 | void set_global_transform(const Transform2D &p_transform); |
| 104 | void set_global_position(const Point2 &p_pos); |
| 105 | void set_global_rotation(const real_t p_radians); |
| 106 | void set_global_rotation_degrees(const real_t p_degrees); |
| 107 | void set_global_skew(const real_t p_radians); |
| 108 | void set_global_scale(const Size2 &p_scale); |
| 109 | |
| 110 | void look_at(const Vector2 &p_pos); |
| 111 | real_t get_angle_to(const Vector2 &p_pos) const; |
| 112 | |
| 113 | Point2 to_local(Point2 p_global) const; |
| 114 | Point2 to_global(Point2 p_local) const; |
| 115 | |
| 116 | Transform2D get_relative_transform_to_parent(const Node *p_parent) const; |
| 117 | |
| 118 | Transform2D get_transform() const override; |
| 119 | |
| 120 | Node2D() {} |
| 121 | }; |
| 122 | |
| 123 | #endif // NODE_2D_H |
| 124 | |