Implemented SDL_SetWindowMouseRect() on Windows

main
Sam Lantinga 2021-11-08 16:29:19 -08:00
parent 684b3b312a
commit 7d21322df1
5 changed files with 42 additions and 11 deletions

View File

@ -235,6 +235,7 @@ struct SDL_VideoDevice
int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp); int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp); int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
void* (*GetWindowICCProfile) (_THIS, SDL_Window * window, size_t* size); void* (*GetWindowICCProfile) (_THIS, SDL_Window * window, size_t* size);
int (*SetWindowMouseRect)(_THIS, SDL_Window * window, const SDL_Rect * rect);
void (*SetWindowMouseGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); void (*SetWindowMouseGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*SetWindowKeyboardGrab) (_THIS, SDL_Window * window, SDL_bool grabbed); void (*SetWindowKeyboardGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
void (*DestroyWindow) (_THIS, SDL_Window * window); void (*DestroyWindow) (_THIS, SDL_Window * window);
@ -243,7 +244,6 @@ struct SDL_VideoDevice
void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window); void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
void (*OnWindowEnter) (_THIS, SDL_Window * window); void (*OnWindowEnter) (_THIS, SDL_Window * window);
int (*FlashWindow) (_THIS, SDL_Window * window, SDL_FlashOperation operation); int (*FlashWindow) (_THIS, SDL_Window * window, SDL_FlashOperation operation);
int (*SetWindowMouseRect)(_THIS, SDL_Window * window, const SDL_Rect * rect);
/* * * */ /* * * */
/* /*

View File

@ -167,6 +167,7 @@ WIN_CreateDevice(int devindex)
device->SetWindowGammaRamp = WIN_SetWindowGammaRamp; device->SetWindowGammaRamp = WIN_SetWindowGammaRamp;
device->GetWindowICCProfile = WIN_GetWindowICCProfile; device->GetWindowICCProfile = WIN_GetWindowICCProfile;
device->GetWindowGammaRamp = WIN_GetWindowGammaRamp; device->GetWindowGammaRamp = WIN_GetWindowGammaRamp;
device->SetWindowMouseRect = WIN_SetWindowMouseRect;
device->SetWindowMouseGrab = WIN_SetWindowMouseGrab; device->SetWindowMouseGrab = WIN_SetWindowMouseGrab;
device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab; device->SetWindowKeyboardGrab = WIN_SetWindowKeyboardGrab;
device->DestroyWindow = WIN_DestroyWindow; device->DestroyWindow = WIN_DestroyWindow;

View File

@ -814,6 +814,19 @@ void WIN_UngrabKeyboard(SDL_Window *window)
} }
} }
void
WIN_SetWindowMouseRect(_THIS, SDL_Window * window, SDL_Rect * rect)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
if (rect) {
SDL_memcpy(&data->mouse_rect, rect, sizeof(*rect));
} else {
SDL_zero(data->mouse_rect);
}
WIN_UpdateClipCursor(window);
}
void void
WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed) WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
{ {
@ -998,7 +1011,8 @@ WIN_UpdateClipCursor(SDL_Window *window)
return; return;
} }
if ((mouse->relative_mode || (window->flags & SDL_WINDOW_MOUSE_GRABBED)) && if ((mouse->relative_mode || (window->flags & SDL_WINDOW_MOUSE_GRABBED) ||
(data->mouse_rect.w > 0 && data->mouse_rect.h > 0)) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS)) { (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp) { if (mouse->relative_mode && !mouse->relative_mode_warp) {
if (GetWindowRect(data->hwnd, &rect)) { if (GetWindowRect(data->hwnd, &rect)) {
@ -1020,13 +1034,33 @@ WIN_UpdateClipCursor(SDL_Window *window)
} }
} }
} else { } else {
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { if (GetClientRect(data->hwnd, &rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect); ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
if (data->mouse_rect.w > 0 && data->mouse_rect.h > 0) {
RECT mouse_rect, intersection;
mouse_rect.left = rect.left + data->mouse_rect.x;
mouse_rect.top = rect.top + data->mouse_rect.y;
mouse_rect.right = mouse_rect.left + data->mouse_rect.w - 1;
mouse_rect.bottom = mouse_rect.top + data->mouse_rect.h - 1;
if (IntersectRect(&intersection, &rect, &mouse_rect)) {
SDL_memcpy(&rect, &intersection, sizeof(rect));
} else if ((window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0) {
/* Mouse rect was invalid, just do the normal grab */
} else {
SDL_zero(rect);
}
}
if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) { if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
if (!IsRectEmpty(&rect)) {
if (ClipCursor(&rect)) { if (ClipCursor(&rect)) {
data->cursor_clipped_rect = rect; data->cursor_clipped_rect = rect;
} }
} else {
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}
} }
} }
} }

View File

@ -51,6 +51,7 @@ typedef struct
Uint32 last_updated_clipcursor; Uint32 last_updated_clipcursor;
SDL_bool windowed_mode_was_maximized; SDL_bool windowed_mode_was_maximized;
SDL_bool in_window_deactivation; SDL_bool in_window_deactivation;
SDL_Rect mouse_rect;
RECT cursor_clipped_rect; RECT cursor_clipped_rect;
SDL_Point last_raw_mouse_position; SDL_Point last_raw_mouse_position;
SDL_bool mouse_tracked; SDL_bool mouse_tracked;
@ -81,6 +82,7 @@ extern void WIN_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay
extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp); extern int WIN_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
extern void* WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size); extern void* WIN_GetWindowICCProfile(_THIS, SDL_Window * window, size_t * size);
extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp); extern int WIN_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
extern void WIN_SetWindowMouseRect(_THIS, SDL_Window * window, SDL_Rect * rect);
extern void WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void WIN_SetWindowMouseGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed); extern void WIN_SetWindowKeyboardGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
extern void WIN_DestroyWindow(_THIS, SDL_Window * window); extern void WIN_DestroyWindow(_THIS, SDL_Window * window);

View File

@ -331,12 +331,6 @@ SetupWindowData(_THIS, SDL_Window * window, Window w, BOOL created)
} }
} }
#if SDL_VIDEO_DRIVER_X11_XFIXES
data->pointer_barrier_active = SDL_FALSE;
SDL_memset(&data->barrier, 0, sizeof(data->barrier));
SDL_memset(&data->barrier_rect, 0, sizeof(SDL_Rect));
#endif /* SDL_VIDEO_DRIVER_X11_XFIXES */
/* All done! */ /* All done! */
window->driverdata = data; window->driverdata = data;
return 0; return 0;