1 /** 2 Base class for different kinds of buttons. 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.basebutton; 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.control; 24 import godot.inputevent; 25 import godot.buttongroup; 26 import godot.shortcut; 27 /** 28 Base class for different kinds of buttons. 29 30 BaseButton is the abstract base class for buttons, so it shouldn't be used directly (it doesn't display anything). Other types of buttons inherit from it. 31 */ 32 @GodotBaseClass struct BaseButton 33 { 34 package(godot) enum string _GODOT_internal_name = "BaseButton"; 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 GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 45 @GodotName("_pressed") GodotMethod!(void) _pressed; 46 @GodotName("_toggled") GodotMethod!(void, bool) _toggled; 47 @GodotName("_unhandled_input") GodotMethod!(void, InputEvent) _unhandledInput; 48 @GodotName("get_action_mode") GodotMethod!(BaseButton.ActionMode) getActionMode; 49 @GodotName("get_button_group") GodotMethod!(ButtonGroup) getButtonGroup; 50 @GodotName("get_button_mask") GodotMethod!(long) getButtonMask; 51 @GodotName("get_draw_mode") GodotMethod!(BaseButton.DrawMode) getDrawMode; 52 @GodotName("get_enabled_focus_mode") GodotMethod!(Control.FocusMode) getEnabledFocusMode; 53 @GodotName("get_shortcut") GodotMethod!(ShortCut) getShortcut; 54 @GodotName("is_disabled") GodotMethod!(bool) isDisabled; 55 @GodotName("is_hovered") GodotMethod!(bool) isHovered; 56 @GodotName("is_keep_pressed_outside") GodotMethod!(bool) isKeepPressedOutside; 57 @GodotName("is_pressed") GodotMethod!(bool) isPressed; 58 @GodotName("is_shortcut_in_tooltip_enabled") GodotMethod!(bool) isShortcutInTooltipEnabled; 59 @GodotName("is_toggle_mode") GodotMethod!(bool) isToggleMode; 60 @GodotName("set_action_mode") GodotMethod!(void, long) setActionMode; 61 @GodotName("set_button_group") GodotMethod!(void, ButtonGroup) setButtonGroup; 62 @GodotName("set_button_mask") GodotMethod!(void, long) setButtonMask; 63 @GodotName("set_disabled") GodotMethod!(void, bool) setDisabled; 64 @GodotName("set_enabled_focus_mode") GodotMethod!(void, long) setEnabledFocusMode; 65 @GodotName("set_keep_pressed_outside") GodotMethod!(void, bool) setKeepPressedOutside; 66 @GodotName("set_pressed") GodotMethod!(void, bool) setPressed; 67 @GodotName("set_shortcut") GodotMethod!(void, ShortCut) setShortcut; 68 @GodotName("set_shortcut_in_tooltip") GodotMethod!(void, bool) setShortcutInTooltip; 69 @GodotName("set_toggle_mode") GodotMethod!(void, bool) setToggleMode; 70 } 71 /// 72 pragma(inline, true) bool opEquals(in BaseButton other) const 73 { return _godot_object.ptr is other._godot_object.ptr; } 74 /// 75 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 76 { _godot_object.ptr = n; return null; } 77 /// 78 pragma(inline, true) bool opEquals(typeof(null) n) const 79 { return _godot_object.ptr is n; } 80 /// 81 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 82 mixin baseCasts; 83 /// Construct a new instance of BaseButton. 84 /// Note: use `memnew!BaseButton` instead. 85 static BaseButton _new() 86 { 87 static godot_class_constructor constructor; 88 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("BaseButton"); 89 if(constructor is null) return typeof(this).init; 90 return cast(BaseButton)(constructor()); 91 } 92 @disable new(size_t s); 93 /// 94 enum ActionMode : int 95 { 96 /** 97 Require just a press to consider the button clicked. 98 */ 99 actionModeButtonPress = 0, 100 /** 101 Require a press and a subsequent release before considering the button clicked. 102 */ 103 actionModeButtonRelease = 1, 104 } 105 /// 106 enum DrawMode : int 107 { 108 /** 109 The normal state (i.e. not pressed, not hovered, not toggled and enabled) of buttons. 110 */ 111 drawNormal = 0, 112 /** 113 The state of buttons are pressed. 114 */ 115 drawPressed = 1, 116 /** 117 The state of buttons are hovered. 118 */ 119 drawHover = 2, 120 /** 121 The state of buttons are disabled. 122 */ 123 drawDisabled = 3, 124 /** 125 The state of buttons are both hovered and pressed. 126 */ 127 drawHoverPressed = 4, 128 } 129 /// 130 enum Constants : int 131 { 132 drawNormal = 0, 133 actionModeButtonPress = 0, 134 drawPressed = 1, 135 actionModeButtonRelease = 1, 136 drawHover = 2, 137 drawDisabled = 3, 138 drawHoverPressed = 4, 139 } 140 /** 141 142 */ 143 void _guiInput(InputEvent arg0) 144 { 145 Array _GODOT_args = Array.make(); 146 _GODOT_args.append(arg0); 147 String _GODOT_method_name = String("_gui_input"); 148 this.callv(_GODOT_method_name, _GODOT_args); 149 } 150 /** 151 Called when the button is pressed. If you need to know the button's pressed state (and $(D toggleMode) is active), use $(D _toggled) instead. 152 */ 153 void _pressed() 154 { 155 Array _GODOT_args = Array.make(); 156 String _GODOT_method_name = String("_pressed"); 157 this.callv(_GODOT_method_name, _GODOT_args); 158 } 159 /** 160 Called when the button is toggled (only if $(D toggleMode) is active). 161 */ 162 void _toggled(in bool button_pressed) 163 { 164 Array _GODOT_args = Array.make(); 165 _GODOT_args.append(button_pressed); 166 String _GODOT_method_name = String("_toggled"); 167 this.callv(_GODOT_method_name, _GODOT_args); 168 } 169 /** 170 171 */ 172 void _unhandledInput(InputEvent arg0) 173 { 174 Array _GODOT_args = Array.make(); 175 _GODOT_args.append(arg0); 176 String _GODOT_method_name = String("_unhandled_input"); 177 this.callv(_GODOT_method_name, _GODOT_args); 178 } 179 /** 180 181 */ 182 BaseButton.ActionMode getActionMode() const 183 { 184 checkClassBinding!(typeof(this))(); 185 return ptrcall!(BaseButton.ActionMode)(GDNativeClassBinding.getActionMode, _godot_object); 186 } 187 /** 188 189 */ 190 Ref!ButtonGroup getButtonGroup() const 191 { 192 checkClassBinding!(typeof(this))(); 193 return ptrcall!(ButtonGroup)(GDNativeClassBinding.getButtonGroup, _godot_object); 194 } 195 /** 196 197 */ 198 long getButtonMask() const 199 { 200 checkClassBinding!(typeof(this))(); 201 return ptrcall!(long)(GDNativeClassBinding.getButtonMask, _godot_object); 202 } 203 /** 204 Returns the visual state used to draw the button. This is useful mainly when implementing your own draw code by either overriding _draw() or connecting to "draw" signal. The visual state of the button is defined by the $(D drawmode) enum. 205 */ 206 BaseButton.DrawMode getDrawMode() const 207 { 208 checkClassBinding!(typeof(this))(); 209 return ptrcall!(BaseButton.DrawMode)(GDNativeClassBinding.getDrawMode, _godot_object); 210 } 211 /** 212 213 */ 214 Control.FocusMode getEnabledFocusMode() const 215 { 216 checkClassBinding!(typeof(this))(); 217 return ptrcall!(Control.FocusMode)(GDNativeClassBinding.getEnabledFocusMode, _godot_object); 218 } 219 /** 220 221 */ 222 Ref!ShortCut getShortcut() const 223 { 224 checkClassBinding!(typeof(this))(); 225 return ptrcall!(ShortCut)(GDNativeClassBinding.getShortcut, _godot_object); 226 } 227 /** 228 229 */ 230 bool isDisabled() const 231 { 232 checkClassBinding!(typeof(this))(); 233 return ptrcall!(bool)(GDNativeClassBinding.isDisabled, _godot_object); 234 } 235 /** 236 Returns `true` if the mouse has entered the button and has not left it yet. 237 */ 238 bool isHovered() const 239 { 240 checkClassBinding!(typeof(this))(); 241 return ptrcall!(bool)(GDNativeClassBinding.isHovered, _godot_object); 242 } 243 /** 244 245 */ 246 bool isKeepPressedOutside() const 247 { 248 checkClassBinding!(typeof(this))(); 249 return ptrcall!(bool)(GDNativeClassBinding.isKeepPressedOutside, _godot_object); 250 } 251 /** 252 253 */ 254 bool isPressed() const 255 { 256 checkClassBinding!(typeof(this))(); 257 return ptrcall!(bool)(GDNativeClassBinding.isPressed, _godot_object); 258 } 259 /** 260 261 */ 262 bool isShortcutInTooltipEnabled() const 263 { 264 checkClassBinding!(typeof(this))(); 265 return ptrcall!(bool)(GDNativeClassBinding.isShortcutInTooltipEnabled, _godot_object); 266 } 267 /** 268 269 */ 270 bool isToggleMode() const 271 { 272 checkClassBinding!(typeof(this))(); 273 return ptrcall!(bool)(GDNativeClassBinding.isToggleMode, _godot_object); 274 } 275 /** 276 277 */ 278 void setActionMode(in long mode) 279 { 280 checkClassBinding!(typeof(this))(); 281 ptrcall!(void)(GDNativeClassBinding.setActionMode, _godot_object, mode); 282 } 283 /** 284 285 */ 286 void setButtonGroup(ButtonGroup button_group) 287 { 288 checkClassBinding!(typeof(this))(); 289 ptrcall!(void)(GDNativeClassBinding.setButtonGroup, _godot_object, button_group); 290 } 291 /** 292 293 */ 294 void setButtonMask(in long mask) 295 { 296 checkClassBinding!(typeof(this))(); 297 ptrcall!(void)(GDNativeClassBinding.setButtonMask, _godot_object, mask); 298 } 299 /** 300 301 */ 302 void setDisabled(in bool disabled) 303 { 304 checkClassBinding!(typeof(this))(); 305 ptrcall!(void)(GDNativeClassBinding.setDisabled, _godot_object, disabled); 306 } 307 /** 308 309 */ 310 void setEnabledFocusMode(in long mode) 311 { 312 checkClassBinding!(typeof(this))(); 313 ptrcall!(void)(GDNativeClassBinding.setEnabledFocusMode, _godot_object, mode); 314 } 315 /** 316 317 */ 318 void setKeepPressedOutside(in bool enabled) 319 { 320 checkClassBinding!(typeof(this))(); 321 ptrcall!(void)(GDNativeClassBinding.setKeepPressedOutside, _godot_object, enabled); 322 } 323 /** 324 325 */ 326 void setPressed(in bool pressed) 327 { 328 checkClassBinding!(typeof(this))(); 329 ptrcall!(void)(GDNativeClassBinding.setPressed, _godot_object, pressed); 330 } 331 /** 332 333 */ 334 void setShortcut(ShortCut shortcut) 335 { 336 checkClassBinding!(typeof(this))(); 337 ptrcall!(void)(GDNativeClassBinding.setShortcut, _godot_object, shortcut); 338 } 339 /** 340 341 */ 342 void setShortcutInTooltip(in bool enabled) 343 { 344 checkClassBinding!(typeof(this))(); 345 ptrcall!(void)(GDNativeClassBinding.setShortcutInTooltip, _godot_object, enabled); 346 } 347 /** 348 349 */ 350 void setToggleMode(in bool enabled) 351 { 352 checkClassBinding!(typeof(this))(); 353 ptrcall!(void)(GDNativeClassBinding.setToggleMode, _godot_object, enabled); 354 } 355 /** 356 Determines when the button is considered clicked, one of the $(D actionmode) constants. 357 */ 358 @property BaseButton.ActionMode actionMode() 359 { 360 return getActionMode(); 361 } 362 /// ditto 363 @property void actionMode(long v) 364 { 365 setActionMode(v); 366 } 367 /** 368 Binary mask to choose which mouse buttons this button will respond to. 369 To allow both left-click and right-click, use `BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT`. 370 */ 371 @property long buttonMask() 372 { 373 return getButtonMask(); 374 } 375 /// ditto 376 @property void buttonMask(long v) 377 { 378 setButtonMask(v); 379 } 380 /** 381 If `true`, the button is in disabled state and can't be clicked or toggled. 382 */ 383 @property bool disabled() 384 { 385 return isDisabled(); 386 } 387 /// ditto 388 @property void disabled(bool v) 389 { 390 setDisabled(v); 391 } 392 /** 393 $(I Deprecated.) This property has been deprecated due to redundancy and no longer has any effect when set. Please use $(D Control.focusMode) instead. 394 */ 395 @property Control.FocusMode enabledFocusMode() 396 { 397 return getEnabledFocusMode(); 398 } 399 /// ditto 400 @property void enabledFocusMode(long v) 401 { 402 setEnabledFocusMode(v); 403 } 404 /** 405 $(D ButtonGroup) associated to the button. 406 */ 407 @property ButtonGroup group() 408 { 409 return getButtonGroup(); 410 } 411 /// ditto 412 @property void group(ButtonGroup v) 413 { 414 setButtonGroup(v); 415 } 416 /** 417 If `true`, the button stays pressed when moving the cursor outside the button while pressing it. 418 $(B Note:) This property only affects the button's visual appearance. Signals will be emitted at the same moment regardless of this property's value. 419 */ 420 @property bool keepPressedOutside() 421 { 422 return isKeepPressedOutside(); 423 } 424 /// ditto 425 @property void keepPressedOutside(bool v) 426 { 427 setKeepPressedOutside(v); 428 } 429 /** 430 If `true`, the button's state is pressed. Means the button is pressed down or toggled (if $(D toggleMode) is active). 431 */ 432 @property bool pressed() 433 { 434 return isPressed(); 435 } 436 /// ditto 437 @property void pressed(bool v) 438 { 439 setPressed(v); 440 } 441 /** 442 $(D ShortCut) associated to the button. 443 */ 444 @property ShortCut shortcut() 445 { 446 return getShortcut(); 447 } 448 /// ditto 449 @property void shortcut(ShortCut v) 450 { 451 setShortcut(v); 452 } 453 /** 454 If `true`, the button will add information about its shortcut in the tooltip. 455 */ 456 @property bool shortcutInTooltip() 457 { 458 return isShortcutInTooltipEnabled(); 459 } 460 /// ditto 461 @property void shortcutInTooltip(bool v) 462 { 463 setShortcutInTooltip(v); 464 } 465 /** 466 If `true`, the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked. 467 */ 468 @property bool toggleMode() 469 { 470 return isToggleMode(); 471 } 472 /// ditto 473 @property void toggleMode(bool v) 474 { 475 setToggleMode(v); 476 } 477 }