The mouse position is relative to the client window.
authorSam Lantinga <slouken@libsdl.org>
Sat, 03 Jan 2009 06:03:56 +0000
changeset 2974d2f68ec8c1d0
parent 2973 ab0c00f1b070
child 2975 317b2f8e5e4f
The mouse position is relative to the client window.
Fixed setting the mouse focus when the mouse enters/leaves the window.
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32mouse.c
src/video/win32/SDL_win32video.h
     1.1 --- a/src/video/win32/SDL_win32events.c	Sat Jan 03 05:42:18 2009 +0000
     1.2 +++ b/src/video/win32/SDL_win32events.c	Sat Jan 03 06:03:56 2009 +0000
     1.3 @@ -221,6 +221,7 @@
     1.4              const RAWMOUSE *raw_mouse = NULL;
     1.5              POINT point;
     1.6              USHORT flags;
     1.7 +            int w, h;
     1.8  
     1.9              /* we're collecting data from the mouse */
    1.10              GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size,
    1.11 @@ -241,6 +242,16 @@
    1.12              }
    1.13  /* FIXME: Doesn't this defeat the point of using raw input? */
    1.14              GetCursorPos(&point);
    1.15 +            ScreenToClient(hwnd, &point);
    1.16 +
    1.17 +            SDL_GetWindowSize(data->windowID, &w, &h);
    1.18 +            if (point.x >= 0 && point.y >= 0 && point.x < w && point.y < h) {
    1.19 +                SDL_SetMouseFocus(index, data->windowID);
    1.20 +            } else {
    1.21 +                SDL_SetMouseFocus(index, 0);
    1.22 +                /* FIXME: Should we be doing anything else here? */
    1.23 +                break;
    1.24 +            }
    1.25  
    1.26              /* if the message was sent by a tablet we have to send also pressure */
    1.27              if (index == tablet) {
    1.28 @@ -286,14 +297,14 @@
    1.29  
    1.30      case WM_MOUSELEAVE:
    1.31          {
    1.32 -            int index;
    1.33 -            SDL_Mouse *mouse;
    1.34 +            int i;
    1.35  
    1.36 -            index = data->videodata->mouse;
    1.37 -            mouse = SDL_GetMouse(index);
    1.38 +            for (i = 0; i < SDL_GetNumMice(); ++i) {
    1.39 +                SDL_Mouse *mouse = SDL_GetMouse(i);
    1.40  
    1.41 -            if (mouse->focus == data->windowID) {
    1.42 -                SDL_SetMouseFocus(index, 0);
    1.43 +                if (mouse->focus == data->windowID) {
    1.44 +                    SDL_SetMouseFocus(i, 0);
    1.45 +                }
    1.46              }
    1.47          }
    1.48          return (0);
     2.1 --- a/src/video/win32/SDL_win32mouse.c	Sat Jan 03 05:42:18 2009 +0000
     2.2 +++ b/src/video/win32/SDL_win32mouse.c	Sat Jan 03 06:03:56 2009 +0000
     2.3 @@ -175,11 +175,9 @@
     2.4              int cursors;
     2.5              data->WTInfoA(WTI_DEVICES, DVC_NPRESSURE, &pressure);
     2.6              data->WTInfoA(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
     2.7 -            data->mouse =
     2.8 -                SDL_AddMouse(&mouse, device_name, pressure.axMax,
     2.9 -                             pressure.axMin, cursors);
    2.10 +            SDL_AddMouse(&mouse, device_name, pressure.axMax, pressure.axMin, cursors);
    2.11          } else {
    2.12 -            data->mouse = SDL_AddMouse(&mouse, device_name, 0, 0, 1);
    2.13 +            SDL_AddMouse(&mouse, device_name, 0, 0, 1);
    2.14          }
    2.15          ++index;
    2.16          SDL_free(buffer);
     3.1 --- a/src/video/win32/SDL_win32video.h	Sat Jan 03 05:42:18 2009 +0000
     3.2 +++ b/src/video/win32/SDL_win32video.h	Sat Jan 03 06:03:56 2009 +0000
     3.3 @@ -75,7 +75,6 @@
     3.4      BOOL (*WTClose) (HCTX);
     3.5  /* *INDENT-ON* */
     3.6  
     3.7 -    int mouse;
     3.8      int keyboard;
     3.9      SDL_scancode *key_layout;
    3.10  } SDL_VideoData;