summaryrefslogtreecommitdiff
path: root/core/input
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2021-03-25 19:58:48 -0400
committerAaron Franke <arnfranke@yahoo.com>2021-06-20 11:53:01 -0400
commite919d894f84ea86ee43a3e1b8a675b9fec28f01c (patch)
tree56108ded1c02939ead6dcf9f06950fb24b6cead5 /core/input
parent1acc76fecc9e613724c920633af6bae059444030 (diff)
Move many input enums to their own file
Diffstat (limited to 'core/input')
-rw-r--r--core/input/input.cpp40
-rw-r--r--core/input/input.h18
-rw-r--r--core/input/input_enums.h126
-rw-r--r--core/input/input_event.h67
4 files changed, 148 insertions, 103 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp
index be536aa730..384b617d13 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -993,21 +993,21 @@ 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);
@@ -1162,17 +1162,17 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J
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.");
diff --git a/core/input/input.h b/core/input/input.h
index ecb4981b13..0d9976cb40 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;
};
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.h b/core/input/input_event.h
index 3ef135221d..d5a034f44d 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.