src/video/photon/SDL_ph_events.c
changeset 320 66f815c147ed
parent 297 f6ffac90895c
child 571 8e3ce997621c
     1.1 --- a/src/video/photon/SDL_ph_events.c	Tue Mar 26 17:37:31 2002 +0000
     1.2 +++ b/src/video/photon/SDL_ph_events.c	Thu Mar 28 16:20:10 2002 +0000
     1.3 @@ -74,7 +74,7 @@
     1.4  					(peekevent->timestamp == event->timestamp)	
     1.5  				) {
     1.6  					repeated = 1;
     1.7 -					 //PhEventNext( peekevent, EVENT_SIZE );  
     1.8 +					 /* PhEventNext( peekevent, EVENT_SIZE ); */
     1.9  				}				
    1.10  			}
    1.11  		}
    1.12 @@ -85,7 +85,7 @@
    1.13  		}
    1.14  		break;
    1.15  
    1.16 -		default: // no events pending
    1.17 +		default: /* no events pending */
    1.18  	}
    1.19  	return(repeated);
    1.20  }
    1.21 @@ -93,11 +93,12 @@
    1.22  
    1.23  static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent)
    1.24  {
    1.25 -	PhPointerEvent_t *pointer = PhGetData( winEvent );
    1.26 +/*	PhPointerEvent_t *pointer = PhGetData( winEvent ); */
    1.27  	PhRect_t *rect = PhGetRects( winEvent );
    1.28  
    1.29  	int centre_x, centre_y;
    1.30 -	int dx, dy, abs_x, abs_y;
    1.31 +	int dx, dy;
    1.32 +        short abs_x, abs_y;
    1.33  	int posted;
    1.34  
    1.35  	centre_x = SDL_VideoSurface->w / 2;
    1.36 @@ -155,177 +156,168 @@
    1.37  
    1.38  static int ph_DispatchEvent(_THIS)
    1.39  {
    1.40 -	int posted;
    1.41 -	PhRect_t* rect;
    1.42 -	PhPointerEvent_t* pointerEvent;
    1.43 -	PhKeyEvent_t* keyEvent;
    1.44 -	PhWindowEvent_t* winEvent;
    1.45 -	int i, buttons;
    1.46 -	SDL_Rect sdlrects[50]; 
    1.47 +    int posted;
    1.48 +    PhRect_t* rect;
    1.49 +    PhPointerEvent_t* pointerEvent;
    1.50 +    PhKeyEvent_t* keyEvent;
    1.51 +    PhWindowEvent_t* winEvent;
    1.52 +    int i, buttons;
    1.53 +    SDL_Rect sdlrects[50]; 
    1.54  	
    1.55 -	posted = 0;
    1.56 +    posted = 0;
    1.57  	
    1.58 -	switch (event->type) {
    1.59 -		case Ph_EV_BOUNDARY:
    1.60 +    switch (event->type)
    1.61 +    {
    1.62 +        case Ph_EV_BOUNDARY:
    1.63 +        {
    1.64 +            if (event->subtype == Ph_EV_PTR_ENTER)
    1.65 +            {
    1.66 +                posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
    1.67 +            }
    1.68 +            else if (event->subtype ==Ph_EV_PTR_LEAVE)
    1.69 +            {
    1.70 +                posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
    1.71 +            }
    1.72 +        }
    1.73 +        break;
    1.74 +
    1.75 +        case Ph_EV_PTR_MOTION_BUTTON:
    1.76 +        case Ph_EV_PTR_MOTION_NOBUTTON:
    1.77 +        {
    1.78 +            if (SDL_VideoSurface)
    1.79 +            {
    1.80 +                pointerEvent = PhGetData(event);
    1.81 +                rect = PhGetRects(event);
    1.82 +
    1.83 +                if (mouse_relative)
    1.84 +                {
    1.85 +                    posted = ph_WarpedMotion(this, event);
    1.86 +                }
    1.87 +                else
    1.88 +                {
    1.89 +                    posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y);
    1.90 +                }
    1.91 +            }
    1.92 +        }
    1.93 +        break;
    1.94 +
    1.95 +        case Ph_EV_BUT_PRESS:
    1.96 +        {
    1.97 +            pointerEvent = PhGetData( event );
    1.98 +            buttons = ph2sdl_mousebutton( pointerEvent->buttons );
    1.99 +            if (buttons != 0)
   1.100 +            {
   1.101 +                posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0);
   1.102 +            }
   1.103 +        }
   1.104 +        break;
   1.105 +
   1.106 +        case Ph_EV_BUT_RELEASE:
   1.107 +        {
   1.108 +            pointerEvent = PhGetData(event);
   1.109 +            buttons = ph2sdl_mousebutton(pointerEvent->buttons);
   1.110 +            if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0)
   1.111 +            {
   1.112 +                posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
   1.113 +            }
   1.114 +            else if(event->subtype == Ph_EV_RELEASE_PHANTOM)
   1.115 +            {
   1.116 +                /* If the mouse is outside the window,
   1.117 +                 * only a phantom release event is sent, so
   1.118 +                 * check if the window doesn't have mouse focus.
   1.119 +                 * Not perfect, maybe checking the mouse button
   1.120 +                 * state for Ph_EV_BOUNDARY events would be
   1.121 +                 * better. */
   1.122 +                if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0)
   1.123  		{
   1.124 -			if (event->subtype == Ph_EV_PTR_ENTER)
   1.125 -				posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.126 -			else if (event->subtype ==Ph_EV_PTR_LEAVE)
   1.127 -				posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);	
   1.128 -		}
   1.129 -		break;
   1.130 +                    posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0);
   1.131 +                }
   1.132 +            }
   1.133 +        }
   1.134 +        break;
   1.135  
   1.136 -		case Ph_EV_PTR_MOTION_BUTTON:
   1.137 -		case Ph_EV_PTR_MOTION_NOBUTTON:
   1.138 -		{
   1.139 -			if ( SDL_VideoSurface ) {
   1.140 -				pointerEvent = PhGetData( event );
   1.141 -				rect = PhGetRects( event );
   1.142 -				if( mouse_relative )
   1.143 -				{
   1.144 -					posted = ph_WarpedMotion(this, event);
   1.145 -				}
   1.146 -				else
   1.147 -					posted = SDL_PrivateMouseMotion(0, 0,
   1.148 -							rect->ul.x, rect->ul.y);
   1.149 -			}
   1.150 -		}
   1.151 -		break;
   1.152 +        case Ph_EV_WM:
   1.153 +        {
   1.154 +            winEvent = PhGetData(event);
   1.155  
   1.156 -		case Ph_EV_BUT_PRESS:
   1.157 -		{
   1.158 -			pointerEvent = PhGetData( event );
   1.159 -			buttons = ph2sdl_mousebutton( pointerEvent->buttons );
   1.160 -			if( buttons != 0 )
   1.161 -			posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons,
   1.162 -					0, 0 );
   1.163 -		}
   1.164 -		break;
   1.165 +            /* losing focus */
   1.166 +            if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
   1.167 +            {
   1.168 +                set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   1.169 +                posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   1.170  
   1.171 -		case Ph_EV_BUT_RELEASE:
   1.172 -		{
   1.173 -			pointerEvent = PhGetData(event);
   1.174 -			buttons = ph2sdl_mousebutton(pointerEvent->buttons);
   1.175 -			if( event->subtype == Ph_EV_RELEASE_REAL && 
   1.176 -					buttons != 0 )
   1.177 -			{
   1.178 -				posted = SDL_PrivateMouseButton( SDL_RELEASED,
   1.179 -						buttons, 0, 0 );
   1.180 -			}
   1.181 -			else if( event->subtype == Ph_EV_RELEASE_PHANTOM )
   1.182 -			{
   1.183 -				/* If the mouse is outside the window,
   1.184 -				 * only a phantom release event is sent, so
   1.185 -				 * check if the window doesn't have mouse focus.
   1.186 -				 * Not perfect, maybe checking the mouse button
   1.187 -				 * state for Ph_EV_BOUNDARY events would be
   1.188 -				 * better. */
   1.189 -				if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 )
   1.190 -				{
   1.191 -					posted = SDL_PrivateMouseButton( SDL_RELEASED,
   1.192 -						buttons, 0, 0 );
   1.193 -				}
   1.194 -			}
   1.195 -		}
   1.196 -		break;
   1.197 +                /* Queue leaving fullscreen mode */
   1.198 +                switch_waiting = 0x01;
   1.199 +                switch_time = SDL_GetTicks() + 200;
   1.200 +            }
   1.201 +            /* gaining focus */
   1.202 +            else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   1.203 +            {
   1.204 +                set_motion_sensitivity(this, -1);
   1.205 +                posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.206 +            }
   1.207 +            /* request to quit */
   1.208 +            else if (winEvent->event_f==Ph_WM_CLOSE)
   1.209 +            {
   1.210 +                posted = SDL_PrivateQuit();
   1.211 +            }
   1.212 +            /* request to resize */
   1.213 +            else if (winEvent->event_f==Ph_WM_RESIZE)
   1.214 +            {
   1.215 +                SDL_PrivateResize(winEvent->size.w, winEvent->size.h);
   1.216 +            }
   1.217 +            /* request to maximize */
   1.218 +            else if (winEvent->event_f==Ph_WM_MAX)
   1.219 +            {
   1.220 +                /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */
   1.221 +            }
   1.222 +        }
   1.223 +        break;
   1.224  
   1.225 -		case Ph_EV_WM:
   1.226 -		{
   1.227 -			winEvent = PhGetData( event );
   1.228 -			
   1.229 -			/* losing focus */
   1.230 -			if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.231 -				(winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST))
   1.232 -			{
   1.233 -				set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON);
   1.234 -				posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);	
   1.235 +        /* window has been resized, moved or removed */
   1.236 +        case Ph_EV_EXPOSE:
   1.237 +        {
   1.238 +            if (SDL_VideoSurface)
   1.239 +            {
   1.240 +                rect = PhGetRects(event);
   1.241  
   1.242 -				/* Queue leaving fullscreen mode */
   1.243 -				switch_waiting = 0x01;
   1.244 -				switch_time = SDL_GetTicks() + 200;
   1.245 -			}
   1.246 +                for(i=0;i<event->num_rects;i++)
   1.247 +                {
   1.248 +                    sdlrects[i].x = rect[i].ul.x;
   1.249 +                    sdlrects[i].y = rect[i].ul.y;
   1.250 +                    sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   1.251 +                    sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   1.252 +                }
   1.253  
   1.254 -			/* gaining focus */
   1.255 -			else if ((winEvent->event_f==Ph_WM_FOCUS)&&
   1.256 -					(winEvent->event_state==Ph_WM_EVSTATE_FOCUS))
   1.257 -			{
   1.258 -				set_motion_sensitivity(this, -1);
   1.259 -				posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
   1.260 -#if 0
   1.261 -				/* Queue entry into fullscreen mode */
   1.262 -				switch_waiting = 0x01 | SDL_FULLSCREEN;
   1.263 -				switch_time = SDL_GetTicks() + 1500;
   1.264 -#endif
   1.265 -			}
   1.266 +                this->UpdateRects(this, event->num_rects, sdlrects);
   1.267 +            }
   1.268 +        }
   1.269 +	break;
   1.270  
   1.271 -			/* request to quit */
   1.272 -			else if (winEvent->event_f==Ph_WM_CLOSE)
   1.273 -			{
   1.274 -				posted = SDL_PrivateQuit();
   1.275 -			}
   1.276 -			else if (winEvent->event_f==Ph_WM_RESIZE)
   1.277 -			{
   1.278 -				PhDim_t *size;
   1.279 +        case Ph_EV_KEY:
   1.280 +        {
   1.281 +            SDL_keysym keysym;
   1.282  
   1.283 -				PtGetResource( window, Pt_ARG_DIM, &size, 0 );
   1.284 -				SDL_PrivateResize(size->w,size->h);
   1.285 -			}
   1.286 -		}
   1.287 -		break;
   1.288 -		
   1.289 -		/* window has been resized, moved or removed */
   1.290 -		case Ph_EV_EXPOSE:
   1.291 -		{
   1.292 -			if (SDL_VideoSurface)
   1.293 -			{
   1.294 -				rect = PhGetRects( event );
   1.295 +            posted = 0;
   1.296  
   1.297 -				//PgSetClipping(1, rect );
   1.298 -				for(i=0;i<event->num_rects;i++)
   1.299 -				{
   1.300 -					sdlrects[i].x = rect[i].ul.x;
   1.301 -					sdlrects[i].y = rect[i].ul.y;
   1.302 -					sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1;
   1.303 -					sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1;
   1.304 -				}
   1.305 +            keyEvent = PhGetData( event );
   1.306  
   1.307 -				this->UpdateRects(this, event->num_rects, sdlrects);
   1.308 +            if (Pk_KF_Key_Down & keyEvent->key_flags)
   1.309 +            {
   1.310 +                posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym));
   1.311 +            }
   1.312 +            else /* must be key release */
   1.313 +            {
   1.314 +                 /* Ignore repeated key release events */
   1.315 +                 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */
   1.316  
   1.317 -			}
   1.318 -		}
   1.319 -		break;
   1.320 +                posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym));
   1.321 +            }
   1.322 +        }
   1.323 +        break;
   1.324 +    }
   1.325  
   1.326 -		case Ph_EV_KEY:
   1.327 -		{
   1.328 -	
   1.329 -			SDL_keysym keysym;
   1.330 -			
   1.331 -			posted = 0;
   1.332 -			
   1.333 -			keyEvent = PhGetData( event );
   1.334 -
   1.335 -			if (Pk_KF_Key_Down & keyEvent->key_flags)
   1.336 -			{
   1.337 -				
   1.338 -				posted = SDL_PrivateKeyboard(SDL_PRESSED,
   1.339 -                			ph_TranslateKey( keyEvent, &keysym));
   1.340 -			}
   1.341 -			else /* must be key release */
   1.342 - 			{
   1.343 - 				/* Ignore repeated key release events */
   1.344 -				/*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/
   1.345 -				
   1.346 -					posted = SDL_PrivateKeyboard(SDL_RELEASED,
   1.347 -        					ph_TranslateKey( keyEvent, &keysym));
   1.348 -				/*}*/
   1.349 -			}
   1.350 -		}
   1.351 -		break;
   1.352 -	}
   1.353 -	
   1.354 -		
   1.355 -	
   1.356 -	return(posted);
   1.357 +    return(posted);
   1.358  }
   1.359  
   1.360  /* perform a blocking read if no events available */