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.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.control; 23 import godot.inputevent; 24 import godot.shortcut; 25 import godot.buttongroup; 26 import godot.canvasitem; 27 import godot.node; 28 /** 29 Base class for different kinds of buttons. 30 31 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. 32 */ 33 @GodotBaseClass struct BaseButton 34 { 35 enum string _GODOT_internal_name = "BaseButton"; 36 public: 37 @nogc nothrow: 38 union { godot_object _godot_object; Control _GODOT_base; } 39 alias _GODOT_base this; 40 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 41 package(godot) __gshared bool _classBindingInitialized = false; 42 package(godot) static struct _classBinding 43 { 44 __gshared: 45 @GodotName("_pressed") GodotMethod!(void) _pressed; 46 @GodotName("_toggled") GodotMethod!(void, bool) _toggled; 47 @GodotName("_gui_input") GodotMethod!(void, InputEvent) _guiInput; 48 @GodotName("_unhandled_input") GodotMethod!(void, InputEvent) _unhandledInput; 49 @GodotName("set_pressed") GodotMethod!(void, bool) setPressed; 50 @GodotName("is_pressed") GodotMethod!(bool) isPressed; 51 @GodotName("is_hovered") GodotMethod!(bool) isHovered; 52 @GodotName("set_toggle_mode") GodotMethod!(void, bool) setToggleMode; 53 @GodotName("is_toggle_mode") GodotMethod!(bool) isToggleMode; 54 @GodotName("set_disabled") GodotMethod!(void, bool) setDisabled; 55 @GodotName("is_disabled") GodotMethod!(bool) isDisabled; 56 @GodotName("set_action_mode") GodotMethod!(void, long) setActionMode; 57 @GodotName("get_action_mode") GodotMethod!(BaseButton.ActionMode) getActionMode; 58 @GodotName("set_button_mask") GodotMethod!(void, long) setButtonMask; 59 @GodotName("get_button_mask") GodotMethod!(long) getButtonMask; 60 @GodotName("get_draw_mode") GodotMethod!(BaseButton.DrawMode) getDrawMode; 61 @GodotName("set_enabled_focus_mode") GodotMethod!(void, long) setEnabledFocusMode; 62 @GodotName("get_enabled_focus_mode") GodotMethod!(Control.FocusMode) getEnabledFocusMode; 63 @GodotName("set_shortcut") GodotMethod!(void, ShortCut) setShortcut; 64 @GodotName("get_shortcut") GodotMethod!(ShortCut) getShortcut; 65 @GodotName("set_button_group") GodotMethod!(void, ButtonGroup) setButtonGroup; 66 @GodotName("get_button_group") GodotMethod!(ButtonGroup) getButtonGroup; 67 } 68 bool opEquals(in BaseButton other) const { return _godot_object.ptr is other._godot_object.ptr; } 69 BaseButton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 70 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 71 mixin baseCasts; 72 static BaseButton _new() 73 { 74 static godot_class_constructor constructor; 75 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("BaseButton"); 76 if(constructor is null) return typeof(this).init; 77 return cast(BaseButton)(constructor()); 78 } 79 @disable new(size_t s); 80 /// 81 enum ActionMode : int 82 { 83 /** 84 Require just a press to consider the button clicked. 85 */ 86 actionModeButtonPress = 0, 87 /** 88 Require a press and a subsequent release before considering the button clicked. 89 */ 90 actionModeButtonRelease = 1, 91 } 92 /// 93 enum DrawMode : int 94 { 95 /** 96 The normal state (i.e. not pressed, not hovered, not toggled and enabled) of buttons. 97 */ 98 drawNormal = 0, 99 /** 100 The state of buttons are pressed. 101 */ 102 drawPressed = 1, 103 /** 104 The state of buttons are hovered. 105 */ 106 drawHover = 2, 107 /** 108 The state of buttons are disabled. 109 */ 110 drawDisabled = 3, 111 /** 112 113 */ 114 drawHoverPressed = 4, 115 } 116 /// 117 enum Constants : int 118 { 119 drawNormal = 0, 120 actionModeButtonPress = 0, 121 drawPressed = 1, 122 actionModeButtonRelease = 1, 123 drawHover = 2, 124 drawDisabled = 3, 125 drawHoverPressed = 4, 126 } 127 /** 128 Called when the button is pressed. 129 */ 130 void _pressed() 131 { 132 Array _GODOT_args = Array.empty_array; 133 String _GODOT_method_name = String("_pressed"); 134 this.callv(_GODOT_method_name, _GODOT_args); 135 } 136 /** 137 Called when the button is toggled (only if toggle_mode is active). 138 */ 139 void _toggled(in bool button_pressed) 140 { 141 Array _GODOT_args = Array.empty_array; 142 _GODOT_args.append(button_pressed); 143 String _GODOT_method_name = String("_toggled"); 144 this.callv(_GODOT_method_name, _GODOT_args); 145 } 146 /** 147 148 */ 149 void _guiInput(InputEvent arg0) 150 { 151 Array _GODOT_args = Array.empty_array; 152 _GODOT_args.append(arg0); 153 String _GODOT_method_name = String("_gui_input"); 154 this.callv(_GODOT_method_name, _GODOT_args); 155 } 156 /** 157 158 */ 159 void _unhandledInput(InputEvent arg0) 160 { 161 Array _GODOT_args = Array.empty_array; 162 _GODOT_args.append(arg0); 163 String _GODOT_method_name = String("_unhandled_input"); 164 this.callv(_GODOT_method_name, _GODOT_args); 165 } 166 /** 167 168 */ 169 void setPressed(in bool pressed) 170 { 171 checkClassBinding!(typeof(this))(); 172 ptrcall!(void)(_classBinding.setPressed, _godot_object, pressed); 173 } 174 /** 175 176 */ 177 bool isPressed() const 178 { 179 checkClassBinding!(typeof(this))(); 180 return ptrcall!(bool)(_classBinding.isPressed, _godot_object); 181 } 182 /** 183 Return true if the mouse has entered the button and has not left it yet. 184 */ 185 bool isHovered() const 186 { 187 checkClassBinding!(typeof(this))(); 188 return ptrcall!(bool)(_classBinding.isHovered, _godot_object); 189 } 190 /** 191 192 */ 193 void setToggleMode(in bool enabled) 194 { 195 checkClassBinding!(typeof(this))(); 196 ptrcall!(void)(_classBinding.setToggleMode, _godot_object, enabled); 197 } 198 /** 199 200 */ 201 bool isToggleMode() const 202 { 203 checkClassBinding!(typeof(this))(); 204 return ptrcall!(bool)(_classBinding.isToggleMode, _godot_object); 205 } 206 /** 207 208 */ 209 void setDisabled(in bool disabled) 210 { 211 checkClassBinding!(typeof(this))(); 212 ptrcall!(void)(_classBinding.setDisabled, _godot_object, disabled); 213 } 214 /** 215 216 */ 217 bool isDisabled() const 218 { 219 checkClassBinding!(typeof(this))(); 220 return ptrcall!(bool)(_classBinding.isDisabled, _godot_object); 221 } 222 /** 223 224 */ 225 void setActionMode(in long mode) 226 { 227 checkClassBinding!(typeof(this))(); 228 ptrcall!(void)(_classBinding.setActionMode, _godot_object, mode); 229 } 230 /** 231 232 */ 233 BaseButton.ActionMode getActionMode() const 234 { 235 checkClassBinding!(typeof(this))(); 236 return ptrcall!(BaseButton.ActionMode)(_classBinding.getActionMode, _godot_object); 237 } 238 /** 239 240 */ 241 void setButtonMask(in long mask) 242 { 243 checkClassBinding!(typeof(this))(); 244 ptrcall!(void)(_classBinding.setButtonMask, _godot_object, mask); 245 } 246 /** 247 248 */ 249 long getButtonMask() const 250 { 251 checkClassBinding!(typeof(this))(); 252 return ptrcall!(long)(_classBinding.getButtonMask, _godot_object); 253 } 254 /** 255 Return 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 DRAW_* enum. 256 */ 257 BaseButton.DrawMode getDrawMode() const 258 { 259 checkClassBinding!(typeof(this))(); 260 return ptrcall!(BaseButton.DrawMode)(_classBinding.getDrawMode, _godot_object); 261 } 262 /** 263 264 */ 265 void setEnabledFocusMode(in long mode) 266 { 267 checkClassBinding!(typeof(this))(); 268 ptrcall!(void)(_classBinding.setEnabledFocusMode, _godot_object, mode); 269 } 270 /** 271 272 */ 273 Control.FocusMode getEnabledFocusMode() const 274 { 275 checkClassBinding!(typeof(this))(); 276 return ptrcall!(Control.FocusMode)(_classBinding.getEnabledFocusMode, _godot_object); 277 } 278 /** 279 280 */ 281 void setShortcut(ShortCut shortcut) 282 { 283 checkClassBinding!(typeof(this))(); 284 ptrcall!(void)(_classBinding.setShortcut, _godot_object, shortcut); 285 } 286 /** 287 288 */ 289 Ref!ShortCut getShortcut() const 290 { 291 checkClassBinding!(typeof(this))(); 292 return ptrcall!(ShortCut)(_classBinding.getShortcut, _godot_object); 293 } 294 /** 295 296 */ 297 void setButtonGroup(ButtonGroup button_group) 298 { 299 checkClassBinding!(typeof(this))(); 300 ptrcall!(void)(_classBinding.setButtonGroup, _godot_object, button_group); 301 } 302 /** 303 304 */ 305 Ref!ButtonGroup getButtonGroup() const 306 { 307 checkClassBinding!(typeof(this))(); 308 return ptrcall!(ButtonGroup)(_classBinding.getButtonGroup, _godot_object); 309 } 310 /** 311 If `true` the button is in disabled state and can't be clicked or toggled. 312 */ 313 @property bool disabled() 314 { 315 return isDisabled(); 316 } 317 /// ditto 318 @property void disabled(bool v) 319 { 320 setDisabled(v); 321 } 322 /** 323 If `true` the button is in toggle mode. Makes the button flip state between pressed and unpressed each time its area is clicked. 324 */ 325 @property bool toggleMode() 326 { 327 return isToggleMode(); 328 } 329 /// ditto 330 @property void toggleMode(bool v) 331 { 332 setToggleMode(v); 333 } 334 /** 335 If `true` the button's state is pressed. Means the button is pressed down or toggled (if toggle_mode is active). 336 */ 337 @property bool pressed() 338 { 339 return isPressed(); 340 } 341 /// ditto 342 @property void pressed(bool v) 343 { 344 setPressed(v); 345 } 346 /** 347 Determines when the button is considered clicked, one of the ACTION_MODE_* constants. 348 */ 349 @property BaseButton.ActionMode actionMode() 350 { 351 return getActionMode(); 352 } 353 /// ditto 354 @property void actionMode(long v) 355 { 356 setActionMode(v); 357 } 358 /** 359 Binary mask to choose which mouse buttons this button will respond to. 360 To allow both left-click and right-click, set this to 3, because it's BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT. 361 */ 362 @property long buttonMask() 363 { 364 return getButtonMask(); 365 } 366 /// ditto 367 @property void buttonMask(long v) 368 { 369 setButtonMask(v); 370 } 371 /** 372 Focus access mode to use when switching between enabled/disabled (see $(D Control.setFocusMode) and $(D disabled)). 373 */ 374 @property Control.FocusMode enabledFocusMode() 375 { 376 return getEnabledFocusMode(); 377 } 378 /// ditto 379 @property void enabledFocusMode(long v) 380 { 381 setEnabledFocusMode(v); 382 } 383 /** 384 $(D Shortcut) associated to the button. 385 */ 386 @property ShortCut shortcut() 387 { 388 return getShortcut(); 389 } 390 /// ditto 391 @property void shortcut(ShortCut v) 392 { 393 setShortcut(v); 394 } 395 /** 396 $(D ButtonGroup) associated to the button. 397 */ 398 @property ButtonGroup group() 399 { 400 return getButtonGroup(); 401 } 402 /// ditto 403 @property void group(ButtonGroup v) 404 { 405 setButtonGroup(v); 406 } 407 }