From 91887f926b41be716ac2550375f0f9c1848f0932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Wed, 23 Aug 2023 02:47:14 +0200 Subject: [PATCH] 'Mouse.RelX' and 'Mouse.RelY' are two new properties that return how much the mouse cursor has moved. [GB.SDL2] * NEW: 'Mouse.RelX' and 'Mouse.RelY' are two new properties that return how much the mouse cursor has moved. --- gb.sdl2/src/c_mouse.c | 21 +++++++++++++++++++++ gb.sdl2/src/c_mouse.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/gb.sdl2/src/c_mouse.c b/gb.sdl2/src/c_mouse.c index b24e32a63..b40f95da6 100644 --- a/gb.sdl2/src/c_mouse.c +++ b/gb.sdl2/src/c_mouse.c @@ -47,11 +47,16 @@ static void update_event() _info = info = &window->mouse; + info->xrel = 0; + info->yrel = 0; + switch (_current->type) { case SDL_MOUSEMOTION: info->x = _current->motion.x; info->y = _current->motion.y; + info->xrel = _current->motion.xrel; + info->yrel = _current->motion.yrel; info->wheel_x = 0; info->wheel_y = 0; info->state = _current->motion.state; @@ -137,6 +142,20 @@ BEGIN_PROPERTY(Mouse_Y) END_PROPERTY +BEGIN_PROPERTY(Mouse_RelX) + + CHECK_EVENT(); + GB.ReturnInteger(_info->xrel); + +END_PROPERTY + +BEGIN_PROPERTY(Mouse_RelY) + + CHECK_EVENT(); + GB.ReturnInteger(_info->yrel); + +END_PROPERTY + BEGIN_PROPERTY(Mouse_WheelX) CHECK_EVENT(); @@ -259,6 +278,8 @@ GB_DESC MouseDesc[] = GB_STATIC_PROPERTY_READ("StartY", "i", Mouse_StartY), GB_STATIC_PROPERTY_READ("X", "i", Mouse_X), GB_STATIC_PROPERTY_READ("Y", "i", Mouse_Y), + GB_STATIC_PROPERTY_READ("RelX", "i", Mouse_RelX), + GB_STATIC_PROPERTY_READ("RelY", "i", Mouse_RelY), GB_STATIC_PROPERTY_READ("WheelX", "i", Mouse_WheelX), GB_STATIC_PROPERTY_READ("WheelY", "i", Mouse_WheelY), diff --git a/gb.sdl2/src/c_mouse.h b/gb.sdl2/src/c_mouse.h index 2f1199438..a53136939 100644 --- a/gb.sdl2/src/c_mouse.h +++ b/gb.sdl2/src/c_mouse.h @@ -34,6 +34,8 @@ typedef struct { int x; int y; + int xrel; + int yrel; int wheel_x; int wheel_y; int state;