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