SDL_vglevents.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:9k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*
  2.     SDL - Simple DirectMedia Layer
  3.     Copyright (C) 1997, 1998, 1999, 2000  Sam Lantinga
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.     You should have received a copy of the GNU Library General Public
  13.     License along with this library; if not, write to the Free
  14.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  15.     Sam Lantinga
  16.     slouken@libsdl.org
  17. */
  18. #ifdef SAVE_RCSID
  19. static char rcsid =
  20.  "@(#) $Id: SDL_vglevents.c,v 1.3 2002/04/22 21:38:05 wmay Exp $";
  21. #endif
  22. /* Handle the event stream, converting X11 events into SDL events */
  23. #include <stdio.h>
  24. #include <sys/fbio.h>
  25. #include <sys/consio.h>
  26. #include <sys/kbio.h>
  27. #include <vgl.h>
  28. #include "SDL.h"
  29. #include "SDL_thread.h"
  30. #include "SDL_sysevents.h"
  31. #include "SDL_events_c.h"
  32. #include "SDL_vglvideo.h"
  33. #include "SDL_vglevents_c.h"
  34. /* The translation tables from a console scancode to a SDL keysym */
  35. /* FIXME: Free the keymap when we shut down the video mode */
  36. static keymap_t *vga_keymap = NULL;
  37. static SDLKey keymap[128];
  38. static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym);
  39. static int posted = 0;
  40. static int oldx = -1;
  41. static int oldy = -1;
  42. static struct mouse_info mouseinfo;
  43. /* Ugh, we have to duplicate the kernel's keysym mapping code...
  44.    Oh, it's not so bad. :-)
  45.    FIXME: Add keyboard LED handling code
  46.  */
  47. int VGL_initkeymaps(int fd)
  48. {
  49. vga_keymap = malloc(sizeof(keymap_t));
  50. if ( ! vga_keymap ) {
  51. SDL_OutOfMemory();
  52. return(-1);
  53. }
  54. if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) {
  55. free(vga_keymap);
  56. vga_keymap = NULL;
  57. SDL_SetError("Unable to get keyboard map");
  58. return(-1);
  59. }
  60. return(0);
  61. }
  62. static void handle_keyboard(_THIS)
  63. {
  64. SDL_keysym keysym;
  65. int c, pressed, scancode;
  66. while ((c = VGLKeyboardGetCh()) != 0) {
  67. scancode = c & 0x7F;
  68.                 if (c & 0x80) {
  69.                         pressed = SDL_RELEASED;
  70.                 } else {
  71.                         pressed = SDL_PRESSED;
  72.                 }
  73. posted += SDL_PrivateKeyboard(pressed,
  74.  TranslateKey(scancode, &keysym));
  75. }
  76. }
  77. int VGL_initmouse(int fd)
  78. {
  79. mouseinfo.operation = MOUSE_GETINFO;
  80. if (ioctl(fd, CONS_MOUSECTL, &mouseinfo) != 0)
  81. return -1;
  82. return 0;
  83. }
  84. static void handle_mouse(_THIS)
  85. {
  86. char buttons;
  87. int x, y;
  88. int button_state, state_changed, state;
  89. int i;
  90. ioctl(0, CONS_MOUSECTL, &mouseinfo);
  91. x = mouseinfo.u.data.x;
  92. y = mouseinfo.u.data.y;
  93. buttons = mouseinfo.u.data.buttons;
  94. if ((x != oldx) || (y != oldy)) {
  95. posted += SDL_PrivateMouseMotion(0, 0, x, y);
  96. oldx = x;
  97. oldy = y;
  98. }
  99. /* See what's changed */
  100. button_state = SDL_GetMouseState(NULL, NULL);
  101. state_changed = button_state ^ buttons;
  102. for (i = 0; i < 8; i++) {
  103. if (state_changed & (1<<i)) {
  104. if (buttons & (1<<i)) {
  105. state = SDL_PRESSED;
  106. } else {
  107. state = SDL_RELEASED;
  108. }
  109. posted += SDL_PrivateMouseButton(state, i + 1, 0, 0);
  110. }
  111. }
  112. }
  113. void VGL_PumpEvents(_THIS)
  114. {
  115. do {
  116. posted = 0;
  117. handle_keyboard(this);
  118. handle_mouse(this);
  119. } while (posted != 0);
  120. }
  121. void VGL_InitOSKeymap(_THIS)
  122. {
  123. int i;
  124. /* Initialize the BeOS key translation table */
  125. for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
  126. keymap[i] = SDLK_UNKNOWN;
  127. keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
  128. keymap[SCANCODE_1] = SDLK_1;
  129. keymap[SCANCODE_2] = SDLK_2;
  130. keymap[SCANCODE_3] = SDLK_3;
  131. keymap[SCANCODE_4] = SDLK_4;
  132. keymap[SCANCODE_5] = SDLK_5;
  133. keymap[SCANCODE_6] = SDLK_6;
  134. keymap[SCANCODE_7] = SDLK_7;
  135. keymap[SCANCODE_8] = SDLK_8;
  136. keymap[SCANCODE_9] = SDLK_9;
  137. keymap[SCANCODE_0] = SDLK_0;
  138. keymap[SCANCODE_MINUS] = SDLK_MINUS;
  139. keymap[SCANCODE_EQUAL] = SDLK_EQUALS;
  140. keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
  141. keymap[SCANCODE_TAB] = SDLK_TAB;
  142. keymap[SCANCODE_Q] = SDLK_q;
  143. keymap[SCANCODE_W] = SDLK_w;
  144. keymap[SCANCODE_E] = SDLK_e;
  145. keymap[SCANCODE_R] = SDLK_r;
  146. keymap[SCANCODE_T] = SDLK_t;
  147. keymap[SCANCODE_Y] = SDLK_y;
  148. keymap[SCANCODE_U] = SDLK_u;
  149. keymap[SCANCODE_I] = SDLK_i;
  150. keymap[SCANCODE_O] = SDLK_o;
  151. keymap[SCANCODE_P] = SDLK_p;
  152. keymap[SCANCODE_BRACKET_LEFT] = SDLK_LEFTBRACKET;
  153. keymap[SCANCODE_BRACKET_RIGHT] = SDLK_RIGHTBRACKET;
  154. keymap[SCANCODE_ENTER] = SDLK_RETURN;
  155. keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
  156. keymap[SCANCODE_A] = SDLK_a;
  157. keymap[SCANCODE_S] = SDLK_s;
  158. keymap[SCANCODE_D] = SDLK_d;
  159. keymap[SCANCODE_F] = SDLK_f;
  160. keymap[SCANCODE_G] = SDLK_g;
  161. keymap[SCANCODE_H] = SDLK_h;
  162. keymap[SCANCODE_J] = SDLK_j;
  163. keymap[SCANCODE_K] = SDLK_k;
  164. keymap[SCANCODE_L] = SDLK_l;
  165. keymap[SCANCODE_SEMICOLON] = SDLK_SEMICOLON;
  166. keymap[SCANCODE_APOSTROPHE] = SDLK_QUOTE;
  167. keymap[SCANCODE_GRAVE] = SDLK_BACKQUOTE;
  168. keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
  169. keymap[SCANCODE_BACKSLASH] = SDLK_BACKSLASH;
  170. keymap[SCANCODE_Z] = SDLK_z;
  171. keymap[SCANCODE_X] = SDLK_x;
  172. keymap[SCANCODE_C] = SDLK_c;
  173. keymap[SCANCODE_V] = SDLK_v;
  174. keymap[SCANCODE_B] = SDLK_b;
  175. keymap[SCANCODE_N] = SDLK_n;
  176. keymap[SCANCODE_M] = SDLK_m;
  177. keymap[SCANCODE_COMMA] = SDLK_COMMA;
  178. keymap[SCANCODE_PERIOD] = SDLK_PERIOD;
  179. keymap[SCANCODE_SLASH] = SDLK_SLASH;
  180. keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
  181. keymap[SCANCODE_KEYPADMULTIPLY] = SDLK_KP_MULTIPLY;
  182. keymap[SCANCODE_LEFTALT] = SDLK_LALT;
  183. keymap[SCANCODE_SPACE] = SDLK_SPACE;
  184. keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
  185. keymap[SCANCODE_F1] = SDLK_F1;
  186. keymap[SCANCODE_F2] = SDLK_F2;
  187. keymap[SCANCODE_F3] = SDLK_F3;
  188. keymap[SCANCODE_F4] = SDLK_F4;
  189. keymap[SCANCODE_F5] = SDLK_F5;
  190. keymap[SCANCODE_F6] = SDLK_F6;
  191. keymap[SCANCODE_F7] = SDLK_F7;
  192. keymap[SCANCODE_F8] = SDLK_F8;
  193. keymap[SCANCODE_F9] = SDLK_F9;
  194. keymap[SCANCODE_F10] = SDLK_F10;
  195. keymap[SCANCODE_NUMLOCK] = SDLK_NUMLOCK;
  196. keymap[SCANCODE_SCROLLLOCK] = SDLK_SCROLLOCK;
  197. keymap[SCANCODE_KEYPAD7] = SDLK_KP7;
  198. keymap[SCANCODE_CURSORUPLEFT] = SDLK_KP7;
  199. keymap[SCANCODE_KEYPAD8] = SDLK_KP8;
  200. keymap[SCANCODE_CURSORUP] = SDLK_KP8;
  201. keymap[SCANCODE_KEYPAD9] = SDLK_KP9;
  202. keymap[SCANCODE_CURSORUPRIGHT] = SDLK_KP9;
  203. keymap[SCANCODE_KEYPADMINUS] = SDLK_KP_MINUS;
  204. keymap[SCANCODE_KEYPAD4] = SDLK_KP4;
  205. keymap[SCANCODE_CURSORLEFT] = SDLK_KP4;
  206. keymap[SCANCODE_KEYPAD5] = SDLK_KP5;
  207. keymap[SCANCODE_KEYPAD6] = SDLK_KP6;
  208. keymap[SCANCODE_CURSORRIGHT] = SDLK_KP6;
  209. keymap[SCANCODE_KEYPADPLUS] = SDLK_KP_PLUS;
  210. keymap[SCANCODE_KEYPAD1] = SDLK_KP1;
  211. keymap[SCANCODE_CURSORDOWNLEFT] = SDLK_KP1;
  212. keymap[SCANCODE_KEYPAD2] = SDLK_KP2;
  213. keymap[SCANCODE_CURSORDOWN] = SDLK_KP2;
  214. keymap[SCANCODE_KEYPAD3] = SDLK_KP3;
  215. keymap[SCANCODE_CURSORDOWNRIGHT] = SDLK_KP3;
  216. keymap[SCANCODE_KEYPAD0] = SDLK_KP0;
  217. keymap[SCANCODE_KEYPADPERIOD] = SDLK_KP_PERIOD;
  218. keymap[SCANCODE_LESS] = SDLK_LESS;
  219. keymap[SCANCODE_F11] = SDLK_F11;
  220. keymap[SCANCODE_F12] = SDLK_F12;
  221. keymap[SCANCODE_KEYPADENTER] = SDLK_KP_ENTER;
  222. keymap[SCANCODE_RIGHTCONTROL] = SDLK_RCTRL;
  223. keymap[SCANCODE_CONTROL] = SDLK_RCTRL;
  224. keymap[SCANCODE_KEYPADDIVIDE] = SDLK_KP_DIVIDE;
  225. keymap[SCANCODE_PRINTSCREEN] = SDLK_PRINT;
  226. keymap[SCANCODE_RIGHTALT] = SDLK_RALT;
  227. keymap[SCANCODE_BREAK] = SDLK_BREAK;
  228. keymap[SCANCODE_BREAK_ALTERNATIVE] = SDLK_UNKNOWN;
  229. keymap[SCANCODE_HOME] = SDLK_HOME;
  230. keymap[SCANCODE_CURSORBLOCKUP] = SDLK_UP;
  231. keymap[SCANCODE_PAGEUP] = SDLK_PAGEUP;
  232. keymap[SCANCODE_CURSORBLOCKLEFT] = SDLK_LEFT;
  233. keymap[SCANCODE_CURSORBLOCKRIGHT] = SDLK_RIGHT;
  234. keymap[SCANCODE_END] = SDLK_END;
  235. keymap[SCANCODE_CURSORBLOCKDOWN] = SDLK_DOWN;
  236. keymap[SCANCODE_PAGEDOWN] = SDLK_PAGEDOWN;
  237. keymap[SCANCODE_INSERT] = SDLK_INSERT;
  238. keymap[SCANCODE_REMOVE] = SDLK_DELETE;
  239. keymap[119] = SDLK_PAUSE;
  240. keymap[SCANCODE_RIGHTWIN] = SDLK_RSUPER;
  241. keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER;
  242. keymap[127] = SDLK_MENU;
  243. }
  244. static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym)
  245. {
  246. /* Set the keysym information */
  247. keysym->scancode = scancode;
  248. keysym->sym = keymap[scancode];
  249. keysym->mod = KMOD_NONE;
  250. /* If UNICODE is on, get the UNICODE value for the key */
  251. keysym->unicode = 0;
  252. if ( SDL_TranslateUNICODE && vga_keymap ) {
  253. int map;
  254. SDLMod modstate;
  255. modstate = SDL_GetModState();
  256. map = 0;
  257. if ( modstate & KMOD_SHIFT ) {
  258. map += 1;
  259. }
  260. if ( modstate & KMOD_CTRL ) {
  261. map += 2;
  262. }
  263. if ( modstate & KMOD_ALT ) {
  264. map += 4;
  265. }
  266. if ( !(vga_keymap->key[scancode].spcl & (0x80 >> map)) ) {
  267. keysym->unicode = vga_keymap->key[scancode].map[map];
  268. }
  269. }
  270. return(keysym);
  271. }