From 83ecf3f4fa9e245d792010614e6193ada804889d Mon Sep 17 00:00:00 2001 From: Xottab-DUTY Date: Sun, 5 Jan 2025 22:21:36 +0300 Subject: [PATCH] xrUICore: add helper functions to get window center position --- src/xrUICore/Windows/UIWindow.cpp | 2 +- src/xrUICore/Windows/UIWindow.h | 14 ++++++++++++-- src/xrUICore/uiabstract.h | 9 +++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/xrUICore/Windows/UIWindow.cpp b/src/xrUICore/Windows/UIWindow.cpp index 8cf5608e73c..c940abe8860 100644 --- a/src/xrUICore/Windows/UIWindow.cpp +++ b/src/xrUICore/Windows/UIWindow.cpp @@ -126,7 +126,7 @@ void CUIWindow::DetachAll() } } -void CUIWindow::GetAbsoluteRect(Frect& r) +void CUIWindow::GetAbsoluteRect(Frect& r) const { auto parent = GetParent(); if (parent == nullptr) diff --git a/src/xrUICore/Windows/UIWindow.h b/src/xrUICore/Windows/UIWindow.h index 6b8aab22f50..bb8f8127450 100644 --- a/src/xrUICore/Windows/UIWindow.h +++ b/src/xrUICore/Windows/UIWindow.h @@ -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); } diff --git a/src/xrUICore/uiabstract.h b/src/xrUICore/uiabstract.h index 54ba0e70bda..f2d38bd5e22 100644 --- a/src/xrUICore/uiabstract.h +++ b/src/xrUICore/uiabstract.h @@ -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; };