Debian Codegraph @

scene/2d/sprite_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* sprite_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 #pragma once
32
33 #include "scene/2d/node_2d.h"
34 #include "scene/resources/texture.h"
35
36 class Sprite2D : public Node2D {
37 GDCLASS(Sprite2D, Node2D);
38
39 Ref<Texture2D> texture;
40
41 #ifdef TOOLS_ENABLED
42 bool dragging_to_resize_rect = false;
43 #endif // TOOLS_ENABLED
44
45 bool centered = true;
46 Point2 offset;
47
48 bool hflip = false;
49 bool vflip = false;
50 bool region_enabled = false;
51 Rect2 region_rect;
52 bool region_filter_clip_enabled = false;
53
54 int frame = 0;
55
56 int vframes = 1;
57 int hframes = 1;
58
59 void _get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_clip_enabled) const;
60 Point2 _get_rect_offset(const Size2i &p_size) const;
61
62 void _texture_changed();
63 void _emit_region_rect_enabled();
64
65 protected:
66 void _notification(int p_what);
67
68 static void _bind_methods();
69
70 void _validate_property(PropertyInfo &p_property) const;
71
72 public:
73 #ifdef TOOLS_ENABLED
74 virtual Dictionary _edit_get_state() const override;
75 virtual void _edit_set_state(const Dictionary &p_state) override;
76
77 virtual void _edit_set_pivot(const Point2 &p_pivot) override;
78 virtual Point2 _edit_get_pivot() const override;
79 virtual bool _edit_use_pivot() const override;
80
81 virtual void _edit_set_rect(const Rect2 &p_rect) override;
82 #endif // TOOLS_ENABLED
83
84 #ifdef DEBUG_ENABLED
85 virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
86
87 virtual Rect2 _edit_get_rect() const override;
88 virtual bool _edit_use_rect() const override;
89 #endif // DEBUG_ENABLED
90
91 #ifdef TOOLS_ENABLED
92 void _editor_set_dragging_to_resize_rect(bool p_dragging_to_resize_rect);
93 bool _editor_is_dragging_to_resiz_rect() const;
94 #endif
95
96 bool is_pixel_opaque(const Point2 &p_point) const;
97 bool is_editor_region_rect_draggable() const;
98
99 void set_texture(const Ref<Texture2D> &p_texture);
100 Ref<Texture2D> get_texture() const;
101
102 void set_centered(bool p_center);
103 bool is_centered() const;
104
105 void set_offset(const Point2 &p_offset);
106 Point2 get_offset() const;
107
108 void set_flip_h(bool p_flip);
109 bool is_flipped_h() const;
110
111 void set_flip_v(bool p_flip);
112 bool is_flipped_v() const;
113
114 void set_region_enabled(bool p_enabled);
115 bool is_region_enabled() const;
116
117 void set_region_filter_clip_enabled(bool p_enabled);
118 bool is_region_filter_clip_enabled() const;
119
120 void set_region_rect(const Rect2 &p_region_rect);
121 Rect2 get_region_rect() const;
122
123 void set_frame(int p_frame);
124 int get_frame() const;
125
126 void set_frame_coords(const Vector2i &p_coord);
127 Vector2i get_frame_coords() const;
128
129 void set_vframes(int p_amount);
130 int get_vframes() const;
131
132 void set_hframes(int p_amount);
133 int get_hframes() const;
134
135 Rect2 get_rect() const;
136 virtual Rect2 get_anchorable_rect() const override;
137
138 Sprite2D();
139 };