Win: Capture mouse when mouse button is down.

This commit is contained in:
Branimir Karadžić 2014-12-20 19:07:01 -08:00
parent 0d20d7e6c8
commit e1a7daf38a

View file

@ -306,6 +306,18 @@ namespace entry
tinystl::string m_title; tinystl::string m_title;
}; };
static void mouseCapture(HWND _hwnd, bool _capture)
{
if (_capture)
{
SetCapture(_hwnd);
}
else
{
ReleaseCapture();
}
}
struct Context struct Context
{ {
Context() Context()
@ -699,6 +711,7 @@ namespace entry
case WM_LBUTTONUP: case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
{ {
mouseCapture(_hwnd, _id == WM_LBUTTONDOWN);
int32_t mx = GET_X_LPARAM(_lparam); int32_t mx = GET_X_LPARAM(_lparam);
int32_t my = GET_Y_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam);
m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Left, _id == WM_LBUTTONDOWN); m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Left, _id == WM_LBUTTONDOWN);
@ -709,16 +722,18 @@ namespace entry
case WM_MBUTTONUP: case WM_MBUTTONUP:
case WM_MBUTTONDBLCLK: case WM_MBUTTONDBLCLK:
{ {
mouseCapture(_hwnd, _id == WM_MBUTTONDOWN);
int32_t mx = GET_X_LPARAM(_lparam); int32_t mx = GET_X_LPARAM(_lparam);
int32_t my = GET_Y_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam);
m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Middle, _id == WM_MBUTTONDOWN); m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Middle, _id == WM_MBUTTONDOWN);
} }
break; break;
case WM_RBUTTONUP:
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDBLCLK: case WM_RBUTTONDBLCLK:
{ {
mouseCapture(_hwnd, _id == WM_RBUTTONDOWN);
int32_t mx = GET_X_LPARAM(_lparam); int32_t mx = GET_X_LPARAM(_lparam);
int32_t my = GET_Y_LPARAM(_lparam); int32_t my = GET_Y_LPARAM(_lparam);
m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Right, _id == WM_RBUTTONDOWN); m_eventQueue.postMouseEvent(findHandle(_hwnd), mx, my, m_mz, MouseButton::Right, _id == WM_RBUTTONDOWN);