comparison src/events/SDL_mouse.c @ 1722:5daa04d862f1 SDL-1.3

Added a userdata parameter for event filters. Added a function to filter the existing queued events. Added explicit support for relative mouse mode to the API.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Jun 2006 08:18:44 +0000
parents a1ebb17f9c52
children 6c63fc2bd986
comparison
equal deleted inserted replaced
1721:1cc762cafff8 1722:5daa04d862f1
163 return 0; 163 return 0;
164 } 164 }
165 return mouse->focus; 165 return mouse->focus;
166 } 166 }
167 167
168 static int
169 FlushMouseMotion(void *param, SDL_Event * event)
170 {
171 if (event->type == SDL_MOUSEMOTION
172 && event->motion.which == (Uint8) SDL_current_mouse) {
173 return 0;
174 } else {
175 return 1;
176 }
177 }
178
179 int
180 SDL_SetRelativeMouseMode(SDL_bool enabled)
181 {
182 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
183
184 if (!mouse) {
185 return -1;
186 }
187
188 /* Flush pending mouse motion */
189 mouse->flush_motion = SDL_TRUE;
190 SDL_PumpEvents();
191 mouse->flush_motion = SDL_FALSE;
192 SDL_FilterEvents(FlushMouseMotion, mouse);
193
194 /* Set the relative mode */
195 mouse->relative_mode = enabled;
196
197 /* Update cursor visibility */
198 SDL_SetCursor(NULL);
199
200 if (!enabled) {
201 /* Restore the expected mouse position */
202 SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
203 }
204 return 0;
205 }
206
207 SDL_bool
208 SDL_GetRelativeMouseMode()
209 {
210 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
211
212 if (!mouse) {
213 return SDL_FALSE;
214 }
215 return mouse->relative_mode;
216 }
217
168 Uint8 218 Uint8
169 SDL_GetMouseState(int *x, int *y) 219 SDL_GetMouseState(int *x, int *y)
170 { 220 {
171 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 221 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
172 222
222 SDL_Mouse *mouse = SDL_GetMouse(index); 272 SDL_Mouse *mouse = SDL_GetMouse(index);
223 int posted; 273 int posted;
224 int xrel; 274 int xrel;
225 int yrel; 275 int yrel;
226 276
227 if (!mouse) { 277 if (!mouse || mouse->flush_motion) {
228 return 0; 278 return 0;
229 } 279 }
230 280
231 if (windowID) { 281 if (windowID) {
232 mouse->focus = windowID; 282 mouse->focus = windowID;
250 #endif 300 #endif
251 return 0; 301 return 0;
252 } 302 }
253 303
254 /* Update internal mouse state */ 304 /* Update internal mouse state */
255 mouse->x = x; 305 if (!mouse->relative_mode) {
256 mouse->y = y; 306 mouse->x = x;
307 mouse->y = y;
308 }
257 mouse->xdelta += xrel; 309 mouse->xdelta += xrel;
258 mouse->ydelta += yrel; 310 mouse->ydelta += yrel;
259 311
260 /* Move the mouse cursor, if needed */ 312 /* Move the mouse cursor, if needed */
261 if (mouse->MoveCursor && mouse->cur_cursor) { 313 if (mouse->cursor_shown && !mouse->relative_mode &&
314 mouse->MoveCursor && mouse->cur_cursor) {
262 mouse->MoveCursor(mouse->cur_cursor); 315 mouse->MoveCursor(mouse->cur_cursor);
263 } 316 }
264 317
265 /* Post the event, if desired */ 318 /* Post the event, if desired */
266 posted = 0; 319 posted = 0;
272 event.motion.x = mouse->x; 325 event.motion.x = mouse->x;
273 event.motion.y = mouse->y; 326 event.motion.y = mouse->y;
274 event.motion.xrel = xrel; 327 event.motion.xrel = xrel;
275 event.motion.yrel = yrel; 328 event.motion.yrel = yrel;
276 event.motion.windowID = mouse->focus; 329 event.motion.windowID = mouse->focus;
277 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { 330 if ((SDL_EventOK == NULL)
331 || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
278 posted = 1; 332 posted = 1;
279 SDL_PushEvent(&event); 333 SDL_PushEvent(&event);
280 } 334 }
281 } 335 }
282 return posted; 336 return posted;
330 event.button.state = state; 384 event.button.state = state;
331 event.button.button = button; 385 event.button.button = button;
332 event.button.x = mouse->x; 386 event.button.x = mouse->x;
333 event.button.y = mouse->y; 387 event.button.y = mouse->y;
334 event.button.windowID = mouse->focus; 388 event.button.windowID = mouse->focus;
335 if ((SDL_EventOK == NULL) || (*SDL_EventOK) (&event)) { 389 if ((SDL_EventOK == NULL)
390 || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
336 posted = 1; 391 posted = 1;
337 SDL_PushEvent(&event); 392 SDL_PushEvent(&event);
338 } 393 }
339 } 394 }
340 return posted; 395 return posted;
455 mouse->cur_cursor = cursor; 510 mouse->cur_cursor = cursor;
456 } else { 511 } else {
457 cursor = mouse->cur_cursor; 512 cursor = mouse->cur_cursor;
458 } 513 }
459 514
460 if (cursor && mouse->cursor_shown) { 515 if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
461 if (mouse->ShowCursor) { 516 if (mouse->ShowCursor) {
462 mouse->ShowCursor(cursor); 517 mouse->ShowCursor(cursor);
463 } 518 }
464 } else { 519 } else {
465 if (mouse->ShowCursor) { 520 if (mouse->ShowCursor) {