1 /** 2 Texture-based button. Supports Pressed, Hover, Disabled and Focused states. 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.texturebutton; 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.basebutton; 24 import godot.texture; 25 import godot.bitmap; 26 import godot.control; 27 import godot.canvasitem; 28 import godot.node; 29 /** 30 Texture-based button. Supports Pressed, Hover, Disabled and Focused states. 31 32 `TextureButton` has the same functionality as $(D Button), except it uses sprites instead of Godot's $(D Theme) resource. It is faster to create, but it doesn't support localization like more complex Controls. 33 The Normal state's texture is required. Others are optional. 34 */ 35 @GodotBaseClass struct TextureButton 36 { 37 enum string _GODOT_internal_name = "TextureButton"; 38 public: 39 @nogc nothrow: 40 union { godot_object _godot_object; BaseButton _GODOT_base; } 41 alias _GODOT_base this; 42 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 43 package(godot) __gshared bool _classBindingInitialized = false; 44 package(godot) static struct _classBinding 45 { 46 __gshared: 47 @GodotName("set_normal_texture") GodotMethod!(void, Texture) setNormalTexture; 48 @GodotName("set_pressed_texture") GodotMethod!(void, Texture) setPressedTexture; 49 @GodotName("set_hover_texture") GodotMethod!(void, Texture) setHoverTexture; 50 @GodotName("set_disabled_texture") GodotMethod!(void, Texture) setDisabledTexture; 51 @GodotName("set_focused_texture") GodotMethod!(void, Texture) setFocusedTexture; 52 @GodotName("set_click_mask") GodotMethod!(void, BitMap) setClickMask; 53 @GodotName("set_expand") GodotMethod!(void, bool) setExpand; 54 @GodotName("set_stretch_mode") GodotMethod!(void, long) setStretchMode; 55 @GodotName("get_normal_texture") GodotMethod!(Texture) getNormalTexture; 56 @GodotName("get_pressed_texture") GodotMethod!(Texture) getPressedTexture; 57 @GodotName("get_hover_texture") GodotMethod!(Texture) getHoverTexture; 58 @GodotName("get_disabled_texture") GodotMethod!(Texture) getDisabledTexture; 59 @GodotName("get_focused_texture") GodotMethod!(Texture) getFocusedTexture; 60 @GodotName("get_click_mask") GodotMethod!(BitMap) getClickMask; 61 @GodotName("get_expand") GodotMethod!(bool) getExpand; 62 @GodotName("get_stretch_mode") GodotMethod!(TextureButton.StretchMode) getStretchMode; 63 } 64 bool opEquals(in TextureButton other) const { return _godot_object.ptr is other._godot_object.ptr; } 65 TextureButton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 66 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 67 mixin baseCasts; 68 static TextureButton _new() 69 { 70 static godot_class_constructor constructor; 71 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("TextureButton"); 72 if(constructor is null) return typeof(this).init; 73 return cast(TextureButton)(constructor()); 74 } 75 @disable new(size_t s); 76 /// 77 enum StretchMode : int 78 { 79 /** 80 Scale to fit the node's bounding rectangle. 81 */ 82 stretchScale = 0, 83 /** 84 Tile inside the node's bounding rectangle. 85 */ 86 stretchTile = 1, 87 /** 88 The texture keeps its original size and stays in the bounding rectangle's top-left corner. 89 */ 90 stretchKeep = 2, 91 /** 92 The texture keeps its original size and stays centered in the node's bounding rectangle. 93 */ 94 stretchKeepCentered = 3, 95 /** 96 Scale the texture to fit the node's bounding rectangle, but maintain the texture's aspect ratio. 97 */ 98 stretchKeepAspect = 4, 99 /** 100 Scale the texture to fit the node's bounding rectangle, center it, and maintain its aspect ratio. 101 */ 102 stretchKeepAspectCentered = 5, 103 /** 104 Scale the texture so that the shorter side fits the bounding rectangle. The other side clips to the node's limits. 105 */ 106 stretchKeepAspectCovered = 6, 107 } 108 /// 109 enum Constants : int 110 { 111 stretchScale = 0, 112 stretchTile = 1, 113 stretchKeep = 2, 114 stretchKeepCentered = 3, 115 stretchKeepAspect = 4, 116 stretchKeepAspectCentered = 5, 117 stretchKeepAspectCovered = 6, 118 } 119 /** 120 121 */ 122 void setNormalTexture(Texture texture) 123 { 124 checkClassBinding!(typeof(this))(); 125 ptrcall!(void)(_classBinding.setNormalTexture, _godot_object, texture); 126 } 127 /** 128 129 */ 130 void setPressedTexture(Texture texture) 131 { 132 checkClassBinding!(typeof(this))(); 133 ptrcall!(void)(_classBinding.setPressedTexture, _godot_object, texture); 134 } 135 /** 136 137 */ 138 void setHoverTexture(Texture texture) 139 { 140 checkClassBinding!(typeof(this))(); 141 ptrcall!(void)(_classBinding.setHoverTexture, _godot_object, texture); 142 } 143 /** 144 145 */ 146 void setDisabledTexture(Texture texture) 147 { 148 checkClassBinding!(typeof(this))(); 149 ptrcall!(void)(_classBinding.setDisabledTexture, _godot_object, texture); 150 } 151 /** 152 153 */ 154 void setFocusedTexture(Texture texture) 155 { 156 checkClassBinding!(typeof(this))(); 157 ptrcall!(void)(_classBinding.setFocusedTexture, _godot_object, texture); 158 } 159 /** 160 161 */ 162 void setClickMask(BitMap mask) 163 { 164 checkClassBinding!(typeof(this))(); 165 ptrcall!(void)(_classBinding.setClickMask, _godot_object, mask); 166 } 167 /** 168 169 */ 170 void setExpand(in bool p_expand) 171 { 172 checkClassBinding!(typeof(this))(); 173 ptrcall!(void)(_classBinding.setExpand, _godot_object, p_expand); 174 } 175 /** 176 177 */ 178 void setStretchMode(in long p_mode) 179 { 180 checkClassBinding!(typeof(this))(); 181 ptrcall!(void)(_classBinding.setStretchMode, _godot_object, p_mode); 182 } 183 /** 184 185 */ 186 Ref!Texture getNormalTexture() const 187 { 188 checkClassBinding!(typeof(this))(); 189 return ptrcall!(Texture)(_classBinding.getNormalTexture, _godot_object); 190 } 191 /** 192 193 */ 194 Ref!Texture getPressedTexture() const 195 { 196 checkClassBinding!(typeof(this))(); 197 return ptrcall!(Texture)(_classBinding.getPressedTexture, _godot_object); 198 } 199 /** 200 201 */ 202 Ref!Texture getHoverTexture() const 203 { 204 checkClassBinding!(typeof(this))(); 205 return ptrcall!(Texture)(_classBinding.getHoverTexture, _godot_object); 206 } 207 /** 208 209 */ 210 Ref!Texture getDisabledTexture() const 211 { 212 checkClassBinding!(typeof(this))(); 213 return ptrcall!(Texture)(_classBinding.getDisabledTexture, _godot_object); 214 } 215 /** 216 217 */ 218 Ref!Texture getFocusedTexture() const 219 { 220 checkClassBinding!(typeof(this))(); 221 return ptrcall!(Texture)(_classBinding.getFocusedTexture, _godot_object); 222 } 223 /** 224 225 */ 226 Ref!BitMap getClickMask() const 227 { 228 checkClassBinding!(typeof(this))(); 229 return ptrcall!(BitMap)(_classBinding.getClickMask, _godot_object); 230 } 231 /** 232 233 */ 234 bool getExpand() const 235 { 236 checkClassBinding!(typeof(this))(); 237 return ptrcall!(bool)(_classBinding.getExpand, _godot_object); 238 } 239 /** 240 241 */ 242 TextureButton.StretchMode getStretchMode() const 243 { 244 checkClassBinding!(typeof(this))(); 245 return ptrcall!(TextureButton.StretchMode)(_classBinding.getStretchMode, _godot_object); 246 } 247 /** 248 Texture to display by default, when the node is $(B not) in the disabled, focused, hover or pressed state. 249 */ 250 @property Texture textureNormal() 251 { 252 return getNormalTexture(); 253 } 254 /// ditto 255 @property void textureNormal(Texture v) 256 { 257 setNormalTexture(v); 258 } 259 /** 260 Texture to display on mouse down over the node, if the node has keyboard focus and the player presses the enter key or if the player presses the $(D BaseButton.shortcut) key. 261 */ 262 @property Texture texturePressed() 263 { 264 return getPressedTexture(); 265 } 266 /// ditto 267 @property void texturePressed(Texture v) 268 { 269 setPressedTexture(v); 270 } 271 /** 272 Texture to display when the mouse hovers the node. 273 */ 274 @property Texture textureHover() 275 { 276 return getHoverTexture(); 277 } 278 /// ditto 279 @property void textureHover(Texture v) 280 { 281 setHoverTexture(v); 282 } 283 /** 284 Texture to display when the node is disabled. See $(D BaseButton.disabled). 285 */ 286 @property Texture textureDisabled() 287 { 288 return getDisabledTexture(); 289 } 290 /// ditto 291 @property void textureDisabled(Texture v) 292 { 293 setDisabledTexture(v); 294 } 295 /** 296 Texture to display when the node has mouse or keyboard focus. 297 */ 298 @property Texture textureFocused() 299 { 300 return getFocusedTexture(); 301 } 302 /// ditto 303 @property void textureFocused(Texture v) 304 { 305 setFocusedTexture(v); 306 } 307 /** 308 Pure black and white $(D Bitmap) image to use for click detection. On the mask, white pixels represent the button's clickable area. Use it to create buttons with curved shapes. 309 */ 310 @property BitMap textureClickMask() 311 { 312 return getClickMask(); 313 } 314 /// ditto 315 @property void textureClickMask(BitMap v) 316 { 317 setClickMask(v); 318 } 319 /** 320 If `true` the texture stretches to the edges of the node's bounding rectangle using the $(D stretchMode). If `false` the texture will not scale with the node. Default value: `false`. 321 */ 322 @property bool expand() 323 { 324 return getExpand(); 325 } 326 /// ditto 327 @property void expand(bool v) 328 { 329 setExpand(v); 330 } 331 /** 332 Controls the texture's behavior when you resize the node's bounding rectangle, $(B only if) $(D expand) is `true`. Set it to one of the `STRETCH_*` constants. See the constants to learn more. 333 */ 334 @property TextureButton.StretchMode stretchMode() 335 { 336 return getStretchMode(); 337 } 338 /// ditto 339 @property void stretchMode(long v) 340 { 341 setStretchMode(v); 342 } 343 }