ba44d7a31c834db4054791bfd9ef9c48fb60789b
[reactos.git] / reactos / lib / user32 / windows / rect.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 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: rect.c,v 1.7 2002/09/03 22:44:20 dwelch Exp $
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
23 * PURPOSE: Input
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <windows.h>
32 #include <user32.h>
33 #include <debug.h>
34
35 /* FUNCTIONS *****************************************************************/
36
37 WINBOOL STDCALL
38 CopyRect(LPRECT lprcDst, CONST RECT *lprcSrc)
39 {
40 *lprcDst = *lprcSrc;
41 return(TRUE);
42 }
43
44 WINBOOL
45 STDCALL
46 EqualRect(
47 CONST RECT *lprc1,
48 CONST RECT *lprc2)
49 {
50 UNIMPLEMENTED;
51 return FALSE;
52 }
53
54 WINBOOL STDCALL
55 InflateRect(LPRECT rect, int dx, int dy)
56 {
57 rect->left -= dx;
58 rect->top -= dy;
59 rect->right -= dx;
60 rect->bottom -= dy;
61 return(TRUE);
62 }
63
64 WINBOOL STDCALL
65 IntersectRect(LPRECT lprcDst,
66 CONST RECT *lprcSrc1,
67 CONST RECT *lprcSrc2)
68 {
69 if (IsRectEmpty(lprcSrc1) || IsRectEmpty(lprcSrc2) ||
70 lprcSrc1->left >= lprcSrc2->right ||
71 lprcSrc2->left >= lprcSrc1->right ||
72 lprcSrc1->top >= lprcSrc2->bottom ||
73 lprcSrc2->top >= lprcSrc1->bottom)
74 {
75 SetRectEmpty(lprcDst);
76 return(FALSE);
77 }
78 lprcDst->left = max(lprcSrc1->left, lprcSrc2->left);
79 lprcDst->right = min(lprcSrc1->right, lprcSrc2->right);
80 lprcDst->top = max(lprcSrc1->top, lprcSrc2->top);
81 lprcDst->bottom = min(lprcSrc1->bottom, lprcSrc2->bottom);
82 }
83
84 WINBOOL STDCALL
85 IsRectEmpty(CONST RECT *lprc)
86 {
87 return((lprc->left >= lprc->right) || (lprc->top >= lprc->bottom));
88 }
89
90 WINBOOL STDCALL
91 OffsetRect(LPRECT rect, int dx, int dy)
92 {
93 rect->left += dx;
94 rect->top += dy;
95 rect->right += dx;
96 rect->bottom += dy;
97 return(TRUE);
98 }
99
100 WINBOOL STDCALL
101 PtInRect(CONST RECT *lprc, POINT pt)
102 {
103 return((pt.x >= lprc->left) && (pt.x < lprc->right) &&
104 (pt.y >= lprc->top) && (pt.y < lprc->bottom));
105 }
106
107 WINBOOL STDCALL
108 SetRect(LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom)
109 {
110 lprc->left = xLeft;
111 lprc->top = yTop;
112 lprc->right = xRight;
113 lprc->bottom = yBottom;
114 return(TRUE);
115 }
116
117 BOOL STDCALL
118 SetRectEmpty(LPRECT lprc)
119 {
120 lprc->left = lprc->right = lprc->top = lprc->bottom = 0;
121 return(TRUE);
122 }
123
124 WINBOOL STDCALL
125 SubtractRect(LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
126 {
127 UNIMPLEMENTED;
128 return FALSE;
129 }
130
131 WINBOOL STDCALL
132 UnionRect(LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
133 {
134 if (IsRectEmpty(lprcSrc1))
135 {
136 if (IsRectEmpty(lprcSrc2))
137 {
138 SetRectEmpty(lprcDst);
139 return(FALSE);
140 }
141 else
142 {
143 *lprcDst = *lprcSrc2;
144 }
145 }
146 else
147 {
148 if (IsRectEmpty(lprcSrc2))
149 {
150 *lprcDst = *lprcSrc1;
151 }
152 else
153 {
154 lprcDst->left = min(lprcSrc1->left, lprcSrc2->left);
155 lprcDst->top = min(lprcSrc1->top, lprcSrc2->top);
156 lprcDst->right = max(lprcSrc1->right, lprcSrc2->right);
157 lprcDst->bottom = max(lprcSrc1->bottom, lprcSrc2->bottom);
158 }
159 }
160 return(TRUE);
161 }