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