mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-08-29 01:51:37 +00:00
Mouse coordinates are floating point
You can get sub-pixel mouse coordinates and motion depending on the platform and display scaling. Fixes https://github.com/libsdl-org/SDL/issues/2999
This commit is contained in:
@@ -1304,7 +1304,7 @@ SDL_GetWindowPixelFormat(SDL_Window *window)
|
||||
|
||||
static void SDL_RestoreMousePosition(SDL_Window *window)
|
||||
{
|
||||
int x, y;
|
||||
float x, y;
|
||||
|
||||
if (window == SDL_GetMouseFocus()) {
|
||||
SDL_GetMouseState(&x, &y);
|
||||
@@ -2992,7 +2992,7 @@ void SDL_OnWindowFocusGained(SDL_Window *window)
|
||||
if (mouse && mouse->relative_mode) {
|
||||
SDL_SetMouseFocus(window);
|
||||
if (mouse->relative_mode_warp) {
|
||||
SDL_PerformWarpMouseInWindow(window, window->w / 2, window->h / 2, SDL_TRUE);
|
||||
SDL_PerformWarpMouseInWindow(window, (float)window->w / 2.0f, (float)window->h / 2.0f, SDL_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
|
||||
changes = state & ~last_state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseMotion(0, window, 0, relative, x, y);
|
||||
SDL_SendMouseButton(0, window, 0, SDL_PRESSED, button);
|
||||
break;
|
||||
|
||||
@@ -232,13 +232,13 @@ void Android_OnMouse(SDL_Window *window, int state, int action, float x, float y
|
||||
changes = last_state & ~state;
|
||||
button = TranslateButton(changes);
|
||||
last_state = state;
|
||||
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseMotion(0, window, 0, relative, x, y);
|
||||
SDL_SendMouseButton(0, window, 0, SDL_RELEASED, button);
|
||||
break;
|
||||
|
||||
case ACTION_MOVE:
|
||||
case ACTION_HOVER_MOVE:
|
||||
SDL_SendMouseMotion(0, window, 0, relative, (int)x, (int)y);
|
||||
SDL_SendMouseMotion(0, window, 0, relative, x, y);
|
||||
break;
|
||||
|
||||
case ACTION_SCROLL:
|
||||
|
||||
@@ -230,13 +230,13 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor)
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y)
|
||||
static SDL_Window *SDL_FindWindowAtPoint(const float x, const float y)
|
||||
{
|
||||
const SDL_Point pt = { x, y };
|
||||
const SDL_FPoint pt = { x, y };
|
||||
SDL_Window *i;
|
||||
for (i = SDL_GetVideoDevice()->windows; i; i = i->next) {
|
||||
const SDL_Rect r = { i->x, i->y, i->w, i->h };
|
||||
if (SDL_PointInRect(&pt, &r)) {
|
||||
const SDL_FRect r = { (float)i->x, (float)i->y, (float)i->w, (float)i->h };
|
||||
if (SDL_PointInRectFloat(&pt, &r)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ static SDL_Window *SDL_FindWindowAtPoint(const int x, const int y)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Cocoa_WarpMouseGlobal(int x, int y)
|
||||
static int Cocoa_WarpMouseGlobal(float x, float y)
|
||||
{
|
||||
CGPoint point;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
@@ -256,7 +256,7 @@ static int Cocoa_WarpMouseGlobal(int x, int y)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
point = CGPointMake((float)x, (float)y);
|
||||
point = CGPointMake(x, y);
|
||||
|
||||
Cocoa_HandleMouseWarp(point.x, point.y);
|
||||
|
||||
@@ -285,7 +285,7 @@ static int Cocoa_WarpMouseGlobal(int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Cocoa_WarpMouse(SDL_Window *window, int x, int y)
|
||||
static void Cocoa_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
Cocoa_WarpMouseGlobal(window->x + x, window->y + y);
|
||||
}
|
||||
@@ -340,14 +340,14 @@ static int Cocoa_CaptureMouse(SDL_Window *window)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Uint32 Cocoa_GetGlobalMouseState(int *x, int *y)
|
||||
static Uint32 Cocoa_GetGlobalMouseState(float *x, float *y)
|
||||
{
|
||||
const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons];
|
||||
const NSPoint cocoaLocation = [NSEvent mouseLocation];
|
||||
Uint32 retval = 0;
|
||||
|
||||
*x = (int)cocoaLocation.x;
|
||||
*y = (int)(CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
|
||||
*x = cocoaLocation.x;
|
||||
*y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
|
||||
|
||||
retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
|
||||
retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;
|
||||
@@ -495,7 +495,7 @@ void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
|
||||
}
|
||||
|
||||
SDL_SendMouseMotion(Cocoa_GetEventTimestamp([event timestamp]), mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
|
||||
SDL_SendMouseMotion(Cocoa_GetEventTimestamp([event timestamp]), mouse->focus, mouseID, 1, deltaX, deltaY);
|
||||
}
|
||||
|
||||
void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
||||
|
||||
@@ -53,7 +53,7 @@ typedef enum
|
||||
PendingWindowOperation pendingWindowOperation;
|
||||
BOOL isMoving;
|
||||
NSInteger focusClickPending;
|
||||
int pendingWindowWarpX, pendingWindowWarpY;
|
||||
float pendingWindowWarpX, pendingWindowWarpY;
|
||||
BOOL isDragAreaRunning;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ typedef enum
|
||||
- (BOOL)isMovingOrFocusClickPending;
|
||||
- (void)setFocusClickPending:(NSInteger)button;
|
||||
- (void)clearFocusClickPending:(NSInteger)button;
|
||||
- (void)setPendingMoveX:(int)x Y:(int)y;
|
||||
- (void)setPendingMoveX:(float)x Y:(float)y;
|
||||
- (void)windowDidFinishMoving;
|
||||
- (void)onMovingOrFocusClickPendingStateCleared;
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#error SDL for macOS must be built with a 10.7 SDK or above.
|
||||
#endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1070 */
|
||||
|
||||
#include <float.h> /* For FLT_MAX */
|
||||
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "../../events/SDL_keyboard_c.h"
|
||||
#include "../../events/SDL_mouse_c.h"
|
||||
@@ -170,7 +172,7 @@
|
||||
NSArray *array;
|
||||
NSPoint point;
|
||||
SDL_Mouse *mouse;
|
||||
int x, y;
|
||||
float x, y;
|
||||
|
||||
if (desiredType == nil) {
|
||||
return NO; /* can't accept anything that's being dropped here. */
|
||||
@@ -187,9 +189,9 @@
|
||||
/* Code addon to update the mouse location */
|
||||
point = [sender draggingLocation];
|
||||
mouse = SDL_GetMouse();
|
||||
x = (int)point.x;
|
||||
y = (int)(sdlwindow->h - point.y);
|
||||
if (x >= 0 && x < sdlwindow->w && y >= 0 && y < sdlwindow->h) {
|
||||
x = point.x;
|
||||
y = (sdlwindow->h - point.y);
|
||||
if (x >= 0.0f && x < (float)sdlwindow->w && y >= 0.0f && y < (float)sdlwindow->h) {
|
||||
SDL_SendMouseMotion(0, sdlwindow, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
/* Code addon to update the mouse location */
|
||||
@@ -370,7 +372,7 @@ static SDL_bool ShouldAdjustCoordinatesForGrab(SDL_Window *window)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoint *adjusted)
|
||||
static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, float x, float y, CGPoint *adjusted)
|
||||
{
|
||||
if (window->mouse_rect.w > 0 && window->mouse_rect.h > 0) {
|
||||
SDL_Rect window_rect;
|
||||
@@ -382,10 +384,10 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoi
|
||||
window_rect.h = window->h;
|
||||
|
||||
if (SDL_GetRectIntersection(&window->mouse_rect, &window_rect, &mouse_rect)) {
|
||||
int left = window->x + mouse_rect.x;
|
||||
int right = left + mouse_rect.w - 1;
|
||||
int top = window->y + mouse_rect.y;
|
||||
int bottom = top + mouse_rect.h - 1;
|
||||
float left = (float)window->x + mouse_rect.x;
|
||||
float right = left + mouse_rect.w - 1;
|
||||
float top = (float)window->y + mouse_rect.y;
|
||||
float bottom = top + mouse_rect.h - 1;
|
||||
if (x < left || x > right || y < top || y > bottom) {
|
||||
adjusted->x = SDL_clamp(x, left, right);
|
||||
adjusted->y = SDL_clamp(y, top, bottom);
|
||||
@@ -396,10 +398,10 @@ static SDL_bool AdjustCoordinatesForGrab(SDL_Window *window, int x, int y, CGPoi
|
||||
}
|
||||
|
||||
if ((window->flags & SDL_WINDOW_MOUSE_GRABBED) != 0) {
|
||||
int left = window->x;
|
||||
int right = left + window->w - 1;
|
||||
int top = window->y;
|
||||
int bottom = top + window->h - 1;
|
||||
float left = (float)window->x;
|
||||
float right = left + window->w - 1;
|
||||
float top = (float)window->y;
|
||||
float bottom = top + window->h - 1;
|
||||
if (x < left || x > right || y < top || y > bottom) {
|
||||
adjusted->x = SDL_clamp(x, left, right);
|
||||
adjusted->y = SDL_clamp(y, top, bottom);
|
||||
@@ -450,7 +452,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
} else {
|
||||
/* Move the cursor to the nearest point in the window */
|
||||
if (ShouldAdjustCoordinatesForGrab(window)) {
|
||||
int x, y;
|
||||
float x, y;
|
||||
CGPoint cgpoint;
|
||||
|
||||
SDL_GetGlobalMouseState(&x, &y);
|
||||
@@ -479,7 +481,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
pendingWindowOperation = PENDING_OPERATION_NONE;
|
||||
isMoving = NO;
|
||||
isDragAreaRunning = NO;
|
||||
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
||||
pendingWindowWarpX = pendingWindowWarpY = FLT_MAX;
|
||||
|
||||
center = [NSNotificationCenter defaultCenter];
|
||||
|
||||
@@ -672,7 +674,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setPendingMoveX:(int)x Y:(int)y
|
||||
- (void)setPendingMoveX:(float)x Y:(float)y
|
||||
{
|
||||
pendingWindowWarpX = x;
|
||||
pendingWindowWarpY = y;
|
||||
@@ -690,14 +692,14 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
{
|
||||
if (![self isMovingOrFocusClickPending]) {
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (pendingWindowWarpX != INT_MAX && pendingWindowWarpY != INT_MAX) {
|
||||
if (pendingWindowWarpX != FLT_MAX && pendingWindowWarpY != FLT_MAX) {
|
||||
mouse->WarpMouseGlobal(pendingWindowWarpX, pendingWindowWarpY);
|
||||
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
||||
pendingWindowWarpX = pendingWindowWarpY = FLT_MAX;
|
||||
}
|
||||
if (mouse->relative_mode && !mouse->relative_mode_warp && mouse->focus == _data.window) {
|
||||
/* Move the cursor to the nearest point in the window */
|
||||
{
|
||||
int x, y;
|
||||
float x, y;
|
||||
CGPoint cgpoint;
|
||||
|
||||
SDL_GetMouseState(&x, &y);
|
||||
@@ -731,7 +733,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
- (void)windowWillMove:(NSNotification *)aNotification
|
||||
{
|
||||
if ([_data.nswindow isKindOfClass:[SDLWindow class]]) {
|
||||
pendingWindowWarpX = pendingWindowWarpY = INT_MAX;
|
||||
pendingWindowWarpX = pendingWindowWarpY = FLT_MAX;
|
||||
isMoving = YES;
|
||||
}
|
||||
}
|
||||
@@ -848,13 +850,13 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
|
||||
/* If we just gained focus we need the updated mouse position */
|
||||
if (!mouse->relative_mode) {
|
||||
NSPoint point;
|
||||
int x, y;
|
||||
float x, y;
|
||||
|
||||
point = [_data.nswindow mouseLocationOutsideOfEventStream];
|
||||
x = (int)point.x;
|
||||
y = (int)(window->h - point.y);
|
||||
x = point.x;
|
||||
y = (window->h - point.y);
|
||||
|
||||
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
|
||||
if (x >= 0.0f && x < (float)window->w && y >= 0.0f && y < (float)window->h) {
|
||||
SDL_SendMouseMotion(0, window, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
}
|
||||
@@ -1317,7 +1319,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_MouseID mouseID;
|
||||
NSPoint point;
|
||||
int x, y;
|
||||
float x, y;
|
||||
SDL_Window *window;
|
||||
|
||||
if (!mouse) {
|
||||
@@ -1337,8 +1339,8 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
|
||||
}
|
||||
|
||||
point = [theEvent locationInWindow];
|
||||
x = (int)point.x;
|
||||
y = (int)(window->h - point.y);
|
||||
x = point.x;
|
||||
y = (window->h - point.y);
|
||||
|
||||
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_13_2) {
|
||||
/* Mouse grab is taken care of by the confinement rect */
|
||||
|
||||
@@ -613,8 +613,7 @@ static EM_BOOL Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEv
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
const int isPointerLocked = window_data->has_pointer_lock;
|
||||
int mx, my;
|
||||
static double residualx = 0, residualy = 0;
|
||||
float mx, my;
|
||||
|
||||
/* rescale (in case canvas is being scaled)*/
|
||||
double client_w, client_h, xscale, yscale;
|
||||
@@ -623,16 +622,11 @@ static EM_BOOL Emscripten_HandleMouseMove(int eventType, const EmscriptenMouseEv
|
||||
yscale = window_data->window->h / client_h;
|
||||
|
||||
if (isPointerLocked) {
|
||||
residualx += mouseEvent->movementX * xscale;
|
||||
residualy += mouseEvent->movementY * yscale;
|
||||
/* Let slow sub-pixel motion accumulate. Don't lose it. */
|
||||
mx = residualx;
|
||||
residualx -= mx;
|
||||
my = residualy;
|
||||
residualy -= my;
|
||||
mx = (float)(mouseEvent->movementX * xscale);
|
||||
my = (float)(mouseEvent->movementY * yscale);
|
||||
} else {
|
||||
mx = mouseEvent->targetX * xscale;
|
||||
my = mouseEvent->targetY * yscale;
|
||||
mx = (float)(mouseEvent->targetX * xscale);
|
||||
my = (float)(mouseEvent->targetY * yscale);
|
||||
}
|
||||
|
||||
SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my);
|
||||
@@ -687,16 +681,16 @@ static EM_BOOL Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseE
|
||||
{
|
||||
SDL_WindowData *window_data = userData;
|
||||
|
||||
int mx = mouseEvent->targetX, my = mouseEvent->targetY;
|
||||
const int isPointerLocked = window_data->has_pointer_lock;
|
||||
|
||||
if (!isPointerLocked) {
|
||||
/* rescale (in case canvas is being scaled)*/
|
||||
float mx, my;
|
||||
double client_w, client_h;
|
||||
emscripten_get_element_css_size(window_data->canvas_id, &client_w, &client_h);
|
||||
|
||||
mx = mx * (window_data->window->w / client_w);
|
||||
my = my * (window_data->window->h / client_h);
|
||||
mx = (float)(mouseEvent->targetX * (window_data->window->w / client_w));
|
||||
my = (float)(mouseEvent->targetY * (window_data->window->h / client_h));
|
||||
SDL_SendMouseMotion(0, window_data->window, 0, isPointerLocked, mx, my);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,11 +204,6 @@ static int Emscripten_ShowCursor(SDL_Cursor *cursor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Emscripten_WarpMouse(SDL_Window *window, int x, int y)
|
||||
{
|
||||
SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int Emscripten_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
SDL_Window *window;
|
||||
@@ -241,7 +236,6 @@ void Emscripten_InitMouse()
|
||||
mouse->CreateCursor = Emscripten_CreateCursor;
|
||||
mouse->ShowCursor = Emscripten_ShowCursor;
|
||||
mouse->FreeCursor = Emscripten_FreeCursor;
|
||||
mouse->WarpMouse = Emscripten_WarpMouse;
|
||||
mouse->CreateSystemCursor = Emscripten_CreateSystemCursor;
|
||||
mouse->SetRelativeMouseMode = Emscripten_SetRelativeMouseMode;
|
||||
|
||||
|
||||
@@ -254,12 +254,12 @@ class SDL_BApp : public BApplication
|
||||
SDL_GetWindowPosition(win, &winPosX, &winPosY);
|
||||
int dx = x - (winWidth / 2);
|
||||
int dy = y - (winHeight / 2);
|
||||
SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, dx, dy);
|
||||
SDL_SendMouseMotion(0, win, 0, SDL_GetMouse()->relative_mode, (float)dx, (float)dy);
|
||||
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
|
||||
if (!be_app->IsCursorHidden())
|
||||
be_app->HideCursor();
|
||||
} else {
|
||||
SDL_SendMouseMotion(0, win, 0, 0, x, y);
|
||||
SDL_SendMouseMotion(0, win, 0, 0, (float)x, (float)y);
|
||||
if (SDL_CursorVisible() && be_app->IsCursorHidden())
|
||||
be_app->ShowCursor();
|
||||
}
|
||||
|
||||
@@ -37,8 +37,6 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_
|
||||
static int KMSDRM_ShowCursor(SDL_Cursor *cursor);
|
||||
static void KMSDRM_MoveCursor(SDL_Cursor *cursor);
|
||||
static void KMSDRM_FreeCursor(SDL_Cursor *cursor);
|
||||
static void KMSDRM_WarpMouse(SDL_Window *window, int x, int y);
|
||||
static int KMSDRM_WarpMouseGlobal(int x, int y);
|
||||
|
||||
/**************************************************************************************/
|
||||
/* BEFORE CODING ANYTHING MOUSE/CURSOR RELATED, REMEMBER THIS. */
|
||||
@@ -354,15 +352,7 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static void KMSDRM_WarpMouse(SDL_Window *window, int x, int y)
|
||||
{
|
||||
/* Only one global/fullscreen window is supported */
|
||||
KMSDRM_WarpMouseGlobal(x, y);
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static int KMSDRM_WarpMouseGlobal(int x, int y)
|
||||
static int KMSDRM_WarpMouseGlobal(float x, float y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
@@ -378,7 +368,7 @@ static int KMSDRM_WarpMouseGlobal(int x, int y)
|
||||
if (dispdata->cursor_bo) {
|
||||
int ret = 0;
|
||||
|
||||
ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, x, y);
|
||||
ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)x, (int)y);
|
||||
|
||||
if (ret) {
|
||||
SDL_SetError("drmModeMoveCursor() failed.");
|
||||
@@ -395,6 +385,12 @@ static int KMSDRM_WarpMouseGlobal(int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
static void KMSDRM_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
/* Only one global/fullscreen window is supported */
|
||||
KMSDRM_WarpMouseGlobal(x, y);
|
||||
}
|
||||
|
||||
void KMSDRM_InitMouse(_THIS, SDL_VideoDisplay *display)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
@@ -44,8 +44,6 @@ static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y);
|
||||
static int RPI_ShowCursor(SDL_Cursor *cursor);
|
||||
static void RPI_MoveCursor(SDL_Cursor *cursor);
|
||||
static void RPI_FreeCursor(SDL_Cursor *cursor);
|
||||
static void RPI_WarpMouse(SDL_Window *window, int x, int y);
|
||||
static int RPI_WarpMouseGlobal(int x, int y);
|
||||
|
||||
static SDL_Cursor *global_cursor;
|
||||
|
||||
@@ -223,14 +221,61 @@ static void RPI_FreeCursor(SDL_Cursor *cursor)
|
||||
}
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static void RPI_WarpMouse(SDL_Window *window, int x, int y)
|
||||
static int RPI_WarpMouseGlobalGraphically(float x, float y)
|
||||
{
|
||||
RPI_WarpMouseGlobal(x, y);
|
||||
RPI_CursorData *curdata;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
int ret;
|
||||
VC_RECT_T dst_rect;
|
||||
VC_RECT_T src_rect;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
|
||||
if (curdata->element == DISPMANX_NO_HANDLE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
update = vc_dispmanx_update_start(0);
|
||||
if (!update) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.height = curdata->h << 16;
|
||||
dst_rect.x = (int)x - curdata->hot_x;
|
||||
dst_rect.y = (int)y - curdata->hot_y;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.height = curdata->h;
|
||||
|
||||
ret = vc_dispmanx_element_change_attributes(
|
||||
update,
|
||||
curdata->element,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&dst_rect,
|
||||
&src_rect,
|
||||
DISPMANX_NO_HANDLE,
|
||||
DISPMANX_NO_ROTATE);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
|
||||
}
|
||||
|
||||
/* Submit asynchronously, otherwise the peformance suffers a lot */
|
||||
ret = vc_dispmanx_update_submit(update, 0, NULL);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_update_submit() failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static int RPI_WarpMouseGlobal(int x, int y)
|
||||
static int RPI_WarpMouseGlobal(float x, float y)
|
||||
{
|
||||
RPI_CursorData *curdata;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
@@ -246,100 +291,12 @@ static int RPI_WarpMouseGlobal(int x, int y)
|
||||
/* Update internal mouse position. */
|
||||
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y);
|
||||
|
||||
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
|
||||
if (curdata->element == DISPMANX_NO_HANDLE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
update = vc_dispmanx_update_start(0);
|
||||
if (!update) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.height = curdata->h << 16;
|
||||
dst_rect.x = x - curdata->hot_x;
|
||||
dst_rect.y = y - curdata->hot_y;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.height = curdata->h;
|
||||
|
||||
ret = vc_dispmanx_element_change_attributes(
|
||||
update,
|
||||
curdata->element,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&dst_rect,
|
||||
&src_rect,
|
||||
DISPMANX_NO_HANDLE,
|
||||
DISPMANX_NO_ROTATE);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
|
||||
}
|
||||
|
||||
/* Submit asynchronously, otherwise the peformance suffers a lot */
|
||||
ret = vc_dispmanx_update_submit(update, 0, NULL);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_update_submit() failed");
|
||||
}
|
||||
return 0;
|
||||
return RPI_WarpMouseGlobalGraphically(x, y);
|
||||
}
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
static int RPI_WarpMouseGlobalGraphicOnly(int x, int y)
|
||||
static void RPI_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
RPI_CursorData *curdata;
|
||||
DISPMANX_UPDATE_HANDLE_T update;
|
||||
int ret;
|
||||
VC_RECT_T dst_rect;
|
||||
VC_RECT_T src_rect;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse == NULL || mouse->cur_cursor == NULL || mouse->cur_cursor->driverdata == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
curdata = (RPI_CursorData *)mouse->cur_cursor->driverdata;
|
||||
if (curdata->element == DISPMANX_NO_HANDLE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
update = vc_dispmanx_update_start(0);
|
||||
if (!update) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
src_rect.x = 0;
|
||||
src_rect.y = 0;
|
||||
src_rect.width = curdata->w << 16;
|
||||
src_rect.height = curdata->h << 16;
|
||||
dst_rect.x = x - curdata->hot_x;
|
||||
dst_rect.y = y - curdata->hot_y;
|
||||
dst_rect.width = curdata->w;
|
||||
dst_rect.height = curdata->h;
|
||||
|
||||
ret = vc_dispmanx_element_change_attributes(
|
||||
update,
|
||||
curdata->element,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
&dst_rect,
|
||||
&src_rect,
|
||||
DISPMANX_NO_HANDLE,
|
||||
DISPMANX_NO_ROTATE);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_element_change_attributes() failed");
|
||||
}
|
||||
|
||||
/* Submit asynchronously, otherwise the peformance suffers a lot */
|
||||
ret = vc_dispmanx_update_submit(update, 0, NULL);
|
||||
if (ret != DISPMANX_SUCCESS) {
|
||||
return SDL_SetError("vc_dispmanx_update_submit() failed");
|
||||
}
|
||||
return 0;
|
||||
RPI_WarpMouseGlobal(x, y);
|
||||
}
|
||||
|
||||
void RPI_InitMouse(_THIS)
|
||||
@@ -369,7 +326,7 @@ static void RPI_MoveCursor(SDL_Cursor *cursor)
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
/* We must NOT call SDL_SendMouseMotion() on the next call or we will enter recursivity,
|
||||
* so we create a version of WarpMouseGlobal without it. */
|
||||
RPI_WarpMouseGlobalGraphicOnly(mouse->x, mouse->y);
|
||||
RPI_WarpMouseGlobalGraphically(mouse->x, mouse->y);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_DRIVER_RPI */
|
||||
|
||||
@@ -126,7 +126,7 @@ void RISCOS_PollMouse(_THIS)
|
||||
buttons = regs.r[2];
|
||||
|
||||
if (mouse->x != x || mouse->y != y) {
|
||||
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, x, y);
|
||||
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 0, (float)x, (float)y);
|
||||
}
|
||||
|
||||
if (driverdata->last_mouse_buttons != buttons) {
|
||||
|
||||
@@ -320,7 +320,7 @@ static void OnGCMouseConnected(GCMouse *mouse) API_AVAILABLE(macos(11.0), ios(14
|
||||
|
||||
mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput *mouseInput, float deltaX, float deltaY) {
|
||||
if (SDL_GCMouseRelativeMode()) {
|
||||
SDL_SendMouseMotion(0, SDL_GetMouseFocus(), mouseID, 1, (int)deltaX, -(int)deltaY);
|
||||
SDL_SendMouseMotion(0, SDL_GetMouseFocus(), mouseID, 1, deltaX, -deltaY);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
|
||||
point.x -= origin.x;
|
||||
point.y -= origin.y;
|
||||
|
||||
SDL_SendMouseMotion(0, sdlwindow, 0, 0, (int)point.x, (int)point.y);
|
||||
SDL_SendMouseMotion(0, sdlwindow, 0, 0, point.x, point.y);
|
||||
}
|
||||
return [UIPointerRegion regionWithRect:self.bounds identifier:nil];
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ void VITA_PollMouse(void)
|
||||
prev_buttons = m_reports[i].buttons;
|
||||
|
||||
if (m_reports[i].rel_x || m_reports[i].rel_y) {
|
||||
SDL_SendMouseMotion(0, Vita_Window, 0, 1, m_reports[i].rel_x, m_reports[i].rel_y);
|
||||
SDL_SendMouseMotion(0, Vita_Window, 0, 1, (float)m_reports[i].rel_x, (float)m_reports[i].rel_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,10 +500,8 @@ static void pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
||||
input->sx_w = sx_w;
|
||||
input->sy_w = sy_w;
|
||||
if (input->pointer_focus) {
|
||||
const float sx_f = (float)wl_fixed_to_double(sx_w);
|
||||
const float sy_f = (float)wl_fixed_to_double(sy_w);
|
||||
const int sx = (int)SDL_floorf(sx_f * window->pointer_scale_x);
|
||||
const int sy = (int)SDL_floorf(sy_f * window->pointer_scale_y);
|
||||
float sx = (float)(wl_fixed_to_double(sx_w) * window->pointer_scale_x);
|
||||
float sy = (float)(wl_fixed_to_double(sy_w) * window->pointer_scale_y);
|
||||
SDL_SendMouseMotion(Wayland_GetPointerTimestamp(input, time), window->sdlwindow, 0, 0, sx, sy);
|
||||
}
|
||||
}
|
||||
@@ -2215,10 +2213,8 @@ static void tablet_tool_handle_motion(void *data, struct zwp_tablet_tool_v2 *too
|
||||
input->sx_w = sx_w;
|
||||
input->sy_w = sy_w;
|
||||
if (input->tool_focus) {
|
||||
const float sx_f = (float)wl_fixed_to_double(sx_w);
|
||||
const float sy_f = (float)wl_fixed_to_double(sy_w);
|
||||
const int sx = (int)SDL_floorf(sx_f * window->pointer_scale_x);
|
||||
const int sy = (int)SDL_floorf(sy_f * window->pointer_scale_y);
|
||||
float sx = (float)(wl_fixed_to_double(sx_w) * window->pointer_scale_x);
|
||||
float sy = (float)(wl_fixed_to_double(sy_w) * window->pointer_scale_y);
|
||||
SDL_SendMouseMotion(0, window->sdlwindow, 0, 0, sx, sy);
|
||||
}
|
||||
}
|
||||
@@ -2572,21 +2568,12 @@ static void relative_pointer_handle_relative_motion(void *data,
|
||||
SDL_WindowData *window = input->pointer_focus;
|
||||
double dx_unaccel;
|
||||
double dy_unaccel;
|
||||
double dx;
|
||||
double dy;
|
||||
|
||||
dx_unaccel = wl_fixed_to_double(dx_unaccel_w);
|
||||
dy_unaccel = wl_fixed_to_double(dy_unaccel_w);
|
||||
|
||||
/* Add left over fraction from last event. */
|
||||
dx_unaccel += input->dx_frac;
|
||||
dy_unaccel += input->dy_frac;
|
||||
|
||||
input->dx_frac = modf(dx_unaccel, &dx);
|
||||
input->dy_frac = modf(dy_unaccel, &dy);
|
||||
|
||||
if (input->pointer_focus && d->relative_mouse_mode) {
|
||||
SDL_SendMouseMotion(0, window->sdlwindow, 0, 1, (int)dx, (int)dy);
|
||||
SDL_SendMouseMotion(0, window->sdlwindow, 0, 1, (float)dx_unaccel, (float)dy_unaccel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,9 +110,6 @@ struct SDL_WaylandInput
|
||||
|
||||
uint32_t buttons_pressed;
|
||||
|
||||
double dx_frac;
|
||||
double dy_frac;
|
||||
|
||||
struct
|
||||
{
|
||||
struct xkb_keymap *keymap;
|
||||
|
||||
@@ -525,7 +525,7 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Wayland_WarpMouse(SDL_Window *window, int x, int y)
|
||||
static void Wayland_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
SDL_VideoDevice *vd = SDL_GetVideoDevice();
|
||||
SDL_VideoData *d = vd->driverdata;
|
||||
@@ -543,11 +543,6 @@ static void Wayland_WarpMouse(SDL_Window *window, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
static int Wayland_WarpMouseGlobal(int x, int y)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int Wayland_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
SDL_VideoDevice *vd = SDL_GetVideoDevice();
|
||||
@@ -646,7 +641,6 @@ void Wayland_InitMouse(void)
|
||||
mouse->ShowCursor = Wayland_ShowCursor;
|
||||
mouse->FreeCursor = Wayland_FreeCursor;
|
||||
mouse->WarpMouse = Wayland_WarpMouse;
|
||||
mouse->WarpMouseGlobal = Wayland_WarpMouseGlobal;
|
||||
mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode;
|
||||
|
||||
input->relative_mode_override = SDL_FALSE;
|
||||
|
||||
@@ -517,12 +517,10 @@ static void WIN_UpdateFocus(SDL_Window *window, SDL_bool expect_focus)
|
||||
|
||||
/* In relative mode we are guaranteed to have mouse focus if we have keyboard focus */
|
||||
if (!SDL_GetMouse()->relative_mode) {
|
||||
SDL_Point point;
|
||||
SDL_FPoint point;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
point.x = cursorPos.x;
|
||||
point.y = cursorPos.y;
|
||||
WIN_ClientPointToSDL(data->window, &point.x, &point.y);
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), window, 0, 0, point.x, point.y);
|
||||
}
|
||||
|
||||
@@ -830,10 +828,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
/* Only generate mouse events for real mouse */
|
||||
if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH &&
|
||||
lParam != data->last_pointer_update) {
|
||||
int x = GET_X_LPARAM(lParam);
|
||||
int y = GET_Y_LPARAM(lParam);
|
||||
float x, y;
|
||||
|
||||
WIN_ClientPointToSDL(data->window, &x, &y);
|
||||
WIN_ClientPointToSDLFloat(data->window, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), &x, &y);
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, x, y);
|
||||
}
|
||||
@@ -897,7 +894,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
rawmouse = &inp.data.mouse;
|
||||
|
||||
if ((rawmouse->usFlags & 0x01) == MOUSE_MOVE_RELATIVE) {
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, (int)rawmouse->lLastX, (int)rawmouse->lLastY);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, (float)rawmouse->lLastX, (float)rawmouse->lLastY);
|
||||
} else if (rawmouse->lLastX || rawmouse->lLastY) {
|
||||
/* This is absolute motion, either using a tablet or mouse over RDP
|
||||
|
||||
@@ -953,7 +950,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
const int MAX_RELATIVE_MOTION = (h / 6);
|
||||
if (SDL_abs(relX) < MAX_RELATIVE_MOTION &&
|
||||
SDL_abs(relY) < MAX_RELATIVE_MOTION) {
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, relX, relY);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, (float)relX, (float)relY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -963,7 +960,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
SDL_abs(relY) > MAXIMUM_TABLET_RELATIVE_MOTION) {
|
||||
/* Ignore this motion, probably a pen lift and drop */
|
||||
} else {
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, relX, relY);
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 1, (float)relX, (float)relY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -991,12 +988,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
if (SDL_GetMouseFocus() == data->window && !SDL_GetMouse()->relative_mode && !IsIconic(hwnd)) {
|
||||
SDL_Mouse *mouse;
|
||||
POINT cursorPos;
|
||||
SDL_Point point;
|
||||
SDL_FPoint point;
|
||||
GetCursorPos(&cursorPos);
|
||||
ScreenToClient(hwnd, &cursorPos);
|
||||
point.x = cursorPos.x;
|
||||
point.y = cursorPos.y;
|
||||
WIN_ClientPointToSDL(data->window, &point.x, &point.y);
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
mouse = SDL_GetMouse();
|
||||
if (!mouse->was_touch_mouse_events) { /* we're not a touch handler causing a mouse leave? */
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, 0, 0, point.x, point.y);
|
||||
@@ -1783,10 +1778,8 @@ static void WIN_UpdateMouseCapture()
|
||||
if (GetCursorPos(&cursorPos) && ScreenToClient(data->hwnd, &cursorPos)) {
|
||||
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
SDL_MouseID mouseID = SDL_GetMouse()->mouseID;
|
||||
SDL_Point point;
|
||||
point.x = cursorPos.x;
|
||||
point.y = cursorPos.y;
|
||||
WIN_ClientPointToSDL(data->window, &point.x, &point.y);
|
||||
SDL_FPoint point;
|
||||
WIN_ClientPointToSDLFloat(data->window, cursorPos.x, cursorPos.y, &point.x, &point.y);
|
||||
|
||||
SDL_SendMouseMotion(WIN_GetEventTimestamp(), data->window, mouseID, 0, point.x, point.y);
|
||||
SDL_SendMouseButton(WIN_GetEventTimestamp(), data->window, mouseID, GetAsyncKeyState(VK_LBUTTON) & 0x8000 ? SDL_PRESSED : SDL_RELEASED, !swapButtons ? SDL_BUTTON_LEFT : SDL_BUTTON_RIGHT);
|
||||
|
||||
@@ -585,39 +585,47 @@ int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
|
||||
* Returns the DPI of the monitor that was closest to x, y and used for the conversion.
|
||||
*/
|
||||
void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut)
|
||||
{
|
||||
POINT pt = { 0, 0 };
|
||||
WIN_ScreenPointFromSDLFloat((float)*x, (float)*y, &pt.x, &pt.y, dpiOut);
|
||||
*x = pt.x;
|
||||
*y = pt.y;
|
||||
}
|
||||
|
||||
void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *dpiOut)
|
||||
{
|
||||
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
||||
const SDL_VideoData *videodata;
|
||||
int displayIndex;
|
||||
SDL_Rect bounds;
|
||||
float ddpi, hdpi, vdpi;
|
||||
int x_sdl, y_sdl;
|
||||
SDL_Point point;
|
||||
point.x = *x;
|
||||
point.y = *y;
|
||||
|
||||
point.x = (int)x;
|
||||
point.y = (int)y;
|
||||
|
||||
if (dpiOut) {
|
||||
*dpiOut = 96;
|
||||
}
|
||||
|
||||
if (videodevice == NULL || !videodevice->driverdata) {
|
||||
return;
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
videodata = (SDL_VideoData *)videodevice->driverdata;
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
return;
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
/* Can't use MonitorFromPoint for this because we currently have SDL coordinates, not pixels */
|
||||
displayIndex = SDL_GetDisplayIndexForPoint(&point);
|
||||
|
||||
if (displayIndex < 0) {
|
||||
return;
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (SDL_GetDisplayBounds(displayIndex, &bounds) < 0 || SDL_GetDisplayDPI(displayIndex, &ddpi, &hdpi, &vdpi) < 0) {
|
||||
return;
|
||||
goto passthrough;
|
||||
}
|
||||
|
||||
if (dpiOut) {
|
||||
@@ -625,15 +633,18 @@ void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut)
|
||||
}
|
||||
|
||||
/* Undo the DPI-scaling within the monitor bounds to convert back to pixels */
|
||||
x_sdl = *x;
|
||||
y_sdl = *y;
|
||||
*x = bounds.x + MulDiv(x_sdl - bounds.x, (int)ddpi, 96);
|
||||
*y = bounds.y + MulDiv(y_sdl - bounds.y, (int)ddpi, 96);
|
||||
*xOut = bounds.x + SDL_lroundf(((x - bounds.x) * ddpi) / 96.0f);
|
||||
*yOut = bounds.y + SDL_lroundf(((y - bounds.y) * ddpi) / 96.0f);
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointFromSDL: (%d, %d) points -> (%d x %d) pixels, using %d DPI monitor",
|
||||
x_sdl, y_sdl, *x, *y, (int)ddpi);
|
||||
SDL_Log("WIN_ScreenPointFromSDL: (%g, %g) points -> (%d x %d) pixels, using %g DPI monitor",
|
||||
x, y, *xOut, *yOut, ddpi);
|
||||
#endif
|
||||
return;
|
||||
|
||||
passthrough:
|
||||
*xOut = SDL_lroundf(x);
|
||||
*yOut = SDL_lroundf(y);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -643,6 +654,14 @@ void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut)
|
||||
* No-op if DPI scaling is not enabled.
|
||||
*/
|
||||
void WIN_ScreenPointToSDL(int *x, int *y)
|
||||
{
|
||||
SDL_FPoint pt;
|
||||
WIN_ScreenPointToSDLFloat(*x, *y, &pt.x, &pt.y);
|
||||
*x = SDL_lroundf(pt.x);
|
||||
*y = SDL_lroundf(pt.y);
|
||||
}
|
||||
|
||||
void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut)
|
||||
{
|
||||
const SDL_VideoDevice *videodevice = SDL_GetVideoDevice();
|
||||
const SDL_VideoData *videodata;
|
||||
@@ -651,7 +670,6 @@ void WIN_ScreenPointToSDL(int *x, int *y)
|
||||
int i, displayIndex;
|
||||
SDL_Rect bounds;
|
||||
float ddpi, hdpi, vdpi;
|
||||
int x_pixels, y_pixels;
|
||||
|
||||
if (videodevice == NULL || !videodevice->driverdata) {
|
||||
return;
|
||||
@@ -659,11 +677,13 @@ void WIN_ScreenPointToSDL(int *x, int *y)
|
||||
|
||||
videodata = (SDL_VideoData *)videodevice->driverdata;
|
||||
if (!videodata->dpi_scaling_enabled) {
|
||||
*xOut = (float)x;
|
||||
*yOut = (float)y;
|
||||
return;
|
||||
}
|
||||
|
||||
point.x = *x;
|
||||
point.y = *y;
|
||||
point.x = x;
|
||||
point.y = y;
|
||||
monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
/* Search for the corresponding SDL monitor */
|
||||
@@ -684,14 +704,12 @@ void WIN_ScreenPointToSDL(int *x, int *y)
|
||||
}
|
||||
|
||||
/* Convert the point's offset within the monitor from pixels to DPI-scaled points */
|
||||
x_pixels = *x;
|
||||
y_pixels = *y;
|
||||
*x = bounds.x + MulDiv(x_pixels - bounds.x, 96, (int)ddpi);
|
||||
*y = bounds.y + MulDiv(y_pixels - bounds.y, 96, (int)ddpi);
|
||||
*xOut = (float)bounds.x + ((float)(x - bounds.x) * 96.0f) / ddpi;
|
||||
*yOut = (float)bounds.y + ((float)(y - bounds.y) * 96.0f) / ddpi;
|
||||
|
||||
#ifdef HIGHDPI_DEBUG_VERBOSE
|
||||
SDL_Log("WIN_ScreenPointToSDL: (%d, %d) pixels -> (%d x %d) points, using %d DPI monitor",
|
||||
x_pixels, y_pixels, *x, *y, (int)ddpi);
|
||||
SDL_Log("WIN_ScreenPointToSDL: (%d, %d) pixels -> (%g x %g) points, using %g DPI monitor",
|
||||
x, y, *xOut, *yOut, ddpi);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ extern int WIN_InitModes(_THIS);
|
||||
extern int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern int WIN_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect);
|
||||
extern void WIN_ScreenPointFromSDL(int *x, int *y, int *dpiOut);
|
||||
extern void WIN_ScreenPointFromSDLFloat(float x, float y, LONG *xOut, LONG *yOut, int *dpiOut);
|
||||
extern void WIN_ScreenPointToSDL(int *x, int *y);
|
||||
extern void WIN_ScreenPointToSDLFloat(LONG x, LONG y, float *xOut, float *yOut);
|
||||
extern int WIN_GetDisplayDPI(_THIS, SDL_VideoDisplay *display, float *ddpi, float *hdpi, float *vdpi);
|
||||
extern void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay *display);
|
||||
extern int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
|
||||
|
||||
@@ -277,7 +277,7 @@ void WIN_SetCursorPos(int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
static void WIN_WarpMouse(SDL_Window *window, int x, int y)
|
||||
static void WIN_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
HWND hwnd = data->hwnd;
|
||||
@@ -288,8 +288,7 @@ static void WIN_WarpMouse(SDL_Window *window, int x, int y)
|
||||
return;
|
||||
}
|
||||
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
WIN_ClientPointFromSDLFloat(window, x, y, &pt.x, &pt.y);
|
||||
ClientToScreen(hwnd, &pt);
|
||||
WIN_SetCursorPos(pt.x, pt.y);
|
||||
|
||||
@@ -297,13 +296,11 @@ static void WIN_WarpMouse(SDL_Window *window, int x, int y)
|
||||
SDL_SendMouseMotion(0, window, SDL_GetMouse()->mouseID, 0, x, y);
|
||||
}
|
||||
|
||||
static int WIN_WarpMouseGlobal(int x, int y)
|
||||
static int WIN_WarpMouseGlobal(float x, float y)
|
||||
{
|
||||
POINT pt;
|
||||
|
||||
WIN_ScreenPointFromSDL(&x, &y, NULL);
|
||||
pt.x = x;
|
||||
pt.y = y;
|
||||
WIN_ScreenPointFromSDLFloat(x, y, &pt.x, &pt.y, NULL);
|
||||
SetCursorPos(pt.x, pt.y);
|
||||
return 0;
|
||||
}
|
||||
@@ -333,16 +330,14 @@ static int WIN_CaptureMouse(SDL_Window *window)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Uint32 WIN_GetGlobalMouseState(int *x, int *y)
|
||||
static Uint32 WIN_GetGlobalMouseState(float *x, float *y)
|
||||
{
|
||||
Uint32 retval = 0;
|
||||
POINT pt = { 0, 0 };
|
||||
SDL_bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0;
|
||||
|
||||
GetCursorPos(&pt);
|
||||
*x = (int)pt.x;
|
||||
*y = (int)pt.y;
|
||||
WIN_ScreenPointToSDL(x, y);
|
||||
WIN_ScreenPointToSDLFloat(pt.x, pt.y, x, y);
|
||||
|
||||
retval |= GetAsyncKeyState(!swapButtons ? VK_LBUTTON : VK_RBUTTON) & 0x8000 ? SDL_BUTTON_LMASK : 0;
|
||||
retval |= GetAsyncKeyState(!swapButtons ? VK_RBUTTON : VK_LBUTTON) & 0x8000 ? SDL_BUTTON_RMASK : 0;
|
||||
|
||||
@@ -1357,6 +1357,20 @@ void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y)
|
||||
*y = MulDiv(*y, 96, data->scaling_dpi);
|
||||
}
|
||||
|
||||
void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float *xOut, float *yOut)
|
||||
{
|
||||
const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata);
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (videodata->dpi_scaling_enabled) {
|
||||
*xOut = (float)(x * 96) / data->scaling_dpi;
|
||||
*yOut = (float)(y * 96) / data->scaling_dpi;
|
||||
} else {
|
||||
*xOut = (float)x;
|
||||
*yOut = (float)y;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a point in the client area from DPI-scaled points to pixels.
|
||||
*
|
||||
@@ -1375,6 +1389,20 @@ void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y)
|
||||
*y = MulDiv(*y, data->scaling_dpi, 96);
|
||||
}
|
||||
|
||||
void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LONG *xOut, LONG *yOut)
|
||||
{
|
||||
const SDL_WindowData *data = ((SDL_WindowData *)window->driverdata);
|
||||
const SDL_VideoData *videodata = data->videodata;
|
||||
|
||||
if (videodata->dpi_scaling_enabled) {
|
||||
*xOut = (LONG)SDL_roundf((x * data->scaling_dpi) / 96.0f);
|
||||
*yOut = (LONG)SDL_roundf((y * data->scaling_dpi) / 96.0f);
|
||||
} else {
|
||||
*xOut = (LONG)SDL_roundf(x);
|
||||
*yOut = (LONG)SDL_roundf(y);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
|
||||
void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept)
|
||||
{
|
||||
|
||||
@@ -104,7 +104,9 @@ extern void WIN_OnWindowEnter(_THIS, SDL_Window *window);
|
||||
extern void WIN_UpdateClipCursor(SDL_Window *window);
|
||||
extern int WIN_SetWindowHitTest(SDL_Window *window, SDL_bool enabled);
|
||||
extern void WIN_ClientPointToSDL(const SDL_Window *window, int *x, int *y);
|
||||
extern void WIN_ClientPointToSDLFloat(const SDL_Window *window, LONG x, LONG y, float *xOut, float *yOut);
|
||||
extern void WIN_ClientPointFromSDL(const SDL_Window *window, int *x, int *y);
|
||||
extern void WIN_ClientPointFromSDLFloat(const SDL_Window *window, float x, float y, LONG *xOut, LONG *yOut);
|
||||
extern void WIN_AcceptDragAndDrop(SDL_Window *window, SDL_bool accept);
|
||||
extern int WIN_FlashWindow(_THIS, SDL_Window *window, SDL_FlashOperation operation);
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ void WINRT_ProcessPointerMovedEvent(SDL_Window *window, Windows::UI::Input::Poin
|
||||
SDL_SendMouseButton(0, window, 0, pressed, button);
|
||||
}
|
||||
|
||||
SDL_SendMouseMotion(0, window, 0, 0, (int)windowPoint.X, (int)windowPoint.Y);
|
||||
SDL_SendMouseMotion(0, window, 0, 0, windowPoint.X, windowPoint.Y);
|
||||
} else {
|
||||
SDL_SendTouchMotion(0,
|
||||
WINRT_TouchID,
|
||||
@@ -390,8 +390,8 @@ void WINRT_ProcessMouseMovedEvent(SDL_Window *window, Windows::Devices::Input::M
|
||||
window,
|
||||
0,
|
||||
1,
|
||||
SDL_lroundf(mouseDeltaInSDLWindowCoords.X),
|
||||
SDL_lroundf(mouseDeltaInSDLWindowCoords.Y));
|
||||
mouseDeltaInSDLWindowCoords.X,
|
||||
mouseDeltaInSDLWindowCoords.Y);
|
||||
}
|
||||
|
||||
#endif // SDL_VIDEO_DRIVER_WINRT
|
||||
|
||||
@@ -932,7 +932,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
#endif
|
||||
|
||||
if (!mouse->relative_mode) {
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, xevent->xcrossing.x, xevent->xcrossing.y);
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y);
|
||||
}
|
||||
|
||||
/* We ungrab in LeaveNotify, so we may need to grab again here */
|
||||
@@ -954,7 +954,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
}
|
||||
#endif
|
||||
if (!SDL_GetMouse()->relative_mode) {
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, xevent->xcrossing.x, xevent->xcrossing.y);
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xcrossing.x, (float)xevent->xcrossing.y);
|
||||
}
|
||||
|
||||
if (xevent->xcrossing.mode != NotifyGrab &&
|
||||
@@ -1311,7 +1311,7 @@ static void X11_DispatchEvent(_THIS, XEvent *xevent)
|
||||
printf("window %p: X11 motion: %d,%d\n", data, xevent->xmotion.x, xevent->xmotion.y);
|
||||
#endif
|
||||
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, xevent->xmotion.x, xevent->xmotion.y);
|
||||
SDL_SendMouseMotion(0, data->window, 0, 0, (float)xevent->xmotion.x, (float)xevent->xmotion.y);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
||||
@@ -324,7 +324,7 @@ static int X11_ShowCursor(SDL_Cursor *cursor)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void X11_WarpMouseInternal(Window xwindow, const int x, const int y)
|
||||
static void X11_WarpMouseInternal(Window xwindow, float x, float y)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)SDL_GetVideoDevice()->driverdata;
|
||||
Display *display = videodata->display;
|
||||
@@ -337,17 +337,17 @@ static void X11_WarpMouseInternal(Window xwindow, const int x, const int y)
|
||||
X11_XIGetClientPointer(display, None, &deviceid);
|
||||
}
|
||||
if (deviceid != 0) {
|
||||
X11_XIWarpPointer(display, deviceid, None, xwindow, 0.0, 0.0, 0, 0, (double)x, (double)y);
|
||||
X11_XIWarpPointer(display, deviceid, None, xwindow, 0.0, 0.0, 0, 0, x, y);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
X11_XWarpPointer(display, None, xwindow, 0, 0, 0, 0, x, y);
|
||||
X11_XWarpPointer(display, None, xwindow, 0, 0, 0, 0, (int)x, (int)y);
|
||||
}
|
||||
X11_XSync(display, False);
|
||||
videodata->global_mouse_changed = SDL_TRUE;
|
||||
}
|
||||
|
||||
static void X11_WarpMouse(SDL_Window *window, int x, int y)
|
||||
static void X11_WarpMouse(SDL_Window *window, float x, float y)
|
||||
{
|
||||
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
||||
|
||||
@@ -361,7 +361,7 @@ static void X11_WarpMouse(SDL_Window *window, int x, int y)
|
||||
#endif
|
||||
}
|
||||
|
||||
static int X11_WarpMouseGlobal(int x, int y)
|
||||
static int X11_WarpMouseGlobal(float x, float y)
|
||||
{
|
||||
X11_WarpMouseInternal(DefaultRootWindow(GetDisplay()), x, y);
|
||||
return 0;
|
||||
@@ -405,7 +405,7 @@ static int X11_CaptureMouse(SDL_Window *window)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static Uint32 X11_GetGlobalMouseState(int *x, int *y)
|
||||
static Uint32 X11_GetGlobalMouseState(float *x, float *y)
|
||||
{
|
||||
SDL_VideoData *videodata = (SDL_VideoData *)SDL_GetVideoDevice()->driverdata;
|
||||
Display *display = GetDisplay();
|
||||
@@ -452,8 +452,8 @@ static Uint32 X11_GetGlobalMouseState(int *x, int *y)
|
||||
|
||||
SDL_assert(!videodata->global_mouse_changed); /* The pointer wasn't on any X11 screen?! */
|
||||
|
||||
*x = videodata->global_mouse_position.x;
|
||||
*y = videodata->global_mouse_position.y;
|
||||
*x = (float)videodata->global_mouse_position.x;
|
||||
*y = (float)videodata->global_mouse_position.y;
|
||||
return videodata->global_mouse_buttons;
|
||||
}
|
||||
|
||||
|
||||
@@ -306,7 +306,7 @@ int X11_HandleXinput2Event(SDL_VideoData *videodata, XGenericEventCookie *cookie
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, (int)processed_coords[0], (int)processed_coords[1]);
|
||||
SDL_SendMouseMotion(0, mouse->focus, mouse->mouseID, 1, (float)processed_coords[0], (float)processed_coords[1]);
|
||||
devinfo->prev_coords[0] = coords[0];
|
||||
devinfo->prev_coords[1] = coords[1];
|
||||
devinfo->prev_time = rawev->time;
|
||||
@@ -347,7 +347,7 @@ int X11_HandleXinput2Event(SDL_VideoData *videodata, XGenericEventCookie *cookie
|
||||
if (!mouse->relative_mode || mouse->relative_mode_warp) {
|
||||
SDL_Window *window = xinput2_get_sdlwindow(videodata, xev->event);
|
||||
if (window) {
|
||||
SDL_SendMouseMotion(0, window, 0, 0, xev->event_x, xev->event_y);
|
||||
SDL_SendMouseMotion(0, window, 0, 0, (float)xev->event_x, (float)xev->event_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user