3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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.
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.
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.
20 * PROJECT: ReactOS user32.dll
21 * FILE: win32ss/user/user32/windows/rect.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * 09-05-2001 CSH Created
28 /* INCLUDES ******************************************************************/
32 #include <wine/debug.h>
34 /* FUNCTIONS *****************************************************************/
41 CopyRect(LPRECT lprcDst
,
44 if (lprcDst
== NULL
|| lprcSrc
== NULL
)
58 EqualRect(CONST RECT
*lprc1
,
61 if (lprc1
== NULL
|| lprc2
== NULL
)
64 return (lprc1
->left
== lprc2
->left
) && (lprc1
->top
== lprc2
->top
) &&
65 (lprc1
->right
== lprc2
->right
) && (lprc1
->bottom
== lprc2
->bottom
);
74 InflateRect(LPRECT rect
,
95 IntersectRect(LPRECT lprcDst
,
99 if (lprcDst
== NULL
|| lprcSrc1
== NULL
|| lprcSrc2
== NULL
)
102 if (IsRectEmpty(lprcSrc1
) || IsRectEmpty(lprcSrc2
) ||
103 lprcSrc1
->left
>= lprcSrc2
->right
||
104 lprcSrc2
->left
>= lprcSrc1
->right
||
105 lprcSrc1
->top
>= lprcSrc2
->bottom
||
106 lprcSrc2
->top
>= lprcSrc1
->bottom
)
108 SetRectEmpty(lprcDst
);
112 lprcDst
->left
= max(lprcSrc1
->left
, lprcSrc2
->left
);
113 lprcDst
->right
= min(lprcSrc1
->right
, lprcSrc2
->right
);
114 lprcDst
->top
= max(lprcSrc1
->top
, lprcSrc2
->top
);
115 lprcDst
->bottom
= min(lprcSrc1
->bottom
, lprcSrc2
->bottom
);
126 IsRectEmpty(CONST RECT
*lprc
)
131 return ((lprc
->left
>= lprc
->right
) || (lprc
->top
>= lprc
->bottom
));
140 OffsetRect(LPRECT rect
,
161 PtInRect(CONST RECT
*lprc
,
167 return((pt
.x
>= lprc
->left
) && (pt
.x
< lprc
->right
) &&
168 (pt
.y
>= lprc
->top
) && (pt
.y
< lprc
->bottom
));
184 lprc
->right
= xRight
;
185 lprc
->bottom
= yBottom
;
196 SetRectEmpty(LPRECT lprc
)
201 lprc
->left
= lprc
->right
= lprc
->top
= lprc
->bottom
= 0;
212 SubtractRect(LPRECT lprcDst
,
213 CONST RECT
*lprcSrc1
,
214 CONST RECT
*lprcSrc2
)
218 if (lprcDst
== NULL
|| lprcSrc1
== NULL
|| lprcSrc2
== NULL
)
221 if (!IntersectRect(&tempRect
, lprcSrc1
, lprcSrc2
))
223 *lprcDst
= *lprcSrc1
;
227 if (EqualRect(&tempRect
, lprcSrc1
))
229 SetRectEmpty(lprcDst
);
233 *lprcDst
= *lprcSrc1
;
235 if (lprcDst
->top
== tempRect
.top
&& lprcDst
->bottom
== tempRect
.bottom
)
237 if (lprcDst
->left
== tempRect
.left
)
238 lprcDst
->left
= tempRect
.right
;
239 else if (lprcDst
->right
== tempRect
.right
)
240 lprcDst
->right
= tempRect
.left
;
242 else if (lprcDst
->left
== tempRect
.left
&& lprcDst
->right
== tempRect
.right
)
244 if (lprcDst
->top
== tempRect
.top
)
245 lprcDst
->top
= tempRect
.bottom
;
246 else if (lprcDst
->bottom
== tempRect
.bottom
)
247 lprcDst
->bottom
= tempRect
.top
;
259 UnionRect(LPRECT lprcDst
,
260 CONST RECT
*lprcSrc1
,
261 CONST RECT
*lprcSrc2
)
263 if (lprcDst
== NULL
|| lprcSrc1
== NULL
|| lprcSrc2
== NULL
)
266 if (IsRectEmpty(lprcSrc1
))
268 if (IsRectEmpty(lprcSrc2
))
270 SetRectEmpty(lprcDst
);
275 *lprcDst
= *lprcSrc2
;
280 if (IsRectEmpty(lprcSrc2
))
282 *lprcDst
= *lprcSrc1
;
286 lprcDst
->left
= min(lprcSrc1
->left
, lprcSrc2
->left
);
287 lprcDst
->top
= min(lprcSrc1
->top
, lprcSrc2
->top
);
288 lprcDst
->right
= max(lprcSrc1
->right
, lprcSrc2
->right
);
289 lprcDst
->bottom
= max(lprcSrc1
->bottom
, lprcSrc2
->bottom
);