1 /** 2 General purpose Sprite node. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.sprite; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.node2d; 24 import godot.texture; 25 import godot.canvasitem; 26 import godot.node; 27 /** 28 General purpose Sprite node. 29 30 A node that displays a 2D texture. The texture displayed can be a region from a larger atlas texture, or a frame from a sprite sheet animation. 31 */ 32 @GodotBaseClass struct Sprite 33 { 34 enum string _GODOT_internal_name = "Sprite"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; Node2D _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct _classBinding 42 { 43 __gshared: 44 @GodotName("set_texture") GodotMethod!(void, Texture) setTexture; 45 @GodotName("get_texture") GodotMethod!(Texture) getTexture; 46 @GodotName("set_normal_map") GodotMethod!(void, Texture) setNormalMap; 47 @GodotName("get_normal_map") GodotMethod!(Texture) getNormalMap; 48 @GodotName("set_centered") GodotMethod!(void, bool) setCentered; 49 @GodotName("is_centered") GodotMethod!(bool) isCentered; 50 @GodotName("set_offset") GodotMethod!(void, Vector2) setOffset; 51 @GodotName("get_offset") GodotMethod!(Vector2) getOffset; 52 @GodotName("set_flip_h") GodotMethod!(void, bool) setFlipH; 53 @GodotName("is_flipped_h") GodotMethod!(bool) isFlippedH; 54 @GodotName("set_flip_v") GodotMethod!(void, bool) setFlipV; 55 @GodotName("is_flipped_v") GodotMethod!(bool) isFlippedV; 56 @GodotName("set_region") GodotMethod!(void, bool) setRegion; 57 @GodotName("is_region") GodotMethod!(bool) isRegion; 58 @GodotName("is_pixel_opaque") GodotMethod!(bool, Vector2) isPixelOpaque; 59 @GodotName("set_region_rect") GodotMethod!(void, Rect2) setRegionRect; 60 @GodotName("get_region_rect") GodotMethod!(Rect2) getRegionRect; 61 @GodotName("set_region_filter_clip") GodotMethod!(void, bool) setRegionFilterClip; 62 @GodotName("is_region_filter_clip_enabled") GodotMethod!(bool) isRegionFilterClipEnabled; 63 @GodotName("set_frame") GodotMethod!(void, long) setFrame; 64 @GodotName("get_frame") GodotMethod!(long) getFrame; 65 @GodotName("set_vframes") GodotMethod!(void, long) setVframes; 66 @GodotName("get_vframes") GodotMethod!(long) getVframes; 67 @GodotName("set_hframes") GodotMethod!(void, long) setHframes; 68 @GodotName("get_hframes") GodotMethod!(long) getHframes; 69 @GodotName("get_rect") GodotMethod!(Rect2) getRect; 70 } 71 bool opEquals(in Sprite other) const { return _godot_object.ptr is other._godot_object.ptr; } 72 Sprite opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 73 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 74 mixin baseCasts; 75 static Sprite _new() 76 { 77 static godot_class_constructor constructor; 78 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Sprite"); 79 if(constructor is null) return typeof(this).init; 80 return cast(Sprite)(constructor()); 81 } 82 @disable new(size_t s); 83 /** 84 85 */ 86 void setTexture(Texture texture) 87 { 88 checkClassBinding!(typeof(this))(); 89 ptrcall!(void)(_classBinding.setTexture, _godot_object, texture); 90 } 91 /** 92 93 */ 94 Ref!Texture getTexture() const 95 { 96 checkClassBinding!(typeof(this))(); 97 return ptrcall!(Texture)(_classBinding.getTexture, _godot_object); 98 } 99 /** 100 101 */ 102 void setNormalMap(Texture normal_map) 103 { 104 checkClassBinding!(typeof(this))(); 105 ptrcall!(void)(_classBinding.setNormalMap, _godot_object, normal_map); 106 } 107 /** 108 109 */ 110 Ref!Texture getNormalMap() const 111 { 112 checkClassBinding!(typeof(this))(); 113 return ptrcall!(Texture)(_classBinding.getNormalMap, _godot_object); 114 } 115 /** 116 117 */ 118 void setCentered(in bool centered) 119 { 120 checkClassBinding!(typeof(this))(); 121 ptrcall!(void)(_classBinding.setCentered, _godot_object, centered); 122 } 123 /** 124 125 */ 126 bool isCentered() const 127 { 128 checkClassBinding!(typeof(this))(); 129 return ptrcall!(bool)(_classBinding.isCentered, _godot_object); 130 } 131 /** 132 133 */ 134 void setOffset(in Vector2 offset) 135 { 136 checkClassBinding!(typeof(this))(); 137 ptrcall!(void)(_classBinding.setOffset, _godot_object, offset); 138 } 139 /** 140 141 */ 142 Vector2 getOffset() const 143 { 144 checkClassBinding!(typeof(this))(); 145 return ptrcall!(Vector2)(_classBinding.getOffset, _godot_object); 146 } 147 /** 148 149 */ 150 void setFlipH(in bool flip_h) 151 { 152 checkClassBinding!(typeof(this))(); 153 ptrcall!(void)(_classBinding.setFlipH, _godot_object, flip_h); 154 } 155 /** 156 157 */ 158 bool isFlippedH() const 159 { 160 checkClassBinding!(typeof(this))(); 161 return ptrcall!(bool)(_classBinding.isFlippedH, _godot_object); 162 } 163 /** 164 165 */ 166 void setFlipV(in bool flip_v) 167 { 168 checkClassBinding!(typeof(this))(); 169 ptrcall!(void)(_classBinding.setFlipV, _godot_object, flip_v); 170 } 171 /** 172 173 */ 174 bool isFlippedV() const 175 { 176 checkClassBinding!(typeof(this))(); 177 return ptrcall!(bool)(_classBinding.isFlippedV, _godot_object); 178 } 179 /** 180 181 */ 182 void setRegion(in bool enabled) 183 { 184 checkClassBinding!(typeof(this))(); 185 ptrcall!(void)(_classBinding.setRegion, _godot_object, enabled); 186 } 187 /** 188 189 */ 190 bool isRegion() const 191 { 192 checkClassBinding!(typeof(this))(); 193 return ptrcall!(bool)(_classBinding.isRegion, _godot_object); 194 } 195 /** 196 197 */ 198 bool isPixelOpaque(in Vector2 pos) const 199 { 200 checkClassBinding!(typeof(this))(); 201 return ptrcall!(bool)(_classBinding.isPixelOpaque, _godot_object, pos); 202 } 203 /** 204 205 */ 206 void setRegionRect(in Rect2 rect) 207 { 208 checkClassBinding!(typeof(this))(); 209 ptrcall!(void)(_classBinding.setRegionRect, _godot_object, rect); 210 } 211 /** 212 213 */ 214 Rect2 getRegionRect() const 215 { 216 checkClassBinding!(typeof(this))(); 217 return ptrcall!(Rect2)(_classBinding.getRegionRect, _godot_object); 218 } 219 /** 220 221 */ 222 void setRegionFilterClip(in bool enabled) 223 { 224 checkClassBinding!(typeof(this))(); 225 ptrcall!(void)(_classBinding.setRegionFilterClip, _godot_object, enabled); 226 } 227 /** 228 229 */ 230 bool isRegionFilterClipEnabled() const 231 { 232 checkClassBinding!(typeof(this))(); 233 return ptrcall!(bool)(_classBinding.isRegionFilterClipEnabled, _godot_object); 234 } 235 /** 236 237 */ 238 void setFrame(in long frame) 239 { 240 checkClassBinding!(typeof(this))(); 241 ptrcall!(void)(_classBinding.setFrame, _godot_object, frame); 242 } 243 /** 244 245 */ 246 long getFrame() const 247 { 248 checkClassBinding!(typeof(this))(); 249 return ptrcall!(long)(_classBinding.getFrame, _godot_object); 250 } 251 /** 252 253 */ 254 void setVframes(in long vframes) 255 { 256 checkClassBinding!(typeof(this))(); 257 ptrcall!(void)(_classBinding.setVframes, _godot_object, vframes); 258 } 259 /** 260 261 */ 262 long getVframes() const 263 { 264 checkClassBinding!(typeof(this))(); 265 return ptrcall!(long)(_classBinding.getVframes, _godot_object); 266 } 267 /** 268 269 */ 270 void setHframes(in long hframes) 271 { 272 checkClassBinding!(typeof(this))(); 273 ptrcall!(void)(_classBinding.setHframes, _godot_object, hframes); 274 } 275 /** 276 277 */ 278 long getHframes() const 279 { 280 checkClassBinding!(typeof(this))(); 281 return ptrcall!(long)(_classBinding.getHframes, _godot_object); 282 } 283 /** 284 Returns a Rect2 representing the Sprite's boundary relative to its local coordinates. 285 */ 286 Rect2 getRect() const 287 { 288 checkClassBinding!(typeof(this))(); 289 return ptrcall!(Rect2)(_classBinding.getRect, _godot_object); 290 } 291 /** 292 $(D Texture) object to draw. 293 */ 294 @property Texture texture() 295 { 296 return getTexture(); 297 } 298 /// ditto 299 @property void texture(Texture v) 300 { 301 setTexture(v); 302 } 303 /** 304 The normal map gives depth to the Sprite. 305 */ 306 @property Texture normalMap() 307 { 308 return getNormalMap(); 309 } 310 /// ditto 311 @property void normalMap(Texture v) 312 { 313 setNormalMap(v); 314 } 315 /** 316 If `true` texture is centered. Default value: `true`. 317 */ 318 @property bool centered() 319 { 320 return isCentered(); 321 } 322 /// ditto 323 @property void centered(bool v) 324 { 325 setCentered(v); 326 } 327 /** 328 The texture's drawing offset. 329 */ 330 @property Vector2 offset() 331 { 332 return getOffset(); 333 } 334 /// ditto 335 @property void offset(Vector2 v) 336 { 337 setOffset(v); 338 } 339 /** 340 If `true` texture is flipped horizontally. Default value: `false`. 341 */ 342 @property bool flipH() 343 { 344 return isFlippedH(); 345 } 346 /// ditto 347 @property void flipH(bool v) 348 { 349 setFlipH(v); 350 } 351 /** 352 If `true` texture is flipped vertically. Default value: `false`. 353 */ 354 @property bool flipV() 355 { 356 return isFlippedV(); 357 } 358 /// ditto 359 @property void flipV(bool v) 360 { 361 setFlipV(v); 362 } 363 /** 364 The number of rows in the sprite sheet. 365 */ 366 @property long vframes() 367 { 368 return getVframes(); 369 } 370 /// ditto 371 @property void vframes(long v) 372 { 373 setVframes(v); 374 } 375 /** 376 The number of columns in the sprite sheet. 377 */ 378 @property long hframes() 379 { 380 return getHframes(); 381 } 382 /// ditto 383 @property void hframes(long v) 384 { 385 setHframes(v); 386 } 387 /** 388 Current frame to display from sprite sheet. $(D vframes) or $(D hframes) must be greater than 1. 389 */ 390 @property long frame() 391 { 392 return getFrame(); 393 } 394 /// ditto 395 @property void frame(long v) 396 { 397 setFrame(v); 398 } 399 /** 400 If `true` texture is cut from a larger atlas texture. See `region_rect`. Default value: `false`. 401 */ 402 @property bool regionEnabled() 403 { 404 return isRegion(); 405 } 406 /// ditto 407 @property void regionEnabled(bool v) 408 { 409 setRegion(v); 410 } 411 /** 412 The region of the atlas texture to display. $(D regionEnabled) must be `true`. 413 */ 414 @property Rect2 regionRect() 415 { 416 return getRegionRect(); 417 } 418 /// ditto 419 @property void regionRect(Rect2 v) 420 { 421 setRegionRect(v); 422 } 423 /** 424 If `true` the outermost pixels get blurred out. 425 */ 426 @property bool regionFilterClip() 427 { 428 return isRegionFilterClipEnabled(); 429 } 430 /// ditto 431 @property void regionFilterClip(bool v) 432 { 433 setRegionFilterClip(v); 434 } 435 }