diff --git a/src/game/client/ui_rect.cpp b/src/game/client/ui_rect.cpp index f9d0eb3aa..9f44a89f2 100644 --- a/src/game/client/ui_rect.cpp +++ b/src/game/client/ui_rect.cpp @@ -136,34 +136,29 @@ void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const } } -void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const +void CUIRect::Margin(vec2 Cut, CUIRect *pOtherRect) const { CUIRect r = *this; - pOtherRect->x = r.x + Cut; - pOtherRect->y = r.y + Cut; - pOtherRect->w = r.w - 2 * Cut; - pOtherRect->h = r.h - 2 * Cut; + pOtherRect->x = r.x + Cut.x; + pOtherRect->y = r.y + Cut.y; + pOtherRect->w = r.w - 2 * Cut.x; + pOtherRect->h = r.h - 2 * Cut.y; +} + +void CUIRect::Margin(float Cut, CUIRect *pOtherRect) const +{ + Margin(vec2(Cut, Cut), pOtherRect); } void CUIRect::VMargin(float Cut, CUIRect *pOtherRect) const { - CUIRect r = *this; - - pOtherRect->x = r.x + Cut; - pOtherRect->y = r.y; - pOtherRect->w = r.w - 2 * Cut; - pOtherRect->h = r.h; + Margin(vec2(Cut, 0.0f), pOtherRect); } void CUIRect::HMargin(float Cut, CUIRect *pOtherRect) const { - CUIRect r = *this; - - pOtherRect->x = r.x; - pOtherRect->y = r.y + Cut; - pOtherRect->w = r.w; - pOtherRect->h = r.h - 2 * Cut; + Margin(vec2(0.0f, Cut), pOtherRect); } bool CUIRect::Inside(float PointX, float PointY) const diff --git a/src/game/client/ui_rect.h b/src/game/client/ui_rect.h index 18143d1fd..c95067b52 100644 --- a/src/game/client/ui_rect.h +++ b/src/game/client/ui_rect.h @@ -81,6 +81,15 @@ public: */ void VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const; + /** + * Places pOtherRect inside *this* CUIRect with Cut as the margin. + * + * @param Cut The margin as a vec2. + * The x component applies to the vertical axis. + * The y component applies to the horizontal axis. + * @param pOtherRect The CUIRect to place inside *this* CUIRect. + */ + void Margin(vec2 Cut, CUIRect *pOtherRect) const; /** * Places pOtherRect inside *this* CUIRect with Cut as the margin. *