src/video/gem/SDL_gemevents.c
branchSDL-1.2
changeset 6583 15c1dc6ac329
parent 6582 8b7e21749630
child 6584 6b04ece9686b
equal deleted inserted replaced
6582:8b7e21749630 6583:15c1dc6ac329
    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);
    53 static void do_keyboard(short kc);
    54 static void do_keyboard_special(short ks);
    54 static void do_keyboard_special(short ks);
    55 static void do_mouse(_THIS, short mx, short my, short mb);
    55 static void do_mouse_motion(_THIS, short mx, short my);
       
    56 static void do_mouse_buttons(_THIS, short mb);
    56 
    57 
    57 /* Functions */
    58 /* Functions */
    58 
    59 
    59 void GEM_InitOSKeymap(_THIS)
    60 void GEM_InitOSKeymap(_THIS)
    60 {
    61 {
    68 }
    69 }
    69 
    70 
    70 void GEM_PumpEvents(_THIS)
    71 void GEM_PumpEvents(_THIS)
    71 {
    72 {
    72 	short prevkc;
    73 	short prevkc;
    73 	static short maskmouseb=0;
    74 	static short prevmb=0;
    74 	int i;
    75 	int i;
    75 	SDL_keysym	keysym;
    76 	SDL_keysym	keysym;
    76 
    77 
    77 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    78 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    78 	prevkc = 0;
    79 	prevkc = 0;
    97 				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
    98 				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
    98 		}
    99 		}
    99 
   100 
   100 		resultat = evnt_multi(
   101 		resultat = evnt_multi(
   101 			event_mask,
   102 			event_mask,
   102 			0x101,7,maskmouseb,
   103 			0x101,7,prevmb,
   103 			mouse_event,x2,y2,w2,h2,
   104 			mouse_event,x2,y2,w2,h2,
   104 			0,0,0,0,0,
   105 			0,0,0,0,0,
   105 			buffer,
   106 			buffer,
   106 			10,
   107 			10,
   107 			&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
   108 			&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
   136 			GEM_CheckMouseMode(this);
   137 			GEM_CheckMouseMode(this);
   137 		}
   138 		}
   138 
   139 
   139 		/* Mouse button event ? */
   140 		/* Mouse button event ? */
   140 		if (resultat & MU_BUTTON) {
   141 		if (resultat & MU_BUTTON) {
   141 			do_mouse(this, mousex, mousey, mouseb);
   142 			do_mouse_motion(this, mousex, mousey);
   142 			maskmouseb = mouseb & 7;
   143 			do_mouse_buttons(this, mouseb);
       
   144 			prevmb = mouseb & 7;
   143 		}
   145 		}
   144 
   146 
   145 		/* Timer event ? */
   147 		/* Timer event ? */
   146 		if ((resultat & MU_TIMER) || quit)
   148 		if ((resultat & MU_TIMER) || quit)
   147 			break;
   149 			break;
   302 		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   304 		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   303 	if (ks & K_ALT)
   305 	if (ks & K_ALT)
   304 		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   306 		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   305 }
   307 }
   306 
   308 
   307 static void do_mouse(_THIS, short mx, short my, short mb)
   309 static void do_mouse_motion(_THIS, short mx, short my)
   308 {
   310 {
   309 	static short prevmousex=0, prevmousey=0, prevmouseb=0;
   311 	static short prevmousex=0, prevmousey=0;
   310 	short x2, y2, w2, h2;
   312 	short x2, y2, w2, h2;
   311 
   313 
   312 	/* Don't return mouse events if out of window */
   314 	/* Don't return mouse events if out of window */
   313 	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
   315 	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
   314 		return;
   316 		return;
   318 	x2 = y2 = 0;
   320 	x2 = y2 = 0;
   319 	w2 = VDI_w;
   321 	w2 = VDI_w;
   320 	h2 = VDI_h;
   322 	h2 = VDI_h;
   321 	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
   323 	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
   322 		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   324 		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
   323 
       
   324 		/* Do not generate mouse button event if out of window working area */
       
   325 		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
       
   326 			mb=prevmouseb;
       
   327 		}
       
   328 	}
   325 	}
   329 
   326 
   330 	/* Mouse motion ? */
   327 	/* Mouse motion ? */
   331 	if (GEM_mouse_relative) {
   328 	if (GEM_mouse_relative) {
   332 		if (GEM_usedevmouse) {
   329 		if (GEM_usedevmouse) {
   349 			SDL_PrivateMouseMotion(0, 0, posx, posy);
   346 			SDL_PrivateMouseMotion(0, 0, posx, posy);
   350 		}
   347 		}
   351 		prevmousex = mx;
   348 		prevmousex = mx;
   352 		prevmousey = my;
   349 		prevmousey = my;
   353 	}
   350 	}
   354 
   351 }
   355 	/* Mouse button ? */
   352 
   356 	if (prevmouseb!=mb) {
   353 static void do_mouse_buttons(_THIS, short mb)
   357 		int i;
   354 {
   358 
   355 	static short prevmouseb=0;
   359 		for (i=0;i<3;i++) {
   356 	int i;
   360 			int curbutton, prevbutton;
   357 
       
   358 	/* Don't return mouse events if out of window */
       
   359 	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0)
       
   360 		return;
       
   361 
       
   362 	if (prevmouseb==mb)
       
   363 		return;
       
   364 
       
   365 	for (i=0;i<3;i++) {
       
   366 		int curbutton, prevbutton;
   361 		
   367 		
   362 			curbutton = mb & (1<<i);
   368 		curbutton = mb & (1<<i);
   363 			prevbutton = prevmouseb & (1<<i);
   369 		prevbutton = prevmouseb & (1<<i);
   364 		
   370 	
   365 			if (curbutton && !prevbutton) {
   371 		if (curbutton && !prevbutton) {
   366 				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
   372 			SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
   367 			}
   373 		}
   368 			if (!curbutton && prevbutton) {
   374 		if (!curbutton && prevbutton) {
   369 				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   375 			SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   370 			}
   376 		}
   371 		}
   377 	}
   372 		prevmouseb = mb;
   378 
   373 	}
   379 	prevmouseb = mb;
   374 }
   380 }