From 4fbca828f40ec39d9d30d19d1ca68c34ba814e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 26 Jan 2022 20:19:25 +0100 Subject: [PATCH] Add optional Spacing parameter to H/VSplitMid --- src/game/client/ui.cpp | 23 ++++++++++++----------- src/game/client/ui.h | 10 ++++++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 64ae48d25..bdf5d2a9a 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -216,25 +216,26 @@ void CUI::ClipDisable() Graphics()->ClipDisable(); } -void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom) const +void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const { CUIRect r = *this; - float Cut = r.h / 2; + const float Cut = r.h / 2; + const float HalfSpacing = Spacing / 2; if(pTop) { pTop->x = r.x; pTop->y = r.y; pTop->w = r.w; - pTop->h = Cut; + pTop->h = Cut - HalfSpacing; } if(pBottom) { pBottom->x = r.x; - pBottom->y = r.y + Cut; + pBottom->y = r.y + Cut + HalfSpacing; pBottom->w = r.w; - pBottom->h = r.h - Cut; + pBottom->h = r.h - Cut - HalfSpacing; } } @@ -282,25 +283,25 @@ void CUIRect::HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const } } -void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight) const +void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing) const { CUIRect r = *this; - float Cut = r.w / 2; - // Cut *= Scale(); + const float Cut = r.w / 2; + const float HalfSpacing = Spacing / 2; if(pLeft) { pLeft->x = r.x; pLeft->y = r.y; - pLeft->w = Cut; + pLeft->w = Cut - HalfSpacing; pLeft->h = r.h; } if(pRight) { - pRight->x = r.x + Cut; + pRight->x = r.x + Cut + HalfSpacing; pRight->y = r.y; - pRight->w = r.w - Cut; + pRight->w = r.w - Cut - HalfSpacing; pRight->h = r.h; } } diff --git a/src/game/client/ui.h b/src/game/client/ui.h index 85a2c09b2..fccd7d4f0 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -19,10 +19,11 @@ public: /** * Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers. * - * @param pTop This rect will end up taking the top half of this CUIRect - * @param pBottom This rect will end up taking the bottom half of this CUIRect + * @param pTop This rect will end up taking the top half of this CUIRect. + * @param pBottom This rect will end up taking the bottom half of this CUIRect. + * @param Spacing Total size of margin between split rects. */ - void HSplitMid(CUIRect *pTop, CUIRect *pBottom) const; + void HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing = 0.0f) const; /** * Splits 2 CUIRect inside *this* CUIRect. * @@ -52,8 +53,9 @@ public: * * @param pLeft This rect will take up the left half of *this* CUIRect. * @param pRight This rect will take up the right half of *this* CUIRect. + * @param Spacing Total size of margin between split rects. */ - void VSplitMid(CUIRect *pLeft, CUIRect *pRight) const; + void VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing = 0.0f) const; /** * Splits 2 CUIRect inside *this* CUIRect. *