1 /** 2 Generic input event 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.inputevent; 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.resource; 23 import godot.reference; 24 /** 25 Generic input event 26 27 Base class of all sort of input event. See $(D Node._input). 28 */ 29 @GodotBaseClass struct InputEvent 30 { 31 enum string _GODOT_internal_name = "InputEvent"; 32 public: 33 @nogc nothrow: 34 union { godot_object _godot_object; Resource _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct _classBinding 39 { 40 __gshared: 41 @GodotName("set_device") GodotMethod!(void, long) setDevice; 42 @GodotName("get_device") GodotMethod!(long) getDevice; 43 @GodotName("is_action") GodotMethod!(bool, String) isAction; 44 @GodotName("is_action_pressed") GodotMethod!(bool, String) isActionPressed; 45 @GodotName("is_action_released") GodotMethod!(bool, String) isActionReleased; 46 @GodotName("get_action_strength") GodotMethod!(double, String) getActionStrength; 47 @GodotName("is_pressed") GodotMethod!(bool) isPressed; 48 @GodotName("is_echo") GodotMethod!(bool) isEcho; 49 @GodotName("as_text") GodotMethod!(String) asText; 50 @GodotName("shortcut_match") GodotMethod!(bool, InputEvent) shortcutMatch; 51 @GodotName("is_action_type") GodotMethod!(bool) isActionType; 52 @GodotName("xformed_by") GodotMethod!(InputEvent, Transform2D, Vector2) xformedBy; 53 } 54 bool opEquals(in InputEvent other) const { return _godot_object.ptr is other._godot_object.ptr; } 55 InputEvent opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 56 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 57 mixin baseCasts; 58 static InputEvent _new() 59 { 60 static godot_class_constructor constructor; 61 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputEvent"); 62 if(constructor is null) return typeof(this).init; 63 return cast(InputEvent)(constructor()); 64 } 65 @disable new(size_t s); 66 /** 67 68 */ 69 void setDevice(in long device) 70 { 71 checkClassBinding!(typeof(this))(); 72 ptrcall!(void)(_classBinding.setDevice, _godot_object, device); 73 } 74 /** 75 76 */ 77 long getDevice() const 78 { 79 checkClassBinding!(typeof(this))(); 80 return ptrcall!(long)(_classBinding.getDevice, _godot_object); 81 } 82 /** 83 Returns `true` if this input event matches a pre-defined action of any type. 84 */ 85 bool isAction(StringArg0)(in StringArg0 action) const 86 { 87 checkClassBinding!(typeof(this))(); 88 return ptrcall!(bool)(_classBinding.isAction, _godot_object, action); 89 } 90 /** 91 Returns `true` if the given action is being pressed (and is not an echo event for KEY events). Not relevant for the event types `MOUSE_MOTION`, `SCREEN_DRAG` or `NONE`. 92 */ 93 bool isActionPressed(StringArg0)(in StringArg0 action) const 94 { 95 checkClassBinding!(typeof(this))(); 96 return ptrcall!(bool)(_classBinding.isActionPressed, _godot_object, action); 97 } 98 /** 99 Returns `true` if the given action is released (i.e. not pressed). Not relevant for the event types `MOUSE_MOTION`, `SCREEN_DRAG` or `NONE`. 100 */ 101 bool isActionReleased(StringArg0)(in StringArg0 action) const 102 { 103 checkClassBinding!(typeof(this))(); 104 return ptrcall!(bool)(_classBinding.isActionReleased, _godot_object, action); 105 } 106 /** 107 108 */ 109 double getActionStrength(StringArg0)(in StringArg0 action) const 110 { 111 checkClassBinding!(typeof(this))(); 112 return ptrcall!(double)(_classBinding.getActionStrength, _godot_object, action); 113 } 114 /** 115 Returns `true` if this input event is pressed. Not relevant for the event types `MOUSE_MOTION`, `SCREEN_DRAG` or `NONE`. 116 */ 117 bool isPressed() const 118 { 119 checkClassBinding!(typeof(this))(); 120 return ptrcall!(bool)(_classBinding.isPressed, _godot_object); 121 } 122 /** 123 Returns `true` if this input event is an echo event (only for events of type KEY). 124 */ 125 bool isEcho() const 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(bool)(_classBinding.isEcho, _godot_object); 129 } 130 /** 131 Returns a $(D String) representation of the event. 132 */ 133 String asText() const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(String)(_classBinding.asText, _godot_object); 137 } 138 /** 139 140 */ 141 bool shortcutMatch(InputEvent event) const 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(bool)(_classBinding.shortcutMatch, _godot_object, event); 145 } 146 /** 147 Returns `true` if this input event's type is one of the `InputEvent` constants. 148 */ 149 bool isActionType() const 150 { 151 checkClassBinding!(typeof(this))(); 152 return ptrcall!(bool)(_classBinding.isActionType, _godot_object); 153 } 154 /** 155 156 */ 157 Ref!InputEvent xformedBy(in Transform2D xform, in Vector2 local_ofs = Vector2(0, 0)) const 158 { 159 checkClassBinding!(typeof(this))(); 160 return ptrcall!(InputEvent)(_classBinding.xformedBy, _godot_object, xform, local_ofs); 161 } 162 /** 163 The event's device ID. 164 */ 165 @property long device() 166 { 167 return getDevice(); 168 } 169 /// ditto 170 @property void device(long v) 171 { 172 setDevice(v); 173 } 174 }