ddnet/src/game/client/ui_rect.cpp

169 lines
2.9 KiB
C++
Raw Normal View History

/* (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 x_, float y_) const
{
return x_ >= this->x && x_ < this->x + this->w && y_ >= this->y && y_ < this->y + this->h;
}