gem: Handle mouse motion by checking when cursor leave previous position. Add function to check mouse focus using visible window areas. SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Fri, 12 Oct 2012 18:45:10 +0200
branchSDL-1.2
changeset 6585bc23c3b164fa
parent 6584 6b04ece9686b
child 6647 42abe340dc14
gem: Handle mouse motion by checking when cursor leave previous position. Add function to check mouse focus using visible window areas.
src/video/gem/SDL_gemevents.c
     1.1 --- a/src/video/gem/SDL_gemevents.c	Fri Oct 12 18:37:59 2012 +0200
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Fri Oct 12 18:45:10 2012 +0200
     1.3 @@ -54,6 +54,7 @@
     1.4  static void do_keyboard_special(short ks);
     1.5  static void do_mouse_motion(_THIS, short mx, short my);
     1.6  static void do_mouse_buttons(_THIS, short mb);
     1.7 +static int mouse_in_work_area(int winhandle, short mx, short my);
     1.8  
     1.9  /* Functions */
    1.10  
    1.11 @@ -70,38 +71,26 @@
    1.12  
    1.13  void GEM_PumpEvents(_THIS)
    1.14  {
    1.15 -	short prevkc;
    1.16 -	static short prevmb=0;
    1.17 +	short prevkc=0;
    1.18 +	static short prevmx=0, prevmy=0, prevmb=0;
    1.19  	int i;
    1.20  	SDL_keysym	keysym;
    1.21  
    1.22  	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    1.23 -	prevkc = 0;
    1.24  
    1.25  	for (;;)
    1.26  	{
    1.27 -		int quit, resultat, event_mask, mouse_event;
    1.28 +		int quit, resultat;
    1.29  		short buffer[8], kc;
    1.30 -		short x2,y2,w2,h2;
    1.31  		short mousex, mousey, mouseb, dummy;
    1.32  		short kstate;
    1.33  
    1.34 -		quit =
    1.35 -			mouse_event =
    1.36 -			x2=y2=w2=h2 = 0;
    1.37 -
    1.38 -		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON;
    1.39 -		if (!GEM_fullscreen && (GEM_handle>=0)) {
    1.40 -			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
    1.41 -			event_mask |= MU_M1;
    1.42 -			mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
    1.43 -				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
    1.44 -		}
    1.45 +		quit = 0;
    1.46  
    1.47  		resultat = evnt_multi(
    1.48 -			event_mask,
    1.49 +			MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON|MU_M1,
    1.50  			0x101,7,prevmb,
    1.51 -			mouse_event,x2,y2,w2,h2,
    1.52 +			MO_LEAVE,prevmx,prevmy,1,1,
    1.53  			0,0,0,0,0,
    1.54  			buffer,
    1.55  			10,
    1.56 @@ -127,19 +116,25 @@
    1.57  			}
    1.58  		}
    1.59  
    1.60 -		/* Mouse entering/leaving window */
    1.61 +		/* Mouse motion event ? */
    1.62  		if (resultat & MU_M1) {
    1.63  			if (this->input_grab == SDL_GRAB_OFF) {
    1.64  				/* Switch mouse focus state */
    1.65 -				SDL_PrivateAppActive((mouse_event == MO_ENTER),
    1.66 -					SDL_APPMOUSEFOCUS);
    1.67 +				if (!GEM_fullscreen && (GEM_handle>=0)) {
    1.68 +					SDL_PrivateAppActive(
    1.69 +						mouse_in_work_area(GEM_handle, mousex,mousey),
    1.70 +						SDL_APPMOUSEFOCUS);
    1.71 +				}
    1.72  			}
    1.73  			GEM_CheckMouseMode(this);
    1.74 +
    1.75 +			do_mouse_motion(this, mousex, mousey);
    1.76 +			prevmx = mousex;
    1.77 +			prevmy = mousey;
    1.78  		}
    1.79  
    1.80  		/* Mouse button event ? */
    1.81  		if (resultat & MU_BUTTON) {
    1.82 -			do_mouse_motion(this, mousex, mousey);
    1.83  			do_mouse_buttons(this, mouseb);
    1.84  			prevmb = mouseb & 7;
    1.85  		}
    1.86 @@ -379,3 +374,26 @@
    1.87  
    1.88  	prevmouseb = mb;
    1.89  }
    1.90 +
    1.91 +/* Check if mouse in visible area of the window */
    1.92 +static int mouse_in_work_area(int winhandle, short mx, short my)
    1.93 +{
    1.94 +	short todo[4];
    1.95 +	short inside[4] = {mx,my,1,1};
    1.96 +
    1.97 +	/* Browse the rectangle list */
    1.98 +	if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
    1.99 +		while (todo[2] && todo[3]) {
   1.100 +			if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
   1.101 +				return 1;
   1.102 +			}
   1.103 +
   1.104 +			if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
   1.105 +				break;
   1.106 +			}
   1.107 +		}
   1.108 +
   1.109 +	}
   1.110 +
   1.111 +	return 0;
   1.112 +}