34013b1cbfa73f17296ebac9014535322144a485
[tpg/acess2.git] / Usermode / Applications / axwin4_src / Server / CRect.cpp
1 /*
2  * Acess2 GUI v4
3  * - By John Hodge (thePowersGang)
4  *
5  * CRect.cpp
6  * - Rectangle
7  */
8 #include <CRect.hpp>
9 #include <algorithm>
10
11 namespace AxWin {
12
13 CRect::CRect(int x, int y, unsigned int w, unsigned int h):
14         m_x(x), m_y(y),
15         m_w(w), m_h(h),
16         m_x2(x+w), m_y2(y+h)
17 {
18 }
19
20 void CRect::Move(int NewX, int NewY)
21 {
22         // TODO: Add a parent rectangle, and prevent this from fully leaving its bounds
23         m_x = NewX;
24         m_y = NewY;
25         m_x2 = m_x + m_w;
26         m_y2 = m_y + m_h;
27 }
28
29 bool CRect::HasIntersection(const CRect& other) const
30 {
31         // If other's origin is past our far corner
32         if( m_x2 < other.m_x )
33                 return false;
34         if( m_y2 < other.m_y )
35                 return false;
36         
37         // If other's far corner is before our origin
38         if( m_x > other.m_x2 )
39                 return false;
40         if( m_y > other.m_y2 )
41                 return false;
42         return true;
43 }
44
45 CRect CRect::Intersection(const CRect& other) const
46 {
47         int x1 = ::std::max(m_x, other.m_x);
48         int y1 = ::std::max(m_y, other.m_y);
49         int x2 = ::std::min(m_x2, other.m_x2);
50         int y2 = ::std::min(m_y2, other.m_y2);
51         
52         if( x1 <= x2 || y2 <= y1 )
53                 return CRect();
54         
55         return CRect(x1, y1, x2-x1, y2-y2);
56 }
57
58 CRect CRect::RelativeIntersection(const CRect& area)
59 {
60         CRect   ret = Intersection(area);
61         ret.m_x -= m_x;
62         ret.m_x2 -= m_x;
63         ret.m_y -= m_y;
64         ret.m_y2 -= m_y;
65         return ret;
66 }
67
68 };
69

UCC git Repository :: git.ucc.asn.au