src/video/gem/SDL_gemevents.c
branchSDL-1.2
changeset 6582 8b7e21749630
parent 6572 0d391c407a4f
child 6583 15c1dc6ac329
equal deleted inserted replaced
6572:0d391c407a4f 6582:8b7e21749630
    48 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
    48 static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
    49 
    49 
    50 /* Functions prototypes */
    50 /* Functions prototypes */
    51 
    51 
    52 static int do_messages(_THIS, short *message);
    52 static int do_messages(_THIS, short *message);
    53 static void do_keyboard(short kc, short ks);
    53 static void do_keyboard(short kc);
    54 static void do_mouse(_THIS, short mx, short my, short mb, short ks);
    54 static void do_keyboard_special(short ks);
       
    55 static void do_mouse(_THIS, short mx, short my, short mb);
    55 
    56 
    56 /* Functions */
    57 /* Functions */
    57 
    58 
    58 void GEM_InitOSKeymap(_THIS)
    59 void GEM_InitOSKeymap(_THIS)
    59 {
    60 {
    66 	SDL_Atari_InitInternalKeymap(this);
    67 	SDL_Atari_InitInternalKeymap(this);
    67 }
    68 }
    68 
    69 
    69 void GEM_PumpEvents(_THIS)
    70 void GEM_PumpEvents(_THIS)
    70 {
    71 {
    71 	short prevkc, prevks;
    72 	short prevkc;
    72 	static short maskmouseb=0;
    73 	static short maskmouseb=0;
    73 	int i;
    74 	int i;
    74 	SDL_keysym	keysym;
    75 	SDL_keysym	keysym;
    75 
    76 
    76 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    77 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    77 	prevkc = prevks = 0;
    78 	prevkc = 0;
    78 
    79 
    79 	for (;;)
    80 	for (;;)
    80 	{
    81 	{
    81 		int quit, resultat, event_mask, mouse_event;
    82 		int quit, resultat, event_mask, mouse_event;
    82 		short buffer[8], kc;
    83 		short buffer[8], kc;
   108 
   109 
   109 		/* Message event ? */
   110 		/* Message event ? */
   110 		if (resultat & MU_MESAG)
   111 		if (resultat & MU_MESAG)
   111 			quit = do_messages(this, buffer);
   112 			quit = do_messages(this, buffer);
   112 
   113 
       
   114 		/* Special keys ? */
       
   115 		if (resultat & (MU_KEYBD|MU_BUTTON))
       
   116 			do_keyboard_special(kstate);
       
   117 
   113 		/* Keyboard event ? */
   118 		/* Keyboard event ? */
   114 		if (resultat & MU_KEYBD) {
   119 		if (resultat & MU_KEYBD) {
   115 			if ((prevkc != kc) || (prevks != kstate)) {
   120 			if (prevkc != kc) {
   116 				do_keyboard(kc,kstate);
   121 				do_keyboard(kc);
   117 				prevkc = kc;
   122 				prevkc = kc;
   118 				prevks = ks;
       
   119 			} else {
   123 			} else {
   120 				/* Avoid looping, if repeating same key */
   124 				/* Avoid looping, if repeating same key */
   121 				break;
   125 				quit = 1;
   122 			}
   126 			}
   123 		}
   127 		}
   124 
   128 
   125 		/* Mouse entering/leaving window */
   129 		/* Mouse entering/leaving window */
   126 		if (resultat & MU_M1) {
   130 		if (resultat & MU_M1) {
   132 			GEM_CheckMouseMode(this);
   136 			GEM_CheckMouseMode(this);
   133 		}
   137 		}
   134 
   138 
   135 		/* Mouse button event ? */
   139 		/* Mouse button event ? */
   136 		if (resultat & MU_BUTTON) {
   140 		if (resultat & MU_BUTTON) {
   137 			do_mouse(this, mousex, mousey, mouseb, kstate);
   141 			do_mouse(this, mousex, mousey, mouseb);
   138 			maskmouseb = mouseb & 7;
   142 			maskmouseb = mouseb & 7;
   139 		}
   143 		}
   140 
   144 
   141 		/* Timer event ? */
   145 		/* Timer event ? */
   142 		if ((resultat & MU_TIMER) || quit)
   146 		if ((resultat & MU_TIMER) || quit)
   275 	}
   279 	}
   276 	
   280 	
   277 	return quit;
   281 	return quit;
   278 }
   282 }
   279 
   283 
   280 static void do_keyboard(short kc, short ks)
   284 static void do_keyboard(short kc)
   281 {
   285 {
   282 	int scancode;
   286 	int scancode;
   283 
   287 
   284 	if (kc) {
   288 	if (kc) {
   285 		scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
   289 		scancode=(kc>>8) & (ATARIBIOS_MAXKEYS-1);
   286 		gem_currentkeyboard[scancode]=0xFF;
   290 		gem_currentkeyboard[scancode]=0xFF;
   287 	}
   291 	}
   288 
   292 }
       
   293 
       
   294 static void do_keyboard_special(short ks)
       
   295 {
   289 	/* Read special keys */
   296 	/* Read special keys */
   290 	if (ks & K_RSHIFT)
   297 	if (ks & K_RSHIFT)
   291 		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   298 		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   292 	if (ks & K_LSHIFT)
   299 	if (ks & K_LSHIFT)
   293 		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
   300 		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
   295 		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   302 		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   296 	if (ks & K_ALT)
   303 	if (ks & K_ALT)
   297 		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   304 		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   298 }
   305 }
   299 
   306 
   300 static void do_mouse(_THIS, short mx, short my, short mb, short ks)
   307 static void do_mouse(_THIS, short mx, short my, short mb)
   301 {
   308 {
   302 	static short prevmousex=0, prevmousey=0, prevmouseb=0;
   309 	static short prevmousex=0, prevmousey=0, prevmouseb=0;
   303 	short x2, y2, w2, h2;
   310 	short x2, y2, w2, h2;
   304 
   311 
   305 	/* Don't return mouse events if out of window */
   312 	/* Don't return mouse events if out of window */
   362 				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   369 				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   363 			}
   370 			}
   364 		}
   371 		}
   365 		prevmouseb = mb;
   372 		prevmouseb = mb;
   366 	}
   373 	}
   367 
   374 }
   368 	/* Read special keys */
       
   369 	if (ks & K_RSHIFT)
       
   370 		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
       
   371 	if (ks & K_LSHIFT)
       
   372 		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
       
   373 	if (ks & K_CTRL)
       
   374 		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
       
   375 	if (ks & K_ALT)
       
   376 		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
       
   377 }