changeset 2974:d2f68ec8c1d0

The mouse position is relative to the client window. Fixed setting the mouse focus when the mouse enters/leaves the window.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 03 Jan 2009 06:03:56 +0000
parents ab0c00f1b070
children 317b2f8e5e4f
files src/video/win32/SDL_win32events.c src/video/win32/SDL_win32mouse.c src/video/win32/SDL_win32video.h
diffstat 3 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/win32/SDL_win32events.c	Sat Jan 03 05:42:18 2009 +0000
+++ b/src/video/win32/SDL_win32events.c	Sat Jan 03 06:03:56 2009 +0000
@@ -221,6 +221,7 @@
             const RAWMOUSE *raw_mouse = NULL;
             POINT point;
             USHORT flags;
+            int w, h;
 
             /* we're collecting data from the mouse */
             GetRawInputData((HRAWINPUT) lParam, RID_INPUT, NULL, &size,
@@ -241,6 +242,16 @@
             }
 /* FIXME: Doesn't this defeat the point of using raw input? */
             GetCursorPos(&point);
+            ScreenToClient(hwnd, &point);
+
+            SDL_GetWindowSize(data->windowID, &w, &h);
+            if (point.x >= 0 && point.y >= 0 && point.x < w && point.y < h) {
+                SDL_SetMouseFocus(index, data->windowID);
+            } else {
+                SDL_SetMouseFocus(index, 0);
+                /* FIXME: Should we be doing anything else here? */
+                break;
+            }
 
             /* if the message was sent by a tablet we have to send also pressure */
             if (index == tablet) {
@@ -286,14 +297,14 @@
 
     case WM_MOUSELEAVE:
         {
-            int index;
-            SDL_Mouse *mouse;
+            int i;
 
-            index = data->videodata->mouse;
-            mouse = SDL_GetMouse(index);
+            for (i = 0; i < SDL_GetNumMice(); ++i) {
+                SDL_Mouse *mouse = SDL_GetMouse(i);
 
-            if (mouse->focus == data->windowID) {
-                SDL_SetMouseFocus(index, 0);
+                if (mouse->focus == data->windowID) {
+                    SDL_SetMouseFocus(i, 0);
+                }
             }
         }
         return (0);
--- a/src/video/win32/SDL_win32mouse.c	Sat Jan 03 05:42:18 2009 +0000
+++ b/src/video/win32/SDL_win32mouse.c	Sat Jan 03 06:03:56 2009 +0000
@@ -175,11 +175,9 @@
             int cursors;
             data->WTInfoA(WTI_DEVICES, DVC_NPRESSURE, &pressure);
             data->WTInfoA(WTI_DEVICES, DVC_NCSRTYPES, &cursors);
-            data->mouse =
-                SDL_AddMouse(&mouse, device_name, pressure.axMax,
-                             pressure.axMin, cursors);
+            SDL_AddMouse(&mouse, device_name, pressure.axMax, pressure.axMin, cursors);
         } else {
-            data->mouse = SDL_AddMouse(&mouse, device_name, 0, 0, 1);
+            SDL_AddMouse(&mouse, device_name, 0, 0, 1);
         }
         ++index;
         SDL_free(buffer);
--- a/src/video/win32/SDL_win32video.h	Sat Jan 03 05:42:18 2009 +0000
+++ b/src/video/win32/SDL_win32video.h	Sat Jan 03 06:03:56 2009 +0000
@@ -75,7 +75,6 @@
     BOOL (*WTClose) (HCTX);
 /* *INDENT-ON* */
 
-    int mouse;
     int keyboard;
     SDL_scancode *key_layout;
 } SDL_VideoData;