Skip to content

Commit 482d6df

Browse files
committed
Update game cursor visibility on any mouse event
1 parent ca697e8 commit 482d6df

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/xrGame/UIDialogHolder.cpp

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -233,26 +233,7 @@ void CDialogHolder::OnFrame()
233233

234234
m_b_in_update = true;
235235

236-
if (m_is_foremost && !GEnv.isDedicatedServer)
237-
{
238-
auto& cursor = GetUICursor();
239-
const bool need_cursor = TopInputReceiver() && TopInputReceiver()->NeedCursor();
240-
241-
const u32 cur_time = Device.dwTimeContinual;
242-
243-
if (need_cursor)
244-
{
245-
if (!cursor.IsVisible())
246-
{
247-
cursor.Show();
248-
m_become_visible_time = cur_time;
249-
}
250-
}
251-
else if (float(cur_time - m_become_visible_time) > (psControllerCursorAutohideTime * 1000.f))
252-
{
253-
cursor.Hide();
254-
}
255-
}
236+
UpdateCursorVisibility();
256237

257238
CUIDialogWnd* wnd = TopInputReceiver();
258239
if (wnd && wnd->IsEnabled())
@@ -288,6 +269,33 @@ void CDialogHolder::CleanInternals()
288269
GetUICursor().Hide();
289270
}
290271

272+
void CDialogHolder::UpdateCursorVisibility()
273+
{
274+
if (m_is_foremost && !GEnv.isDedicatedServer)
275+
{
276+
auto& cursor = GetUICursor();
277+
const bool cursor_is_visible = cursor.IsVisible();
278+
const bool need_cursor = TopInputReceiver() && TopInputReceiver()->NeedCursor();
279+
280+
const u32 cur_time = Device.dwTimeContinual;
281+
282+
// These conditions are optimal, don't reorder.
283+
if (need_cursor)
284+
{
285+
if (!cursor_is_visible)
286+
{
287+
cursor.Show();
288+
m_become_visible_time = cur_time;
289+
}
290+
}
291+
else if (cursor_is_visible)
292+
{
293+
if (cur_time - m_become_visible_time > psControllerCursorAutohideTime * 1000.f)
294+
cursor.Hide();
295+
}
296+
}
297+
}
298+
291299
bool CDialogHolder::IR_UIOnKeyboardPress(int dik)
292300
{
293301
CUIDialogWnd* TIR = TopInputReceiver();
@@ -426,6 +434,8 @@ bool CDialogHolder::IR_UIOnMouseWheel(float x, float y)
426434
if (!TIR->IR_process())
427435
return false;
428436

437+
UpdateCursorVisibility();
438+
429439
// Vertical scroll is in higher priority
430440
EUIMessages wheelMessage;
431441
if (y > 0)
@@ -449,6 +459,9 @@ bool CDialogHolder::IR_UIOnMouseMove(int dx, int dy)
449459
return false;
450460
if (!TIR->IR_process())
451461
return false;
462+
463+
UpdateCursorVisibility();
464+
452465
if (GetUICursor().IsVisible())
453466
{
454467
GetUICursor().UpdateCursorPosition(dx, dy);

src/xrGame/UIDialogHolder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class CDialogHolder : public pureFrame, public CUIDebuggable, public CUIFocusSys
4949
protected:
5050
void DoRenderDialogs();
5151
void CleanInternals();
52+
void UpdateCursorVisibility();
5253

5354
public:
5455
CDialogHolder();

0 commit comments

Comments
 (0)