Add option for Never Hide Mouse Cursor

Instead of having a single GUI checkbox for "Always Hide Mouse Cursor",
I have instead opted to use radio buttons so the user can swap between
different states of mouse visibility. "Movement" is the default
behavior, "Never" will hide the mouse cursor the entire time the game is
running, and "Always" will keep the mouse cursor always visible.
This commit is contained in:
sowens99
2021-09-22 23:57:52 -04:00
parent 5145853351
commit 2aa400e72f
9 changed files with 99 additions and 36 deletions

View File

@ -83,7 +83,7 @@ RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent)
m_mouse_timer->setSingleShot(true);
setMouseTracking(true);
connect(&Settings::Instance(), &Settings::HideCursorChanged, this,
connect(&Settings::Instance(), &Settings::CursorVisibilityChanged, this,
&RenderWidget::OnHideCursorChanged);
connect(&Settings::Instance(), &Settings::LockCursorChanged, this,
&RenderWidget::OnLockCursorChanged);
@ -139,6 +139,7 @@ void RenderWidget::OnHideCursorChanged()
{
UpdateCursor();
}
void RenderWidget::OnLockCursorChanged()
{
SetCursorLocked(false);
@ -155,14 +156,16 @@ void RenderWidget::UpdateCursor()
// on top of the game window in the background
const bool keep_on_top = (windowFlags() & Qt::WindowStaysOnTopHint) != 0;
const bool should_hide =
Settings::Instance().GetHideCursor() &&
(Settings::Instance().GetCursorVisibility() == SConfig::ShowCursor::Never) &&
(keep_on_top || SConfig::GetInstance().m_BackgroundInput || isActiveWindow());
setCursor(should_hide ? Qt::BlankCursor : Qt::ArrowCursor);
}
else
{
setCursor((m_cursor_locked && Settings::Instance().GetHideCursor()) ? Qt::BlankCursor :
Qt::ArrowCursor);
setCursor((m_cursor_locked &&
Settings::Instance().GetCursorVisibility() == SConfig::ShowCursor::Never) ?
Qt::BlankCursor :
Qt::ArrowCursor);
}
}
@ -185,7 +188,8 @@ void RenderWidget::HandleCursorTimer()
{
if (!isActiveWindow())
return;
if (!Settings::Instance().GetLockCursor() || m_cursor_locked)
if ((!Settings::Instance().GetLockCursor() || m_cursor_locked) &&
Settings::Instance().GetCursorVisibility() == SConfig::ShowCursor::OnMovement)
{
setCursor(Qt::BlankCursor);
}
@ -268,7 +272,7 @@ void RenderWidget::SetCursorLocked(bool locked, bool follow_aspect_ratio)
{
m_cursor_locked = true;
if (Settings::Instance().GetHideCursor())
if (Settings::Instance().GetCursorVisibility() != SConfig::ShowCursor::Constantly)
{
setCursor(Qt::BlankCursor);
}
@ -370,7 +374,7 @@ bool RenderWidget::event(QEvent* event)
break;
case QEvent::MouseMove:
// Unhide on movement
if (!Settings::Instance().GetHideCursor())
if (Settings::Instance().GetCursorVisibility() == SConfig::ShowCursor::OnMovement)
{
setCursor(Qt::ArrowCursor);
m_mouse_timer->start(MOUSE_HIDE_DELAY);
@ -381,7 +385,8 @@ bool RenderWidget::event(QEvent* event)
break;
case QEvent::Show:
// Don't do if "stay on top" changed (or was true)
if (Settings::Instance().GetLockCursor() && Settings::Instance().GetHideCursor() &&
if (Settings::Instance().GetLockCursor() &&
Settings::Instance().GetCursorVisibility() != SConfig::ShowCursor::Constantly &&
!m_dont_lock_cursor_on_show)
{
// Auto lock when this window is shown (it was hidden)