Skip to content

Commit

Permalink
CUICursor: ability to warp cursor to specific UI window position
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Aug 9, 2023
1 parent cce060b commit 1ef6b74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/xrUICore/Cursor/UICursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,23 @@ void CUICursor::SetUICursorPosition(Fvector2 pos)
p.y = iFloor(vPos.y / correction.y);
pInput->iSetMousePos(p);
}

void CUICursor::WarpToWindow(CUIWindow* wnd, bool change_visibility /*= true*/)
{
if (!wnd)
{
if (change_visibility)
Hide();
return;
}

if (!IsVisible() && change_visibility)
Show();

Fvector2 pos;
wnd->GetAbsolutePos(pos);
Fvector2 size = wnd->GetWndSize();
const Fvector2 sizeOfThird = Fvector2(size).div(3);
pos.add(size).sub(sizeOfThird);
SetUICursorPosition(pos);
}
1 change: 1 addition & 0 deletions src/xrUICore/Cursor/UICursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class XRUICORE_API CUICursor : public pureRender, public CDeviceResetNotifier, p

Fvector2 GetCursorPosition();
void SetUICursorPosition(Fvector2 pos);
void WarpToWindow(CUIWindow* wnd, bool change_visibility = true);
void UpdateCursorPosition(int _dx, int _dy);

void OnDeviceReset() override;
Expand Down

0 comments on commit 1ef6b74

Please sign in to comment.