8a78d90265cfbe1c288b27d19f9c763dd47cf7cd
[reactos.git] / reactos / win32ss / user / winsrv / consrv / include / rect.h
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: consrv/include/rect.h
5 * PURPOSE: Rectangle helper functions
6 * PROGRAMMERS: Gé van Geldorp
7 * Jeffrey Morlan
8 */
9
10 #pragma once
11
12 #define ConioInitRect(Rect, top, left, bottom, right) \
13 do { \
14 ((Rect)->Top) = top; \
15 ((Rect)->Left) = left; \
16 ((Rect)->Bottom) = bottom; \
17 ((Rect)->Right) = right; \
18 } while (0)
19 #define ConioIsRectEmpty(Rect) \
20 (((Rect)->Left > (Rect)->Right) || ((Rect)->Top > (Rect)->Bottom))
21
22 #define ConioRectHeight(Rect) \
23 (((Rect)->Top) > ((Rect)->Bottom) ? 0 : ((Rect)->Bottom) - ((Rect)->Top) + 1)
24 #define ConioRectWidth(Rect) \
25 (((Rect)->Left) > ((Rect)->Right) ? 0 : ((Rect)->Right) - ((Rect)->Left) + 1)
26
27
28 static __inline BOOLEAN
29 ConioGetIntersection(OUT PSMALL_RECT Intersection,
30 IN PSMALL_RECT Rect1,
31 IN PSMALL_RECT Rect2)
32 {
33 if ( ConioIsRectEmpty(Rect1) ||
34 ConioIsRectEmpty(Rect2) ||
35 (Rect1->Top > Rect2->Bottom) ||
36 (Rect1->Left > Rect2->Right) ||
37 (Rect1->Bottom < Rect2->Top) ||
38 (Rect1->Right < Rect2->Left) )
39 {
40 /* The rectangles do not intersect */
41 ConioInitRect(Intersection, 0, -1, 0, -1);
42 return FALSE;
43 }
44
45 ConioInitRect(Intersection,
46 max(Rect1->Top , Rect2->Top ),
47 max(Rect1->Left , Rect2->Left ),
48 min(Rect1->Bottom, Rect2->Bottom),
49 min(Rect1->Right , Rect2->Right ));
50
51 return TRUE;
52 }
53
54 static __inline BOOLEAN
55 ConioGetUnion(OUT PSMALL_RECT Union,
56 IN PSMALL_RECT Rect1,
57 IN PSMALL_RECT Rect2)
58 {
59 if (ConioIsRectEmpty(Rect1))
60 {
61 if (ConioIsRectEmpty(Rect2))
62 {
63 ConioInitRect(Union, 0, -1, 0, -1);
64 return FALSE;
65 }
66 else
67 {
68 *Union = *Rect2;
69 }
70 }
71 else if (ConioIsRectEmpty(Rect2))
72 {
73 *Union = *Rect1;
74 }
75 else
76 {
77 ConioInitRect(Union,
78 min(Rect1->Top , Rect2->Top ),
79 min(Rect1->Left , Rect2->Left ),
80 max(Rect1->Bottom, Rect2->Bottom),
81 max(Rect1->Right , Rect2->Right ));
82 }
83
84 return TRUE;
85 }