2022-07-08 15:56:06 +00:00
|
|
|
/* (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"
|
|
|
|
|
2022-08-07 16:12:07 +00:00
|
|
|
#include <engine/graphics.h>
|
|
|
|
|
|
|
|
IGraphics *CUIRect::s_pGraphics = nullptr;
|
|
|
|
|
2022-07-08 15:56:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-08 16:02:26 +00:00
|
|
|
bool CUIRect::Inside(float PointX, float PointY) const
|
2022-07-08 15:56:06 +00:00
|
|
|
{
|
2022-07-08 16:02:26 +00:00
|
|
|
return PointX >= x && PointX < x + w && PointY >= y && PointY < y + h;
|
2022-07-08 15:56:06 +00:00
|
|
|
}
|
2022-08-07 16:12:07 +00:00
|
|
|
|
|
|
|
void CUIRect::Draw(ColorRGBA Color, int Corners, float Rounding) const
|
|
|
|
{
|
|
|
|
s_pGraphics->DrawRect(x, y, w, h, Color, Corners, Rounding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CUIRect::Draw4(ColorRGBA ColorTopLeft, ColorRGBA ColorTopRight, ColorRGBA ColorBottomLeft, ColorRGBA ColorBottomRight, int Corners, float Rounding) const
|
|
|
|
{
|
|
|
|
s_pGraphics->DrawRect4(x, y, w, h, ColorTopLeft, ColorTopRight, ColorBottomLeft, ColorBottomRight, Corners, Rounding);
|
|
|
|
}
|