mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 18:41:14 +00:00
Dynamically on/off virtual cursor (#567)
* ✨ feat: eliminate need of draw_cursor config * 🩹 fix: type mismatch
This commit is contained in:
parent
9d8cb64a19
commit
4e8ac86415
@ -103,6 +103,7 @@ MxFloat g_lastJoystickMouseX = 0;
|
|||||||
MxFloat g_lastJoystickMouseY = 0;
|
MxFloat g_lastJoystickMouseY = 0;
|
||||||
MxFloat g_lastMouseX = 320;
|
MxFloat g_lastMouseX = 320;
|
||||||
MxFloat g_lastMouseY = 240;
|
MxFloat g_lastMouseY = 240;
|
||||||
|
MxBool g_mouseWarped = FALSE;
|
||||||
|
|
||||||
bool g_dpadUp = false;
|
bool g_dpadUp = false;
|
||||||
bool g_dpadDown = false;
|
bool g_dpadDown = false;
|
||||||
@ -603,6 +604,10 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_EVENT_MOUSE_MOTION:
|
case SDL_EVENT_MOUSE_MOTION:
|
||||||
|
if (g_mouseWarped) {
|
||||||
|
g_mouseWarped = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
if (detectedTouchEvents) {
|
if (detectedTouchEvents) {
|
||||||
break;
|
break;
|
||||||
@ -619,9 +624,13 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event)
|
|||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
g_lastMouseX = event->motion.x;
|
||||||
|
g_lastMouseY = event->motion.y;
|
||||||
|
|
||||||
if (g_isle->GetDrawCursor()) {
|
SDL_ShowCursor();
|
||||||
VideoManager()->MoveCursor(Min((MxS32) event->motion.x, 639), Min((MxS32) event->motion.y, 479));
|
g_isle->SetDrawCursor(FALSE);
|
||||||
|
if (VideoManager()) {
|
||||||
|
VideoManager()->SetCursorBitmap(NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_FINGER_MOTION: {
|
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 x = SDL_clamp(event->tfinger.x, 0, 1) * 640;
|
||||||
float y = SDL_clamp(event->tfinger.y, 0, 1) * 480;
|
float y = SDL_clamp(event->tfinger.y, 0, 1) * 480;
|
||||||
|
|
||||||
|
g_lastMouseX = x;
|
||||||
|
g_lastMouseY = y;
|
||||||
|
|
||||||
if (InputManager()) {
|
if (InputManager()) {
|
||||||
InputManager()->QueueEvent(c_notificationMouseMove, LegoEventNotificationParam::c_lButtonState, x, y, 0);
|
InputManager()->QueueEvent(c_notificationMouseMove, LegoEventNotificationParam::c_lButtonState, x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (g_isle->GetDrawCursor()) {
|
SDL_HideCursor();
|
||||||
VideoManager()->MoveCursor(Min((MxS32) x, 639), Min((MxS32) y, 479));
|
g_isle->SetDrawCursor(FALSE);
|
||||||
|
if (VideoManager()) {
|
||||||
|
VideoManager()->SetCursorBitmap(NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -808,12 +822,9 @@ MxResult IsleApp::SetupWindow()
|
|||||||
m_cursorBusy = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
m_cursorBusy = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
|
||||||
m_cursorNo = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
|
m_cursorNo = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NOT_ALLOWED);
|
||||||
SDL_SetCursor(m_cursorCurrent);
|
SDL_SetCursor(m_cursorCurrent);
|
||||||
if (g_isle->GetDrawCursor()) {
|
|
||||||
SDL_HideCursor();
|
|
||||||
m_cursorCurrentBitmap = m_cursorArrowBitmap = &arrow_cursor;
|
m_cursorCurrentBitmap = m_cursorArrowBitmap = &arrow_cursor;
|
||||||
m_cursorBusyBitmap = &busy_cursor;
|
m_cursorBusyBitmap = &busy_cursor;
|
||||||
m_cursorNoBitmap = &no_cursor;
|
m_cursorNoBitmap = &no_cursor;
|
||||||
}
|
|
||||||
|
|
||||||
SDL_PropertiesID props = SDL_CreateProperties();
|
SDL_PropertiesID props = SDL_CreateProperties();
|
||||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, g_targetWidth);
|
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()->SetUseJoystick(m_useJoystick);
|
||||||
LegoOmni::GetInstance()->GetInputManager()->SetJoystickIndex(m_joystickIndex);
|
LegoOmni::GetInstance()->GetInputManager()->SetJoystickIndex(m_joystickIndex);
|
||||||
}
|
}
|
||||||
if (LegoOmni::GetInstance()->GetVideoManager() && g_isle->GetDrawCursor()) {
|
if (LegoOmni::GetInstance()->GetVideoManager()) {
|
||||||
LegoOmni::GetInstance()->GetVideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
|
LegoOmni::GetInstance()->GetVideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
|
||||||
}
|
}
|
||||||
MxDirect3D* d3d = LegoOmni::GetInstance()->GetVideoManager()->GetDirect3D();
|
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:UseJoystick", m_useJoystick ? "true" : "false");
|
||||||
iniparser_set(dict, "isle:JoystickIndex", SDL_itoa(m_joystickIndex, buf, 10));
|
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);
|
SDL_snprintf(buf, sizeof(buf), "%f", m_cursorSensitivity);
|
||||||
iniparser_set(dict, "isle:Cursor Sensitivity", buf);
|
iniparser_set(dict, "isle:Cursor Sensitivity", buf);
|
||||||
|
|
||||||
@ -1042,7 +1052,6 @@ bool IsleApp::LoadConfig()
|
|||||||
m_useMusic = iniparser_getboolean(dict, "isle:Music", m_useMusic);
|
m_useMusic = iniparser_getboolean(dict, "isle:Music", m_useMusic);
|
||||||
m_useJoystick = iniparser_getboolean(dict, "isle:UseJoystick", m_useJoystick);
|
m_useJoystick = iniparser_getboolean(dict, "isle:UseJoystick", m_useJoystick);
|
||||||
m_joystickIndex = iniparser_getint(dict, "isle:JoystickIndex", m_joystickIndex);
|
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);
|
m_cursorSensitivity = iniparser_getdouble(dict, "isle:Cursor Sensitivity", m_cursorSensitivity);
|
||||||
|
|
||||||
MxS32 backBuffersInVRAM = iniparser_getboolean(dict, "isle:Back Buffers in Video RAM", -1);
|
MxS32 backBuffersInVRAM = iniparser_getboolean(dict, "isle:Back Buffers in Video RAM", -1);
|
||||||
@ -1213,13 +1222,8 @@ void IsleApp::SetupCursor(Cursor p_cursor)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_isle->GetDrawCursor()) {
|
if (g_isle->GetDrawCursor()) {
|
||||||
if (m_cursorCurrentBitmap == NULL) {
|
|
||||||
VideoManager()->SetCursorBitmap(NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
VideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
|
VideoManager()->SetCursorBitmap(m_cursorCurrentBitmap);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (m_cursorCurrent != NULL) {
|
if (m_cursorCurrent != NULL) {
|
||||||
SDL_SetCursor(m_cursorCurrent);
|
SDL_SetCursor(m_cursorCurrent);
|
||||||
@ -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));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@ class IsleApp {
|
|||||||
|
|
||||||
void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
|
void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
|
||||||
void SetGameStarted(MxS32 p_gameStarted) { m_gameStarted = p_gameStarted; }
|
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 ParseArguments(int argc, char** argv);
|
||||||
MxResult VerifyFilesystem();
|
MxResult VerifyFilesystem();
|
||||||
|
|||||||
@ -6,4 +6,5 @@ DEFINE_GUID(IID_IDirect3DRMMiniwinDevice, 0x6eb09673, 0x8d30, 0x4d8a, 0x8d, 0x81
|
|||||||
|
|
||||||
struct IDirect3DRMMiniwinDevice : virtual public IUnknown {
|
struct IDirect3DRMMiniwinDevice : virtual public IUnknown {
|
||||||
virtual bool ConvertEventToRenderCoordinates(SDL_Event* event) = 0;
|
virtual bool ConvertEventToRenderCoordinates(SDL_Event* event) = 0;
|
||||||
|
virtual bool ConvertRenderToWindowCoordinates(Sint32 inX, Sint32 inY, Sint32& outX, Sint32& outY) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -198,3 +198,11 @@ bool Direct3DRMDevice2Impl::ConvertEventToRenderCoordinates(SDL_Event* event)
|
|||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -34,6 +34,7 @@ struct Direct3DRMDevice2Impl : public Direct3DRMObjectBaseImpl<IDirect3DRMDevice
|
|||||||
|
|
||||||
// IDirect3DRMMiniwinDevice interface
|
// IDirect3DRMMiniwinDevice interface
|
||||||
bool ConvertEventToRenderCoordinates(SDL_Event* event) override;
|
bool ConvertEventToRenderCoordinates(SDL_Event* event) override;
|
||||||
|
bool ConvertRenderToWindowCoordinates(Sint32 inX, Sint32 inY, Sint32& outX, Sint32& outY) override;
|
||||||
|
|
||||||
Direct3DRMRenderer* m_renderer;
|
Direct3DRMRenderer* m_renderer;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user