comparison src/video/vgl/SDL_vglevents.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
39 39
40 /* The translation tables from a console scancode to a SDL keysym */ 40 /* The translation tables from a console scancode to a SDL keysym */
41 /* FIXME: Free the keymap when we shut down the video mode */ 41 /* FIXME: Free the keymap when we shut down the video mode */
42 static keymap_t *vga_keymap = NULL; 42 static keymap_t *vga_keymap = NULL;
43 static SDLKey keymap[128]; 43 static SDLKey keymap[128];
44 static SDL_keysym *TranslateKey (int scancode, SDL_keysym * keysym); 44 static SDL_keysym *TranslateKey(int scancode, SDL_keysym * keysym);
45 45
46 static int posted = 0; 46 static int posted = 0;
47 static int oldx = -1; 47 static int oldx = -1;
48 static int oldy = -1; 48 static int oldy = -1;
49 static struct mouse_info mouseinfo; 49 static struct mouse_info mouseinfo;
52 Oh, it's not so bad. :-) 52 Oh, it's not so bad. :-)
53 53
54 FIXME: Add keyboard LED handling code 54 FIXME: Add keyboard LED handling code
55 */ 55 */
56 int 56 int
57 VGL_initkeymaps (int fd) 57 VGL_initkeymaps(int fd)
58 { 58 {
59 vga_keymap = SDL_malloc (sizeof (keymap_t)); 59 vga_keymap = SDL_malloc(sizeof(keymap_t));
60 if (!vga_keymap) { 60 if (!vga_keymap) {
61 SDL_OutOfMemory (); 61 SDL_OutOfMemory();
62 return (-1); 62 return (-1);
63 } 63 }
64 if (ioctl (fd, GIO_KEYMAP, vga_keymap) == -1) { 64 if (ioctl(fd, GIO_KEYMAP, vga_keymap) == -1) {
65 SDL_free (vga_keymap); 65 SDL_free(vga_keymap);
66 vga_keymap = NULL; 66 vga_keymap = NULL;
67 SDL_SetError ("Unable to get keyboard map"); 67 SDL_SetError("Unable to get keyboard map");
68 return (-1); 68 return (-1);
69 } 69 }
70 return (0); 70 return (0);
71 } 71 }
72 72
73 static void 73 static void
74 handle_keyboard (_THIS) 74 handle_keyboard(_THIS)
75 { 75 {
76 SDL_keysym keysym; 76 SDL_keysym keysym;
77 int c, pressed, scancode; 77 int c, pressed, scancode;
78 78
79 while ((c = VGLKeyboardGetCh ()) != 0) { 79 while ((c = VGLKeyboardGetCh()) != 0) {
80 scancode = c & 0x7F; 80 scancode = c & 0x7F;
81 if (c & 0x80) { 81 if (c & 0x80) {
82 pressed = SDL_RELEASED; 82 pressed = SDL_RELEASED;
83 } else { 83 } else {
84 pressed = SDL_PRESSED; 84 pressed = SDL_PRESSED;
85 } 85 }
86 86
87 posted += SDL_PrivateKeyboard (pressed, 87 posted += SDL_PrivateKeyboard(pressed,
88 TranslateKey (scancode, &keysym)); 88 TranslateKey(scancode, &keysym));
89 } 89 }
90 } 90 }
91 91
92 int 92 int
93 VGL_initmouse (int fd) 93 VGL_initmouse(int fd)
94 { 94 {
95 mouseinfo.operation = MOUSE_GETINFO; 95 mouseinfo.operation = MOUSE_GETINFO;
96 if (ioctl (fd, CONS_MOUSECTL, &mouseinfo) != 0) 96 if (ioctl(fd, CONS_MOUSECTL, &mouseinfo) != 0)
97 return -1; 97 return -1;
98 98
99 return 0; 99 return 0;
100 } 100 }
101 101
102 static void 102 static void
103 handle_mouse (_THIS) 103 handle_mouse(_THIS)
104 { 104 {
105 char buttons; 105 char buttons;
106 int x, y; 106 int x, y;
107 int button_state, state_changed, state; 107 int button_state, state_changed, state;
108 int i; 108 int i;
109 109
110 ioctl (0, CONS_MOUSECTL, &mouseinfo); 110 ioctl(0, CONS_MOUSECTL, &mouseinfo);
111 x = mouseinfo.u.data.x; 111 x = mouseinfo.u.data.x;
112 y = mouseinfo.u.data.y; 112 y = mouseinfo.u.data.y;
113 buttons = mouseinfo.u.data.buttons; 113 buttons = mouseinfo.u.data.buttons;
114 114
115 if ((x != oldx) || (y != oldy)) { 115 if ((x != oldx) || (y != oldy)) {
116 posted += SDL_PrivateMouseMotion (0, 0, x, y); 116 posted += SDL_PrivateMouseMotion(0, 0, x, y);
117 oldx = x; 117 oldx = x;
118 oldy = y; 118 oldy = y;
119 } 119 }
120 120
121 /* See what's changed */ 121 /* See what's changed */
122 button_state = SDL_GetMouseState (NULL, NULL); 122 button_state = SDL_GetMouseState(NULL, NULL);
123 state_changed = button_state ^ buttons; 123 state_changed = button_state ^ buttons;
124 for (i = 0; i < 8; i++) { 124 for (i = 0; i < 8; i++) {
125 if (state_changed & (1 << i)) { 125 if (state_changed & (1 << i)) {
126 if (buttons & (1 << i)) { 126 if (buttons & (1 << i)) {
127 state = SDL_PRESSED; 127 state = SDL_PRESSED;
128 } else { 128 } else {
129 state = SDL_RELEASED; 129 state = SDL_RELEASED;
130 } 130 }
131 posted += SDL_PrivateMouseButton (state, i + 1, 0, 0); 131 posted += SDL_PrivateMouseButton(state, i + 1, 0, 0);
132 } 132 }
133 } 133 }
134 } 134 }
135 135
136 136
137 void 137 void
138 VGL_PumpEvents (_THIS) 138 VGL_PumpEvents(_THIS)
139 { 139 {
140 do { 140 do {
141 posted = 0; 141 posted = 0;
142 handle_keyboard (this); 142 handle_keyboard(this);
143 handle_mouse (this); 143 handle_mouse(this);
144 } 144 }
145 while (posted != 0); 145 while (posted != 0);
146 } 146 }
147 147
148 void 148 void
149 VGL_InitOSKeymap (_THIS) 149 VGL_InitOSKeymap(_THIS)
150 { 150 {
151 int i; 151 int i;
152 152
153 /* Initialize the BeOS key translation table */ 153 /* Initialize the BeOS key translation table */
154 for (i = 0; i < SDL_arraysize (keymap); ++i) 154 for (i = 0; i < SDL_arraysize(keymap); ++i)
155 keymap[i] = SDLK_UNKNOWN; 155 keymap[i] = SDLK_UNKNOWN;
156 156
157 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE; 157 keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
158 keymap[SCANCODE_1] = SDLK_1; 158 keymap[SCANCODE_1] = SDLK_1;
159 keymap[SCANCODE_2] = SDLK_2; 159 keymap[SCANCODE_2] = SDLK_2;
271 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER; 271 keymap[SCANCODE_LEFTWIN] = SDLK_LSUPER;
272 keymap[127] = SDLK_MENU; 272 keymap[127] = SDLK_MENU;
273 } 273 }
274 274
275 static SDL_keysym * 275 static SDL_keysym *
276 TranslateKey (int scancode, SDL_keysym * keysym) 276 TranslateKey(int scancode, SDL_keysym * keysym)
277 { 277 {
278 /* Set the keysym information */ 278 /* Set the keysym information */
279 keysym->scancode = scancode; 279 keysym->scancode = scancode;
280 keysym->sym = keymap[scancode]; 280 keysym->sym = keymap[scancode];
281 keysym->mod = KMOD_NONE; 281 keysym->mod = KMOD_NONE;
284 keysym->unicode = 0; 284 keysym->unicode = 0;
285 if (SDL_TranslateUNICODE && vga_keymap) { 285 if (SDL_TranslateUNICODE && vga_keymap) {
286 int map; 286 int map;
287 SDLMod modstate; 287 SDLMod modstate;
288 288
289 modstate = SDL_GetModState (); 289 modstate = SDL_GetModState();
290 map = 0; 290 map = 0;
291 if (modstate & KMOD_SHIFT) { 291 if (modstate & KMOD_SHIFT) {
292 map += 1; 292 map += 1;
293 } 293 }
294 if (modstate & KMOD_CTRL) { 294 if (modstate & KMOD_CTRL) {