[win32] WM_MOUSEMOVE fix

Using GLFW
2004-12-21
2012-11-08
  • David Bregman

    David Bregman - 2004-12-21

    glfw currently treats LOWORD(lParam) and HIWORD(lParam) as unsigned values, but this is incorrect.
    Since these coordinates are relative to the window's client area, they may be negative if cursor is above or to the left of the client rectangle.

    Here is my proposed fix to win32_window.c:

        case WM\_MOUSEMOVE:
            \{
                int NewMouseX = \(short\)LOWORD\(lParam\);
                int NewMouseY = \(short\)HIWORD\(lParam\);
    
                if\( NewMouseX \!= \_glfwInput.OldMouseX ||
                    NewMouseY \!= \_glfwInput.OldMouseY \)
                \{
                    if\( \_glfwWin.MouseLock \)
                    \{
                        \_glfwInput.MousePosX += NewMouseX -
                                                \_glfwInput.OldMouseX;
                        \_glfwInput.MousePosY += NewMouseY -
                                                \_glfwInput.OldMouseY;
                    \}
                    else
                    \{
                        \_glfwInput.MousePosX = NewMouseX;
                        \_glfwInput.MousePosY = NewMouseY;
                    \}
    
                    \_glfwInput.OldMouseX = NewMouseX;
                    \_glfwInput.OldMouseY = NewMouseY;
                    \_glfwInput.MouseMoved = GL\_TRUE;
    
                    // Call user callback function
                    if\( \_glfwWin.MousePosCallback \)
                    \{
                        \_glfwWin.MousePosCallback\( \_glfwInput.MousePosX,
                                                \_glfwInput.MousePosY \);
                    \}
                \}
            \}
            return 0;
    
     
    • Marcus Geelnard

      Marcus Geelnard - 2004-12-31

      Thanks! You are right. I went ahead and stole the MinGW32 definitions of the GET_X_LPARAM/GET_Y_LPARAM macros:

      NewMouseX = (int)((short)LOWORD(lParam)); NewMouseY = (int)((short)HIWORD(lParam));