Use GetMessagePos, not GetCursorPos to make sure we get the right mouse position. Also, no need to get mouse position at time of keypress, every mouse movement before the keypress is processed in an earlier WM_MOUSE message already, so mouse position in the window state is all we need.

git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1515 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
dcnieho 2013-02-27 05:58:56 +00:00
parent b1274e9078
commit 6f9152c92e

View File

@ -176,7 +176,6 @@ static LRESULT fghWindowProcKeyPress(SFG_Window *window, UINT uMsg, GLboolean ke
rControl = 0, rShift = 0, rAlt = 0; rControl = 0, rShift = 0, rAlt = 0;
int keypress = -1; int keypress = -1;
POINT mouse_pos ;
/* if keydown, check for repeat */ /* if keydown, check for repeat */
/* If repeat is globally switched off, it cannot be switched back on per window. /* If repeat is globally switched off, it cannot be switched back on per window.
@ -190,12 +189,6 @@ static LRESULT fghWindowProcKeyPress(SFG_Window *window, UINT uMsg, GLboolean ke
/* Remember the current modifiers state so user can query it from their callback */ /* Remember the current modifiers state so user can query it from their callback */
fgState.Modifiers = fgPlatformGetModifiers( ); fgState.Modifiers = fgPlatformGetModifiers( );
/* Get mouse position roughly at time of keypress */
GetCursorPos( &mouse_pos );
ScreenToClient( window->Window.Handle, &mouse_pos );
window->State.MouseX = mouse_pos.x;
window->State.MouseY = mouse_pos.y;
/* Convert the Win32 keystroke codes to GLUTtish way */ /* Convert the Win32 keystroke codes to GLUTtish way */
# define KEY(a,b) case a: keypress = b; break; # define KEY(a,b) case a: keypress = b; break;
@ -339,8 +332,12 @@ void fghWindowUnderCursor(SFG_Window *window, SFG_Window **child_window)
SFG_WindowHandleType hwnd; SFG_WindowHandleType hwnd;
SFG_Window* temp_window; SFG_Window* temp_window;
GetCursorPos( &mouse_pos ); /* Get mouse position at time of message */
DWORD mouse_pos_Dword = GetMessagePos();
mouse_pos.x = GET_X_LPARAM(mouse_pos_Dword);
mouse_pos.y = GET_Y_LPARAM(mouse_pos_Dword);
ScreenToClient( window->Window.Handle, &mouse_pos ); ScreenToClient( window->Window.Handle, &mouse_pos );
hwnd = ChildWindowFromPoint(window->Window.Handle, mouse_pos); hwnd = ChildWindowFromPoint(window->Window.Handle, mouse_pos);
if (hwnd && hwnd!=window->Window.Handle) /* can be NULL if mouse outside parent by the time we get here, or can be same as parent if we didn't find a child */ if (hwnd && hwnd!=window->Window.Handle) /* can be NULL if mouse outside parent by the time we get here, or can be same as parent if we didn't find a child */
{ {
@ -559,6 +556,7 @@ LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPAR
#if 0 #if 0
case WM_ACTIVATE: case WM_ACTIVATE:
//printf("WM_ACTIVATE: %x %d %d\n",lParam, HIWORD(wParam), LOWORD(wParam));
if (LOWORD(wParam) != WA_INACTIVE) if (LOWORD(wParam) != WA_INACTIVE)
{ {
/* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window, /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,