Skip to content

Commit

Permalink
Update game cursor visibility on any mouse event
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Dec 23, 2024
1 parent ca697e8 commit 482d6df
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
53 changes: 33 additions & 20 deletions src/xrGame/UIDialogHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,26 +233,7 @@ void CDialogHolder::OnFrame()

m_b_in_update = true;

if (m_is_foremost && !GEnv.isDedicatedServer)
{
auto& cursor = GetUICursor();
const bool need_cursor = TopInputReceiver() && TopInputReceiver()->NeedCursor();

const u32 cur_time = Device.dwTimeContinual;

if (need_cursor)
{
if (!cursor.IsVisible())
{
cursor.Show();
m_become_visible_time = cur_time;
}
}
else if (float(cur_time - m_become_visible_time) > (psControllerCursorAutohideTime * 1000.f))
{
cursor.Hide();
}
}
UpdateCursorVisibility();

CUIDialogWnd* wnd = TopInputReceiver();
if (wnd && wnd->IsEnabled())
Expand Down Expand Up @@ -288,6 +269,33 @@ void CDialogHolder::CleanInternals()
GetUICursor().Hide();
}

void CDialogHolder::UpdateCursorVisibility()
{
if (m_is_foremost && !GEnv.isDedicatedServer)
{
auto& cursor = GetUICursor();
const bool cursor_is_visible = cursor.IsVisible();
const bool need_cursor = TopInputReceiver() && TopInputReceiver()->NeedCursor();

const u32 cur_time = Device.dwTimeContinual;

// These conditions are optimal, don't reorder.
if (need_cursor)
{
if (!cursor_is_visible)
{
cursor.Show();
m_become_visible_time = cur_time;
}
}
else if (cursor_is_visible)
{
if (cur_time - m_become_visible_time > psControllerCursorAutohideTime * 1000.f)
cursor.Hide();
}
}
}

bool CDialogHolder::IR_UIOnKeyboardPress(int dik)
{
CUIDialogWnd* TIR = TopInputReceiver();
Expand Down Expand Up @@ -426,6 +434,8 @@ bool CDialogHolder::IR_UIOnMouseWheel(float x, float y)
if (!TIR->IR_process())
return false;

UpdateCursorVisibility();

// Vertical scroll is in higher priority
EUIMessages wheelMessage;
if (y > 0)
Expand All @@ -449,6 +459,9 @@ bool CDialogHolder::IR_UIOnMouseMove(int dx, int dy)
return false;
if (!TIR->IR_process())
return false;

UpdateCursorVisibility();

if (GetUICursor().IsVisible())
{
GetUICursor().UpdateCursorPosition(dx, dy);
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/UIDialogHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CDialogHolder : public pureFrame, public CUIDebuggable, public CUIFocusSys
protected:
void DoRenderDialogs();
void CleanInternals();
void UpdateCursorVisibility();

public:
CDialogHolder();
Expand Down

0 comments on commit 482d6df

Please sign in to comment.