update for HEAD-2003091401
[reactos.git] / subsys / win32k / objects / rect.c
1 /*
2  *  ReactOS W32 Subsystem
3  *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$ */
20 #include <windows.h>
21 #include <ddk/ntddk.h>
22 #include <win32k/region.h>
23 #include <win32k/gdiobj.h>
24 #include <include/rect.h>
25
26 #define NDEBUG
27 #include <win32k/debug1.h>
28
29 /* FUNCTIONS *****************************************************************/
30
31 BOOL STDCALL
32 NtGdiSetEmptyRect(PRECT Rect)
33 {
34   Rect->left = Rect->right = Rect->top = Rect->bottom = 0;
35   return(TRUE);
36 }
37
38 BOOL STDCALL
39 NtGdiIsEmptyRect(const RECT* Rect)
40 {
41   return(Rect->left >= Rect->right || Rect->top >= Rect->bottom);
42 }
43
44 BOOL STDCALL
45 NtGdiOffsetRect(LPRECT Rect, INT x, INT y)
46 {
47   Rect->left += x;
48   Rect->right += x;
49   Rect->top += y;
50   Rect->bottom += y;
51   return(TRUE);
52 }
53
54
55 BOOL STDCALL
56 NtGdiUnionRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
57 {
58   if (NtGdiIsEmptyRect(Src1))
59     {
60       if (NtGdiIsEmptyRect(Src2))
61         {
62           NtGdiSetEmptyRect(Dest);
63           return(FALSE);
64         }
65       else
66         {
67           *Dest = *Src2;
68         }
69     }
70   else
71     {
72       if (NtGdiIsEmptyRect(Src2))
73         {
74           *Dest = *Src1;
75         }
76       else
77         {
78           Dest->left = min(Src1->left, Src2->left);
79           Dest->top = min(Src1->top, Src2->top);
80           Dest->right = max(Src1->right, Src2->right);
81           Dest->bottom = max(Src1->bottom, Src2->bottom);
82         }
83     }
84   return(TRUE);
85 }
86
87 BOOL STDCALL
88 NtGdiSetRect(PRECT Rect, INT left, INT top, INT right, INT bottom)
89 {
90   Rect->left = left;
91   Rect->top = top;
92   Rect->right = right;
93   Rect->bottom = bottom;
94   return(TRUE);
95 }
96
97 BOOL STDCALL
98 NtGdiIntersectRect(PRECT Dest, const RECT* Src1, const RECT* Src2)
99 {
100   if (NtGdiIsEmptyRect(Src1) || NtGdiIsEmptyRect(Src2) ||
101       Src1->left >= Src2->right || Src2->left >= Src1->right ||
102       Src1->top >= Src2->bottom || Src2->top >= Src1->bottom)
103     {
104       NtGdiSetEmptyRect(Dest);
105       return(FALSE);
106     }
107   Dest->left = max(Src1->left, Src2->left);
108   Dest->right = min(Src1->right, Src2->right);
109   Dest->top = max(Src1->top, Src2->top);
110   Dest->bottom = min(Src1->bottom, Src2->bottom);
111   return(TRUE);
112 }
113 /* EOF */