src/events/SDL_mouse.c
changeset 12943 49190e92b7d1
parent 12934 d03900e991a2
child 12979 bbbb30026158
equal deleted inserted replaced
12942:2c2adb2ebc96 12943:49190e92b7d1
   154                         SDL_TouchMouseEventsChanged, mouse);
   154                         SDL_TouchMouseEventsChanged, mouse);
   155 
   155 
   156     SDL_AddHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
   156     SDL_AddHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
   157                         SDL_MouseTouchEventsChanged, mouse);
   157                         SDL_MouseTouchEventsChanged, mouse);
   158 
   158 
       
   159     mouse->was_touch_mouse_events = SDL_FALSE; /* no touch to mouse movement event pending */
       
   160 
   159     mouse->cursor_shown = SDL_TRUE;
   161     mouse->cursor_shown = SDL_TRUE;
   160 
   162 
   161     return (0);
   163     return (0);
   162 }
   164 }
   163 
   165 
   242     SDL_SetCursor(NULL);
   244     SDL_SetCursor(NULL);
   243 }
   245 }
   244 
   246 
   245 /* Check to see if we need to synthesize focus events */
   247 /* Check to see if we need to synthesize focus events */
   246 static SDL_bool
   248 static SDL_bool
   247 SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
   249 SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
   248 {
   250 {
   249     SDL_Mouse *mouse = SDL_GetMouse();
   251     SDL_Mouse *mouse = SDL_GetMouse();
   250     SDL_bool inWindow = SDL_TRUE;
   252     SDL_bool inWindow = SDL_TRUE;
   251 
   253 
   252     if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
   254     if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
   273 #endif
   275 #endif
   274         if (window == mouse->focus) {
   276         if (window == mouse->focus) {
   275 #ifdef DEBUG_MOUSE
   277 #ifdef DEBUG_MOUSE
   276             printf("Mouse left window, synthesizing move & focus lost event\n");
   278             printf("Mouse left window, synthesizing move & focus lost event\n");
   277 #endif
   279 #endif
   278             SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
   280             if (send_mouse_motion) {
       
   281                 SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
       
   282             }
   279             SDL_SetMouseFocus(NULL);
   283             SDL_SetMouseFocus(NULL);
   280         }
   284         }
   281         return SDL_FALSE;
   285         return SDL_FALSE;
   282     }
   286     }
   283 
   287 
   284     if (window != mouse->focus) {
   288     if (window != mouse->focus) {
   285 #ifdef DEBUG_MOUSE
   289 #ifdef DEBUG_MOUSE
   286         printf("Mouse entered window, synthesizing focus gain & move event\n");
   290         printf("Mouse entered window, synthesizing focus gain & move event\n");
   287 #endif
   291 #endif
   288         SDL_SetMouseFocus(window);
   292         SDL_SetMouseFocus(window);
   289         SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
   293         if (send_mouse_motion) {
       
   294             SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
       
   295         }
   290     }
   296     }
   291     return SDL_TRUE;
   297     return SDL_TRUE;
   292 }
   298 }
   293 
   299 
   294 int
   300 int
   295 SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
   301 SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
   296 {
   302 {
   297     if (window && !relative) {
   303     if (window && !relative) {
   298         SDL_Mouse *mouse = SDL_GetMouse();
   304         SDL_Mouse *mouse = SDL_GetMouse();
   299         if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
   305         if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
   300             return 0;
   306             return 0;
   301         }
   307         }
   302     }
   308     }
   303 
   309 
   304     return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
   310     return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
   444     if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
   450     if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
   445         SDL_Event event;
   451         SDL_Event event;
   446         event.motion.type = SDL_MOUSEMOTION;
   452         event.motion.type = SDL_MOUSEMOTION;
   447         event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
   453         event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
   448         event.motion.which = mouseID;
   454         event.motion.which = mouseID;
       
   455         /* Set us pending (or clear during a normal mouse movement event) as having triggered */
       
   456         mouse->was_touch_mouse_events = (mouseID == SDL_TOUCH_MOUSEID)? SDL_TRUE : SDL_FALSE;
   449         event.motion.state = mouse->buttonstate;
   457         event.motion.state = mouse->buttonstate;
   450         event.motion.x = mouse->x;
   458         event.motion.x = mouse->x;
   451         event.motion.y = mouse->y;
   459         event.motion.y = mouse->y;
   452         event.motion.xrel = xrel;
   460         event.motion.xrel = xrel;
   453         event.motion.yrel = yrel;
   461         event.motion.yrel = yrel;
   528         return 0;
   536         return 0;
   529     }
   537     }
   530 
   538 
   531     /* We do this after calculating buttonstate so button presses gain focus */
   539     /* We do this after calculating buttonstate so button presses gain focus */
   532     if (window && state == SDL_PRESSED) {
   540     if (window && state == SDL_PRESSED) {
   533         SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
   541         SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
   534     }
   542     }
   535 
   543 
   536     if (buttonstate == mouse->buttonstate) {
   544     if (buttonstate == mouse->buttonstate) {
   537         /* Ignore this event, no state change */
   545         /* Ignore this event, no state change */
   538         return 0;
   546         return 0;
   578         posted = (SDL_PushEvent(&event) > 0);
   586         posted = (SDL_PushEvent(&event) > 0);
   579     }
   587     }
   580 
   588 
   581     /* We do this after dispatching event so button releases can lose focus */
   589     /* We do this after dispatching event so button releases can lose focus */
   582     if (window && state == SDL_RELEASED) {
   590     if (window && state == SDL_RELEASED) {
   583         SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
   591         SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
   584     }
   592     }
   585 
   593 
   586     return posted;
   594     return posted;
   587 }
   595 }
   588 
   596