Kernel/VTerm - Add 2DCmd push image support
[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 void CRect::Resize(int NewW, int NewH)
30 {
31         m_w = NewW;
32         m_h = NewH;
33         m_x2 = m_x + m_w;
34         m_y2 = m_y + m_h;
35 }
36
37 bool CRect::HasIntersection(const CRect& other) const
38 {
39         // If other's origin is past our far corner
40         if( m_x2 < other.m_x )
41                 return false;
42         if( m_y2 < other.m_y )
43                 return false;
44         
45         // If other's far corner is before our origin
46         if( m_x > other.m_x2 )
47                 return false;
48         if( m_y > other.m_y2 )
49                 return false;
50         return true;
51 }
52
53 CRect CRect::Intersection(const CRect& other) const
54 {
55         int x1 = ::std::max(m_x, other.m_x);
56         int y1 = ::std::max(m_y, other.m_y);
57         int x2 = ::std::min(m_x2, other.m_x2);
58         int y2 = ::std::min(m_y2, other.m_y2);
59         
60         if( x1 <= x2 || y2 <= y1 )
61                 return CRect();
62         
63         return CRect(x1, y1, x2-x1, y2-y2);
64 }
65
66 CRect CRect::RelativeIntersection(const CRect& area)
67 {
68         CRect   ret = Intersection(area);
69         ret.m_x -= m_x;
70         ret.m_x2 -= m_x;
71         ret.m_y -= m_y;
72         ret.m_y2 -= m_y;
73         return ret;
74 }
75
76 };
77

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