summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/core_constants.cpp4
-rw-r--r--core/input/input.cpp94
-rw-r--r--core/input/input.h46
-rw-r--r--core/input/input_enums.h126
-rw-r--r--core/input/input_event.cpp18
-rw-r--r--core/input/input_event.h93
-rw-r--r--core/os/midi_driver.cpp8
-rw-r--r--core/variant/binder_common.h7
-rw-r--r--doc/classes/DisplayServer.xml2
-rw-r--r--doc/classes/Input.xml6
-rw-r--r--doc/classes/InputEventJoypadButton.xml2
-rw-r--r--doc/classes/InputEventJoypadMotion.xml2
-rw-r--r--doc/classes/InputEventMIDI.xml2
-rw-r--r--doc/classes/InputEventMouseButton.xml2
-rw-r--r--editor/action_map_editor.cpp10
-rw-r--r--editor/plugins/curve_editor_plugin.cpp2
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp2
-rw-r--r--editor/plugins/script_editor_plugin.cpp4
-rw-r--r--modules/gdnative/xr/xr_interface_gdnative.cpp4
-rw-r--r--platform/android/display_server_android.cpp28
-rw-r--r--platform/android/display_server_android.h10
-rw-r--r--platform/android/java_godot_lib_jni.cpp8
-rw-r--r--platform/javascript/display_server_javascript.cpp8
-rw-r--r--platform/linuxbsd/display_server_x11.cpp22
-rw-r--r--platform/linuxbsd/display_server_x11.h6
-rw-r--r--platform/linuxbsd/joypad_linux.cpp20
-rw-r--r--platform/osx/display_server_osx.h4
-rw-r--r--platform/osx/display_server_osx.mm15
-rw-r--r--platform/osx/joypad_osx.cpp26
-rw-r--r--platform/uwp/app.cpp6
-rw-r--r--platform/uwp/os_uwp.cpp4
-rw-r--r--platform/uwp/os_uwp.h4
-rw-r--r--platform/windows/display_server_windows.cpp26
-rw-r--r--platform/windows/display_server_windows.h4
-rw-r--r--platform/windows/joypad_windows.cpp28
-rw-r--r--scene/3d/xr_nodes.cpp6
-rw-r--r--scene/gui/code_edit.cpp2
-rw-r--r--scene/gui/spin_box.cpp2
-rw-r--r--scene/gui/tree.cpp2
-rw-r--r--scene/main/viewport.cpp10
-rw-r--r--servers/display_server.cpp4
-rw-r--r--servers/display_server.h2
42 files changed, 368 insertions, 313 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 7fc09fc3a6..9f5f8f733f 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -106,10 +106,6 @@ static Vector<_CoreConstant> _global_constants;
VARIANT_ENUM_CAST(Key);
VARIANT_ENUM_CAST(KeyModifierMask);
-VARIANT_ENUM_CAST(MouseButton);
-VARIANT_ENUM_CAST(JoyButton);
-VARIANT_ENUM_CAST(JoyAxis);
-VARIANT_ENUM_CAST(MIDIMessage);
void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(SIDE_LEFT);
diff --git a/core/input/input.cpp b/core/input/input.cpp
index be536aa730..a712394b35 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -227,7 +227,7 @@ bool Input::is_key_pressed(int p_keycode) const {
return keys_pressed.has(p_keycode);
}
-bool Input::is_mouse_button_pressed(int p_button) const {
+bool Input::is_mouse_button_pressed(MouseButton p_button) const {
_THREAD_SAFE_METHOD_
return (mouse_button_mask & (1 << (p_button - 1))) != 0;
}
@@ -236,7 +236,7 @@ static int _combine_device(int p_value, int p_device) {
return p_value | (p_device << 20);
}
-bool Input::is_joy_button_pressed(int p_device, int p_button) const {
+bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
_THREAD_SAFE_METHOD_
return joy_buttons_pressed.has(_combine_device(p_button, p_device));
}
@@ -352,7 +352,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po
return vector;
}
-float Input::get_joy_axis(int p_device, int p_axis) const {
+float Input::get_joy_axis(int p_device, JoyAxis p_axis) const {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
if (_joy_axis.has(c)) {
@@ -433,7 +433,7 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S
joy_buttons_pressed.erase(c);
}
for (int i = 0; i < JOY_AXIS_MAX; i++) {
- set_joy_axis(p_idx, i, 0.0f);
+ set_joy_axis(p_idx, (JoyAxis)i, 0.0f);
}
}
joy_names[p_idx] = js;
@@ -488,9 +488,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (mb.is_valid()) {
if (mb->is_pressed()) {
- mouse_button_mask |= (1 << (mb->get_button_index() - 1));
+ mouse_button_mask |= (MouseButton)(1 << (mb->get_button_index() - 1));
} else {
- mouse_button_mask &= ~(1 << (mb->get_button_index() - 1));
+ mouse_button_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1));
}
Point2 pos = mb->get_global_position();
@@ -563,9 +563,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
button_event->set_pressed(st->is_pressed());
button_event->set_button_index(MOUSE_BUTTON_LEFT);
if (st->is_pressed()) {
- button_event->set_button_mask(mouse_button_mask | (1 << (MOUSE_BUTTON_LEFT - 1)));
+ button_event->set_button_mask(MouseButton(mouse_button_mask | MOUSE_BUTTON_MASK_LEFT));
} else {
- button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1)));
+ button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT));
}
_parse_input_event_impl(button_event, true);
@@ -644,7 +644,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
}
}
-void Input::set_joy_axis(int p_device, int p_axis, float p_value) {
+void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {
_THREAD_SAFE_METHOD_
int c = _combine_device(p_axis, p_device);
_joy_axis[c] = p_value;
@@ -794,7 +794,7 @@ void Input::ensure_touch_mouse_raised() {
button_event->set_global_position(mouse_pos);
button_event->set_pressed(false);
button_event->set_button_index(MOUSE_BUTTON_LEFT);
- button_event->set_button_mask(mouse_button_mask & ~(1 << (MOUSE_BUTTON_LEFT - 1)));
+ button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT));
_parse_input_event_impl(button_event, true);
}
@@ -882,7 +882,7 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) {
event_dispatch_function = p_function;
}
-void Input::joy_button(int p_device, int p_button, bool p_pressed) {
+void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
_THREAD_SAFE_METHOD_;
Joypad &joy = joy_names[p_device];
//printf("got button %i, mapping is %i\n", p_button, joy.mapping);
@@ -898,17 +898,17 @@ void Input::joy_button(int p_device, int p_button, bool p_pressed) {
JoyEvent map = _get_mapped_button_event(map_db[joy.mapping], p_button);
if (map.type == TYPE_BUTTON) {
- _button_event(p_device, map.index, p_pressed);
+ _button_event(p_device, (JoyButton)map.index, p_pressed);
return;
}
if (map.type == TYPE_AXIS) {
- _axis_event(p_device, map.index, p_pressed ? map.value : 0.0);
+ _axis_event(p_device, (JoyAxis)map.index, p_pressed ? map.value : 0.0);
}
// no event?
}
-void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) {
+void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) {
_THREAD_SAFE_METHOD_;
ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX);
@@ -949,7 +949,7 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) {
// Button already pressed or released; so ignore.
return;
}
- _button_event(p_device, map.index, pressed);
+ _button_event(p_device, (JoyButton)map.index, pressed);
// Ensure opposite D-Pad button is also released.
switch (map.index) {
@@ -981,7 +981,7 @@ void Input::joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value) {
}
if (map.type == TYPE_AXIS) {
- _axis_event(p_device, map.index, map.value);
+ _axis_event(p_device, (JoyAxis)map.index, map.value);
return;
}
//printf("invalid mapping\n");
@@ -993,24 +993,24 @@ void Input::joy_hat(int p_device, int p_val) {
JoyEvent map[HAT_MAX];
- map[HAT_UP].type = TYPE_BUTTON;
- map[HAT_UP].index = JOY_BUTTON_DPAD_UP;
- map[HAT_UP].value = 0;
+ map[HatDir::HAT_UP].type = TYPE_BUTTON;
+ map[HatDir::HAT_UP].index = JOY_BUTTON_DPAD_UP;
+ map[HatDir::HAT_UP].value = 0;
- map[HAT_RIGHT].type = TYPE_BUTTON;
- map[HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT;
- map[HAT_RIGHT].value = 0;
+ map[HatDir::HAT_RIGHT].type = TYPE_BUTTON;
+ map[HatDir::HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT;
+ map[HatDir::HAT_RIGHT].value = 0;
- map[HAT_DOWN].type = TYPE_BUTTON;
- map[HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN;
- map[HAT_DOWN].value = 0;
+ map[HatDir::HAT_DOWN].type = TYPE_BUTTON;
+ map[HatDir::HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN;
+ map[HatDir::HAT_DOWN].value = 0;
- map[HAT_LEFT].type = TYPE_BUTTON;
- map[HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT;
- map[HAT_LEFT].value = 0;
+ map[HatDir::HAT_LEFT].type = TYPE_BUTTON;
+ map[HatDir::HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT;
+ map[HatDir::HAT_LEFT].value = 0;
if (joy.mapping != -1) {
- _get_mapped_hat_events(map_db[joy.mapping], 0, map);
+ _get_mapped_hat_events(map_db[joy.mapping], (HatDir)0, map);
}
int cur_val = joy_names[p_device].hat_current;
@@ -1018,10 +1018,10 @@ void Input::joy_hat(int p_device, int p_val) {
for (int hat_direction = 0, hat_mask = 1; hat_direction < HAT_MAX; hat_direction++, hat_mask <<= 1) {
if ((p_val & hat_mask) != (cur_val & hat_mask)) {
if (map[hat_direction].type == TYPE_BUTTON) {
- _button_event(p_device, map[hat_direction].index, p_val & hat_mask);
+ _button_event(p_device, (JoyButton)map[hat_direction].index, p_val & hat_mask);
}
if (map[hat_direction].type == TYPE_AXIS) {
- _axis_event(p_device, map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0);
+ _axis_event(p_device, (JoyAxis)map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0);
}
}
}
@@ -1029,7 +1029,7 @@ void Input::joy_hat(int p_device, int p_val) {
joy_names[p_device].hat_current = p_val;
}
-void Input::_button_event(int p_device, int p_index, bool p_pressed) {
+void Input::_button_event(int p_device, JoyButton p_index, bool p_pressed) {
Ref<InputEventJoypadButton> ievent;
ievent.instantiate();
ievent->set_device(p_device);
@@ -1039,7 +1039,7 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) {
parse_input_event(ievent);
}
-void Input::_axis_event(int p_device, int p_axis, float p_value) {
+void Input::_axis_event(int p_device, JoyAxis p_axis, float p_value) {
Ref<InputEventJoypadMotion> ievent;
ievent.instantiate();
ievent->set_device(p_device);
@@ -1049,7 +1049,7 @@ void Input::_axis_event(int p_device, int p_axis, float p_value) {
parse_input_event(ievent);
}
-Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button) {
+Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button) {
JoyEvent event;
event.type = TYPE_MAX;
@@ -1085,7 +1085,7 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping,
return event;
}
-Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value) {
+Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value) {
JoyEvent event;
event.type = TYPE_MAX;
@@ -1156,23 +1156,23 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, i
return event;
}
-void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[]) {
+void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[]) {
for (int i = 0; i < mapping.bindings.size(); i++) {
const JoyBinding binding = mapping.bindings[i];
if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) {
int hat_direction;
switch (binding.input.hat.hat_mask) {
- case HAT_MASK_UP:
- hat_direction = HAT_UP;
+ case HatMask::HAT_MASK_UP:
+ hat_direction = HatDir::HAT_UP;
break;
- case HAT_MASK_RIGHT:
- hat_direction = HAT_RIGHT;
+ case HatMask::HAT_MASK_RIGHT:
+ hat_direction = HatDir::HAT_RIGHT;
break;
- case HAT_MASK_DOWN:
- hat_direction = HAT_DOWN;
+ case HatMask::HAT_MASK_DOWN:
+ hat_direction = HatDir::HAT_DOWN;
break;
- case HAT_MASK_LEFT:
- hat_direction = HAT_LEFT;
+ case HatMask::HAT_MASK_LEFT:
+ hat_direction = HatDir::HAT_LEFT;
break;
default:
ERR_PRINT_ONCE("Joypad button mapping error.");
@@ -1300,11 +1300,11 @@ void Input::parse_mapping(String p_mapping) {
switch (input[0]) {
case 'b':
binding.inputType = TYPE_BUTTON;
- binding.input.button = input.substr(1).to_int();
+ binding.input.button = (JoyButton)input.substr(1).to_int();
break;
case 'a':
binding.inputType = TYPE_AXIS;
- binding.input.axis.axis = input.substr(1).to_int();
+ binding.input.axis.axis = (JoyAxis)input.substr(1).to_int();
binding.input.axis.range = input_range;
binding.input.axis.invert = invert_axis;
break;
@@ -1312,7 +1312,7 @@ void Input::parse_mapping(String p_mapping) {
ERR_CONTINUE_MSG(input.length() != 4 || input[2] != '.',
String(entry[idx] + "\nInvalid hat input: " + input));
binding.inputType = TYPE_HAT;
- binding.input.hat.hat = input.substr(1, 1).to_int();
+ binding.input.hat.hat = (HatDir)input.substr(1, 1).to_int();
binding.input.hat.hat_mask = static_cast<HatMask>(input.substr(3).to_int());
break;
default:
diff --git a/core/input/input.h b/core/input/input.h
index ecb4981b13..fbcd5836ea 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -72,22 +72,6 @@ public:
CURSOR_MAX
};
- enum HatMask {
- HAT_MASK_CENTER = 0,
- HAT_MASK_UP = 1,
- HAT_MASK_RIGHT = 2,
- HAT_MASK_DOWN = 4,
- HAT_MASK_LEFT = 8,
- };
-
- enum HatDir {
- HAT_UP,
- HAT_RIGHT,
- HAT_DOWN,
- HAT_LEFT,
- HAT_MAX,
- };
-
enum {
JOYPADS_MAX = 16,
};
@@ -149,7 +133,7 @@ private:
bool connected = false;
bool last_buttons[JOY_BUTTON_MAX] = { false };
float last_axis[JOY_AXIS_MAX] = { 0.0f };
- int last_hat = HAT_MASK_CENTER;
+ int last_hat = HatMask::HAT_MASK_CENTER;
int mapping = -1;
int hat_current = 0;
};
@@ -183,16 +167,16 @@ private:
struct JoyBinding {
JoyType inputType;
union {
- int button;
+ JoyButton button;
struct {
- int axis;
+ JoyAxis axis;
JoyAxisRange range;
bool invert;
} axis;
struct {
- int hat;
+ HatDir hat;
HatMask hat_mask;
} hat;
@@ -218,13 +202,13 @@ private:
Vector<JoyDeviceMapping> map_db;
- JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, int p_button);
- JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, int p_axis, float p_value);
- void _get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, JoyEvent r_events[HAT_MAX]);
+ JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button);
+ JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value);
+ void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[HAT_MAX]);
JoyButton _get_output_button(String output);
JoyAxis _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);
+ void _button_event(int p_device, JoyButton p_index, bool p_pressed);
+ void _axis_event(int p_device, JoyAxis p_axis, float p_value);
void _parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_emulated);
@@ -261,8 +245,8 @@ public:
static Input *get_singleton();
bool is_key_pressed(int p_keycode) const;
- bool is_mouse_button_pressed(int p_button) const;
- bool is_joy_button_pressed(int p_device, int p_button) const;
+ bool is_mouse_button_pressed(MouseButton p_button) const;
+ bool is_joy_button_pressed(int p_device, JoyButton p_button) const;
bool is_action_pressed(const StringName &p_action, bool p_exact = false) const;
bool is_action_just_pressed(const StringName &p_action, bool p_exact = false) const;
bool is_action_just_released(const StringName &p_action, bool p_exact = false) const;
@@ -272,7 +256,7 @@ public:
float get_axis(const StringName &p_negative_action, const StringName &p_positive_action) const;
Vector2 get_vector(const StringName &p_negative_x, const StringName &p_positive_x, const StringName &p_negative_y, const StringName &p_positive_y, float p_deadzone = -1.0f) const;
- float get_joy_axis(int p_device, int p_axis) const;
+ float get_joy_axis(int p_device, JoyAxis p_axis) const;
String get_joy_name(int p_idx);
Array get_connected_joypads();
Vector2 get_joy_vibration_strength(int p_device);
@@ -299,7 +283,7 @@ public:
void set_accelerometer(const Vector3 &p_accel);
void set_magnetometer(const Vector3 &p_magnetometer);
void set_gyroscope(const Vector3 &p_gyroscope);
- void set_joy_axis(int p_device, int p_axis, float p_value);
+ void set_joy_axis(int p_device, JoyAxis p_axis, float p_value);
void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0);
void stop_joy_vibration(int p_device);
@@ -325,8 +309,8 @@ public:
void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape = Input::CURSOR_ARROW, const Vector2 &p_hotspot = Vector2());
void parse_mapping(String p_mapping);
- void joy_button(int p_device, int p_button, bool p_pressed);
- void joy_axis(int p_device, int p_axis, const JoyAxisValue &p_value);
+ void joy_button(int p_device, JoyButton p_button, bool p_pressed);
+ void joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value);
void joy_hat(int p_device, int p_val);
void add_joy_mapping(String p_mapping, bool p_update_existing = false);
diff --git a/core/input/input_enums.h b/core/input/input_enums.h
new file mode 100644
index 0000000000..4479a85bfe
--- /dev/null
+++ b/core/input/input_enums.h
@@ -0,0 +1,126 @@
+/*************************************************************************/
+/* input_enums.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef INPUT_ENUMS_H
+#define INPUT_ENUMS_H
+
+enum HatDir {
+ HAT_UP = 0,
+ HAT_RIGHT = 1,
+ HAT_DOWN = 2,
+ HAT_LEFT = 3,
+ HAT_MAX = 4,
+};
+
+enum HatMask {
+ HAT_MASK_CENTER = 0,
+ HAT_MASK_UP = 1,
+ HAT_MASK_RIGHT = 2,
+ HAT_MASK_DOWN = 4,
+ HAT_MASK_LEFT = 8,
+};
+
+enum JoyAxis {
+ JOY_AXIS_INVALID = -1,
+ JOY_AXIS_LEFT_X = 0,
+ JOY_AXIS_LEFT_Y = 1,
+ JOY_AXIS_RIGHT_X = 2,
+ JOY_AXIS_RIGHT_Y = 3,
+ JOY_AXIS_TRIGGER_LEFT = 4,
+ JOY_AXIS_TRIGGER_RIGHT = 5,
+ JOY_AXIS_SDL_MAX = 6,
+ JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes.
+};
+
+enum JoyButton {
+ JOY_BUTTON_INVALID = -1,
+ JOY_BUTTON_A = 0,
+ JOY_BUTTON_B = 1,
+ JOY_BUTTON_X = 2,
+ JOY_BUTTON_Y = 3,
+ JOY_BUTTON_BACK = 4,
+ JOY_BUTTON_GUIDE = 5,
+ JOY_BUTTON_START = 6,
+ JOY_BUTTON_LEFT_STICK = 7,
+ JOY_BUTTON_RIGHT_STICK = 8,
+ JOY_BUTTON_LEFT_SHOULDER = 9,
+ JOY_BUTTON_RIGHT_SHOULDER = 10,
+ JOY_BUTTON_DPAD_UP = 11,
+ JOY_BUTTON_DPAD_DOWN = 12,
+ JOY_BUTTON_DPAD_LEFT = 13,
+ JOY_BUTTON_DPAD_RIGHT = 14,
+ JOY_BUTTON_MISC1 = 15,
+ JOY_BUTTON_PADDLE1 = 16,
+ JOY_BUTTON_PADDLE2 = 17,
+ JOY_BUTTON_PADDLE3 = 18,
+ JOY_BUTTON_PADDLE4 = 19,
+ JOY_BUTTON_TOUCHPAD = 20,
+ JOY_BUTTON_SDL_MAX = 21,
+ JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons.
+};
+
+enum MIDIMessage {
+ MIDI_MESSAGE_NONE = 0,
+ MIDI_MESSAGE_NOTE_OFF = 0x8,
+ MIDI_MESSAGE_NOTE_ON = 0x9,
+ MIDI_MESSAGE_AFTERTOUCH = 0xA,
+ MIDI_MESSAGE_CONTROL_CHANGE = 0xB,
+ MIDI_MESSAGE_PROGRAM_CHANGE = 0xC,
+ MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD,
+ MIDI_MESSAGE_PITCH_BEND = 0xE,
+};
+
+enum MouseButton {
+ MOUSE_BUTTON_NONE = 0,
+ MOUSE_BUTTON_LEFT = 1,
+ MOUSE_BUTTON_RIGHT = 2,
+ MOUSE_BUTTON_MIDDLE = 3,
+ MOUSE_BUTTON_WHEEL_UP = 4,
+ MOUSE_BUTTON_WHEEL_DOWN = 5,
+ MOUSE_BUTTON_WHEEL_LEFT = 6,
+ MOUSE_BUTTON_WHEEL_RIGHT = 7,
+ MOUSE_BUTTON_XBUTTON1 = 8,
+ MOUSE_BUTTON_XBUTTON2 = 9,
+ MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)),
+ MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)),
+ MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)),
+ MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)),
+ MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1)),
+};
+
+inline MouseButton &operator|=(MouseButton &a, MouseButton b) {
+ return (MouseButton &)((int &)a |= (int)b);
+}
+
+inline MouseButton &operator&=(MouseButton &a, MouseButton b) {
+ return (MouseButton &)((int &)a &= (int)b);
+}
+
+#endif // INPUT_ENUMS_H
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index 14762f955c..52a6c5d64f 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -516,11 +516,11 @@ float InputEventMouseButton::get_factor() const {
return factor;
}
-void InputEventMouseButton::set_button_index(int p_index) {
+void InputEventMouseButton::set_button_index(MouseButton p_index) {
button_index = p_index;
}
-int InputEventMouseButton::get_button_index() const {
+MouseButton InputEventMouseButton::get_button_index() const {
return button_index;
}
@@ -845,11 +845,11 @@ void InputEventMouseMotion::_bind_methods() {
///////////////////////////////////
-void InputEventJoypadMotion::set_axis(int p_axis) {
+void InputEventJoypadMotion::set_axis(JoyAxis p_axis) {
axis = p_axis;
}
-int InputEventJoypadMotion::get_axis() const {
+JoyAxis InputEventJoypadMotion::get_axis() const {
return axis;
}
@@ -947,11 +947,11 @@ void InputEventJoypadMotion::_bind_methods() {
///////////////////////////////////
-void InputEventJoypadButton::set_button_index(int p_index) {
+void InputEventJoypadButton::set_button_index(JoyButton p_index) {
button_index = p_index;
}
-int InputEventJoypadButton::get_button_index() const {
+JoyButton InputEventJoypadButton::get_button_index() const {
return button_index;
}
@@ -1046,7 +1046,7 @@ String InputEventJoypadButton::to_string() {
return vformat("InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f", button_index, p, pressure);
}
-Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) {
+Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(JoyButton p_btn_index) {
Ref<InputEventJoypadButton> ie;
ie.instantiate();
ie->set_button_index(p_btn_index);
@@ -1403,11 +1403,11 @@ int InputEventMIDI::get_channel() const {
return channel;
}
-void InputEventMIDI::set_message(const int p_message) {
+void InputEventMIDI::set_message(const MIDIMessage p_message) {
message = p_message;
}
-int InputEventMIDI::get_message() const {
+MIDIMessage InputEventMIDI::get_message() const {
return message;
}
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 3ef135221d..76a45c04a4 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -31,6 +31,7 @@
#ifndef INPUT_EVENT_H
#define INPUT_EVENT_H
+#include "core/input/input_enums.h"
#include "core/io/resource.h"
#include "core/math/transform_2d.h"
#include "core/string/ustring.h"
@@ -41,72 +42,6 @@
* The events are pretty obvious.
*/
-enum MouseButton {
- MOUSE_BUTTON_LEFT = 1,
- MOUSE_BUTTON_RIGHT = 2,
- MOUSE_BUTTON_MIDDLE = 3,
- MOUSE_BUTTON_WHEEL_UP = 4,
- MOUSE_BUTTON_WHEEL_DOWN = 5,
- MOUSE_BUTTON_WHEEL_LEFT = 6,
- MOUSE_BUTTON_WHEEL_RIGHT = 7,
- MOUSE_BUTTON_XBUTTON1 = 8,
- MOUSE_BUTTON_XBUTTON2 = 9,
- MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)),
- MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)),
- MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)),
- MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)),
- MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1))
-};
-
-enum JoyButton {
- JOY_BUTTON_INVALID = -1,
- JOY_BUTTON_A = 0,
- JOY_BUTTON_B = 1,
- JOY_BUTTON_X = 2,
- JOY_BUTTON_Y = 3,
- JOY_BUTTON_BACK = 4,
- JOY_BUTTON_GUIDE = 5,
- JOY_BUTTON_START = 6,
- JOY_BUTTON_LEFT_STICK = 7,
- JOY_BUTTON_RIGHT_STICK = 8,
- JOY_BUTTON_LEFT_SHOULDER = 9,
- JOY_BUTTON_RIGHT_SHOULDER = 10,
- JOY_BUTTON_DPAD_UP = 11,
- JOY_BUTTON_DPAD_DOWN = 12,
- JOY_BUTTON_DPAD_LEFT = 13,
- JOY_BUTTON_DPAD_RIGHT = 14,
- JOY_BUTTON_MISC1 = 15,
- JOY_BUTTON_PADDLE1 = 16,
- JOY_BUTTON_PADDLE2 = 17,
- JOY_BUTTON_PADDLE3 = 18,
- JOY_BUTTON_PADDLE4 = 19,
- JOY_BUTTON_TOUCHPAD = 20,
- JOY_BUTTON_SDL_MAX = 21,
- JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons.
-};
-
-enum JoyAxis {
- JOY_AXIS_INVALID = -1,
- JOY_AXIS_LEFT_X = 0,
- JOY_AXIS_LEFT_Y = 1,
- JOY_AXIS_RIGHT_X = 2,
- JOY_AXIS_RIGHT_Y = 3,
- JOY_AXIS_TRIGGER_LEFT = 4,
- JOY_AXIS_TRIGGER_RIGHT = 5,
- JOY_AXIS_SDL_MAX = 6,
- JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes.
-};
-
-enum MIDIMessage {
- MIDI_MESSAGE_NOTE_OFF = 0x8,
- MIDI_MESSAGE_NOTE_ON = 0x9,
- MIDI_MESSAGE_AFTERTOUCH = 0xA,
- MIDI_MESSAGE_CONTROL_CHANGE = 0xB,
- MIDI_MESSAGE_PROGRAM_CHANGE = 0xC,
- MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD,
- MIDI_MESSAGE_PITCH_BEND = 0xE,
-};
-
/**
* Input Modifier Status
* for keyboard/mouse events.
@@ -295,7 +230,7 @@ class InputEventMouseButton : public InputEventMouse {
GDCLASS(InputEventMouseButton, InputEventMouse);
float factor = 1;
- int button_index = 0;
+ MouseButton button_index = MOUSE_BUTTON_NONE;
bool pressed = false; //otherwise released
bool double_click = false; //last even less than double click time
@@ -306,8 +241,8 @@ public:
void set_factor(float p_factor);
float get_factor() const;
- void set_button_index(int p_index);
- int get_button_index() const;
+ void set_button_index(MouseButton p_index);
+ MouseButton get_button_index() const;
void set_pressed(bool p_pressed);
virtual bool is_pressed() const override;
@@ -362,15 +297,15 @@ public:
class InputEventJoypadMotion : public InputEvent {
GDCLASS(InputEventJoypadMotion, InputEvent);
- int axis = 0; ///< Joypad axis
+ JoyAxis axis = (JoyAxis)0; ///< Joypad axis
float axis_value = 0; ///< -1 to 1
protected:
static void _bind_methods();
public:
- void set_axis(int p_axis);
- int get_axis() const;
+ void set_axis(JoyAxis p_axis);
+ JoyAxis get_axis() const;
void set_axis_value(float p_value);
float get_axis_value() const;
@@ -390,15 +325,15 @@ public:
class InputEventJoypadButton : public InputEvent {
GDCLASS(InputEventJoypadButton, InputEvent);
- int button_index = 0;
+ JoyButton button_index = (JoyButton)0;
bool pressed = false;
float pressure = 0; //0 to 1
protected:
static void _bind_methods();
public:
- void set_button_index(int p_index);
- int get_button_index() const;
+ void set_button_index(JoyButton p_index);
+ JoyButton get_button_index() const;
void set_pressed(bool p_pressed);
virtual bool is_pressed() const override;
@@ -414,7 +349,7 @@ public:
virtual String as_text() const override;
virtual String to_string() override;
- static Ref<InputEventJoypadButton> create_reference(int p_btn_index);
+ static Ref<InputEventJoypadButton> create_reference(JoyButton p_btn_index);
InputEventJoypadButton() {}
};
@@ -561,7 +496,7 @@ class InputEventMIDI : public InputEvent {
GDCLASS(InputEventMIDI, InputEvent);
int channel = 0;
- int message = 0;
+ MIDIMessage message = MIDI_MESSAGE_NONE;
int pitch = 0;
int velocity = 0;
int instrument = 0;
@@ -576,8 +511,8 @@ public:
void set_channel(const int p_channel);
int get_channel() const;
- void set_message(const int p_message);
- int get_message() const;
+ void set_message(const MIDIMessage p_message);
+ MIDIMessage get_message() const;
void set_pitch(const int p_pitch);
int get_pitch() const;
diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp
index a33bc6b4c3..ee87346dfc 100644
--- a/core/os/midi_driver.cpp
+++ b/core/os/midi_driver.cpp
@@ -52,16 +52,16 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
if (data[0] >= 0xF0) {
// channel does not apply to system common messages
event->set_channel(0);
- event->set_message(data[0]);
+ event->set_message(MIDIMessage(data[0]));
last_received_message = data[0];
} else if ((data[0] & 0x80) == 0x00) {
// running status
event->set_channel(last_received_message & 0xF);
- event->set_message(last_received_message >> 4);
+ event->set_message(MIDIMessage(last_received_message >> 4));
param_position = 0;
} else {
event->set_channel(data[0] & 0xF);
- event->set_message(data[0] >> 4);
+ event->set_message(MIDIMessage(data[0] >> 4));
param_position = 1;
last_received_message = data[0];
}
@@ -112,6 +112,8 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_
event->set_pressure(data[param_position]);
}
break;
+ default:
+ break;
}
Input *id = Input::get_singleton();
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h
index 830e0a5cbd..0885777429 100644
--- a/core/variant/binder_common.h
+++ b/core/variant/binder_common.h
@@ -31,6 +31,7 @@
#ifndef BINDER_COMMON_H
#define BINDER_COMMON_H
+#include "core/input/input_enums.h"
#include "core/object/object.h"
#include "core/templates/list.h"
#include "core/templates/simple_type.h"
@@ -90,6 +91,12 @@ VARIANT_ENUM_CAST(Error);
VARIANT_ENUM_CAST(Side);
VARIANT_ENUM_CAST(ClockDirection);
VARIANT_ENUM_CAST(Corner);
+VARIANT_ENUM_CAST(HatDir);
+VARIANT_ENUM_CAST(HatMask);
+VARIANT_ENUM_CAST(JoyAxis);
+VARIANT_ENUM_CAST(JoyButton);
+VARIANT_ENUM_CAST(MIDIMessage);
+VARIANT_ENUM_CAST(MouseButton);
VARIANT_ENUM_CAST(Orientation);
VARIANT_ENUM_CAST(HAlign);
VARIANT_ENUM_CAST(VAlign);
diff --git a/doc/classes/DisplayServer.xml b/doc/classes/DisplayServer.xml
index 0a4807f046..ef20174ee6 100644
--- a/doc/classes/DisplayServer.xml
+++ b/doc/classes/DisplayServer.xml
@@ -436,7 +436,7 @@
</description>
</method>
<method name="mouse_get_button_state" qualifiers="const">
- <return type="int">
+ <return type="int" enum="MouseButton">
</return>
<description>
</description>
diff --git a/doc/classes/Input.xml b/doc/classes/Input.xml
index 05a8bd268e..b970070659 100644
--- a/doc/classes/Input.xml
+++ b/doc/classes/Input.xml
@@ -123,7 +123,7 @@
</return>
<argument index="0" name="device" type="int">
</argument>
- <argument index="1" name="axis" type="int">
+ <argument index="1" name="axis" type="int" enum="JoyAxis">
</argument>
<description>
Returns the current value of the joypad axis at given index (see [enum JoyAxis]).
@@ -252,7 +252,7 @@
</return>
<argument index="0" name="device" type="int">
</argument>
- <argument index="1" name="button" type="int">
+ <argument index="1" name="button" type="int" enum="JoyButton">
</argument>
<description>
Returns [code]true[/code] if you are pressing the joypad button (see [enum JoyButton]).
@@ -279,7 +279,7 @@
<method name="is_mouse_button_pressed" qualifiers="const">
<return type="bool">
</return>
- <argument index="0" name="button" type="int">
+ <argument index="0" name="button" type="int" enum="MouseButton">
</argument>
<description>
Returns [code]true[/code] if you are pressing the mouse button specified with [enum MouseButton].
diff --git a/doc/classes/InputEventJoypadButton.xml b/doc/classes/InputEventJoypadButton.xml
index b1f4836f6e..f9afe42a7a 100644
--- a/doc/classes/InputEventJoypadButton.xml
+++ b/doc/classes/InputEventJoypadButton.xml
@@ -12,7 +12,7 @@
<methods>
</methods>
<members>
- <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" default="0">
+ <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" enum="JoyButton" default="0">
Button identifier. One of the [enum JoyButton] button constants.
</member>
<member name="pressed" type="bool" setter="set_pressed" getter="is_pressed" default="false">
diff --git a/doc/classes/InputEventJoypadMotion.xml b/doc/classes/InputEventJoypadMotion.xml
index 39fdb14016..398b9eb6f6 100644
--- a/doc/classes/InputEventJoypadMotion.xml
+++ b/doc/classes/InputEventJoypadMotion.xml
@@ -12,7 +12,7 @@
<methods>
</methods>
<members>
- <member name="axis" type="int" setter="set_axis" getter="get_axis" default="0">
+ <member name="axis" type="int" setter="set_axis" getter="get_axis" enum="JoyAxis" default="0">
Axis identifier. Use one of the [enum JoyAxis] axis constants.
</member>
<member name="axis_value" type="float" setter="set_axis_value" getter="get_axis_value" default="0.0">
diff --git a/doc/classes/InputEventMIDI.xml b/doc/classes/InputEventMIDI.xml
index 13bb9d8b85..afc9d476da 100644
--- a/doc/classes/InputEventMIDI.xml
+++ b/doc/classes/InputEventMIDI.xml
@@ -17,7 +17,7 @@
</member>
<member name="instrument" type="int" setter="set_instrument" getter="get_instrument" default="0">
</member>
- <member name="message" type="int" setter="set_message" getter="get_message" default="0">
+ <member name="message" type="int" setter="set_message" getter="get_message" enum="MIDIMessage" default="0">
</member>
<member name="pitch" type="int" setter="set_pitch" getter="get_pitch" default="0">
</member>
diff --git a/doc/classes/InputEventMouseButton.xml b/doc/classes/InputEventMouseButton.xml
index be71b42567..7a6c7410ef 100644
--- a/doc/classes/InputEventMouseButton.xml
+++ b/doc/classes/InputEventMouseButton.xml
@@ -12,7 +12,7 @@
<methods>
</methods>
<members>
- <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" default="0">
+ <member name="button_index" type="int" setter="set_button_index" getter="get_button_index" enum="MouseButton" default="0">
The mouse button identifier, one of the [enum MouseButton] button or button wheel constants.
</member>
<member name="double_click" type="bool" setter="set_double_click" getter="is_double_click" default="false">
diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp
index af70772ada..0a0c3b1987 100644
--- a/editor/action_map_editor.cpp
+++ b/editor/action_map_editor.cpp
@@ -334,7 +334,7 @@ void InputEventConfigurationDialog::_update_input_list() {
for (int i = 0; i < JOY_BUTTON_MAX; i++) {
Ref<InputEventJoypadButton> joyb;
joyb.instantiate();
- joyb->set_button_index(i);
+ joyb->set_button_index((JoyButton)i);
String desc = get_event_text(joyb);
if (!search_term.is_empty() && desc.findn(search_term) == -1) {
@@ -359,7 +359,7 @@ void InputEventConfigurationDialog::_update_input_list() {
int direction = (i & 1) ? 1 : -1;
Ref<InputEventJoypadMotion> joym;
joym.instantiate();
- joym->set_axis(axis);
+ joym->set_axis((JoyAxis)axis);
joym->set_axis_value(direction);
String desc = get_event_text(joym);
@@ -482,7 +482,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
int idx = selected->get_meta("__index");
Ref<InputEventMouseButton> mb;
mb.instantiate();
- mb->set_button_index(idx);
+ mb->set_button_index((MouseButton)idx);
// Maintain modifier state from checkboxes
mb->set_alt_pressed(mod_checkboxes[MOD_ALT]->is_pressed());
mb->set_shift_pressed(mod_checkboxes[MOD_SHIFT]->is_pressed());
@@ -495,7 +495,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
} break;
case InputEventConfigurationDialog::INPUT_JOY_BUTTON: {
int idx = selected->get_meta("__index");
- Ref<InputEventJoypadButton> jb = InputEventJoypadButton::create_reference(idx);
+ Ref<InputEventJoypadButton> jb = InputEventJoypadButton::create_reference((JoyButton)idx);
_set_event(jb);
} break;
case InputEventConfigurationDialog::INPUT_JOY_MOTION: {
@@ -504,7 +504,7 @@ void InputEventConfigurationDialog::_input_list_item_selected() {
Ref<InputEventJoypadMotion> jm;
jm.instantiate();
- jm->set_axis(axis);
+ jm->set_axis((JoyAxis)axis);
jm->set_axis_value(value);
_set_event(jm);
} break;
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp
index a800232978..706243fe25 100644
--- a/editor/plugins/curve_editor_plugin.cpp
+++ b/editor/plugins/curve_editor_plugin.cpp
@@ -127,6 +127,8 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) {
case MOUSE_BUTTON_LEFT:
_dragging = true;
break;
+ default:
+ break;
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index dcb79832b1..14087801f5 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -1398,6 +1398,8 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
}
} break;
+ default:
+ break;
}
}
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index c11e172ff7..89b486c4df 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1629,7 +1629,7 @@ void ScriptEditor::_help_overview_selected(int p_idx) {
}
void ScriptEditor::_script_selected(int p_idx) {
- grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(1); //amazing hack, simply amazing
+ grab_focus_block = !Input::get_singleton()->is_mouse_button_pressed(MOUSE_BUTTON_LEFT); //amazing hack, simply amazing
_go_to_tab(script_list->get_item_metadata(p_idx));
grab_focus_block = false;
@@ -2771,6 +2771,8 @@ void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) {
case MOUSE_BUTTON_RIGHT: {
_make_script_list_context_menu();
} break;
+ default:
+ break;
}
}
}
diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp
index 80077590df..e51542e23d 100644
--- a/modules/gdnative/xr/xr_interface_gdnative.cpp
+++ b/modules/gdnative/xr/xr_interface_gdnative.cpp
@@ -412,7 +412,7 @@ void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p
if (tracker.is_valid()) {
int joyid = tracker->get_joy_id();
if (joyid != -1) {
- input->joy_button(joyid, p_button, p_is_pressed);
+ input->joy_button(joyid, (JoyButton)p_button, p_is_pressed);
}
}
}
@@ -431,7 +431,7 @@ void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_a
Input::JoyAxisValue jx;
jx.min = p_can_be_negative ? -1 : 0;
jx.value = p_value;
- input->joy_axis(joyid, p_axis, jx);
+ input->joy_axis(joyid, (JoyAxis)p_axis, jx);
}
}
}
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp
index db497133aa..66a2013c4e 100644
--- a/platform/android/display_server_android.cpp
+++ b/platform/android/display_server_android.cpp
@@ -410,8 +410,6 @@ DisplayServerAndroid::DisplayServerAndroid(const String &p_rendering_driver, Dis
keep_screen_on = GLOBAL_GET("display/window/energy_saving/keep_screen_on");
- buttons_state = 0;
-
#if defined(OPENGL_ENABLED)
if (rendering_driver == "opengl") {
bool gl_initialization_error = false;
@@ -484,16 +482,16 @@ DisplayServerAndroid::~DisplayServerAndroid() {
void DisplayServerAndroid::process_joy_event(DisplayServerAndroid::JoypadEvent p_event) {
switch (p_event.type) {
case JOY_EVENT_BUTTON:
- Input::get_singleton()->joy_button(p_event.device, p_event.index, p_event.pressed);
+ Input::get_singleton()->joy_button(p_event.device, (JoyButton)p_event.index, p_event.pressed);
break;
case JOY_EVENT_AXIS:
Input::JoyAxisValue value;
value.min = -1;
value.value = p_event.value;
- Input::get_singleton()->joy_axis(p_event.device, p_event.index, value);
+ Input::get_singleton()->joy_axis(p_event.device, (JoyAxis)p_event.index, value);
break;
case JOY_EVENT_HAT:
- Input::get_singleton()->joy_hat(p_event.device, p_event.hat);
+ Input::get_singleton()->joy_hat(p_event.device, (HatMask)p_event.hat);
break;
default:
return;
@@ -697,7 +695,7 @@ void DisplayServerAndroid::process_hover(int p_type, Point2 p_pos) {
}
void DisplayServerAndroid::process_mouse_event(int input_device, int event_action, int event_android_buttons_mask, Point2 event_pos, float event_vertical_factor, float event_horizontal_factor) {
- int event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask);
+ MouseButton event_buttons_mask = _android_button_mask_to_godot_button_mask(event_android_buttons_mask);
switch (event_action) {
case AMOTION_EVENT_ACTION_BUTTON_PRESS:
case AMOTION_EVENT_ACTION_BUTTON_RELEASE: {
@@ -712,7 +710,7 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio
ev->set_global_position(hover_prev_pos);
}
ev->set_pressed(event_action == AMOTION_EVENT_ACTION_BUTTON_PRESS);
- int changed_button_mask = buttons_state ^ event_buttons_mask;
+ MouseButton changed_button_mask = MouseButton(buttons_state ^ event_buttons_mask);
buttons_state = event_buttons_mask;
@@ -765,11 +763,11 @@ void DisplayServerAndroid::process_mouse_event(int input_device, int event_actio
}
}
-void DisplayServerAndroid::_wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor) {
+void DisplayServerAndroid::_wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor) {
Ref<InputEventMouseButton> evd = ev->duplicate();
_set_key_modifier_state(evd);
evd->set_button_index(wheel_button);
- evd->set_button_mask(event_buttons_mask ^ (1 << (wheel_button - 1)));
+ evd->set_button_mask(MouseButton(event_buttons_mask ^ (1 << (wheel_button - 1))));
evd->set_factor(factor);
Input::get_singleton()->accumulate_input_event(evd);
Ref<InputEventMouseButton> evdd = evd->duplicate();
@@ -779,7 +777,7 @@ void DisplayServerAndroid::_wheel_button_click(int event_buttons_mask, const Ref
}
void DisplayServerAndroid::process_double_tap(int event_android_button_mask, Point2 p_pos) {
- int event_button_mask = _android_button_mask_to_godot_button_mask(event_android_button_mask);
+ MouseButton event_button_mask = _android_button_mask_to_godot_button_mask(event_android_button_mask);
Ref<InputEventMouseButton> ev;
ev.instantiate();
_set_key_modifier_state(ev);
@@ -792,7 +790,7 @@ void DisplayServerAndroid::process_double_tap(int event_android_button_mask, Poi
Input::get_singleton()->accumulate_input_event(ev);
}
-int DisplayServerAndroid::_button_index_from_mask(int button_mask) {
+MouseButton DisplayServerAndroid::_button_index_from_mask(MouseButton button_mask) {
switch (button_mask) {
case MOUSE_BUTTON_MASK_LEFT:
return MOUSE_BUTTON_LEFT;
@@ -805,7 +803,7 @@ int DisplayServerAndroid::_button_index_from_mask(int button_mask) {
case MOUSE_BUTTON_MASK_XBUTTON2:
return MOUSE_BUTTON_XBUTTON2;
default:
- return 0;
+ return MOUSE_BUTTON_NONE;
}
}
@@ -863,12 +861,12 @@ Point2i DisplayServerAndroid::mouse_get_position() const {
return hover_prev_pos;
}
-int DisplayServerAndroid::mouse_get_button_state() const {
+MouseButton DisplayServerAndroid::mouse_get_button_state() const {
return buttons_state;
}
-int DisplayServerAndroid::_android_button_mask_to_godot_button_mask(int android_button_mask) {
- int godot_button_mask = 0;
+MouseButton DisplayServerAndroid::_android_button_mask_to_godot_button_mask(int android_button_mask) {
+ MouseButton godot_button_mask = MOUSE_BUTTON_NONE;
if (android_button_mask & AMOTION_EVENT_BUTTON_PRIMARY) {
godot_button_mask |= MOUSE_BUTTON_MASK_LEFT;
}
diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h
index a2f47dcccb..a39271d524 100644
--- a/platform/android/display_server_android.h
+++ b/platform/android/display_server_android.h
@@ -68,7 +68,7 @@ private:
bool control_mem = false;
bool meta_mem = false;
- int buttons_state;
+ MouseButton buttons_state = MOUSE_BUTTON_NONE;
// https://developer.android.com/reference/android/view/PointerIcon
// mapping between Godot's cursor shape to Android's'
@@ -120,11 +120,11 @@ private:
void _set_key_modifier_state(Ref<InputEventWithModifiers> ev);
- static int _button_index_from_mask(int button_mask);
+ static MouseButton _button_index_from_mask(MouseButton button_mask);
- static int _android_button_mask_to_godot_button_mask(int android_button_mask);
+ static MouseButton _android_button_mask_to_godot_button_mask(int android_button_mask);
- void _wheel_button_click(int event_buttons_mask, const Ref<InputEventMouseButton> &ev, int wheel_button, float factor);
+ void _wheel_button_click(MouseButton event_buttons_mask, const Ref<InputEventMouseButton> &ev, MouseButton wheel_button, float factor);
public:
static DisplayServerAndroid *get_singleton();
@@ -219,7 +219,7 @@ public:
void notify_surface_changed(int p_width, int p_height);
virtual Point2i mouse_get_position() const;
- virtual int mouse_get_button_state() const;
+ virtual MouseButton mouse_get_button_state() const;
DisplayServerAndroid(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
~DisplayServerAndroid();
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index d59366bb64..4c66789a83 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -324,15 +324,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j
int hat = 0;
if (p_hat_x != 0) {
if (p_hat_x < 0)
- hat |= Input::HAT_MASK_LEFT;
+ hat |= HatMask::HAT_MASK_LEFT;
else
- hat |= Input::HAT_MASK_RIGHT;
+ hat |= HatMask::HAT_MASK_RIGHT;
}
if (p_hat_y != 0) {
if (p_hat_y < 0)
- hat |= Input::HAT_MASK_UP;
+ hat |= HatMask::HAT_MASK_UP;
else
- hat |= Input::HAT_MASK_DOWN;
+ hat |= HatMask::HAT_MASK_DOWN;
}
jevent.hat = hat;
diff --git a/platform/javascript/display_server_javascript.cpp b/platform/javascript/display_server_javascript.cpp
index 8831d26190..f1b92264e2 100644
--- a/platform/javascript/display_server_javascript.cpp
+++ b/platform/javascript/display_server_javascript.cpp
@@ -229,8 +229,8 @@ EM_BOOL DisplayServerJavaScript::mouse_button_callback(int p_event_type, const E
}
Input *input = Input::get_singleton();
- int mask = input->get_mouse_button_mask();
- int button_flag = 1 << (ev->get_button_index() - 1);
+ MouseButton mask = input->get_mouse_button_mask();
+ MouseButton button_flag = MouseButton(1 << (ev->get_button_index() - 1));
if (ev->is_pressed()) {
// Since the event is consumed, focus manually. The containing iframe,
// if exists, may not have focus yet, so focus even if already focused.
@@ -478,11 +478,11 @@ EM_BOOL DisplayServerJavaScript::wheel_callback(int p_event_type, const Emscript
int button_flag = 1 << (ev->get_button_index() - 1);
ev->set_pressed(true);
- ev->set_button_mask(input->get_mouse_button_mask() | button_flag);
+ ev->set_button_mask(MouseButton(input->get_mouse_button_mask() | button_flag));
input->parse_input_event(ev);
ev->set_pressed(false);
- ev->set_button_mask(input->get_mouse_button_mask() & ~button_flag);
+ ev->set_button_mask(MouseButton(input->get_mouse_button_mask() & ~button_flag));
input->parse_input_event(ev);
return true;
diff --git a/platform/linuxbsd/display_server_x11.cpp b/platform/linuxbsd/display_server_x11.cpp
index b1bb064274..d2531cbe50 100644
--- a/platform/linuxbsd/display_server_x11.cpp
+++ b/platform/linuxbsd/display_server_x11.cpp
@@ -450,7 +450,7 @@ Point2i DisplayServerX11::mouse_get_absolute_position() const {
return Vector2i();
}
-int DisplayServerX11::mouse_get_button_state() const {
+MouseButton DisplayServerX11::mouse_get_button_state() const {
return last_button_state;
}
@@ -2172,13 +2172,13 @@ void DisplayServerX11::_get_key_modifier_state(unsigned int p_x11_state, Ref<Inp
state->set_meta_pressed((p_x11_state & Mod4Mask));
}
-unsigned int DisplayServerX11::_get_mouse_button_state(unsigned int p_x11_button, int p_x11_type) {
- unsigned int mask = 1 << (p_x11_button - 1);
+MouseButton DisplayServerX11::_get_mouse_button_state(MouseButton p_x11_button, int p_x11_type) {
+ MouseButton mask = MouseButton(1 << (p_x11_button - 1));
if (p_x11_type == ButtonPress) {
last_button_state |= mask;
} else {
- last_button_state &= ~mask;
+ last_button_state &= MouseButton(~mask);
}
return last_button_state;
@@ -3130,11 +3130,11 @@ void DisplayServerX11::process_events() {
mb->set_window_id(window_id);
_get_key_modifier_state(event.xbutton.state, mb);
- mb->set_button_index(event.xbutton.button);
- if (mb->get_button_index() == 2) {
- mb->set_button_index(3);
- } else if (mb->get_button_index() == 3) {
- mb->set_button_index(2);
+ mb->set_button_index((MouseButton)event.xbutton.button);
+ if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) {
+ mb->set_button_index(MOUSE_BUTTON_MIDDLE);
+ } else if (mb->get_button_index() == MOUSE_BUTTON_MIDDLE) {
+ mb->set_button_index(MOUSE_BUTTON_RIGHT);
}
mb->set_button_mask(_get_mouse_button_state(mb->get_button_index(), event.xbutton.type));
mb->set_position(Vector2(event.xbutton.x, event.xbutton.y));
@@ -3297,7 +3297,7 @@ void DisplayServerX11::process_events() {
if (xi.pressure_supported) {
mm->set_pressure(xi.pressure);
} else {
- mm->set_pressure((mouse_get_button_state() & (1 << (MOUSE_BUTTON_LEFT - 1))) ? 1.0f : 0.0f);
+ mm->set_pressure((mouse_get_button_state() & MOUSE_BUTTON_MASK_LEFT) ? 1.0f : 0.0f);
}
mm->set_tilt(xi.tilt);
@@ -3855,8 +3855,6 @@ DisplayServerX11::DisplayServerX11(const String &p_rendering_driver, WindowMode
img[i] = nullptr;
}
- last_button_state = 0;
-
xmbstring = nullptr;
last_click_ms = 0;
diff --git a/platform/linuxbsd/display_server_x11.h b/platform/linuxbsd/display_server_x11.h
index 10686d8424..594a38d39e 100644
--- a/platform/linuxbsd/display_server_x11.h
+++ b/platform/linuxbsd/display_server_x11.h
@@ -162,7 +162,7 @@ class DisplayServerX11 : public DisplayServer {
Point2i last_click_pos;
uint64_t last_click_ms;
int last_click_button_index;
- uint32_t last_button_state;
+ MouseButton last_button_state = MOUSE_BUTTON_NONE;
bool app_focused = false;
uint64_t time_since_no_focus = 0;
@@ -187,7 +187,7 @@ class DisplayServerX11 : public DisplayServer {
bool _refresh_device_info();
- unsigned int _get_mouse_button_state(unsigned int p_x11_button, int p_x11_type);
+ MouseButton _get_mouse_button_state(MouseButton p_x11_button, int p_x11_type);
void _get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
void _flush_mouse_motion();
@@ -279,7 +279,7 @@ public:
virtual void mouse_warp_to_position(const Point2i &p_to);
virtual Point2i mouse_get_position() const;
virtual Point2i mouse_get_absolute_position() const;
- virtual int mouse_get_button_state() const;
+ virtual MouseButton mouse_get_button_state() const;
virtual void clipboard_set(const String &p_text);
virtual String clipboard_get() const;
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp
index e8f4352dff..8b6dbc4c20 100644
--- a/platform/linuxbsd/joypad_linux.cpp
+++ b/platform/linuxbsd/joypad_linux.cpp
@@ -475,7 +475,7 @@ void JoypadLinux::process_joypads() {
switch (ev.type) {
case EV_KEY:
- input->joy_button(i, joy->key_map[ev.code], ev.value);
+ input->joy_button(i, (JoyButton)joy->key_map[ev.code], ev.value);
break;
case EV_ABS:
@@ -484,29 +484,29 @@ void JoypadLinux::process_joypads() {
case ABS_HAT0X:
if (ev.value != 0) {
if (ev.value < 0) {
- joy->dpad = (joy->dpad | Input::HAT_MASK_LEFT) & ~Input::HAT_MASK_RIGHT;
+ joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_LEFT) & ~HatMask::HAT_MASK_RIGHT);
} else {
- joy->dpad = (joy->dpad | Input::HAT_MASK_RIGHT) & ~Input::HAT_MASK_LEFT;
+ joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_RIGHT) & ~HatMask::HAT_MASK_LEFT);
}
} else {
- joy->dpad &= ~(Input::HAT_MASK_LEFT | Input::HAT_MASK_RIGHT);
+ joy->dpad &= ~(HatMask::HAT_MASK_LEFT | HatMask::HAT_MASK_RIGHT);
}
- input->joy_hat(i, joy->dpad);
+ input->joy_hat(i, (HatMask)joy->dpad);
break;
case ABS_HAT0Y:
if (ev.value != 0) {
if (ev.value < 0) {
- joy->dpad = (joy->dpad | Input::HAT_MASK_UP) & ~Input::HAT_MASK_DOWN;
+ joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_UP) & ~HatMask::HAT_MASK_DOWN);
} else {
- joy->dpad = (joy->dpad | Input::HAT_MASK_DOWN) & ~Input::HAT_MASK_UP;
+ joy->dpad = (HatMask)((joy->dpad | HatMask::HAT_MASK_DOWN) & ~HatMask::HAT_MASK_UP);
}
} else {
- joy->dpad &= ~(Input::HAT_MASK_UP | Input::HAT_MASK_DOWN);
+ joy->dpad &= ~(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_DOWN);
}
- input->joy_hat(i, joy->dpad);
+ input->joy_hat(i, (HatMask)joy->dpad);
break;
default:
@@ -526,7 +526,7 @@ void JoypadLinux::process_joypads() {
for (int j = 0; j < MAX_ABS; j++) {
int index = joy->abs_map[j];
if (index != -1) {
- input->joy_axis(i, index, joy->curr_axis[index]);
+ input->joy_axis(i, (JoyAxis)index, joy->curr_axis[index]);
}
}
if (len == 0 || (len < 0 && errno != EAGAIN)) {
diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h
index 9fac99810b..5f7f5f84a2 100644
--- a/platform/osx/display_server_osx.h
+++ b/platform/osx/display_server_osx.h
@@ -173,7 +173,7 @@ public:
MouseMode mouse_mode;
Point2i last_mouse_pos;
- uint32_t last_button_state;
+ MouseButton last_button_state = MOUSE_BUTTON_NONE;
bool window_focused;
bool drop_events;
@@ -217,7 +217,7 @@ public:
virtual void mouse_warp_to_position(const Point2i &p_to) override;
virtual Point2i mouse_get_position() const override;
virtual Point2i mouse_get_absolute_position() const override;
- virtual int mouse_get_button_state() const override;
+ virtual MouseButton mouse_get_button_state() const override;
virtual void clipboard_set(const String &p_text) override;
virtual String clipboard_get() const override;
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm
index 84e8770043..ec51ec78d3 100644
--- a/platform/osx/display_server_osx.mm
+++ b/platform/osx/display_server_osx.mm
@@ -813,14 +813,14 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
DS_OSX->cursor_set_shape(p_shape);
}
-static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, int index, int mask, bool pressed) {
+static void _mouseDownEvent(DisplayServer::WindowID window_id, NSEvent *event, MouseButton index, MouseButton mask, bool pressed) {
ERR_FAIL_COND(!DS_OSX->windows.has(window_id));
DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id];
if (pressed) {
DS_OSX->last_button_state |= mask;
} else {
- DS_OSX->last_button_state &= ~mask;
+ DS_OSX->last_button_state &= (MouseButton)~mask;
}
Ref<InputEventMouseButton> mb;
@@ -1485,11 +1485,11 @@ static int remapKey(unsigned int key, unsigned int state) {
}
}
-inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, double factor, int modifierFlags) {
+inline void sendScrollEvent(DisplayServer::WindowID window_id, MouseButton button, double factor, int modifierFlags) {
ERR_FAIL_COND(!DS_OSX->windows.has(window_id));
DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id];
- unsigned int mask = 1 << (button - 1);
+ MouseButton mask = MouseButton(1 << (button - 1));
Ref<InputEventMouseButton> sc;
sc.instantiate();
@@ -1501,7 +1501,7 @@ inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, doubl
sc->set_pressed(true);
sc->set_position(wd.mouse_pos);
sc->set_global_position(wd.mouse_pos);
- DS_OSX->last_button_state |= mask;
+ DS_OSX->last_button_state |= (MouseButton)mask;
sc->set_button_mask(DS_OSX->last_button_state);
Input::get_singleton()->accumulate_input_event(sc);
@@ -1513,7 +1513,7 @@ inline void sendScrollEvent(DisplayServer::WindowID window_id, int button, doubl
sc->set_pressed(false);
sc->set_position(wd.mouse_pos);
sc->set_global_position(wd.mouse_pos);
- DS_OSX->last_button_state &= ~mask;
+ DS_OSX->last_button_state &= (MouseButton)~mask;
sc->set_button_mask(DS_OSX->last_button_state);
Input::get_singleton()->accumulate_input_event(sc);
@@ -2173,7 +2173,7 @@ Point2i DisplayServerOSX::mouse_get_absolute_position() const {
return Vector2i();
}
-int DisplayServerOSX::mouse_get_button_state() const {
+MouseButton DisplayServerOSX::mouse_get_button_state() const {
return last_button_state;
}
@@ -3755,7 +3755,6 @@ DisplayServerOSX::DisplayServerOSX(const String &p_rendering_driver, WindowMode
key_event_pos = 0;
mouse_mode = MOUSE_MODE_VISIBLE;
- last_button_state = 0;
autoreleasePool = [[NSAutoreleasePool alloc] init];
diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp
index b12526915f..126ebc1908 100644
--- a/platform/osx/joypad_osx.cpp
+++ b/platform/osx/joypad_osx.cpp
@@ -390,38 +390,38 @@ bool joypad::check_ff_features() {
static int process_hat_value(int p_min, int p_max, int p_value) {
int range = (p_max - p_min + 1);
int value = p_value - p_min;
- int hat_value = Input::HAT_MASK_CENTER;
+ int hat_value = HatMask::HAT_MASK_CENTER;
if (range == 4) {
value *= 2;
}
switch (value) {
case 0:
- hat_value = Input::HAT_MASK_UP;
+ hat_value = (HatMask)HatMask::HAT_MASK_UP;
break;
case 1:
- hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT;
+ hat_value = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_RIGHT);
break;
case 2:
- hat_value = Input::HAT_MASK_RIGHT;
+ hat_value = (HatMask)HatMask::HAT_MASK_RIGHT;
break;
case 3:
- hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_RIGHT;
+ hat_value = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_RIGHT);
break;
case 4:
- hat_value = Input::HAT_MASK_DOWN;
+ hat_value = (HatMask)HatMask::HAT_MASK_DOWN;
break;
case 5:
- hat_value = Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT;
+ hat_value = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_LEFT);
break;
case 6:
- hat_value = Input::HAT_MASK_LEFT;
+ hat_value = (HatMask)HatMask::HAT_MASK_LEFT;
break;
case 7:
- hat_value = Input::HAT_MASK_UP | Input::HAT_MASK_LEFT;
+ hat_value = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_LEFT);
break;
default:
- hat_value = Input::HAT_MASK_CENTER;
+ hat_value = (HatMask)HatMask::HAT_MASK_CENTER;
break;
}
return hat_value;
@@ -458,17 +458,17 @@ void JoypadOSX::process_joypads() {
for (int j = 0; j < joy.axis_elements.size(); j++) {
rec_element &elem = joy.axis_elements.write[j];
int value = joy.get_hid_element_state(&elem);
- input->joy_axis(joy.id, j, axis_correct(value, elem.min, elem.max));
+ input->joy_axis(joy.id, (JoyAxis)j, axis_correct(value, elem.min, elem.max));
}
for (int j = 0; j < joy.button_elements.size(); j++) {
int value = joy.get_hid_element_state(&joy.button_elements.write[j]);
- input->joy_button(joy.id, j, (value >= 1));
+ input->joy_button(joy.id, (JoyButton)j, (value >= 1));
}
for (int j = 0; j < joy.hat_elements.size(); j++) {
rec_element &elem = joy.hat_elements.write[j];
int value = joy.get_hid_element_state(&elem);
int hat_value = process_hat_value(elem.min, elem.max, value);
- input->joy_hat(joy.id, hat_value);
+ input->joy_hat(joy.id, (HatMask)hat_value);
}
if (joy.ffservice) {
diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp
index 570c41a8b3..1da17ffc5d 100644
--- a/platform/uwp/app.cpp
+++ b/platform/uwp/app.cpp
@@ -145,7 +145,7 @@ void App::SetWindow(CoreWindow ^ p_window) {
Main::setup2();
}
-static int _get_button(Windows::UI::Input::PointerPoint ^ pt) {
+static MouseButton _get_button(Windows::UI::Input::PointerPoint ^ pt) {
using namespace Windows::UI::Input;
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
@@ -177,7 +177,7 @@ static int _get_button(Windows::UI::Input::PointerPoint ^ pt) {
}
#endif
- return 0;
+ return MOUSE_BUTTON_NONE;
};
static bool _is_touch(Windows::UI::Input::PointerPoint ^ pointerPoint) {
@@ -241,7 +241,7 @@ static int _get_finger(uint32_t p_touch_id) {
void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Core::PointerEventArgs ^ args, bool p_pressed, bool p_is_wheel) {
Windows::UI::Input::PointerPoint ^ point = args->CurrentPoint;
Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os);
- int but = _get_button(point);
+ MouseButton but = _get_button(point);
if (_is_touch(point)) {
Ref<InputEventScreenTouch> screen_touch;
screen_touch.instantiate();
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index b0f6bbd330..e26e204f5f 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -126,8 +126,6 @@ void OS_UWP::set_keep_screen_on(bool p_enabled) {
}
void OS_UWP::initialize_core() {
- last_button_state = 0;
-
//RedirectIOToConsole();
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
@@ -423,7 +421,7 @@ Point2 OS_UWP::get_mouse_position() const {
return Point2(old_x, old_y);
}
-int OS_UWP::get_mouse_button_state() const {
+MouseButton OS_UWP::get_mouse_button_state() const {
return last_button_state;
}
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index a4d3d6d52a..3a735889b0 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -106,7 +106,7 @@ private:
bool control_mem;
bool meta_mem;
bool force_quit;
- uint32_t last_button_state;
+ MouseButton last_button_state = MOUSE_BUTTON_NONE;
CursorShape cursor_shape;
@@ -173,7 +173,7 @@ public:
MouseMode get_mouse_mode() const;
virtual Point2 get_mouse_position() const;
- virtual int get_mouse_button_state() const;
+ virtual MouseButton get_mouse_button_state() const;
virtual void set_window_title(const String &p_title);
virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0);
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index 5a2bb354d7..f7172598ec 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -161,7 +161,7 @@ Point2i DisplayServerWindows::mouse_get_position() const {
//return Point2(old_x, old_y);
}
-int DisplayServerWindows::mouse_get_button_state() const {
+MouseButton DisplayServerWindows::mouse_get_button_state() const {
return last_button_state;
}
@@ -2391,41 +2391,41 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
switch (uMsg) {
case WM_LBUTTONDOWN: {
mb->set_pressed(true);
- mb->set_button_index(1);
+ mb->set_button_index(MOUSE_BUTTON_LEFT);
} break;
case WM_LBUTTONUP: {
mb->set_pressed(false);
- mb->set_button_index(1);
+ mb->set_button_index(MOUSE_BUTTON_LEFT);
} break;
case WM_MBUTTONDOWN: {
mb->set_pressed(true);
- mb->set_button_index(3);
+ mb->set_button_index(MOUSE_BUTTON_MIDDLE);
} break;
case WM_MBUTTONUP: {
mb->set_pressed(false);
- mb->set_button_index(3);
+ mb->set_button_index(MOUSE_BUTTON_MIDDLE);
} break;
case WM_RBUTTONDOWN: {
mb->set_pressed(true);
- mb->set_button_index(2);
+ mb->set_button_index(MOUSE_BUTTON_RIGHT);
} break;
case WM_RBUTTONUP: {
mb->set_pressed(false);
- mb->set_button_index(2);
+ mb->set_button_index(MOUSE_BUTTON_RIGHT);
} break;
case WM_LBUTTONDBLCLK: {
mb->set_pressed(true);
- mb->set_button_index(1);
+ mb->set_button_index(MOUSE_BUTTON_LEFT);
mb->set_double_click(true);
} break;
case WM_RBUTTONDBLCLK: {
mb->set_pressed(true);
- mb->set_button_index(2);
+ mb->set_button_index(MOUSE_BUTTON_RIGHT);
mb->set_double_click(true);
} break;
case WM_MBUTTONDBLCLK: {
mb->set_pressed(true);
- mb->set_button_index(3);
+ mb->set_button_index(MOUSE_BUTTON_MIDDLE);
mb->set_double_click(true);
} break;
case WM_MOUSEWHEEL: {
@@ -2492,9 +2492,9 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
mb->set_alt_pressed(alt_mem);
//mb->is_alt_pressed()=(wParam&MK_MENU)!=0;
if (mb->is_pressed()) {
- last_button_state |= (1 << (mb->get_button_index() - 1));
+ last_button_state |= MouseButton(1 << (mb->get_button_index() - 1));
} else {
- last_button_state &= ~(1 << (mb->get_button_index() - 1));
+ last_button_state &= (MouseButton) ~(1 << (mb->get_button_index() - 1));
}
mb->set_button_mask(last_button_state);
@@ -2534,7 +2534,7 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
//send release for mouse wheel
Ref<InputEventMouseButton> mbd = mb->duplicate();
mbd->set_window_id(window_id);
- last_button_state &= ~(1 << (mbd->get_button_index() - 1));
+ last_button_state &= (MouseButton) ~(1 << (mbd->get_button_index() - 1));
mbd->set_button_mask(last_button_state);
mbd->set_pressed(false);
Input::get_singleton()->accumulate_input_event(mbd);
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index a734077e59..d71e579c67 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -408,7 +408,7 @@ class DisplayServerWindows : public DisplayServer {
bool shift_mem = false;
bool control_mem = false;
bool meta_mem = false;
- uint32_t last_button_state = 0;
+ MouseButton last_button_state = MOUSE_BUTTON_NONE;
bool use_raw_input = false;
bool drop_events = false;
bool in_dispatch_input_event = false;
@@ -449,7 +449,7 @@ public:
virtual void mouse_warp_to_position(const Point2i &p_to);
virtual Point2i mouse_get_position() const;
- virtual int mouse_get_button_state() const;
+ virtual MouseButton mouse_get_button_state() const;
virtual void clipboard_set(const String &p_text);
virtual String clipboard_get() const;
diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp
index da36dc1f2b..94da63e49d 100644
--- a/platform/windows/joypad_windows.cpp
+++ b/platform/windows/joypad_windows.cpp
@@ -330,7 +330,7 @@ void JoypadWindows::process_joypads() {
if (joy.state.dwPacketNumber != joy.last_packet) {
int button_mask = XINPUT_GAMEPAD_DPAD_UP;
for (int j = 0; j <= 16; j++) {
- input->joy_button(joy.id, j, joy.state.Gamepad.wButtons & button_mask);
+ input->joy_button(joy.id, (JoyButton)j, joy.state.Gamepad.wButtons & button_mask);
button_mask = button_mask * 2;
}
@@ -381,12 +381,12 @@ void JoypadWindows::process_joypads() {
for (int j = 0; j < 128; j++) {
if (js.rgbButtons[j] & 0x80) {
if (!joy->last_buttons[j]) {
- input->joy_button(joy->id, j, true);
+ input->joy_button(joy->id, (JoyButton)j, true);
joy->last_buttons[j] = true;
}
} else {
if (joy->last_buttons[j]) {
- input->joy_button(joy->id, j, false);
+ input->joy_button(joy->id, (JoyButton)j, false);
joy->last_buttons[j] = false;
}
}
@@ -400,7 +400,7 @@ void JoypadWindows::process_joypads() {
for (int j = 0; j < joy->joy_axis.size(); j++) {
for (int k = 0; k < count; k++) {
if (joy->joy_axis[j] == axes[k]) {
- input->joy_axis(joy->id, j, axis_correct(values[k]));
+ input->joy_axis(joy->id, (JoyAxis)j, axis_correct(values[k]));
break;
};
};
@@ -410,38 +410,38 @@ void JoypadWindows::process_joypads() {
}
void JoypadWindows::post_hat(int p_device, DWORD p_dpad) {
- int dpad_val = 0;
+ HatMask dpad_val = (HatMask)0;
// Should be -1 when centered, but according to docs:
// "Some drivers report the centered position of the POV indicator as 65,535. Determine whether the indicator is centered as follows:
// BOOL POVCentered = (LOWORD(dwPOV) == 0xFFFF);"
// https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ee416628(v%3Dvs.85)#remarks
if (LOWORD(p_dpad) == 0xFFFF) {
- dpad_val = Input::HAT_MASK_CENTER;
+ dpad_val = (HatMask)HatMask::HAT_MASK_CENTER;
}
if (p_dpad == 0) {
- dpad_val = Input::HAT_MASK_UP;
+ dpad_val = (HatMask)HatMask::HAT_MASK_UP;
} else if (p_dpad == 4500) {
- dpad_val = (Input::HAT_MASK_UP | Input::HAT_MASK_RIGHT);
+ dpad_val = (HatMask)(HatMask::HAT_MASK_UP | HatMask::HAT_MASK_RIGHT);
} else if (p_dpad == 9000) {
- dpad_val = Input::HAT_MASK_RIGHT;
+ dpad_val = (HatMask)HatMask::HAT_MASK_RIGHT;
} else if (p_dpad == 13500) {
- dpad_val = (Input::HAT_MASK_RIGHT | Input::HAT_MASK_DOWN);
+ dpad_val = (HatMask)(HatMask::HAT_MASK_RIGHT | HatMask::HAT_MASK_DOWN);
} else if (p_dpad == 18000) {
- dpad_val = Input::HAT_MASK_DOWN;
+ dpad_val = (HatMask)HatMask::HAT_MASK_DOWN;
} else if (p_dpad == 22500) {
- dpad_val = (Input::HAT_MASK_DOWN | Input::HAT_MASK_LEFT);
+ dpad_val = (HatMask)(HatMask::HAT_MASK_DOWN | HatMask::HAT_MASK_LEFT);
} else if (p_dpad == 27000) {
- dpad_val = Input::HAT_MASK_LEFT;
+ dpad_val = (HatMask)HatMask::HAT_MASK_LEFT;
} else if (p_dpad == 31500) {
- dpad_val = (Input::HAT_MASK_LEFT | Input::HAT_MASK_UP);
+ dpad_val = (HatMask)(HatMask::HAT_MASK_LEFT | HatMask::HAT_MASK_UP);
}
input->joy_hat(p_device, dpad_val);
};
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index 4f2c816934..a91e712b0b 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -204,7 +204,7 @@ void XRController3D::_notification(int p_what) {
// check button states
for (int i = 0; i < 16; i++) {
bool was_pressed = (button_states & mask) == mask;
- bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i);
+ bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i);
if (!was_pressed && is_pressed) {
emit_signal("button_pressed", i);
@@ -304,7 +304,7 @@ bool XRController3D::is_button_pressed(int p_button) const {
return false;
};
- return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button);
+ return Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)p_button);
};
float XRController3D::get_joystick_axis(int p_axis) const {
@@ -313,7 +313,7 @@ float XRController3D::get_joystick_axis(int p_axis) const {
return 0.0;
};
- return Input::get_singleton()->get_joy_axis(joy_id, p_axis);
+ return Input::get_singleton()->get_joy_axis(joy_id, (JoyAxis)p_axis);
};
real_t XRController3D::get_rumble() const {
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 6e6f5d9300..ff7ea17008 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -248,6 +248,8 @@ void CodeEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
update();
} break;
+ default:
+ break;
}
return;
}
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 895f9db353..941dd30057 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -140,6 +140,8 @@ void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
accept_event();
}
} break;
+ default:
+ break;
}
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index b796b494eb..b02b4edd8e 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3161,6 +3161,8 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
}
} break;
+ default:
+ break;
}
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 4ba50eeaa8..e31135b46a 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -644,9 +644,9 @@ void Viewport::_process_picking() {
physics_last_mouse_state.meta = mb->is_meta_pressed();
if (mb->is_pressed()) {
- physics_last_mouse_state.mouse_mask |= (1 << (mb->get_button_index() - 1));
+ physics_last_mouse_state.mouse_mask |= (MouseButton)(1 << (mb->get_button_index() - 1));
} else {
- physics_last_mouse_state.mouse_mask &= ~(1 << (mb->get_button_index() - 1));
+ physics_last_mouse_state.mouse_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1));
// If touch mouse raised, assume we don't know last mouse pos until new events come
if (mb->get_device() == InputEvent::DEVICE_ID_TOUCH_MOUSE) {
@@ -2588,7 +2588,7 @@ void Viewport::_drop_mouse_focus() {
mb.instantiate();
mb->set_position(c->get_local_mouse_position());
mb->set_global_position(c->get_local_mouse_position());
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(false);
c->call(SceneStringNames::get_singleton()->_gui_input, mb);
}
@@ -2666,7 +2666,7 @@ void Viewport::_post_gui_grab_click_focus() {
//send unclick
mb->set_position(click);
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(false);
gui.mouse_focus->call(SceneStringNames::get_singleton()->_gui_input, mb);
}
@@ -2684,7 +2684,7 @@ void Viewport::_post_gui_grab_click_focus() {
//send click
mb->set_position(click);
- mb->set_button_index(i + 1);
+ mb->set_button_index(MouseButton(i + 1));
mb->set_pressed(true);
gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb);
}
diff --git a/servers/display_server.cpp b/servers/display_server.cpp
index ded4b849ef..d746117884 100644
--- a/servers/display_server.cpp
+++ b/servers/display_server.cpp
@@ -148,8 +148,8 @@ Point2i DisplayServer::mouse_get_position() const {
ERR_FAIL_V_MSG(Point2i(), "Mouse is not supported by this display server.");
}
-int DisplayServer::mouse_get_button_state() const {
- ERR_FAIL_V_MSG(0, "Mouse is not supported by this display server.");
+MouseButton DisplayServer::mouse_get_button_state() const {
+ ERR_FAIL_V_MSG(MOUSE_BUTTON_NONE, "Mouse is not supported by this display server.");
}
void DisplayServer::clipboard_set(const String &p_text) {
diff --git a/servers/display_server.h b/servers/display_server.h
index b8201f6fd5..7dab7b7481 100644
--- a/servers/display_server.h
+++ b/servers/display_server.h
@@ -152,7 +152,7 @@ public:
virtual void mouse_warp_to_position(const Point2i &p_to);
virtual Point2i mouse_get_position() const;
virtual Point2i mouse_get_absolute_position() const;
- virtual int mouse_get_button_state() const;
+ virtual MouseButton mouse_get_button_state() const;
virtual void clipboard_set(const String &p_text);
virtual String clipboard_get() const;