Win32: Fix bug where the mouse capture isn't released

This commit is contained in:
David Capello 2014-08-10 00:12:33 -03:00
parent 4d4958bf35
commit 8cf25c49a7
2 changed files with 24 additions and 4 deletions

View File

@ -264,6 +264,8 @@ void _al_win_mouse_handle_button(HWND hwnd, int button, BOOL down, int x, int y,
_exit_critical();
#if 0 /* Aseprite: We handle mouse capture in the she and ui layers */
/* If there is a mouse button pressed we capture the mouse, in any
other cases we release it. */
if (last_mouse_b) {
@ -275,6 +277,8 @@ void _al_win_mouse_handle_button(HWND hwnd, int button, BOOL down, int x, int y,
ReleaseCapture();
}
#endif
_handle_mouse_input();
}

View File

@ -114,6 +114,7 @@ int display_scale;
wndproc_t base_wndproc = NULL;
bool display_has_mouse = false;
bool capture_mouse = false;
static void queue_event(Event& ev)
{
@ -150,6 +151,18 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
}
case WM_MOUSEMOVE: {
// Adjust capture
if (capture_mouse) {
if (GetCapture() != hwnd)
SetCapture(hwnd);
}
else {
if (GetCapture() == hwnd)
ReleaseCapture();
}
//PRINTF("GetCapture=%p hwnd=%p\n", GetCapture(), hwnd);
Event ev;
ev.setPosition(gfx::Point(
GET_X_LPARAM(lparam) / display_scale,
@ -185,7 +198,8 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN: {
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN: {
Event ev;
ev.setType(Event::MouseDown);
ev.setPosition(gfx::Point(
@ -201,7 +215,8 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP: {
case WM_MBUTTONUP:
case WM_XBUTTONUP: {
Event ev;
ev.setType(Event::MouseUp);
ev.setPosition(gfx::Point(
@ -216,6 +231,7 @@ static LRESULT CALLBACK wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpara
// Avoid popup menu for scrollbars
if (msg == WM_RBUTTONUP)
return 0;
break;
}
@ -542,7 +558,7 @@ public:
void captureMouse() {
#ifdef WIN32
SetCapture((HWND)nativeHandle());
capture_mouse = true;
#elif defined(ALLEGRO_UNIX)
@ -557,7 +573,7 @@ public:
void releaseMouse() {
#ifdef WIN32
ReleaseCapture();
capture_mouse = false;
#elif defined(ALLEGRO_UNIX)