mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-02-15 16:14:05 +00:00
Moved WIN_UpdateMouseCapture() to be with the other mouse functions
This commit is contained in:
@@ -317,6 +317,41 @@ static void WIN_CheckAsyncMouseRelease(Uint64 timestamp, SDL_WindowData *data)
|
||||
data->mouse_button_flags = (WPARAM)-1;
|
||||
}
|
||||
|
||||
static void WIN_UpdateMouseCapture(void)
|
||||
{
|
||||
SDL_Window *focusWindow = SDL_GetKeyboardFocus();
|
||||
|
||||
if (focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
|
||||
SDL_WindowData *data = focusWindow->internal;
|
||||
|
||||
if (!data->mouse_tracked) {
|
||||
POINT cursorPos;
|
||||
|
||||
if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
|
||||
bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
SDL_MouseID mouseID = SDL_GLOBAL_MOUSE_ID;
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, false, (float)cursorPos.x, (float)cursorPos.y);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
!swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT,
|
||||
(GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
!swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT,
|
||||
(GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_MIDDLE,
|
||||
(GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_X1,
|
||||
(GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_X2,
|
||||
(GetAsyncKeyState(VK_XBUTTON2) & 0x8000) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void WIN_UpdateFocus(SDL_Window *window, bool expect_focus)
|
||||
{
|
||||
SDL_WindowData *data = window->internal;
|
||||
@@ -2399,43 +2434,6 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
|
||||
static void WIN_UpdateMouseCapture(void)
|
||||
{
|
||||
SDL_Window *focusWindow = SDL_GetKeyboardFocus();
|
||||
|
||||
if (focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE)) {
|
||||
SDL_WindowData *data = focusWindow->internal;
|
||||
|
||||
if (!data->mouse_tracked) {
|
||||
POINT cursorPos;
|
||||
|
||||
if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
|
||||
bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
SDL_MouseID mouseID = SDL_GLOBAL_MOUSE_ID;
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, false, (float)cursorPos.x, (float)cursorPos.y);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
!swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT,
|
||||
(GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
!swapButtons ? SDL_BUTTON_RIGHT : SDL_BUTTON_LEFT,
|
||||
(GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_MIDDLE,
|
||||
(GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_X1,
|
||||
(GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID,
|
||||
SDL_BUTTON_X2,
|
||||
(GetAsyncKeyState(VK_XBUTTON2) & 0x8000) != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
|
||||
|
||||
int WIN_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS)
|
||||
{
|
||||
if (g_WindowsEnableMessageLoop) {
|
||||
|
||||
Reference in New Issue
Block a user