summaryrefslogtreecommitdiff
path: root/core/input/input.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/input/input.h')
-rw-r--r--core/input/input.h102
1 files changed, 60 insertions, 42 deletions
diff --git a/core/input/input.h b/core/input/input.h
index 2e136dbf02..91e3b83b95 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -36,7 +36,6 @@
#include "core/os/thread_safe.h"
class Input : public Object {
-
GDCLASS(Input, Object);
_THREAD_SAFE_CLASS_
@@ -100,7 +99,7 @@ public:
typedef void (*EventDispatchFunc)(const Ref<InputEvent> &p_event);
private:
- int mouse_button_mask;
+ int mouse_button_mask = 0;
Set<int> keys_pressed;
Set<int> joy_buttons_pressed;
@@ -111,7 +110,7 @@ private:
Vector3 magnetometer;
Vector3 gyroscope;
Vector2 mouse_pos;
- int64_t mouse_window;
+ int64_t mouse_window = 0;
struct Action {
uint64_t physics_frame;
@@ -122,13 +121,13 @@ private:
Map<StringName, Action> action_state;
- bool emulate_touch_from_mouse;
- bool emulate_mouse_from_touch;
+ bool emulate_touch_from_mouse = false;
+ bool emulate_mouse_from_touch = false;
+ bool use_accumulated_input = false;
- int mouse_from_touch_index;
+ int mouse_from_touch_index = -1;
struct SpeedTrack {
-
uint64_t last_tick;
Vector2 speed;
Vector2 accum;
@@ -144,37 +143,21 @@ private:
struct Joypad {
StringName name;
StringName uid;
- bool connected;
- bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android
- float last_axis[JOY_AXIS_MAX];
- float filter;
- int last_hat;
- int mapping;
- int hat_current;
-
- Joypad() {
- for (int i = 0; i < JOY_AXIS_MAX; i++) {
-
- last_axis[i] = 0.0f;
- }
- for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) {
-
- last_buttons[i] = false;
- }
- connected = false;
- last_hat = HAT_MASK_CENTER;
- filter = 0.01f;
- mapping = -1;
- hat_current = 0;
- }
+ bool connected = false;
+ bool last_buttons[JOY_BUTTON_MAX] = { false };
+ float last_axis[JOY_AXIS_MAX] = { 0.0f };
+ float filter = 0.01f;
+ int last_hat = HAT_MASK_CENTER;
+ int mapping = -1;
+ int hat_current = 0;
};
SpeedTrack mouse_speed_track;
Map<int, SpeedTrack> touch_speed_track;
Map<int, Joypad> joy_names;
- int fallback_mapping;
+ int fallback_mapping = -1;
- CursorShape default_shape;
+ CursorShape default_shape = CURSOR_ARROW;
enum JoyType {
TYPE_BUTTON,
@@ -183,26 +166,61 @@ private:
TYPE_MAX,
};
+ enum JoyAxisRange {
+ NEGATIVE_HALF_AXIS = -1,
+ FULL_AXIS = 0,
+ POSITIVE_HALF_AXIS = 1
+ };
+
struct JoyEvent {
int type;
int index;
- int value;
+ float value;
};
- struct JoyDeviceMapping {
+ struct JoyBinding {
+ JoyType inputType;
+ union {
+ int button;
+
+ struct {
+ int axis;
+ JoyAxisRange range;
+ bool invert;
+ } axis;
+
+ struct {
+ int hat;
+ HatMask hat_mask;
+ } hat;
+ } input;
+
+ JoyType outputType;
+ union {
+ JoyButtonList button;
+
+ struct {
+ JoyAxisList axis;
+ JoyAxisRange range;
+ } axis;
+
+ } output;
+ };
+
+ struct JoyDeviceMapping {
String uid;
String name;
- Map<int, JoyEvent> buttons;
- Map<int, JoyEvent> axis;
- JoyEvent hat[HAT_MAX];
+ Vector<JoyBinding> bindings;
};
- JoyEvent hat_map_default[HAT_MAX];
-
Vector<JoyDeviceMapping> map_db;
- JoyEvent _find_to_event(String p_to);
+ JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button);
+ JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, const JoyAxis &p_value);
+ void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]);
+ JoyButtonList _get_output_button(String output);
+ JoyAxisList _get_output_axis(String output);
void _button_event(int p_device, int p_index, bool p_pressed);
void _axis_event(int p_device, int p_axis, float p_value);
float _handle_deadzone(int p_device, int p_axis, float p_value);
@@ -210,7 +228,7 @@ private:
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
List<Ref<InputEvent>> accumulated_events;
- bool use_accumulated_input;
+
friend class DisplayServer;
static void (*set_mouse_mode_func)(MouseMode);
@@ -220,7 +238,7 @@ private:
static CursorShape (*get_current_cursor_shape_func)();
static void (*set_custom_mouse_cursor_func)(const RES &, CursorShape, const Vector2 &);
- EventDispatchFunc event_dispatch_function;
+ EventDispatchFunc event_dispatch_function = nullptr;
protected:
struct VibrationInfo {