win32 and SDL2: capture the mouse when the button is pressed

This commit is contained in:
Thomas Bernard 2019-02-04 18:41:33 +01:00
parent cb315e4f0c
commit b184a75c9e
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
2 changed files with 14 additions and 1 deletions

View File

@ -1299,11 +1299,17 @@ int Get_input(int sleep_time)
break;
case SDL_MOUSEBUTTONDOWN:
#ifdef USE_SDL2
SDL_CaptureMouse(SDL_TRUE);
#endif
Handle_mouse_click(&event.button);
user_feedback_required = 1;
break;
case SDL_MOUSEBUTTONUP:
#ifdef USE_SDL2
SDL_CaptureMouse(SDL_FALSE);
#endif
Handle_mouse_release(&event.button);
user_feedback_required = 1;
break;

View File

@ -21,6 +21,7 @@
along with Grafx2; if not, see <http://www.gnu.org/licenses/>
*/
#include <windows.h>
#include <windowsx.h>
#include <malloc.h>
#include <stdio.h>
#if defined(_MSC_VER) && _MSC_VER < 1900
@ -208,32 +209,38 @@ static LRESULT CALLBACK Win32_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP
}
return 0;
case WM_LBUTTONDOWN:
SetCapture(hwnd); // capture mouse when the button is pressed
Input_new_mouse_K |= 1;
Move_cursor_with_constraints(0);
user_feedback_required = 1;
return 0;
case WM_LBUTTONUP:
ReleaseCapture(); // Release mouse when the button is released
Input_new_mouse_K &= ~1;
Move_cursor_with_constraints(0);
user_feedback_required = 1;
return 0;
// WM_LBUTTONDBLCLK
case WM_RBUTTONDOWN:
SetCapture(hwnd); // capture mouse when the button is pressed
Input_new_mouse_K |= 2;
Move_cursor_with_constraints(0);
user_feedback_required = 1;
return 0;
case WM_RBUTTONUP:
ReleaseCapture(); // Release mouse when the button is released
Input_new_mouse_K &= ~2;
Move_cursor_with_constraints(0);
user_feedback_required = 1;
return 0;
// WM_RBUTTONDBLCLK
case WM_MBUTTONDOWN:
//case WM_MBUTTONUP:
Key = KEY_MOUSEMIDDLE|Get_Key_modifiers();
user_feedback_required = 1;
return 0;
case WM_MBUTTONUP:
return 0;
// WM_MBUTTONDBLCLK
case WM_MOUSEWHEEL:
{
short delta = HIWORD(wParam);