usermode/axwin4 - Blit to screen planned
[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 bool CRect::HasIntersection(const CRect& other) const
21 {
22         // If other's origin is past our far corner
23         if( m_x2 < other.m_x )
24                 return false;
25         if( m_y2 < other.m_y )
26                 return false;
27         
28         // If other's far corner is before our origin
29         if( m_x > other.m_x2 )
30                 return false;
31         if( m_y > other.m_y2 )
32                 return false;
33         return true;
34 }
35
36 CRect CRect::Intersection(const CRect& other) const
37 {
38         int x1 = ::std::max(m_x, other.m_x);
39         int y1 = ::std::max(m_y, other.m_y);
40         int x2 = ::std::min(m_x2, other.m_x2);
41         int y2 = ::std::min(m_y2, other.m_y2);
42         
43         if( x1 <= x2 || y2 <= y1 )
44                 return CRect();
45         
46         return CRect(x1, y1, x2-x1, y2-y2);
47 }
48
49 CRect CRect::RelativeIntersection(const CRect& area)
50 {
51         CRect   ret = Intersection(area);
52         ret.m_x -= m_x;
53         ret.m_x2 -= m_x;
54         ret.m_y -= m_y;
55         ret.m_y2 -= m_y;
56         return ret;
57 }
58
59 };
60

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