-
Notifications
You must be signed in to change notification settings - Fork 0
/
aclip.cpp
92 lines (66 loc) · 2.11 KB
/
aclip.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "aclip.h"
void ein_clip::set(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
this->x1 = x1;
this->y1 = y1;
this->x2 = x2;
this->y2 = y2;
}
bool ein_clip::check_point(int32_t& x, int32_t& y)
{
x += xDatum;
y += yDatum;
if (x >= x2 || y >= y2) return false;
if (x < x1 || y < y1) return false;
return true;
}
bool ein_clip::check_block(block_t& z, const int32_t x0, const int32_t y0, const int32_t w, const int32_t h)
{
z.x = x0 + xDatum;
z.y = y0 + yDatum;
if (z.x >= x2 || z.y >= y2) return false;
z.dx = 0;
z.dy = 0;
z.dw = w;
z.dh = h;
if (z.x < x1) { z.dx = x1 - z.x; z.dw -= z.dx; z.x = x1; }
if (z.y < y1) { z.dy = y1 - z.y; z.dh -= z.dy; z.y = y1; }
if (z.x + z.dw > x2 ) z.dw = x2 - z.x;
if (z.y + z.dh > y2 ) z.dh = y2 - z.y;
if (z.dw < 1 || z.dh < 1) return false;
return true;
}
/***************************************************************************************
** Function name: clipWindow
** Description: Clip window xs,yx,xe,ye to screen and viewport
***************************************************************************************/
bool ein_clip::clipClip(int32_t& xs, int32_t& ys, int32_t& xe, int32_t& ye)
{
xs += xDatum;
ys += yDatum;
xe += xDatum;
ye += yDatum;
if ((xs >= x2) || (ys >= y2)) return false;
if ((xe < x1) || (ye < y1)) return false;
if (xs < x1) xs = x1;
if (ys < y1) ys = y1;
if (xe > x2) xe = x2 - 1;
if (ye > y2) ye = y2 - 1;
return true;
}
/***************************************************************************************
** Function name: clipAddrWindow
** Description: Clip address window x,y,w,h to screen and viewport
***************************************************************************************/
bool ein_clip::clipRect(int32_t& x, int32_t& y, int32_t& w, int32_t& h)
{
x+= xDatum;
y+= yDatum;
if ((x >= x2) || (y >= y2)) return false;
if (x < x1) { w += x - x1; x = x1; }
if (y < y1) { h += y - y1; y = y1; }
if ((x + w) > x2) w = x2 - x;
if ((y + h) > y2) h = y2 - y;
if ((w < 1) || (h < 1)) return false;
return true;
}