/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include "ui_rect.h" void CUIRect::HSplitMid(CUIRect *pTop, CUIRect *pBottom, float Spacing) const { CUIRect r = *this; 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 - HalfSpacing; } if(pBottom) { pBottom->x = r.x; pBottom->y = r.y + Cut + HalfSpacing; pBottom->w = r.w; pBottom->h = r.h - Cut - HalfSpacing; } } void CUIRect::HSplitTop(float Cut, CUIRect *pTop, CUIRect *pBottom) const { CUIRect r = *this; if(pTop) { pTop->x = r.x; pTop->y = r.y; pTop->w = r.w; pTop->h = Cut; } if(pBottom) { pBottom->x = r.x; pBottom->y = r.y + Cut; pBottom->w = r.w; pBottom->h = r.h - Cut; } } void CUIRect::HSplitBottom(float Cut, CUIRect *pTop, CUIRect *pBottom) const { CUIRect r = *this; if(pTop) { pTop->x = r.x; pTop->y = r.y; pTop->w = r.w; pTop->h = r.h - Cut; } if(pBottom) { pBottom->x = r.x; pBottom->y = r.y + r.h - Cut; pBottom->w = r.w; pBottom->h = Cut; } } void CUIRect::VSplitMid(CUIRect *pLeft, CUIRect *pRight, float Spacing) const { CUIRect r = *this; const float Cut = r.w / 2; const float HalfSpacing = Spacing / 2; if(pLeft) { pLeft->x = r.x; pLeft->y = r.y; pLeft->w = Cut - HalfSpacing; pLeft->h = r.h; } if(pRight) { pRight->x = r.x + Cut + HalfSpacing; pRight->y = r.y; pRight->w = r.w - Cut - HalfSpacing; pRight->h = r.h; } } void CUIRect::VSplitLeft(float Cut, CUIRect *pLeft, CUIRect *pRight) const { CUIRect r = *this; if(pLeft) { pLeft->x = r.x; pLeft->y = r.y; pLeft->w = Cut; pLeft->h = r.h; } if(pRight) { pRight->x = r.x + Cut; pRight->y = r.y; pRight->w = r.w - Cut; pRight->h = r.h; } } void CUIRect::VSplitRight(float Cut, CUIRect *pLeft, CUIRect *pRight) const { CUIRect r = *this; if(pLeft) { pLeft->x = r.x; pLeft->y = r.y; pLeft->w = r.w - Cut; pLeft->h = r.h; } if(pRight) { pRight->x = r.x + r.w - Cut; pRight->y = r.y; pRight->w = Cut; pRight->h = r.h; } } void CUIRect::Margin(float 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; } 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; } 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; } bool CUIRect::Inside(float PointX, float PointY) const { return PointX >= x && PointX < x + w && PointY >= y && PointY < y + h; }