From 7b464b94657fd8a5ac3853d69a8b4f3d27d68efc Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Fri, 22 Mar 2024 16:33:03 +0800 Subject: [PATCH] Overload ui SplitMid functions with tripple split --- src/game/client/ui_rect.cpp | 64 ++++++++++++++++++++++++++++++++++ src/game/client/ui_rect.h | 68 +++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) diff --git a/src/game/client/ui_rect.cpp b/src/game/client/ui_rect.cpp index 9f44a89f2..1c3e7430e 100644 --- a/src/game/client/ui_rect.cpp +++ b/src/game/client/ui_rect.cpp @@ -29,6 +29,38 @@ void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const } } +void CUIRect::HSpaceAround(CUIRect *pTop, CUIRect *pMiddle, CUIRect *pBottom, float Spacing) const +{ + CUIRect r = *this; + const float Cut = r.h / 3; + const float HalfSpacing = Spacing / 2; + const float Height = Cut - Spacing; + + if(pTop) + { + pTop->x = r.x; + pTop->y = r.y + HalfSpacing; + pTop->w = r.w; + pTop->h = Height; + } + + if(pMiddle) + { + pMiddle->x = r.x; + pMiddle->y = r.y + Cut + HalfSpacing; + pMiddle->w = r.w; + pMiddle->h = Height; + } + + if(pBottom) + { + pBottom->x = r.x; + pBottom->y = r.y + Cut * 2 + HalfSpacing; + pBottom->w = r.w; + pBottom->h = Height; + } +} + void CUIRect::HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const { CUIRect r = *this; @@ -94,6 +126,38 @@ void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing) const } } +void CUIRect::VSpaceAround(CUIRect *pLeft, CUIRect *pMiddle, CUIRect *pRight, float Spacing) const +{ + CUIRect r = *this; + const float Cut = r.w / 3; + const float HalfSpacing = Spacing / 2; + const float Width = Cut - Spacing; + + if(pLeft) + { + pLeft->x = r.x + HalfSpacing; + pLeft->y = r.y; + pLeft->w = Width; + pLeft->h = r.h; + } + + if(pMiddle) + { + pMiddle->x = r.x + Cut + HalfSpacing; + pMiddle->y = r.y; + pMiddle->w = Width; + pMiddle->h = r.h; + } + + if(pRight) + { + pRight->x = r.x + Cut * 2 + HalfSpacing; + pRight->y = r.y; + pRight->w = Width; + pRight->h = r.h; + } +} + void CUIRect::VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const { CUIRect r = *this; diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h index 9d1558188..d5ca7d936 100644 --- a/src/game/client/ui_rect.h +++ b/src/game/client/ui_rect.h @@ -18,12 +18,53 @@ public: /** * Splits 2 CUIRect inside *this* CUIRect horizontally. You can pass null pointers. + * The spacing will be applied between the pTop and pBottom while both stay attached to *this* + * + * @verbatim + * +---------------+ + * |+-------------+| + * || pTop || + * |+-------------+| + * | *this* | + * |+-------------+| + * || pBottom || + * |+-------------+| + * +---------------+ + * @endverbatim * * @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, float Spacing = 0.0f) const; + /** + * Splits 3 CUIRect inside *this* CUIRect horizontally. You can pass null pointers. + * The spacing will be applied between the pTop, pMiddle, pBottom and also the *this* + * + * @verbatim + * +---------------+ + * | *this* | + * |+-------------+| + * || pTop || + * |+-------------+| + * | | + * |+-------------+| + * || pMiddle || + * |+-------------+| + * | | + * |+-------------+| + * || pBottom || + * |+-------------+| + * | | + * +---------------+ + * @endverbatim + * + * @param pTop This rect will end up taking the top third of this CUIRect. + * @param pMiddle This rect will end up taking the middle third of this CUIRect. + * @param pBottom This rect will end up taking the bottom third of this CUIRect. + * @param Spacing Total size of margin between split rects. + */ + void HSpaceAround(CUIRect *pTop, CUIRect *pMiddle, CUIRect *pBottom, float Spacing = 0.0f) const; /** * Splits 2 CUIRect inside *this* CUIRect. * @@ -50,12 +91,39 @@ public: void HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const; /** * Splits 2 CUIRect inside *this* CUIRect vertically. You can pass null pointers. + * The spacing will be applied between the pLeft and pRight while both stay attached to *this* + * + * @verbatim + * +--------------------------+ + * |+-------+ +-------+| + * || pLeft | *this* | pRight|| + * |+-------+ +-------+| + * +--------------------------+ + * @endverbatim * * @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, float Spacing = 0.0f) const; + /** + * Splits 3 CUIRect inside *this* CUIRect vertically. You can pass null pointers. + * The spacing will be applied between the pLeft, pMiddle, pRight and also the *this* + * + * @verbatim + * +--------------------------------------------------------------+ + * | +--------+ +--------+ +--------+ | + * | *this* | pLeft | | pMiddle| | pRight | | + * | +--------+ +--------+ +--------+ | + * +--------------------------------------------------------------+ + * @endverbatim + * + * @param pLeft This rect will take up the left third of *this* CUIRect. + * @param pMiddle This rect will take up the middle third of *this* CUIRect. + * @param pRight This rect will take up the right third of *this* CUIRect. + * @param Spacing Total size of margin between split rects. + */ + void VSpaceAround(CUIRect *pLeft, CUIRect *pMiddle, CUIRect *pRight, float Spacing = 0.0f) const; /** * Splits 2 CUIRect inside *this* CUIRect. *