Subversion Repositories Games.Descent

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Portions of this file are copyright Rebirth contributors and licensed as
  3.  * described in COPYING.txt.
  4.  * Portions of this file are copyright Parallax Software and licensed
  5.  * according to the Parallax license below.
  6.  * See COPYING.txt for license details.
  7.  
  8. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  9. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  10. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  11. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  12. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  13. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  14. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  15. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  16. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
  17. COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  18. */
  19.  
  20. /*
  21.  *
  22.  * Header for keyboard functions
  23.  *
  24.  */
  25.  
  26. #pragma once
  27.  
  28. #include <cstdint>
  29. #include <SDL_version.h>
  30. #if SDL_MAJOR_VERSION == 1
  31. #include <SDL_keysym.h>
  32. #elif SDL_MAJOR_VERSION == 2
  33. #include <SDL_keyboard.h>
  34. #endif
  35. #include "pstypes.h"
  36. #include "maths.h"
  37. #include "fwd-event.h"
  38.  
  39. #define KEY_BUFFER_SIZE 16
  40. #define KEY_REPEAT_DELAY 400
  41. #define KEY_REPEAT_INTERVAL 50
  42.  
  43. #ifdef __cplusplus
  44. #include "dxxsconf.h"
  45. #include "dsx-ns.h"
  46. #include <array>
  47.  
  48. struct SDL_KeyboardEvent;
  49.  
  50. namespace dcx {
  51.  
  52. //==========================================================================
  53. // This installs the int9 vector and initializes the keyboard in buffered
  54. // ASCII mode. key_close simply undoes that.
  55. extern void key_init();
  56.  
  57. // Time in seconds when last key was pressed...
  58. extern fix64 keyd_time_when_last_pressed;
  59.  
  60. // Stores Unicode values registered in one event_loop call
  61. extern std::array<unsigned char, KEY_BUFFER_SIZE> unicode_frame_buffer;
  62.  
  63. extern void key_flush();    // Clears the 256 char buffer
  64. extern void event_keycommand_send(unsigned key); // synthesize a key command event from a keycode
  65. extern int event_key_get(const d_event &event); // Get the keycode from the EVENT_KEY_COMMAND event
  66. extern int event_key_get_raw(const d_event &event);     // same as above but without mod states
  67. unsigned char key_ascii();
  68.  
  69. class pressed_keys
  70. {
  71. // Set to 1 if the key is currently down, else 0
  72.         uint8_t modifier_cache;
  73.         std::array<uint8_t, 256> pressed;
  74. public:
  75.         static constexpr unsigned modifier_shift = 8;
  76.         void update_pressed(std::size_t i, uint8_t p)
  77.         {
  78.                 pressed[i] = p;
  79.         }
  80.         void update(std::size_t, uint8_t);
  81.         uint8_t operator[](const std::size_t i) const
  82.         {
  83.                 return pressed[i];
  84.         }
  85.         unsigned get_modifiers() const
  86.         {
  87.                 return modifier_cache << modifier_shift;
  88.         }
  89. };
  90.  
  91. extern pressed_keys keyd_pressed;
  92.  
  93. #define key_toggle_repeat(E)    key_toggle_repeat##E()
  94. void key_toggle_repeat0();
  95. void key_toggle_repeat1();
  96. window_event_result key_handler(const SDL_KeyboardEvent *kevent);
  97.  
  98. // for key_ismodlck
  99. #define KEY_ISMOD       1
  100. #define KEY_ISLCK       2
  101.  
  102. #define KEY_SHIFTED     0x100
  103. #define KEY_ALTED       0x200
  104. #define KEY_CTRLED      0x400
  105. #define KEY_DEBUGGED    0x800
  106. #define KEY_METAED              0x1000
  107. #define KEY_COMMAND             KEY_METAED      // Mac meta key
  108.  
  109. #define KEY_0           0x0B
  110. #define KEY_1           0x02
  111. #define KEY_2           0x03
  112. #define KEY_3           0x04
  113. #define KEY_4           0x05
  114. #define KEY_5           0x06
  115. #define KEY_6           0x07
  116. #define KEY_7           0x08
  117. #define KEY_8           0x09
  118. #define KEY_9           0x0A
  119.  
  120. #define KEY_A           0x1E
  121. #define KEY_B           0x30
  122. #define KEY_C           0x2E
  123. #define KEY_D           0x20
  124. #define KEY_E           0x12
  125. #define KEY_F           0x21
  126. #define KEY_G           0x22
  127. #define KEY_H           0x23
  128. #define KEY_I           0x17
  129. #define KEY_J           0x24
  130. #define KEY_K           0x25
  131. #define KEY_L           0x26
  132. #define KEY_M           0x32
  133. #define KEY_N           0x31
  134. #define KEY_O           0x18
  135. #define KEY_P           0x19
  136. #define KEY_Q           0x10
  137. #define KEY_R           0x13
  138. #define KEY_S           0x1F
  139. #define KEY_T           0x14
  140. #define KEY_U           0x16
  141. #define KEY_V           0x2F
  142. #define KEY_W           0x11
  143. #define KEY_X           0x2D
  144. #define KEY_Y           0x15
  145. #define KEY_Z           0x2C
  146.  
  147. #define KEY_MINUS       0x0C
  148. #define KEY_EQUAL       0x0D
  149. //Note: this is what we normally think of as slash:
  150. #define KEY_DIVIDE      0x35
  151. //Note: this is BACKslash:
  152. #define KEY_SLASH       0x2B
  153. #define KEY_COMMA       0x33
  154. #define KEY_PERIOD      0x34
  155. #define KEY_SEMICOL     0x27
  156.  
  157. #define KEY_LBRACKET    0x1A
  158. #define KEY_RBRACKET    0x1B
  159.  
  160. #define KEY_RAPOSTRO    0x28
  161. #define KEY_LAPOSTRO    0x29
  162.  
  163. #define KEY_ESC         0x01
  164. #define KEY_ENTER       0x1C
  165. #define KEY_BACKSP      0x0E
  166. #define KEY_TAB         0x0F
  167. #define KEY_SPACEBAR    0x39
  168.  
  169. #define KEY_NUMLOCK     0x45
  170. #define KEY_SCROLLOCK   0x46
  171. #define KEY_CAPSLOCK    0x3A
  172.  
  173. #define KEY_LSHIFT      0x2A
  174. #define KEY_RSHIFT      0x36
  175.  
  176. #define KEY_LALT        0x38
  177. #define KEY_RALT        0xB8
  178.  
  179. #define KEY_LCTRL       0x1D
  180. #define KEY_RCTRL       0x9D
  181. #define KEY_LMETA               0x9E
  182. #define KEY_RMETA               0x9F
  183.  
  184. #define KEY_F1          0x3B
  185. #define KEY_F2          0x3C
  186. #define KEY_F3          0x3D
  187. #define KEY_F4          0x3E
  188. #define KEY_F5          0x3F
  189. #define KEY_F6          0x40
  190. #define KEY_F7          0x41
  191. #define KEY_F8          0x42
  192. #define KEY_F9          0x43
  193. #define KEY_F10         0x44
  194. #define KEY_F11         0x57
  195. #define KEY_F12         0x58
  196.  
  197. #define KEY_PAD0        0x52
  198. #define KEY_PAD1        0x4F
  199. #define KEY_PAD2        0x50
  200. #define KEY_PAD3        0x51
  201. #define KEY_PAD4        0x4B
  202. #define KEY_PAD5        0x4C
  203. #define KEY_PAD6        0x4D
  204. #define KEY_PAD7        0x47
  205. #define KEY_PAD8        0x48
  206. #define KEY_PAD9        0x49
  207. #define KEY_PADMINUS    0x4A
  208. #define KEY_PADPLUS     0x4E
  209. #define KEY_PADPERIOD   0x53
  210. #define KEY_PADDIVIDE   0xB5
  211. #define KEY_PADMULTIPLY 0x37
  212. #define KEY_PADENTER    0x9C
  213.  
  214. #define KEY_INSERT      0xD2
  215. #define KEY_HOME        0xC7
  216. #define KEY_PAGEUP      0xC9
  217. #define KEY_DELETE      0xD3
  218. #define KEY_END         0xCF
  219. #define KEY_PAGEDOWN    0xD1
  220. #define KEY_UP          0xC8
  221. #define KEY_DOWN        0xD0
  222. #define KEY_LEFT        0xCB
  223. #define KEY_RIGHT       0xCD
  224.  
  225. #define KEY_PRINT_SCREEN        0xB7
  226.  
  227. #define KEY_PAUSE                       0x61
  228.  
  229. struct key_props
  230. {
  231.         char key_text[7];
  232.         unsigned char ascii_value;
  233. #if SDL_MAJOR_VERSION == 1
  234.         SDLKey sym;
  235. #elif SDL_MAJOR_VERSION == 2
  236.         SDL_Keycode sym;
  237. #endif
  238. };
  239.  
  240. extern const std::array<key_props, 256> key_properties;
  241.  
  242. }
  243.  
  244. #endif
  245.