Skip to content

Commit

Permalink
Changed meaning of CUICursor::WarpToWindow's second bool parameter
Browse files Browse the repository at this point in the history
There's no need to change visibility with automatic system in CDialogHolder now.
But it's useful to center cursor on something.
  • Loading branch information
Xottab-DUTY committed Jan 15, 2025
1 parent c586796 commit 74ce1f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/xrGame/ui/UIMapFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void CUIMapFilters::SelectFilter(bool select, bool next /*= true*/)
if (!select)
{
m_selected_filter = -1;
cursor.WarpToWindow(nullptr, pInput->IsCurrentInputTypeController());
cursor.WarpToWindow(nullptr);
}
else
{
Expand Down
25 changes: 12 additions & 13 deletions src/xrUICore/Cursor/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,27 @@ void CUICursor::UpdateCursorPosition(int _dx, int _dy)
clamp(vPos.y, 0.f, UI_BASE_HEIGHT);
}

void CUICursor::WarpToWindow(const CUIWindow* wnd, bool change_visibility /*= true*/)
void CUICursor::WarpToWindow(const CUIWindow* wnd, bool center /*= false*/)
{
// When change_visibility is true, call Show/Hide anyway
// to update autohide data
if (!wnd)
{
if (change_visibility)
Hide();
SetUICursorPosition({ UI_BASE_WIDTH / 2.0f, UI_BASE_HEIGHT / 2.0f });
return;
}

if (change_visibility)
Show();

if (!IsVisible())
return;

Fvector2 pos;
wnd->GetAbsolutePos(pos);
Fvector2 size = wnd->GetWndSize();
const Fvector2 sizeOfThird = Fvector2(size).div(3);
pos.add(size).sub(sizeOfThird);
if (center)
{
size.mul(0.5f);
pos.add(size);
}
else
{
const Fvector2 sizeOfThird = Fvector2(size).div(3.0f);
pos.add(size).sub(sizeOfThird);
}
SetUICursorPosition(pos);
}

Expand Down
2 changes: 1 addition & 1 deletion src/xrUICore/Cursor/UICursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class XRUICORE_API CUICursor : public pureRender, public CDeviceResetNotifier, p
void OnDeviceReset() override;
void OnUIReset() override;

void WarpToWindow(const CUIWindow* wnd, bool change_visibility = true);
void WarpToWindow(const CUIWindow* wnd, bool center = false);
void UpdateCursorPosition(int _dx, int _dy);

void SetUICursorPosition(Fvector2 pos);
Expand Down
2 changes: 1 addition & 1 deletion src/xrUICore/ui_focus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void CUIFocusSystem::Update(const CUIWindow* root)
void CUIFocusSystem::SetFocused(const CUIWindow* window)
{
m_current_focused = window;
UI().GetUICursor().WarpToWindow(window, true);
UI().GetUICursor().WarpToWindow(window);
}

std::pair<CUIWindow*, CUIWindow*> CUIFocusSystem::FindClosestFocusable(const Fvector2& from, FocusDirection direction) const
Expand Down

0 comments on commit 74ce1f8

Please sign in to comment.