]> git.vomp.tv Git - vompclient.git/blob - region.cc
Compile fix for MVP re: location change of hmsf
[vompclient.git] / region.cc
1 #include "region.h"
2
3 Region::Region()
4 {
5   x = 0;
6   y = 0;
7   w = 0;
8   h = 0;
9   z = 0;
10 }
11
12 bool Region::overlappedBy(Region& d)
13 {
14   return
15   ( (d.x2() >= x) &&
16     (d.x <= x2()) &&
17     (d.y <= y2()) &&
18     (d.y2() >= y)    );
19 }
20
21 UINT Region::x2()
22 {
23   return x + w - 1;
24 }
25
26 UINT Region::y2()
27 {
28   return y + h - 1;
29 }
30
31 Region Region::operator + (Region& other)
32 {
33   Region toReturn;
34   
35   toReturn.x = (x <= other.x ? x : other.x);
36   toReturn.y = (y <= other.y ? y : other.y);
37   toReturn.w = ((x+w) >= (other.x+other.h) ? (x+w) : (other.x+other.h)) - toReturn.x;
38   toReturn.h = ((y+h) >= (other.y+other.h) ? (y+h) : (other.y+other.h)) - toReturn.y;
39   
40   return toReturn;
41 }
42     
43     
44
45 Region Region::subtract(Region& other)
46 {
47   //OK printf("This:           %i %i %i %i\n", x, y, w, h);
48   //OK printf("Subtract this:  %i %i %i %i\n", other.x, other.y, other.w, other.h);
49
50
51   Region s;
52
53   if (x < other.x)
54   {
55 //OK    printf("Case 1\n");
56     s.x = x;
57     s.y = y;
58     s.w = other.x - x;
59     s.h = h;
60   }
61   else if (x2() > other.x2())
62   {
63 //OK    printf("Case 2\n");
64     s.x = other.x2()+1;
65     s.y = y;
66     s.w = w - s.x;
67     s.h = h;
68   }
69   else if (y < other.y)
70   {
71 //OK    printf("Case 3\n");
72     s.x = x;
73     s.y = y;
74     s.w = w;
75     s.h = other.y - y;
76   }
77   else if (y2() > other.y2())
78   {
79 //OK    printf("Case 4\n");
80     s.x = x;
81     s.y = other.y2()+1;
82     s.w = w;
83     s.h = h - s.y;
84   }
85   else
86   {
87     s.x = 0;
88     s.y = 0;
89     s.w = 0;
90     s.h = 0;
91   }
92   //OK printf("Result:         %i %i %i %i\n", s.x, s.y, s.w, s.h);
93
94   return s;
95 }
96
97
98   //i.x = (x >= other.x ? x : other.x);
99   //i.y = (y >= other.y ? y : other.y);
100   //i.w = (x2() <= other.x2() ? x2() : other.x2()) - i.x;
101   //i.h = (y2() <= other.y2() ? y2() : other.y2()) - i.y;
102   //return i;