Skip to content

Commit

Permalink
xrUICore: add helper functions to get window center position
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Jan 6, 2025
1 parent 7bc2453 commit 83ecf3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/xrUICore/Windows/UIWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void CUIWindow::DetachAll()
}
}

void CUIWindow::GetAbsoluteRect(Frect& r)
void CUIWindow::GetAbsoluteRect(Frect& r) const
{
auto parent = GetParent();
if (parent == nullptr)
Expand Down
14 changes: 12 additions & 2 deletions src/xrUICore/Windows/UIWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,24 @@ class XRUICORE_API CUIWindow : public CUISimpleWindow, public CUIDebuggable
void ShowChildren(bool show);

//абсолютные координаты
void GetAbsoluteRect(Frect& r);
IC void GetAbsolutePos(Fvector2& p)
void GetAbsoluteRect(Frect& r) const;

void GetAbsolutePos(Fvector2& p) const
{
Frect abs;
GetAbsoluteRect(abs);
p.set(abs.x1, abs.y1);
}

Fvector2 GetAbsoluteCenterPos() const
{
Frect abs;
GetAbsoluteRect(abs);
auto size = GetWndSize();
size.div(2.0f);
return { abs.x1 + size.x, abs.y1 + size.y };
}

void SetWndRect_script(Frect rect) { CUISimpleWindow::SetWndRect(rect); }
void SetWndPos_script(Fvector2 pos) { CUISimpleWindow::SetWndPos(pos); }
void SetWndSize_script(Fvector2 size) { CUISimpleWindow::SetWndSize(size); }
Expand Down
9 changes: 9 additions & 0 deletions src/xrUICore/uiabstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,26 @@ class CUISimpleWindow : public Noncopyable

virtual void SetWndPos(const Fvector2& pos) { m_wndPos.set(pos.x, pos.y); }
IC const Fvector2& GetWndPos() const { return m_wndPos; }

Fvector2 GetWndCenterPos() const
{
return { m_wndPos.x + m_wndSize.x / 2.0f, m_wndPos.y + m_wndSize.y / 2.0f, };
}

virtual void SetWndSize(const Fvector2& size) { m_wndSize = size; }
IC const Fvector2& GetWndSize() const { return m_wndSize; }

virtual void SetWndRect(const Frect& rect)
{
m_wndPos.set(rect.lt);
rect.getsize(m_wndSize);
}

virtual void SetHeight(float height) { m_wndSize.y = height; }
IC float GetHeight() const { return m_wndSize.y; }
virtual void SetWidth(float width) { m_wndSize.x = width; }
IC float GetWidth() const { return m_wndSize.x; }

IC void SetVisible(bool vis) { m_bShowMe = vis; }
IC bool GetVisible() const { return m_bShowMe; }
IC void SetAlignment(EWindowAlignment al) { m_alignment = al; };
Expand Down

0 comments on commit 83ecf3f

Please sign in to comment.