input_enums.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #ifndef INPUT_ENUMS_H
  31. #define INPUT_ENUMS_H
  32. enum class HatDir {
  33. UP = 0,
  34. RIGHT = 1,
  35. DOWN = 2,
  36. LEFT = 3,
  37. MAX = 4,
  38. };
  39. enum class HatMask {
  40. CENTER = 0,
  41. UP = 1,
  42. RIGHT = 2,
  43. DOWN = 4,
  44. LEFT = 8,
  45. };
  46. enum class JoyAxis {
  47. INVALID = -1,
  48. LEFT_X = 0,
  49. LEFT_Y = 1,
  50. RIGHT_X = 2,
  51. RIGHT_Y = 3,
  52. TRIGGER_LEFT = 4,
  53. TRIGGER_RIGHT = 5,
  54. SDL_MAX = 6,
  55. MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes.
  56. };
  57. enum class JoyButton {
  58. INVALID = -1,
  59. A = 0,
  60. B = 1,
  61. X = 2,
  62. Y = 3,
  63. BACK = 4,
  64. GUIDE = 5,
  65. START = 6,
  66. LEFT_STICK = 7,
  67. RIGHT_STICK = 8,
  68. LEFT_SHOULDER = 9,
  69. RIGHT_SHOULDER = 10,
  70. DPAD_UP = 11,
  71. DPAD_DOWN = 12,
  72. DPAD_LEFT = 13,
  73. DPAD_RIGHT = 14,
  74. MISC1 = 15,
  75. PADDLE1 = 16,
  76. PADDLE2 = 17,
  77. PADDLE3 = 18,
  78. PADDLE4 = 19,
  79. TOUCHPAD = 20,
  80. SDL_MAX = 21,
  81. MAX = 128, // Android supports up to 36 buttons. DirectInput supports up to 128 buttons.
  82. };
  83. enum class MIDIMessage {
  84. NONE = 0,
  85. NOTE_OFF = 0x8,
  86. NOTE_ON = 0x9,
  87. AFTERTOUCH = 0xA,
  88. CONTROL_CHANGE = 0xB,
  89. PROGRAM_CHANGE = 0xC,
  90. CHANNEL_PRESSURE = 0xD,
  91. PITCH_BEND = 0xE,
  92. SYSTEM_EXCLUSIVE = 0xF0,
  93. QUARTER_FRAME = 0xF1,
  94. SONG_POSITION_POINTER = 0xF2,
  95. SONG_SELECT = 0xF3,
  96. TUNE_REQUEST = 0xF6,
  97. TIMING_CLOCK = 0xF8,
  98. START = 0xFA,
  99. CONTINUE = 0xFB,
  100. STOP = 0xFC,
  101. ACTIVE_SENSING = 0xFE,
  102. SYSTEM_RESET = 0xFF,
  103. };
  104. enum class MouseButton {
  105. NONE = 0,
  106. LEFT = 1,
  107. RIGHT = 2,
  108. MIDDLE = 3,
  109. WHEEL_UP = 4,
  110. WHEEL_DOWN = 5,
  111. WHEEL_LEFT = 6,
  112. WHEEL_RIGHT = 7,
  113. MB_XBUTTON1 = 8, // "XBUTTON1" is a reserved word on Windows.
  114. MB_XBUTTON2 = 9, // "XBUTTON2" is a reserved word on Windows.
  115. MASK_LEFT = (1 << (LEFT - 1)),
  116. MASK_RIGHT = (1 << (RIGHT - 1)),
  117. MASK_MIDDLE = (1 << (MIDDLE - 1)),
  118. MASK_XBUTTON1 = (1 << (MB_XBUTTON1 - 1)),
  119. MASK_XBUTTON2 = (1 << (MB_XBUTTON2 - 1)),
  120. };
  121. inline MouseButton mouse_button_to_mask(MouseButton button) {
  122. return MouseButton(1 << ((int)button - 1));
  123. }
  124. inline MouseButton operator&(MouseButton a, MouseButton b) {
  125. return (MouseButton)((int)a & (int)b);
  126. }
  127. inline MouseButton operator|(MouseButton a, MouseButton b) {
  128. return (MouseButton)((int)a | (int)b);
  129. }
  130. inline MouseButton operator^(MouseButton a, MouseButton b) {
  131. return (MouseButton)((int)a ^ (int)b);
  132. }
  133. inline MouseButton &operator|=(MouseButton &a, MouseButton b) {
  134. return (MouseButton &)((int &)a |= (int)b);
  135. }
  136. inline MouseButton &operator&=(MouseButton &a, MouseButton b) {
  137. return (MouseButton &)((int &)a &= (int)b);
  138. }
  139. inline MouseButton operator~(MouseButton a) {
  140. return (MouseButton)(~(int)a);
  141. }
  142. inline HatMask operator|(HatMask a, HatMask b) {
  143. return (HatMask)((int)a | (int)b);
  144. }
  145. inline HatMask operator&(HatMask a, HatMask b) {
  146. return (HatMask)((int)a & (int)b);
  147. }
  148. inline HatMask &operator&=(HatMask &a, HatMask b) {
  149. return (HatMask &)((int &)a &= (int)b);
  150. }
  151. inline HatMask &operator|=(HatMask &a, HatMask b) {
  152. return (HatMask &)((int &)a |= (int)b);
  153. }
  154. inline HatMask operator~(HatMask a) {
  155. return (HatMask)(~(int)a);
  156. }
  157. #endif // INPUT_ENUMS_H