1 /*************************************************************************/ 2 /* sprite.h */ 3 /*************************************************************************/ 4 /* This file is part of: */ 5 /* GODOT ENGINE */ 6 /* https://godotengine.org */ 7 /*************************************************************************/ 8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2019 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 SPRITE_H 31 #define SPRITE_H 32 33 #include "scene/2d/node_2d.h" 34 #include "scene/resources/texture.h" 35 36 class Sprite : public Node2D { 37 38 OBJ_TYPE(Sprite, Node2D); 39 40 Ref<Texture> texture; 41 42 bool centered; 43 Point2 offset; 44 45 bool hflip; 46 bool vflip; 47 bool region; 48 Rect2 region_rect; 49 50 int frame; 51 52 int vframes; 53 int hframes; 54 55 Color modulate; 56 57 protected: 58 void _notification(int p_what); 59 60 static void _bind_methods(); 61 62 virtual void _validate_property(PropertyInfo &property) const; 63 64 public: 65 virtual void edit_set_pivot(const Point2 &p_pivot); 66 virtual Point2 edit_get_pivot() const; 67 virtual bool edit_has_pivot() const; 68 69 void set_texture(const Ref<Texture> &p_texture); 70 Ref<Texture> get_texture() const; 71 72 void set_centered(bool p_center); 73 bool is_centered() const; 74 75 void set_offset(const Point2 &p_offset); 76 Point2 get_offset() const; 77 78 void set_flip_h(bool p_flip); 79 bool is_flipped_h() const; 80 81 void set_flip_v(bool p_flip); 82 bool is_flipped_v() const; 83 84 void set_region(bool p_region); 85 bool is_region() const; 86 87 void set_region_rect(const Rect2 &p_region_rect); 88 Rect2 get_region_rect() const; 89 90 void set_frame(int p_frame); 91 int get_frame() const; 92 93 void set_vframes(int p_amount); 94 int get_vframes() const; 95 96 void set_hframes(int p_amount); 97 int get_hframes() const; 98 99 void set_modulate(const Color &p_color); 100 Color get_modulate() const; 101 102 virtual Rect2 get_item_rect() const; 103 104 Sprite(); 105 }; 106 107 class ViewportSprite : public Node2D { 108 109 OBJ_TYPE(ViewportSprite, Node2D); 110 111 Ref<Texture> texture; 112 NodePath viewport_path; 113 114 bool centered; 115 Point2 offset; 116 Color modulate; 117 118 protected: 119 void _notification(int p_what); 120 121 static void _bind_methods(); 122 123 public: 124 virtual void edit_set_pivot(const Point2 &p_pivot); 125 virtual Point2 edit_get_pivot() const; 126 virtual bool edit_has_pivot() const; 127 128 void set_viewport_path(const NodePath &p_viewport); 129 NodePath get_viewport_path() const; 130 131 void set_centered(bool p_center); 132 bool is_centered() const; 133 134 void set_offset(const Point2 &p_offset); 135 Point2 get_offset() const; 136 137 void set_modulate(const Color &p_color); 138 Color get_modulate() const; 139 140 virtual Rect2 get_item_rect() const; 141 142 virtual String get_configuration_warning() const; 143 144 ViewportSprite(); 145 }; 146 147 #endif // SPRITE_H 148