Dynamically on/off virtual cursor (#567)

*  feat: eliminate need of draw_cursor config

* 🩹 fix: type mismatch
This commit is contained in:
Helloyunho 2025-07-10 15:58:17 +09:00 committed by GitHub
parent 9d8cb64a19
commit 4e8ac86415
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 45 additions and 20 deletions

View File

@ -103,6 +103,7 @@ MxFloat g_lastJoystickMouseX = 0;
MxFloat g_lastJoystickMouseY = 0;
MxFloat g_lastMouseX = 320;
MxFloat g_lastMouseY = 240;
MxBool g_mouseWarped = FALSE;
bool g_dpadUp = false;
bool g_dpadDown = false;
@ -603,6 +604,10 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
break;
}
case SDL_EVENT_MOUSE_MOTION:
if (g_mouseWarped) {
g_mouseWarped = FALSE;
break;
}
#ifdef __EMSCRIPTEN__
if (detectedTouchEvents) {
break;
@ -619,9 +624,13 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
0
);
}
g_lastMouseX = event->motion.x;
g_lastMouseY = event->motion.y;
if (g_isle->GetDrawCursor()) {
VideoManager()->MoveCursor(Min((MxS32) event->motion.x, 639), Min((MxS32) event->motion.y, 479));
SDL_ShowCursor();
g_isle->SetDrawCursor(FALSE);
if (VideoManager()) {
VideoManager()->SetCursorBitmap(NULL);
}
break;
case SDL_EVENT_FINGER_MOTION: {
@ -633,12 +642,17 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
float x = SDL_clamp(event->tfinger.x, 0, 1) * 640;
float y = SDL_clamp(event->tfinger.y, 0, 1) * 480;
g_lastMouseX = x;
g_lastMouseY = y;
if (InputManager()) {
InputManager()->QueueEvent(c_notificationMouseMove, LegoEventNotificationParam::c_lButtonState, x, y, 0);
}
if (g_isle->GetDrawCursor()) {
VideoManager()->MoveCursor(Min((MxS32) x, 639), Min((MxS32) y, 479));
SDL_HideCursor();
g_isle->SetDrawCursor(FALSE);
if (VideoManager()) {
VideoManager()->SetCursorBitmap(NULL);
}
break;
}
@ -808,12 +822,9 @@ MxResult IsleApp::SetupWindow()
m_cursorBusy = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
m_cursorNo = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
SDL_SetCursor(m_cursorCurrent);
if (g_isle->GetDrawCursor()) {
SDL_HideCursor();
m_cursorCurrentBitmap = m_cursorArrowBitmap = &arrow_cursor;
m_cursorBusyBitmap = &busy_cursor;
m_cursorNoBitmap = &no_cursor;
}
m_cursorCurrentBitmap = m_cursorArrowBitmap = &arrow_cursor;
m_cursorBusyBitmap = &busy_cursor;
m_cursorNoBitmap = &no_cursor;
SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, g_targetWidth);
@ -897,7 +908,7 @@ MxResult IsleApp::SetupWindow()
LegoOmni::GetInstance()->GetInputManager()->SetUseJoystick(m_useJoystick);
LegoOmni::GetInstance()->GetInputManager()->SetJoystickIndex(m_joystickIndex);
}
if (LegoOmni::GetInstance()->GetVideoManager() && g_isle->GetDrawCursor()) {
if (LegoOmni::GetInstance()->GetVideoManager()) {
LegoOmni::GetInstance()->GetVideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
}
MxDirect3D* d3d = LegoOmni::GetInstance()->GetVideoManager()->GetDirect3D();
@ -990,7 +1001,6 @@ bool IsleApp::LoadConfig()
iniparser_set(dict, "isle:UseJoystick", m_useJoystick ? "true" : "false");
iniparser_set(dict, "isle:JoystickIndex", SDL_itoa(m_joystickIndex, buf, 10));
iniparser_set(dict, "isle:Draw Cursor", m_drawCursor ? "true" : "false");
SDL_snprintf(buf, sizeof(buf), "%f", m_cursorSensitivity);
iniparser_set(dict, "isle:Cursor Sensitivity", buf);
@ -1042,7 +1052,6 @@ bool IsleApp::LoadConfig()
m_useMusic = iniparser_getboolean(dict, "isle:Music", m_useMusic);
m_useJoystick = iniparser_getboolean(dict, "isle:UseJoystick", m_useJoystick);
m_joystickIndex = iniparser_getint(dict, "isle:JoystickIndex", m_joystickIndex);
m_drawCursor = iniparser_getboolean(dict, "isle:Draw Cursor", m_drawCursor);
m_cursorSensitivity = iniparser_getdouble(dict, "isle:Cursor Sensitivity", m_cursorSensitivity);
MxS32 backBuffersInVRAM = iniparser_getboolean(dict, "isle:Back Buffers in Video RAM", -1);
@ -1213,12 +1222,7 @@ void IsleApp::SetupCursor(Cursor p_cursor)
}
if (g_isle->GetDrawCursor()) {
if (m_cursorCurrentBitmap == NULL) {
VideoManager()->SetCursorBitmap(NULL);
}
else {
VideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
}
VideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
}
else {
if (m_cursorCurrent != NULL) {
@ -1392,8 +1396,18 @@ void IsleApp::MoveVirtualMouseViaJoystick()
);
}
if (g_isle->GetDrawCursor()) {
SDL_HideCursor();
g_isle->SetDrawCursor(TRUE);
if (VideoManager()) {
VideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
VideoManager()->MoveCursor(Min((MxS32) g_lastMouseX, 639), Min((MxS32) g_lastMouseY, 479));
}
IDirect3DRMMiniwinDevice* device = GetD3DRMMiniwinDevice();
if (device) {
Sint32 x, y;
device->ConvertRenderToWindowCoordinates(g_lastMouseX, g_lastMouseY, x, y);
g_mouseWarped = TRUE;
SDL_WarpMouseInWindow(window, x, y);
}
}
}

