X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=blobdiff_plain;f=Usermode%2FApplications%2Faxwin4_src%2FServer%2FCRect.cpp;fp=Usermode%2FApplications%2Faxwin4_src%2FServer%2FCRect.cpp;h=acbcc27e30b3b7bb51a46089a5c168f1d88654a1;hp=0000000000000000000000000000000000000000;hb=845b6f9d90bb87b5e760e4d49aa93b0e003ab750;hpb=67a7fe2bb79eceaf10c572a99bd8345c4e81cf5b diff --git a/Usermode/Applications/axwin4_src/Server/CRect.cpp b/Usermode/Applications/axwin4_src/Server/CRect.cpp new file mode 100644 index 00000000..acbcc27e --- /dev/null +++ b/Usermode/Applications/axwin4_src/Server/CRect.cpp @@ -0,0 +1,78 @@ +/* + * Acess2 GUI v4 + * - By John Hodge (thePowersGang) + * + * CRect.cpp + * - Rectangle + */ +#include +#include +#include + +namespace AxWin { + +CRect::CRect(int x, int y, unsigned int w, unsigned int h): + m_x(x), m_y(y), + m_w(w), m_h(h), + m_x2(x+w), m_y2(y+h) +{ +} + +void CRect::Move(int NewX, int NewY) +{ + // TODO: Add a parent rectangle, and prevent this from fully leaving its bounds + m_x = NewX; + m_y = NewY; + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; +} + +void CRect::Resize(int NewW, int NewH) +{ + m_w = NewW; + m_h = NewH; + m_x2 = m_x + m_w; + m_y2 = m_y + m_h; +} + +bool CRect::HasIntersection(const CRect& other) const +{ + // If other's origin is past our far corner + if( m_x2 < other.m_x ) + return false; + if( m_y2 < other.m_y ) + return false; + + // If other's far corner is before our origin + if( m_x > other.m_x2 ) + return false; + if( m_y > other.m_y2 ) + return false; + return true; +} + +CRect CRect::Intersection(const CRect& other) const +{ + int x1 = ::std::max(m_x, other.m_x); + int y1 = ::std::max(m_y, other.m_y); + int x2 = ::std::min(m_x2, other.m_x2); + int y2 = ::std::min(m_y2, other.m_y2); + + if( x2 <= x1 || y2 <= y1 ) + return CRect(); + + return CRect(x1, y1, x2-x1, y2-y1); +} + +CRect CRect::RelativeIntersection(const CRect& area) +{ + CRect ret = Intersection(area); + ret.m_x -= m_x; + ret.m_x2 -= m_x; + ret.m_y -= m_y; + ret.m_y2 -= m_y; + return ret; +} + +}; +