comparison src/events/SDL_mouse.c @ 3685:64ce267332c6

Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jan 2010 06:21:52 +0000
parents f8816ffa210b
children af25b5586af7
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
24 /* General mouse handling code for SDL */ 24 /* General mouse handling code for SDL */
25 25
26 #include "SDL_events.h" 26 #include "SDL_events.h"
27 #include "SDL_events_c.h" 27 #include "SDL_events_c.h"
28 #include "default_cursor.h" 28 #include "default_cursor.h"
29 #include "../video/SDL_sysvideo.h"
29 30
30 31
31 static int SDL_num_mice = 0; 32 static int SDL_num_mice = 0;
32 static int SDL_current_mouse = -1; 33 static int SDL_current_mouse = -1;
33 static SDL_Mouse **SDL_mice = NULL; 34 static SDL_Mouse **SDL_mice = NULL;
188 SDL_current_mouse = index; 189 SDL_current_mouse = index;
189 } 190 }
190 return SDL_current_mouse; 191 return SDL_current_mouse;
191 } 192 }
192 193
193 SDL_WindowID 194 SDL_Window *
194 SDL_GetMouseFocusWindow(int index) 195 SDL_GetMouseFocusWindow(int index)
195 { 196 {
196 SDL_Mouse *mouse = SDL_GetMouse(index); 197 SDL_Mouse *mouse = SDL_GetMouse(index);
197 198
198 if (!mouse) { 199 if (!mouse) {
300 mouse->ydelta = 0; 301 mouse->ydelta = 0;
301 return mouse->buttonstate; 302 return mouse->buttonstate;
302 } 303 }
303 304
304 void 305 void
305 SDL_SetMouseFocus(int id, SDL_WindowID windowID) 306 SDL_SetMouseFocus(int id, SDL_Window * window)
306 { 307 {
307 int index = SDL_GetMouseIndexId(id); 308 int index = SDL_GetMouseIndexId(id);
308 SDL_Mouse *mouse = SDL_GetMouse(index); 309 SDL_Mouse *mouse = SDL_GetMouse(index);
309 int i; 310 int i;
310 SDL_bool focus; 311 SDL_bool focus;
311 312
312 if (!mouse || (mouse->focus == windowID)) { 313 if (!mouse || (mouse->focus == window)) {
313 return; 314 return;
314 } 315 }
315 316
316 /* See if the current window has lost focus */ 317 /* See if the current window has lost focus */
317 if (mouse->focus) { 318 if (mouse->focus) {
329 if (!focus) { 330 if (!focus) {
330 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0); 331 SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
331 } 332 }
332 } 333 }
333 334
334 mouse->focus = windowID; 335 mouse->focus = window;
335 336
336 if (mouse->focus) { 337 if (mouse->focus) {
337 focus = SDL_FALSE; 338 focus = SDL_FALSE;
338 for (i = 0; i < SDL_num_mice; ++i) { 339 for (i = 0; i < SDL_num_mice; ++i) {
339 SDL_Mouse *check; 340 SDL_Mouse *check;
370 event.proximity.x = x; 371 event.proximity.x = x;
371 event.proximity.y = y; 372 event.proximity.y = y;
372 event.proximity.cursor = mouse->current_end; 373 event.proximity.cursor = mouse->current_end;
373 event.proximity.type = type; 374 event.proximity.type = type;
374 /* FIXME: is this right? */ 375 /* FIXME: is this right? */
375 event.proximity.windowID = mouse->focus; 376 event.proximity.windowID = mouse->focus->id;
376 posted = (SDL_PushEvent(&event) > 0); 377 posted = (SDL_PushEvent(&event) > 0);
377 if (type == SDL_PROXIMITYIN) { 378 if (type == SDL_PROXIMITYIN) {
378 mouse->proximity = SDL_TRUE; 379 mouse->proximity = SDL_TRUE;
379 } else { 380 } else {
380 mouse->proximity = SDL_FALSE; 381 mouse->proximity = SDL_FALSE;
476 event.motion.tilt_x = 0; 477 event.motion.tilt_x = 0;
477 event.motion.tilt_y = 0; 478 event.motion.tilt_y = 0;
478 event.motion.cursor = mouse->current_end; 479 event.motion.cursor = mouse->current_end;
479 event.motion.xrel = xrel; 480 event.motion.xrel = xrel;
480 event.motion.yrel = yrel; 481 event.motion.yrel = yrel;
481 event.motion.windowID = mouse->focus; 482 event.motion.windowID = mouse->focus->id;
482 posted = (SDL_PushEvent(&event) > 0); 483 posted = (SDL_PushEvent(&event) > 0);
483 } 484 }
484 mouse->last_x = mouse->x; 485 mouse->last_x = mouse->x;
485 mouse->last_y = mouse->y; 486 mouse->last_y = mouse->y;
486 return posted; 487 return posted;
529 event.button.which = (Uint8) index; 530 event.button.which = (Uint8) index;
530 event.button.state = state; 531 event.button.state = state;
531 event.button.button = button; 532 event.button.button = button;
532 event.button.x = mouse->x; 533 event.button.x = mouse->x;
533 event.button.y = mouse->y; 534 event.button.y = mouse->y;
534 event.button.windowID = mouse->focus; 535 event.button.windowID = mouse->focus->id;
535 posted = (SDL_PushEvent(&event) > 0); 536 posted = (SDL_PushEvent(&event) > 0);
536 } 537 }
537 return posted; 538 return posted;
538 } 539 }
539 540
553 SDL_Event event; 554 SDL_Event event;
554 event.type = SDL_MOUSEWHEEL; 555 event.type = SDL_MOUSEWHEEL;
555 event.wheel.which = (Uint8) index; 556 event.wheel.which = (Uint8) index;
556 event.wheel.x = x; 557 event.wheel.x = x;
557 event.wheel.y = y; 558 event.wheel.y = y;
558 event.wheel.windowID = mouse->focus; 559 event.wheel.windowID = mouse->focus->id;
559 posted = (SDL_PushEvent(&event) > 0); 560 posted = (SDL_PushEvent(&event) > 0);
560 } 561 }
561 return posted; 562 return posted;
562 } 563 }
563 564
564 void 565 void
565 SDL_WarpMouseInWindow(SDL_WindowID windowID, int x, int y) 566 SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
566 { 567 {
567 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse); 568 SDL_Mouse *mouse = SDL_GetMouse(SDL_current_mouse);
568 569
569 if (!mouse) { 570 if (!mouse) {
570 return; 571 return;
571 } 572 }
572 573
573 if (mouse->WarpMouse) { 574 if (mouse->WarpMouse) {
574 mouse->WarpMouse(mouse, windowID, x, y); 575 mouse->WarpMouse(mouse, window, x, y);
575 } else { 576 } else {
576 SDL_SetMouseFocus(SDL_current_mouse, windowID); 577 SDL_SetMouseFocus(SDL_current_mouse, window);
577 SDL_SendMouseMotion(SDL_current_mouse, 0, x, y, 0); 578 SDL_SendMouseMotion(SDL_current_mouse, 0, x, y, 0);
578 } 579 }
579 } 580 }
580 581
581 SDL_Cursor * 582 SDL_Cursor *