View File

@ -56,6 +56,7 @@ public:
void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
void SetGameStarted(MxS32 p_gameStarted) { m_gameStarted = p_gameStarted; }
void SetDrawCursor(MxS32 p_drawCursor) { m_drawCursor = p_drawCursor; }
MxResult ParseArguments(int argc, char** argv);
MxResult VerifyFilesystem();

View File

@ -6,4 +6,5 @@ DEFINE_GUID(IID_IDirect3DRMMiniwinDevice, 0x6eb09673, 0x8d30, 0x4d8a, 0x8d, 0x81
struct IDirect3DRMMiniwinDevice : virtual public IUnknown {
virtual bool ConvertEventToRenderCoordinates(SDL_Event* event) = 0;
virtual bool ConvertRenderToWindowCoordinates(Sint32 inX, Sint32 inY, Sint32& outX, Sint32& outY) = 0;
};

View File

@ -198,3 +198,11 @@ bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event)
return true;
}
bool Direct3DRMDevice2Impl::ConvertRenderToWindowCoordinates(Sint32 inX, Sint32 inY, Sint32& outX, Sint32& outY)
{
outX = static_cast<Sint32>(inX * m_viewportTransform.scale + m_viewportTransform.offsetX);
outY = static_cast<Sint32>(inY * m_viewportTransform.scale + m_viewportTransform.offsetY);
return true;
}

View File

@ -34,6 +34,7 @@ struct Direct3DRMDevice2Impl : public Direct3DRMObjectBaseImpl<IDirect3DRMDevice
// IDirect3DRMMiniwinDevice interface
bool ConvertEventToRenderCoordinates(SDL_Event* event) override;
bool ConvertRenderToWindowCoordinates(Sint32 inX, Sint32 inY, Sint32& outX, Sint32& outY) override;
Direct3DRMRenderer* m_renderer;