| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
| 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 |
| 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 |
| 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 |
}; |