comparison src/video/riscos/SDL_riscosevents.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
68 /* Size of array for all keys */ 68 /* Size of array for all keys */
69 #define ROKEYBD_ARRAYSIZE 125 69 #define ROKEYBD_ARRAYSIZE 125
70 70
71 static char RO_pressed[ROKEYBD_ARRAYSIZE]; 71 static char RO_pressed[ROKEYBD_ARRAYSIZE];
72 72
73 static SDL_keysym *TranslateKey (int intkey, SDL_keysym * keysym, 73 static SDL_keysym *TranslateKey(int intkey, SDL_keysym * keysym, int pressed);
74 int pressed); 74
75 75 void RISCOS_PollMouse(_THIS);
76 void RISCOS_PollMouse (_THIS); 76 void RISCOS_PollKeyboard();
77 void RISCOS_PollKeyboard (); 77
78 78 void RISCOS_PollMouseHelper(_THIS, int fullscreen);
79 void RISCOS_PollMouseHelper (_THIS, int fullscreen);
80 79
81 #if SDL_THREADS_DISABLED 80 #if SDL_THREADS_DISABLED
82 extern void DRenderer_FillBuffers (); 81 extern void DRenderer_FillBuffers();
83 82
84 /* Timer running function */ 83 /* Timer running function */
85 extern void RISCOS_CheckTimer (); 84 extern void RISCOS_CheckTimer();
86 85
87 #endif 86 #endif
88 87
89 void 88 void
90 FULLSCREEN_PumpEvents (_THIS) 89 FULLSCREEN_PumpEvents(_THIS)
91 { 90 {
92 /* Current implementation requires keyboard and mouse polling */ 91 /* Current implementation requires keyboard and mouse polling */
93 RISCOS_PollKeyboard (); 92 RISCOS_PollKeyboard();
94 RISCOS_PollMouse (this); 93 RISCOS_PollMouse(this);
95 #if SDL_THREADS_DISABLED 94 #if SDL_THREADS_DISABLED
96 // DRenderer_FillBuffers(); 95 // DRenderer_FillBuffers();
97 if (SDL_timer_running) 96 if (SDL_timer_running)
98 RISCOS_CheckTimer (); 97 RISCOS_CheckTimer();
99 #endif 98 #endif
100 } 99 }
101 100
102 101
103 void 102 void
104 RISCOS_InitOSKeymap (_THIS) 103 RISCOS_InitOSKeymap(_THIS)
105 { 104 {
106 int i; 105 int i;
107 106
108 /* Map the VK keysyms */ 107 /* Map the VK keysyms */
109 for (i = 0; i < SDL_arraysize (RO_keymap); ++i) 108 for (i = 0; i < SDL_arraysize(RO_keymap); ++i)
110 RO_keymap[i] = SDLK_UNKNOWN; 109 RO_keymap[i] = SDLK_UNKNOWN;
111 110
112 RO_keymap[3] = SDLK_LSHIFT; 111 RO_keymap[3] = SDLK_LSHIFT;
113 RO_keymap[4] = SDLK_LCTRL; 112 RO_keymap[4] = SDLK_LCTRL;
114 RO_keymap[5] = SDLK_LALT; 113 RO_keymap[5] = SDLK_LALT;
212 RO_keymap[121] = SDLK_RIGHT; 211 RO_keymap[121] = SDLK_RIGHT;
213 RO_keymap[122] = SDLK_KP4; 212 RO_keymap[122] = SDLK_KP4;
214 RO_keymap[123] = SDLK_KP5; 213 RO_keymap[123] = SDLK_KP5;
215 RO_keymap[124] = SDLK_KP2; 214 RO_keymap[124] = SDLK_KP2;
216 215
217 SDL_memset (RO_pressed, 0, ROKEYBD_ARRAYSIZE); 216 SDL_memset(RO_pressed, 0, ROKEYBD_ARRAYSIZE);
218 } 217 }
219 218
220 219
221 /* Variable for mouse relative processing */ 220 /* Variable for mouse relative processing */
222 int mouse_relative = 0; 221 int mouse_relative = 0;
223 222
224 /* Check to see if we need to enter or leave mouse relative mode */ 223 /* Check to see if we need to enter or leave mouse relative mode */
225 224
226 void 225 void
227 RISCOS_CheckMouseMode (_THIS) 226 RISCOS_CheckMouseMode(_THIS)
228 { 227 {
229 /* If the mouse is hidden and input is grabbed, we use relative mode */ 228 /* If the mouse is hidden and input is grabbed, we use relative mode */
230 if (!(SDL_cursorstate & CURSOR_VISIBLE) && 229 if (!(SDL_cursorstate & CURSOR_VISIBLE) &&
231 (this->input_grab != SDL_GRAB_OFF)) { 230 (this->input_grab != SDL_GRAB_OFF)) {
232 mouse_relative = 1; 231 mouse_relative = 1;
235 } 234 }
236 } 235 }
237 236
238 237
239 void 238 void
240 RISCOS_PollMouse (_THIS) 239 RISCOS_PollMouse(_THIS)
241 { 240 {
242 RISCOS_PollMouseHelper (this, 1); 241 RISCOS_PollMouseHelper(this, 1);
243 } 242 }
244 243
245 extern int mouseInWindow; 244 extern int mouseInWindow;
246 245
247 void 246 void
248 WIMP_PollMouse (_THIS) 247 WIMP_PollMouse(_THIS)
249 { 248 {
250 /* Only poll when mouse is over the window */ 249 /* Only poll when mouse is over the window */
251 if (!mouseInWindow) 250 if (!mouseInWindow)
252 return; 251 return;
253 252
254 RISCOS_PollMouseHelper (this, 0); 253 RISCOS_PollMouseHelper(this, 0);
255 } 254 }
256 255
257 /* Static variables so only changes are reported */ 256 /* Static variables so only changes are reported */
258 static Sint16 last_x = -1, last_y = -1; 257 static Sint16 last_x = -1, last_y = -1;
259 static int last_buttons = 0; 258 static int last_buttons = 0;
260 259
261 /* Share routine between WIMP and FULLSCREEN for polling mouse and 260 /* Share routine between WIMP and FULLSCREEN for polling mouse and
262 passing on events */ 261 passing on events */
263 void 262 void
264 RISCOS_PollMouseHelper (_THIS, int fullscreen) 263 RISCOS_PollMouseHelper(_THIS, int fullscreen)
265 { 264 {
266 _kernel_swi_regs regs; 265 _kernel_swi_regs regs;
267 static int starting = 1; 266 static int starting = 1;
268 267
269 if (_kernel_swi (OS_Mouse, &regs, &regs) == NULL) { 268 if (_kernel_swi(OS_Mouse, &regs, &regs) == NULL) {
270 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */ 269 Sint16 new_x = regs.r[0]; /* Initialy get as OS units */
271 Sint16 new_y = regs.r[1]; 270 Sint16 new_y = regs.r[1];
272 271
273 /* Discard mouse events until they let go of the mouse after starting */ 272 /* Discard mouse events until they let go of the mouse after starting */
274 if (starting && regs.r[2] != 0) 273 if (starting && regs.r[2] != 0)
288 int window_state[9]; 287 int window_state[9];
289 288
290 /* Get current window state */ 289 /* Get current window state */
291 window_state[0] = this->hidden->window_handle; 290 window_state[0] = this->hidden->window_handle;
292 regs.r[1] = (unsigned int) window_state; 291 regs.r[1] = (unsigned int) window_state;
293 _kernel_swi (Wimp_GetWindowState, &regs, &regs); 292 _kernel_swi(Wimp_GetWindowState, &regs, &regs);
294 293
295 topLeftX = window_state[1]; 294 topLeftX = window_state[1];
296 topLeftY = window_state[4]; 295 topLeftY = window_state[4];
297 } 296 }
298 297
309 int centre_x = SDL_VideoSurface->w / 2; 308 int centre_x = SDL_VideoSurface->w / 2;
310 int centre_y = SDL_VideoSurface->h / 2; 309 int centre_y = SDL_VideoSurface->h / 2;
311 310
312 if (centre_x != x || centre_y != y) { 311 if (centre_x != x || centre_y != y) {
313 if (SDL_VideoSurface) 312 if (SDL_VideoSurface)
314 SDL_PrivateMouseMotion (0, 1, 313 SDL_PrivateMouseMotion(0, 1,
315 x - centre_x, 314 x - centre_x,
316 y - centre_y); 315 y - centre_y);
317 last_x = topLeftX + (centre_x << this->hidden->xeig); 316 last_x = topLeftX + (centre_x << this->hidden->xeig);
318 last_y = topLeftY - (centre_y << this->hidden->yeig); 317 last_y = topLeftY - (centre_y << this->hidden->yeig);
319 318
320 /* Re-centre the mouse pointer, so we still get relative 319 /* Re-centre the mouse pointer, so we still get relative
321 movement when the mouse is at the edge of the window 320 movement when the mouse is at the edge of the window
330 block[3] = last_y & 0xFF; 329 block[3] = last_y & 0xFF;
331 block[4] = (last_y >> 8) & 0xFF; 330 block[4] = (last_y >> 8) & 0xFF;
332 331
333 regs.r[0] = 21; /* OSWORD pointer stuff code */ 332 regs.r[0] = 21; /* OSWORD pointer stuff code */
334 regs.r[1] = (int) block; 333 regs.r[1] = (int) block;
335 _kernel_swi (OS_Word, &regs, &regs); 334 _kernel_swi(OS_Word, &regs, &regs);
336 } 335 }
337 } 336 }
338 } else { 337 } else {
339 last_x = new_x; 338 last_x = new_x;
340 last_y = new_y; 339 last_y = new_y;
341 SDL_PrivateMouseMotion (0, 0, x, y); 340 SDL_PrivateMouseMotion(0, 0, x, y);
342 } 341 }
343 } 342 }
344 343
345 if (last_buttons != regs.r[2]) { 344 if (last_buttons != regs.r[2]) {
346 int changed = last_buttons ^ regs.r[2]; 345 int changed = last_buttons ^ regs.r[2];
347 last_buttons = regs.r[2]; 346 last_buttons = regs.r[2];
348 if (changed & 4) 347 if (changed & 4)
349 SDL_PrivateMouseButton ((last_buttons & 4) ? 348 SDL_PrivateMouseButton((last_buttons & 4) ?
350 SDL_PRESSED : SDL_RELEASED, 349 SDL_PRESSED : SDL_RELEASED,
351 SDL_BUTTON_LEFT, 0, 0); 350 SDL_BUTTON_LEFT, 0, 0);
352 if (changed & 2) 351 if (changed & 2)
353 SDL_PrivateMouseButton ((last_buttons & 2) ? 352 SDL_PrivateMouseButton((last_buttons & 2) ?
354 SDL_PRESSED : SDL_RELEASED, 353 SDL_PRESSED : SDL_RELEASED,
355 SDL_BUTTON_MIDDLE, 0, 0); 354 SDL_BUTTON_MIDDLE, 0, 0);
356 if (changed & 1) 355 if (changed & 1)
357 SDL_PrivateMouseButton ((last_buttons & 1) ? 356 SDL_PrivateMouseButton((last_buttons & 1) ?
358 SDL_PRESSED : SDL_RELEASED, 357 SDL_PRESSED : SDL_RELEASED,
359 SDL_BUTTON_RIGHT, 0, 0); 358 SDL_BUTTON_RIGHT, 0, 0);
360 } 359 }
361 } 360 }
362 } 361 }
363 } 362 }
364 363
365 void 364 void
366 RISCOS_PollKeyboard () 365 RISCOS_PollKeyboard()
367 { 366 {
368 int which_key = ROKEY_LEFT_SHIFT; 367 int which_key = ROKEY_LEFT_SHIFT;
369 int j; 368 int j;
370 int min_key, max_key; 369 int min_key, max_key;
371 SDL_keysym key; 370 SDL_keysym key;
372 371
373 /* Scan the keyboard to see what is pressed */ 372 /* Scan the keyboard to see what is pressed */
374 while (which_key <= ROKEY_LAST_KEY) { 373 while (which_key <= ROKEY_LAST_KEY) {
375 which_key = (_kernel_osbyte (121, which_key, 0) & 0xFF); 374 which_key = (_kernel_osbyte(121, which_key, 0) & 0xFF);
376 if (which_key != ROKEY_NONE) { 375 if (which_key != ROKEY_NONE) {
377 switch (which_key) { 376 switch (which_key) {
378 /* Skip over mouse keys */ 377 /* Skip over mouse keys */
379 case ROKEY_LEFT_MOUSE: 378 case ROKEY_LEFT_MOUSE:
380 case ROKEY_CENTRE_MOUSE: 379 case ROKEY_CENTRE_MOUSE:
407 406
408 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) { 407 for (j = ROKEY_LEFT_SHIFT; j <= ROKEY_LAST_KEY; j++) {
409 if (RO_pressed[j]) { 408 if (RO_pressed[j]) {
410 if (RO_pressed[j] == 1) { 409 if (RO_pressed[j] == 1) {
411 RO_pressed[j] = 0; 410 RO_pressed[j] = 0;
412 SDL_PrivateKeyboard (SDL_RELEASED, TranslateKey (j, &key, 0)); 411 SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(j, &key, 0));
413 } else { 412 } else {
414 if (j < min_key) 413 if (j < min_key)
415 min_key = j; 414 min_key = j;
416 if (j > max_key) 415 if (j > max_key)
417 max_key = j; 416 max_key = j;
421 420
422 /* Generate key pressed messages */ 421 /* Generate key pressed messages */
423 for (j = min_key; j <= max_key; j++) { 422 for (j = min_key; j <= max_key; j++) {
424 if (RO_pressed[j]) { 423 if (RO_pressed[j]) {
425 if (RO_pressed[j] == 2) { 424 if (RO_pressed[j] == 2) {
426 SDL_PrivateKeyboard (SDL_PRESSED, TranslateKey (j, &key, 1)); 425 SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(j, &key, 1));
427 } 426 }
428 RO_pressed[j] = 1; 427 RO_pressed[j] = 1;
429 } 428 }
430 } 429 }
431 } 430 }
432 431
433 static SDL_keysym * 432 static SDL_keysym *
434 TranslateKey (int intkey, SDL_keysym * keysym, int pressed) 433 TranslateKey(int intkey, SDL_keysym * keysym, int pressed)
435 { 434 {
436 /* Set the keysym information */ 435 /* Set the keysym information */
437 keysym->scancode = (unsigned char) intkey; 436 keysym->scancode = (unsigned char) intkey;
438 keysym->sym = RO_keymap[intkey]; 437 keysym->sym = RO_keymap[intkey];
439 keysym->mod = KMOD_NONE; 438 keysym->mod = KMOD_NONE;
440 keysym->unicode = 0; 439 keysym->unicode = 0;
441 if (pressed && SDL_TranslateUNICODE) { 440 if (pressed && SDL_TranslateUNICODE) {
442 int state; 441 int state;
443 int ch; 442 int ch;
444 443
445 state = (_kernel_osbyte (202, 0, 255) & 0xFF); 444 state = (_kernel_osbyte(202, 0, 255) & 0xFF);
446 445
447 /*TODO: Take into account other keyboard layouts */ 446 /*TODO: Take into account other keyboard layouts */
448 447
449 ch = keysym->sym; /* This should handle most unshifted keys */ 448 ch = keysym->sym; /* This should handle most unshifted keys */
450 449
475 if (topOfKey) { 474 if (topOfKey) {
476 /* Key produced with shift held down */ 475 /* Key produced with shift held down */
477 476
478 /* Letters just give upper case version */ 477 /* Letters just give upper case version */
479 if (ch >= SDLK_a && ch <= SDLK_z) 478 if (ch >= SDLK_a && ch <= SDLK_z)
480 ch = toupper (ch); 479 ch = toupper(ch);
481 else { 480 else {
482 switch (ch) { 481 switch (ch) {
483 case SDLK_HASH: 482 case SDLK_HASH:
484 ch = '~'; 483 ch = '~';
485 break; 484 break;