From 11b4b7806fa021c0a28ad81da0f6f43d3a0bbb32 Mon Sep 17 00:00:00 2001 From: ravi688 Date: Sat, 5 Oct 2024 04:40:54 +0530 Subject: [PATCH] [SUTK] Added AnchorRect::moveToCenterOfChild() utility function --- sutk/include/sutk/AnchorRect.hpp | 1 + sutk/source/AnchorRect.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/sutk/include/sutk/AnchorRect.hpp b/sutk/include/sutk/AnchorRect.hpp index 807283a5..327e3def 100644 --- a/sutk/include/sutk/AnchorRect.hpp +++ b/sutk/include/sutk/AnchorRect.hpp @@ -36,6 +36,7 @@ namespace SUTK // But it doesn't relcalculate if you change the child's Rect after this function call. // You have to call this function again if you do so. void fitToChildRect() noexcept; + void moveToCenterOfChild() noexcept; // setters diff --git a/sutk/source/AnchorRect.cpp b/sutk/source/AnchorRect.cpp index 4e6b8ab6..230cecbd 100644 --- a/sutk/source/AnchorRect.cpp +++ b/sutk/source/AnchorRect.cpp @@ -64,6 +64,17 @@ namespace SUTK setRect(anchorRect); } + void AnchorRect::moveToCenterOfChild() noexcept + { + _com_assert(m_childRect != NULL); + _com_assert(m_parentRect != NULL); + Rect2Df childRect = m_childRect->getRect(); + Vec2Df size = m_parentRect->getSize(); + Rect2Df anchorRect; + anchorRect.setPosition(childRect.getCenter() / size); + setRect(anchorRect); + } + void AnchorRect::setRect(Rect2Df rect) noexcept { m_rect = rect;