Mercurial > sdl-ios-xcode
comparison src/video/photon/SDL_ph_events.c @ 320:66f815c147ed
Date: Thu, 28 Mar 2002 09:20:03 +0200
From: "Mike Gorchak" <mike@malva.ua>
Subject: New QNX patch.
Hi !
1. Removed warning (possible bug) with invalid type, passing to the function
in ph_WarpedMotion.
2. Rewritten handler of Ph_WM_RESIZE message, now works, but buggy (old
handler doesn't work at all).
3. Added stub handler for Ph_WM_MAX (maximize) message.
4. Added more #ifdef HAVE_OPENGL to disable OpenGL stuff when it not needed.
5. Added support for SDL_NOFRAME and SDL_RESIZABLE flags (in OpenGL windows
too).
6. Added cosmetic changes, if no SDL_RESIZABLE flag defined, disable resize
handlers in window border and maximize button at caption.
7. Fixed my bug with invalid arguments count passed to PtCreateWidget call.
8. Fixed some palette problems.
9. Updated README.QNX file.
And I changed testgl.c test application:
10. Added in testgl.c application support for SDL_NOFRAME flag and
option -noframe.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 28 Mar 2002 16:20:10 +0000 |
parents | f6ffac90895c |
children | 8e3ce997621c |
comparison
equal
deleted
inserted
replaced
319:189a6a3416c7 | 320:66f815c147ed |
---|---|
72 if ( !(Pk_KF_Key_Down & keyEvent->key_flags) && | 72 if ( !(Pk_KF_Key_Down & keyEvent->key_flags) && |
73 (keyEvent->key_cap == keyevent->key_cap) && | 73 (keyEvent->key_cap == keyevent->key_cap) && |
74 (peekevent->timestamp == event->timestamp) | 74 (peekevent->timestamp == event->timestamp) |
75 ) { | 75 ) { |
76 repeated = 1; | 76 repeated = 1; |
77 //PhEventNext( peekevent, EVENT_SIZE ); | 77 /* PhEventNext( peekevent, EVENT_SIZE ); */ |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
81 break; | 81 break; |
82 | 82 |
83 case -1: { | 83 case -1: { |
84 perror( "PhEventPeek failed" ); | 84 perror( "PhEventPeek failed" ); |
85 } | 85 } |
86 break; | 86 break; |
87 | 87 |
88 default: // no events pending | 88 default: /* no events pending */ |
89 } | 89 } |
90 return(repeated); | 90 return(repeated); |
91 } | 91 } |
92 #endif | 92 #endif |
93 | 93 |
94 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) | 94 static int ph_WarpedMotion(_THIS, PhEvent_t *winEvent) |
95 { | 95 { |
96 PhPointerEvent_t *pointer = PhGetData( winEvent ); | 96 /* PhPointerEvent_t *pointer = PhGetData( winEvent ); */ |
97 PhRect_t *rect = PhGetRects( winEvent ); | 97 PhRect_t *rect = PhGetRects( winEvent ); |
98 | 98 |
99 int centre_x, centre_y; | 99 int centre_x, centre_y; |
100 int dx, dy, abs_x, abs_y; | 100 int dx, dy; |
101 short abs_x, abs_y; | |
101 int posted; | 102 int posted; |
102 | 103 |
103 centre_x = SDL_VideoSurface->w / 2; | 104 centre_x = SDL_VideoSurface->w / 2; |
104 centre_y = SDL_VideoSurface->h / 2; | 105 centre_y = SDL_VideoSurface->h / 2; |
105 | 106 |
153 return( mouse_button ); | 154 return( mouse_button ); |
154 } | 155 } |
155 | 156 |
156 static int ph_DispatchEvent(_THIS) | 157 static int ph_DispatchEvent(_THIS) |
157 { | 158 { |
158 int posted; | 159 int posted; |
159 PhRect_t* rect; | 160 PhRect_t* rect; |
160 PhPointerEvent_t* pointerEvent; | 161 PhPointerEvent_t* pointerEvent; |
161 PhKeyEvent_t* keyEvent; | 162 PhKeyEvent_t* keyEvent; |
162 PhWindowEvent_t* winEvent; | 163 PhWindowEvent_t* winEvent; |
163 int i, buttons; | 164 int i, buttons; |
164 SDL_Rect sdlrects[50]; | 165 SDL_Rect sdlrects[50]; |
165 | 166 |
166 posted = 0; | 167 posted = 0; |
167 | 168 |
168 switch (event->type) { | 169 switch (event->type) |
169 case Ph_EV_BOUNDARY: | 170 { |
171 case Ph_EV_BOUNDARY: | |
172 { | |
173 if (event->subtype == Ph_EV_PTR_ENTER) | |
174 { | |
175 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | |
176 } | |
177 else if (event->subtype ==Ph_EV_PTR_LEAVE) | |
178 { | |
179 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | |
180 } | |
181 } | |
182 break; | |
183 | |
184 case Ph_EV_PTR_MOTION_BUTTON: | |
185 case Ph_EV_PTR_MOTION_NOBUTTON: | |
186 { | |
187 if (SDL_VideoSurface) | |
188 { | |
189 pointerEvent = PhGetData(event); | |
190 rect = PhGetRects(event); | |
191 | |
192 if (mouse_relative) | |
193 { | |
194 posted = ph_WarpedMotion(this, event); | |
195 } | |
196 else | |
197 { | |
198 posted = SDL_PrivateMouseMotion(0, 0, rect->ul.x, rect->ul.y); | |
199 } | |
200 } | |
201 } | |
202 break; | |
203 | |
204 case Ph_EV_BUT_PRESS: | |
205 { | |
206 pointerEvent = PhGetData( event ); | |
207 buttons = ph2sdl_mousebutton( pointerEvent->buttons ); | |
208 if (buttons != 0) | |
209 { | |
210 posted = SDL_PrivateMouseButton(SDL_PRESSED, buttons, 0, 0); | |
211 } | |
212 } | |
213 break; | |
214 | |
215 case Ph_EV_BUT_RELEASE: | |
216 { | |
217 pointerEvent = PhGetData(event); | |
218 buttons = ph2sdl_mousebutton(pointerEvent->buttons); | |
219 if (event->subtype == Ph_EV_RELEASE_REAL && buttons != 0) | |
220 { | |
221 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); | |
222 } | |
223 else if(event->subtype == Ph_EV_RELEASE_PHANTOM) | |
224 { | |
225 /* If the mouse is outside the window, | |
226 * only a phantom release event is sent, so | |
227 * check if the window doesn't have mouse focus. | |
228 * Not perfect, maybe checking the mouse button | |
229 * state for Ph_EV_BOUNDARY events would be | |
230 * better. */ | |
231 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) == 0) | |
170 { | 232 { |
171 if (event->subtype == Ph_EV_PTR_ENTER) | 233 posted = SDL_PrivateMouseButton(SDL_RELEASED, buttons, 0, 0); |
172 posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); | 234 } |
173 else if (event->subtype ==Ph_EV_PTR_LEAVE) | 235 } |
174 posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); | 236 } |
175 } | 237 break; |
176 break; | 238 |
177 | 239 case Ph_EV_WM: |
178 case Ph_EV_PTR_MOTION_BUTTON: | 240 { |
179 case Ph_EV_PTR_MOTION_NOBUTTON: | 241 winEvent = PhGetData(event); |
180 { | 242 |
181 if ( SDL_VideoSurface ) { | 243 /* losing focus */ |
182 pointerEvent = PhGetData( event ); | 244 if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) |
183 rect = PhGetRects( event ); | 245 { |
184 if( mouse_relative ) | 246 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); |
185 { | 247 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); |
186 posted = ph_WarpedMotion(this, event); | 248 |
187 } | 249 /* Queue leaving fullscreen mode */ |
188 else | 250 switch_waiting = 0x01; |
189 posted = SDL_PrivateMouseMotion(0, 0, | 251 switch_time = SDL_GetTicks() + 200; |
190 rect->ul.x, rect->ul.y); | 252 } |
191 } | 253 /* gaining focus */ |
192 } | 254 else if ((winEvent->event_f==Ph_WM_FOCUS) && (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) |
193 break; | 255 { |
194 | 256 set_motion_sensitivity(this, -1); |
195 case Ph_EV_BUT_PRESS: | 257 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); |
196 { | 258 } |
197 pointerEvent = PhGetData( event ); | 259 /* request to quit */ |
198 buttons = ph2sdl_mousebutton( pointerEvent->buttons ); | 260 else if (winEvent->event_f==Ph_WM_CLOSE) |
199 if( buttons != 0 ) | 261 { |
200 posted = SDL_PrivateMouseButton( SDL_PRESSED, buttons, | 262 posted = SDL_PrivateQuit(); |
201 0, 0 ); | 263 } |
202 } | 264 /* request to resize */ |
203 break; | 265 else if (winEvent->event_f==Ph_WM_RESIZE) |
204 | 266 { |
205 case Ph_EV_BUT_RELEASE: | 267 SDL_PrivateResize(winEvent->size.w, winEvent->size.h); |
206 { | 268 } |
207 pointerEvent = PhGetData(event); | 269 /* request to maximize */ |
208 buttons = ph2sdl_mousebutton(pointerEvent->buttons); | 270 else if (winEvent->event_f==Ph_WM_MAX) |
209 if( event->subtype == Ph_EV_RELEASE_REAL && | 271 { |
210 buttons != 0 ) | 272 /* TODO: get screen resolution, set window pos to 0, 0 and resize it ! */ |
211 { | 273 } |
212 posted = SDL_PrivateMouseButton( SDL_RELEASED, | 274 } |
213 buttons, 0, 0 ); | 275 break; |
214 } | 276 |
215 else if( event->subtype == Ph_EV_RELEASE_PHANTOM ) | 277 /* window has been resized, moved or removed */ |
216 { | 278 case Ph_EV_EXPOSE: |
217 /* If the mouse is outside the window, | 279 { |
218 * only a phantom release event is sent, so | 280 if (SDL_VideoSurface) |
219 * check if the window doesn't have mouse focus. | 281 { |
220 * Not perfect, maybe checking the mouse button | 282 rect = PhGetRects(event); |
221 * state for Ph_EV_BOUNDARY events would be | 283 |
222 * better. */ | 284 for(i=0;i<event->num_rects;i++) |
223 if( ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) == 0 ) | 285 { |
224 { | 286 sdlrects[i].x = rect[i].ul.x; |
225 posted = SDL_PrivateMouseButton( SDL_RELEASED, | 287 sdlrects[i].y = rect[i].ul.y; |
226 buttons, 0, 0 ); | 288 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; |
227 } | 289 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; |
228 } | 290 } |
229 } | 291 |
230 break; | 292 this->UpdateRects(this, event->num_rects, sdlrects); |
231 | 293 } |
232 case Ph_EV_WM: | 294 } |
233 { | 295 break; |
234 winEvent = PhGetData( event ); | 296 |
235 | 297 case Ph_EV_KEY: |
236 /* losing focus */ | 298 { |
237 if ((winEvent->event_f==Ph_WM_FOCUS)&& | 299 SDL_keysym keysym; |
238 (winEvent->event_state==Ph_WM_EVSTATE_FOCUSLOST)) | 300 |
239 { | 301 posted = 0; |
240 set_motion_sensitivity(this, Ph_EV_PTR_MOTION_BUTTON); | 302 |
241 posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS); | 303 keyEvent = PhGetData( event ); |
242 | 304 |
243 /* Queue leaving fullscreen mode */ | 305 if (Pk_KF_Key_Down & keyEvent->key_flags) |
244 switch_waiting = 0x01; | 306 { |
245 switch_time = SDL_GetTicks() + 200; | 307 posted = SDL_PrivateKeyboard(SDL_PRESSED, ph_TranslateKey(keyEvent, &keysym)); |
246 } | 308 } |
247 | 309 else /* must be key release */ |
248 /* gaining focus */ | 310 { |
249 else if ((winEvent->event_f==Ph_WM_FOCUS)&& | 311 /* Ignore repeated key release events */ |
250 (winEvent->event_state==Ph_WM_EVSTATE_FOCUS)) | 312 /* if (! Pk_KF_Key_Repeat & keyEvent->key_flags ) */ |
251 { | 313 |
252 set_motion_sensitivity(this, -1); | 314 posted = SDL_PrivateKeyboard(SDL_RELEASED, ph_TranslateKey( keyEvent, &keysym)); |
253 posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS); | 315 } |
254 #if 0 | 316 } |
255 /* Queue entry into fullscreen mode */ | 317 break; |
256 switch_waiting = 0x01 | SDL_FULLSCREEN; | 318 } |
257 switch_time = SDL_GetTicks() + 1500; | 319 |
258 #endif | 320 return(posted); |
259 } | |
260 | |
261 /* request to quit */ | |
262 else if (winEvent->event_f==Ph_WM_CLOSE) | |
263 { | |
264 posted = SDL_PrivateQuit(); | |
265 } | |
266 else if (winEvent->event_f==Ph_WM_RESIZE) | |
267 { | |
268 PhDim_t *size; | |
269 | |
270 PtGetResource( window, Pt_ARG_DIM, &size, 0 ); | |
271 SDL_PrivateResize(size->w,size->h); | |
272 } | |
273 } | |
274 break; | |
275 | |
276 /* window has been resized, moved or removed */ | |
277 case Ph_EV_EXPOSE: | |
278 { | |
279 if (SDL_VideoSurface) | |
280 { | |
281 rect = PhGetRects( event ); | |
282 | |
283 //PgSetClipping(1, rect ); | |
284 for(i=0;i<event->num_rects;i++) | |
285 { | |
286 sdlrects[i].x = rect[i].ul.x; | |
287 sdlrects[i].y = rect[i].ul.y; | |
288 sdlrects[i].w = rect[i].lr.x - rect[i].ul.x + 1; | |
289 sdlrects[i].h = rect[i].lr.y - rect[i].ul.y + 1; | |
290 } | |
291 | |
292 this->UpdateRects(this, event->num_rects, sdlrects); | |
293 | |
294 } | |
295 } | |
296 break; | |
297 | |
298 case Ph_EV_KEY: | |
299 { | |
300 | |
301 SDL_keysym keysym; | |
302 | |
303 posted = 0; | |
304 | |
305 keyEvent = PhGetData( event ); | |
306 | |
307 if (Pk_KF_Key_Down & keyEvent->key_flags) | |
308 { | |
309 | |
310 posted = SDL_PrivateKeyboard(SDL_PRESSED, | |
311 ph_TranslateKey( keyEvent, &keysym)); | |
312 } | |
313 else /* must be key release */ | |
314 { | |
315 /* Ignore repeated key release events */ | |
316 /*if (! Pk_KF_Key_Repeat & keyEvent->key_flags )*/ | |
317 | |
318 posted = SDL_PrivateKeyboard(SDL_RELEASED, | |
319 ph_TranslateKey( keyEvent, &keysym)); | |
320 /*}*/ | |
321 } | |
322 } | |
323 break; | |
324 } | |
325 | |
326 | |
327 | |
328 return(posted); | |
329 } | 321 } |
330 | 322 |
331 /* perform a blocking read if no events available */ | 323 /* perform a blocking read if no events available */ |
332 int ph_Pending(_THIS) | 324 int ph_Pending(_THIS) |
333 { | 325 { |