1 /** 2 Control for drawing textures. 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.texturerect; 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.control; 24 import godot.texture; 25 import godot.canvasitem; 26 import godot.node; 27 /** 28 Control for drawing textures. 29 30 Used to draw icons and sprites in a user interface. The texture's placement can be controlled with the $(D stretchMode) property. It can scale, tile, or stay centered inside its bounding rectangle. 31 */ 32 @GodotBaseClass struct TextureRect 33 { 34 enum string _GODOT_internal_name = "TextureRect"; 35 public: 36 @nogc nothrow: 37 union { godot_object _godot_object; Control _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_expand") GodotMethod!(void, bool) setExpand; 47 @GodotName("has_expand") GodotMethod!(bool) hasExpand; 48 @GodotName("set_stretch_mode") GodotMethod!(void, long) setStretchMode; 49 @GodotName("get_stretch_mode") GodotMethod!(TextureRect.StretchMode) getStretchMode; 50 } 51 bool opEquals(in TextureRect other) const { return _godot_object.ptr is other._godot_object.ptr; } 52 TextureRect opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 53 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 54 mixin baseCasts; 55 static TextureRect _new() 56 { 57 static godot_class_constructor constructor; 58 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TextureRect"); 59 if(constructor is null) return typeof(this).init; 60 return cast(TextureRect)(constructor()); 61 } 62 @disable new(size_t s); 63 /// 64 enum StretchMode : int 65 { 66 /** 67 Scale to fit the node's bounding rectangle, only if `expand` is `true`. Default `stretch_mode`, for backwards compatibility. Until you set `expand` to `true`, the texture will behave like `STRETCH_KEEP`. 68 */ 69 stretchScaleOnExpand = 0, 70 /** 71 Scale to fit the node's bounding rectangle. 72 */ 73 stretchScale = 1, 74 /** 75 Tile inside the node's bounding rectangle. 76 */ 77 stretchTile = 2, 78 /** 79 The texture keeps its original size and stays in the bounding rectangle's top-left corner. 80 */ 81 stretchKeep = 3, 82 /** 83 The texture keeps its original size and stays centered in the node's bounding rectangle. 84 */ 85 stretchKeepCentered = 4, 86 /** 87 Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio. 88 */ 89 stretchKeepAspect = 5, 90 /** 91 Scale the texture to fit the node's bounding rectangle, center it and maintain its aspect ratio. 92 */ 93 stretchKeepAspectCentered = 6, 94 /** 95 Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits. 96 */ 97 stretchKeepAspectCovered = 7, 98 } 99 /// 100 enum Constants : int 101 { 102 stretchScaleOnExpand = 0, 103 stretchScale = 1, 104 stretchTile = 2, 105 stretchKeep = 3, 106 stretchKeepCentered = 4, 107 stretchKeepAspect = 5, 108 stretchKeepAspectCentered = 6, 109 stretchKeepAspectCovered = 7, 110 } 111 /** 112 113 */ 114 void setTexture(Texture texture) 115 { 116 checkClassBinding!(typeof(this))(); 117 ptrcall!(void)(_classBinding.setTexture, _godot_object, texture); 118 } 119 /** 120 121 */ 122 Ref!Texture getTexture() const 123 { 124 checkClassBinding!(typeof(this))(); 125 return ptrcall!(Texture)(_classBinding.getTexture, _godot_object); 126 } 127 /** 128 129 */ 130 void setExpand(in bool enable) 131 { 132 checkClassBinding!(typeof(this))(); 133 ptrcall!(void)(_classBinding.setExpand, _godot_object, enable); 134 } 135 /** 136 137 */ 138 bool hasExpand() const 139 { 140 checkClassBinding!(typeof(this))(); 141 return ptrcall!(bool)(_classBinding.hasExpand, _godot_object); 142 } 143 /** 144 145 */ 146 void setStretchMode(in long stretch_mode) 147 { 148 checkClassBinding!(typeof(this))(); 149 ptrcall!(void)(_classBinding.setStretchMode, _godot_object, stretch_mode); 150 } 151 /** 152 153 */ 154 TextureRect.StretchMode getStretchMode() const 155 { 156 checkClassBinding!(typeof(this))(); 157 return ptrcall!(TextureRect.StretchMode)(_classBinding.getStretchMode, _godot_object); 158 } 159 /** 160 The node's $(D Texture) resource. 161 */ 162 @property Texture texture() 163 { 164 return getTexture(); 165 } 166 /// ditto 167 @property void texture(Texture v) 168 { 169 setTexture(v); 170 } 171 /** 172 If `true` the texture scales to fit its bounding rectangle. Default value: `false`. 173 */ 174 @property bool expand() 175 { 176 return hasExpand(); 177 } 178 /// ditto 179 @property void expand(bool v) 180 { 181 setExpand(v); 182 } 183 /** 184 Controls the texture's behavior when resizing the node's bounding rectangle. See $(D stretchmode). 185 */ 186 @property TextureRect.StretchMode stretchMode() 187 { 188 return getStretchMode(); 189 } 190 /// ditto 191 @property void stretchMode(long v) 192 { 193 setStretchMode(v); 194 } 195 }