3c88969c1604973799d62c0f8f7f87756752190e
[reactos.git] / subsys / win32k / objects / rect.c
1 #include <windows.h>
2 #include <ddk/ntddk.h>
3 #include <win32k/region.h>
4 #include <win32k/gdiobj.h>
5 #include <include/rect.h>
6
7 //#define NDEBUG
8 #include <win32k/debug1.h>
9
10 /* FUNCTIONS *****************************************************************/
11
12 BOOL
13 W32kOffsetRect(LPRECT Rect, INT x, INT y)
14 {
15   Rect->left += x;
16   Rect->right += x;
17   Rect->top += y;
18   Rect->bottom += y;
19   return(TRUE);
20 }
21
22
23 BOOL STDCALL
24 W32kUnionRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
25 {
26   if (W32kIsEmptyRect(Src1))
27     {
28       if (W32kIsEmptyRect(Src2))
29         {
30           W32kSetEmptyRect(Dest);
31           return(FALSE);
32         }
33       else
34         {
35           *Dest = *Src2;
36         }
37     }
38   else
39     {
40       if (W32kIsEmptyRect(Src2))
41         {
42           *Dest = *Src1;
43         }
44       else
45         {
46           Dest->left = min(Src1->left, Src2->left);
47           Dest->top = min(Src1->top, Src2->top);
48           Dest->right = max(Src1->right, Src2->right);
49           Dest->bottom = max(Src1->bottom, Src2->bottom);
50         }
51     }
52   return(TRUE);
53 }
54
55 BOOL STDCALL
56 W32kSetEmptyRect(PRECT Rect)
57 {
58   Rect->left = Rect->right = Rect->top = Rect->bottom = 0;
59   return(TRUE);
60 }
61
62 BOOL STDCALL
63 W32kIsEmptyRect(PRECT Rect)
64 {
65   return(Rect->left >= Rect->right || Rect->top >= Rect->bottom);
66 }
67
68 BOOL STDCALL
69 W32kSetRect(PRECT Rect, INT left, INT top, INT right, INT bottom)
70 {
71   Rect->left = left;
72   Rect->top = top;
73   Rect->right = right;
74   Rect->bottom = bottom;
75   return(TRUE);
76 }
77
78 BOOL STDCALL
79 W32kIntersectRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
80 {
81   if (W32kIsEmptyRect(Src1) || W32kIsEmptyRect(Src2) ||
82       Src1->left >= Src2->right || Src2->left >= Src1->right ||
83       Src1->top >= Src2->bottom || Src2->top >= Src1->bottom)
84     {
85       W32kSetEmptyRect(Dest);
86       return(FALSE);
87     }
88   Dest->left = max(Src1->left, Src2->left);
89   Dest->right = min(Src1->right, Src2->right);
90   Dest->top = max(Src1->top, Src2->top);
91   Dest->bottom = min(Src1->bottom, Src2->bottom);
92   return(TRUE);
93 }