input_enums.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /**************************************************************************/
  2. /* input_enums.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/error/error_macros.h"
  32. enum class InputEventType {
  33. INVALID = -1,
  34. KEY,
  35. MOUSE_BUTTON,
  36. MOUSE_MOTION,
  37. JOY_MOTION,
  38. JOY_BUTTON,
  39. SCREEN_TOUCH,
  40. SCREEN_DRAG,
  41. MAGNIFY_GESTURE,
  42. PAN_GESTURE,
  43. MIDI,
  44. SHORTCUT,
  45. ACTION,
  46. MAX,
  47. };
  48. enum class HatDir {
  49. UP = 0,
  50. RIGHT = 1,
  51. DOWN = 2,
  52. LEFT = 3,
  53. MAX = 4,
  54. };
  55. enum class HatMask {
  56. CENTER = 0,
  57. UP = 1,
  58. RIGHT = 2,
  59. DOWN = 4,
  60. LEFT = 8,
  61. };
  62. enum class JoyAxis {
  63. INVALID = -1,
  64. LEFT_X = 0,
  65. LEFT_Y = 1,
  66. RIGHT_X = 2,
  67. RIGHT_Y = 3,
  68. TRIGGER_LEFT = 4,
  69. TRIGGER_RIGHT = 5,
  70. SDL_MAX = 6,
  71. MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes.
  72. };
  73. enum class JoyButton {
  74. INVALID = -1,
  75. A = 0,
  76. B = 1,
  77. X = 2,
  78. Y = 3,
  79. BACK = 4,
  80. GUIDE = 5,
  81. START = 6,
  82. LEFT_STICK = 7,
  83. RIGHT_STICK = 8,
  84. LEFT_SHOULDER = 9,
  85. RIGHT_SHOULDER = 10,
  86. DPAD_UP = 11,
  87. DPAD_DOWN = 12,
  88. DPAD_LEFT = 13,
  89. DPAD_RIGHT = 14,
  90. MISC1 = 15,
  91. PADDLE1 = 16,
  92. PADDLE2 = 17,
  93. PADDLE3 = 18,
  94. PADDLE4 = 19,
  95. TOUCHPAD = 20,
  96. SDL_MAX = 21,
  97. MAX = 128, // Android supports up to 36 buttons. DirectInput supports up to 128 buttons.
  98. };
  99. enum class MIDIMessage {
  100. NONE = 0,
  101. NOTE_OFF = 0x8,
  102. NOTE_ON = 0x9,
  103. AFTERTOUCH = 0xA,
  104. CONTROL_CHANGE = 0xB,
  105. PROGRAM_CHANGE = 0xC,
  106. CHANNEL_PRESSURE = 0xD,
  107. PITCH_BEND = 0xE,
  108. SYSTEM_EXCLUSIVE = 0xF0,
  109. QUARTER_FRAME = 0xF1,
  110. SONG_POSITION_POINTER = 0xF2,
  111. SONG_SELECT = 0xF3,
  112. TUNE_REQUEST = 0xF6,
  113. TIMING_CLOCK = 0xF8,
  114. START = 0xFA,
  115. CONTINUE = 0xFB,
  116. STOP = 0xFC,
  117. ACTIVE_SENSING = 0xFE,
  118. SYSTEM_RESET = 0xFF,
  119. };
  120. enum class MouseButton {
  121. NONE = 0,
  122. LEFT = 1,
  123. RIGHT = 2,
  124. MIDDLE = 3,
  125. WHEEL_UP = 4,
  126. WHEEL_DOWN = 5,
  127. WHEEL_LEFT = 6,
  128. WHEEL_RIGHT = 7,
  129. MB_XBUTTON1 = 8, // "XBUTTON1" is a reserved word on Windows.
  130. MB_XBUTTON2 = 9, // "XBUTTON2" is a reserved word on Windows.
  131. };
  132. enum class MouseButtonMask {
  133. NONE = 0,
  134. LEFT = (1 << (int(MouseButton::LEFT) - 1)),
  135. RIGHT = (1 << (int(MouseButton::RIGHT) - 1)),
  136. MIDDLE = (1 << (int(MouseButton::MIDDLE) - 1)),
  137. MB_XBUTTON1 = (1 << (int(MouseButton::MB_XBUTTON1) - 1)),
  138. MB_XBUTTON2 = (1 << (int(MouseButton::MB_XBUTTON2) - 1)),
  139. };
  140. inline MouseButtonMask mouse_button_to_mask(MouseButton button) {
  141. ERR_FAIL_COND_V(button == MouseButton::NONE, MouseButtonMask::NONE);
  142. return MouseButtonMask(1 << ((int)button - 1));
  143. }
  144. constexpr MouseButtonMask operator|(MouseButtonMask p_a, MouseButtonMask p_b) {
  145. return static_cast<MouseButtonMask>(static_cast<int>(p_a) | static_cast<int>(p_b));
  146. }
  147. constexpr MouseButtonMask &operator|=(MouseButtonMask &p_a, MouseButtonMask p_b) {
  148. return p_a = p_a | p_b;
  149. }