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.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.resource;
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 	package(godot) 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 GDNativeClassBinding
39 	{
40 		__gshared:
41 		@GodotName("accumulate") GodotMethod!(bool, InputEvent) accumulate;
42 		@GodotName("as_text") GodotMethod!(String) asText;
43 		@GodotName("get_action_strength") GodotMethod!(double, String) getActionStrength;
44 		@GodotName("get_device") GodotMethod!(long) getDevice;
45 		@GodotName("is_action") GodotMethod!(bool, String) isAction;
46 		@GodotName("is_action_pressed") GodotMethod!(bool, String, bool) isActionPressed;
47 		@GodotName("is_action_released") GodotMethod!(bool, String) isActionReleased;
48 		@GodotName("is_action_type") GodotMethod!(bool) isActionType;
49 		@GodotName("is_echo") GodotMethod!(bool) isEcho;
50 		@GodotName("is_pressed") GodotMethod!(bool) isPressed;
51 		@GodotName("set_device") GodotMethod!(void, long) setDevice;
52 		@GodotName("shortcut_match") GodotMethod!(bool, InputEvent) shortcutMatch;
53 		@GodotName("xformed_by") GodotMethod!(InputEvent, Transform2D, Vector2) xformedBy;
54 	}
55 	/// 
56 	pragma(inline, true) bool opEquals(in InputEvent other) const
57 	{ return _godot_object.ptr is other._godot_object.ptr; }
58 	/// 
59 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
60 	{ _godot_object.ptr = n; return null; }
61 	/// 
62 	pragma(inline, true) bool opEquals(typeof(null) n) const
63 	{ return _godot_object.ptr is n; }
64 	/// 
65 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
66 	mixin baseCasts;
67 	/// Construct a new instance of InputEvent.
68 	/// Note: use `memnew!InputEvent` instead.
69 	static InputEvent _new()
70 	{
71 		static godot_class_constructor constructor;
72 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("InputEvent");
73 		if(constructor is null) return typeof(this).init;
74 		return cast(InputEvent)(constructor());
75 	}
76 	@disable new(size_t s);
77 	/**
78 	Returns `true` if the given input event and this input event can be added together (only for events of type $(D InputEventMouseMotion)).
79 	The given input event's position, global position and speed will be copied. The resulting `relative` is a sum of both events. Both events' modifiers have to be identical.
80 	*/
81 	bool accumulate(InputEvent with_event)
82 	{
83 		checkClassBinding!(typeof(this))();
84 		return ptrcall!(bool)(GDNativeClassBinding.accumulate, _godot_object, with_event);
85 	}
86 	/**
87 	Returns a $(D String) representation of the event.
88 	*/
89 	String asText() const
90 	{
91 		checkClassBinding!(typeof(this))();
92 		return ptrcall!(String)(GDNativeClassBinding.asText, _godot_object);
93 	}
94 	/**
95 	Returns a value between 0.0 and 1.0 depending on the given actions' state. Useful for getting the value of events of type $(D InputEventJoypadMotion).
96 	*/
97 	double getActionStrength(in String action) const
98 	{
99 		checkClassBinding!(typeof(this))();
100 		return ptrcall!(double)(GDNativeClassBinding.getActionStrength, _godot_object, action);
101 	}
102 	/**
103 	
104 	*/
105 	long getDevice() const
106 	{
107 		checkClassBinding!(typeof(this))();
108 		return ptrcall!(long)(GDNativeClassBinding.getDevice, _godot_object);
109 	}
110 	/**
111 	Returns `true` if this input event matches a pre-defined action of any type.
112 	*/
113 	bool isAction(in String action) const
114 	{
115 		checkClassBinding!(typeof(this))();
116 		return ptrcall!(bool)(GDNativeClassBinding.isAction, _godot_object, action);
117 	}
118 	/**
119 	Returns `true` if the given action is being pressed (and is not an echo event for $(D InputEventKey) events, unless `allow_echo` is `true`). Not relevant for events of type $(D InputEventMouseMotion) or $(D InputEventScreenDrag).
120 	*/
121 	bool isActionPressed(in String action, in bool allow_echo = false) const
122 	{
123 		checkClassBinding!(typeof(this))();
124 		return ptrcall!(bool)(GDNativeClassBinding.isActionPressed, _godot_object, action, allow_echo);
125 	}
126 	/**
127 	Returns `true` if the given action is released (i.e. not pressed). Not relevant for events of type $(D InputEventMouseMotion) or $(D InputEventScreenDrag).
128 	*/
129 	bool isActionReleased(in String action) const
130 	{
131 		checkClassBinding!(typeof(this))();
132 		return ptrcall!(bool)(GDNativeClassBinding.isActionReleased, _godot_object, action);
133 	}
134 	/**
135 	Returns `true` if this input event's type is one that can be assigned to an input action.
136 	*/
137 	bool isActionType() const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(bool)(GDNativeClassBinding.isActionType, _godot_object);
141 	}
142 	/**
143 	Returns `true` if this input event is an echo event (only for events of type $(D InputEventKey)).
144 	*/
145 	bool isEcho() const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(bool)(GDNativeClassBinding.isEcho, _godot_object);
149 	}
150 	/**
151 	Returns `true` if this input event is pressed. Not relevant for events of type $(D InputEventMouseMotion) or $(D InputEventScreenDrag).
152 	*/
153 	bool isPressed() const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(bool)(GDNativeClassBinding.isPressed, _godot_object);
157 	}
158 	/**
159 	
160 	*/
161 	void setDevice(in long device)
162 	{
163 		checkClassBinding!(typeof(this))();
164 		ptrcall!(void)(GDNativeClassBinding.setDevice, _godot_object, device);
165 	}
166 	/**
167 	Returns `true` if the given input event is checking for the same key ($(D InputEventKey)), button ($(D InputEventJoypadButton)) or action ($(D InputEventAction)).
168 	*/
169 	bool shortcutMatch(InputEvent event) const
170 	{
171 		checkClassBinding!(typeof(this))();
172 		return ptrcall!(bool)(GDNativeClassBinding.shortcutMatch, _godot_object, event);
173 	}
174 	/**
175 	Returns a copy of the given input event which has been offset by `local_ofs` and transformed by `xform`. Relevant for events of type $(D InputEventMouseButton), $(D InputEventMouseMotion), $(D InputEventScreenTouch), $(D InputEventScreenDrag), $(D InputEventMagnifyGesture) and $(D InputEventPanGesture).
176 	*/
177 	Ref!InputEvent xformedBy(in Transform2D xform, in Vector2 local_ofs = Vector2(0, 0)) const
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(InputEvent)(GDNativeClassBinding.xformedBy, _godot_object, xform, local_ofs);
181 	}
182 	/**
183 	The event's device ID.
184 	$(B Note:) This device ID will always be `-1` for emulated mouse input from a touchscreen. This can be used to distinguish emulated mouse input from physical mouse input.
185 	*/
186 	@property long device()
187 	{
188 		return getDevice();
189 	}
190 	/// ditto
191 	@property void device(long v)
192 	{
193 		setDevice(v);
194 	}
195 }