src/video/gem/SDL_gemevents.c
branchSDL-1.2
changeset 6585 bc23c3b164fa
parent 6584 6b04ece9686b
child 6647 42abe340dc14
equal deleted inserted replaced
6584:6b04ece9686b 6585:bc23c3b164fa
    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_motion(_THIS, short mx, short my);
    55 static void do_mouse_motion(_THIS, short mx, short my);
    56 static void do_mouse_buttons(_THIS, short mb);
    56 static void do_mouse_buttons(_THIS, short mb);
       
    57 static int mouse_in_work_area(int winhandle, short mx, short my);
    57 
    58 
    58 /* Functions */
    59 /* Functions */
    59 
    60 
    60 void GEM_InitOSKeymap(_THIS)
    61 void GEM_InitOSKeymap(_THIS)
    61 {
    62 {
    68 	SDL_Atari_InitInternalKeymap(this);
    69 	SDL_Atari_InitInternalKeymap(this);
    69 }
    70 }
    70 
    71 
    71 void GEM_PumpEvents(_THIS)
    72 void GEM_PumpEvents(_THIS)
    72 {
    73 {
    73 	short prevkc;
    74 	short prevkc=0;
    74 	static short prevmb=0;
    75 	static short prevmx=0, prevmy=0, prevmb=0;
    75 	int i;
    76 	int i;
    76 	SDL_keysym	keysym;
    77 	SDL_keysym	keysym;
    77 
    78 
    78 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    79 	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    79 	prevkc = 0;
       
    80 
    80 
    81 	for (;;)
    81 	for (;;)
    82 	{
    82 	{
    83 		int quit, resultat, event_mask, mouse_event;
    83 		int quit, resultat;
    84 		short buffer[8], kc;
    84 		short buffer[8], kc;
    85 		short x2,y2,w2,h2;
       
    86 		short mousex, mousey, mouseb, dummy;
    85 		short mousex, mousey, mouseb, dummy;
    87 		short kstate;
    86 		short kstate;
    88 
    87 
    89 		quit =
    88 		quit = 0;
    90 			mouse_event =
       
    91 			x2=y2=w2=h2 = 0;
       
    92 
       
    93 		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON;
       
    94 		if (!GEM_fullscreen && (GEM_handle>=0)) {
       
    95 			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
       
    96 			event_mask |= MU_M1;
       
    97 			mouse_event = ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
       
    98 				== SDL_APPMOUSEFOCUS) ? MO_LEAVE : MO_ENTER;
       
    99 		}
       
   100 
    89 
   101 		resultat = evnt_multi(
    90 		resultat = evnt_multi(
   102 			event_mask,
    91 			MU_MESAG|MU_TIMER|MU_KEYBD|MU_BUTTON|MU_M1,
   103 			0x101,7,prevmb,
    92 			0x101,7,prevmb,
   104 			mouse_event,x2,y2,w2,h2,
    93 			MO_LEAVE,prevmx,prevmy,1,1,
   105 			0,0,0,0,0,
    94 			0,0,0,0,0,
   106 			buffer,
    95 			buffer,
   107 			10,
    96 			10,
   108 			&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
    97 			&mousex,&mousey,&mouseb,&kstate,&kc,&dummy
   109 		);
    98 		);
   125 				/* Avoid looping, if repeating same key */
   114 				/* Avoid looping, if repeating same key */
   126 				quit = 1;
   115 				quit = 1;
   127 			}
   116 			}
   128 		}
   117 		}
   129 
   118 
   130 		/* Mouse entering/leaving window */
   119 		/* Mouse motion event ? */
   131 		if (resultat & MU_M1) {
   120 		if (resultat & MU_M1) {
   132 			if (this->input_grab == SDL_GRAB_OFF) {
   121 			if (this->input_grab == SDL_GRAB_OFF) {
   133 				/* Switch mouse focus state */
   122 				/* Switch mouse focus state */
   134 				SDL_PrivateAppActive((mouse_event == MO_ENTER),
   123 				if (!GEM_fullscreen && (GEM_handle>=0)) {
   135 					SDL_APPMOUSEFOCUS);
   124 					SDL_PrivateAppActive(
       
   125 						mouse_in_work_area(GEM_handle, mousex,mousey),
       
   126 						SDL_APPMOUSEFOCUS);
       
   127 				}
   136 			}
   128 			}
   137 			GEM_CheckMouseMode(this);
   129 			GEM_CheckMouseMode(this);
       
   130 
       
   131 			do_mouse_motion(this, mousex, mousey);
       
   132 			prevmx = mousex;
       
   133 			prevmy = mousey;
   138 		}
   134 		}
   139 
   135 
   140 		/* Mouse button event ? */
   136 		/* Mouse button event ? */
   141 		if (resultat & MU_BUTTON) {
   137 		if (resultat & MU_BUTTON) {
   142 			do_mouse_motion(this, mousex, mousey);
       
   143 			do_mouse_buttons(this, mouseb);
   138 			do_mouse_buttons(this, mouseb);
   144 			prevmb = mouseb & 7;
   139 			prevmb = mouseb & 7;
   145 		}
   140 		}
   146 
   141 
   147 		/* Timer event ? */
   142 		/* Timer event ? */
   377 		}
   372 		}
   378 	}
   373 	}
   379 
   374 
   380 	prevmouseb = mb;
   375 	prevmouseb = mb;
   381 }
   376 }
       
   377 
       
   378 /* Check if mouse in visible area of the window */
       
   379 static int mouse_in_work_area(int winhandle, short mx, short my)
       
   380 {
       
   381 	short todo[4];
       
   382 	short inside[4] = {mx,my,1,1};
       
   383 
       
   384 	/* Browse the rectangle list */
       
   385 	if (wind_get(winhandle, WF_FIRSTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])!=0) {
       
   386 		while (todo[2] && todo[3]) {
       
   387 			if (rc_intersect((GRECT *)inside,(GRECT *)todo)) {
       
   388 				return 1;
       
   389 			}
       
   390 
       
   391 			if (wind_get(winhandle, WF_NEXTXYWH, &todo[0], &todo[1], &todo[2], &todo[3])==0) {
       
   392 				break;
       
   393 			}
       
   394 		}
       
   395 
       
   396 	}
       
   397 
       
   398 	return 0;
       
   399 }