Removed resource.h.
[wine.git] / windows / rect.c
blob9bca84e5e9448a329c66bb6ac14f6fb671915b14
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "wine/winuser16.h"
9 #include "winuser.h"
11 /***********************************************************************
12 * SetRect16 (USER.72)
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15 INT16 right, INT16 bottom )
17 rect->left = left;
18 rect->right = right;
19 rect->top = top;
20 rect->bottom = bottom;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
28 INT right, INT bottom )
30 rect->left = left;
31 rect->right = right;
32 rect->top = top;
33 rect->bottom = bottom;
34 return TRUE;
38 /***********************************************************************
39 * SetRectEmpty16 (USER.73)
41 void WINAPI SetRectEmpty16( LPRECT16 rect )
43 rect->left = rect->right = rect->top = rect->bottom = 0;
47 /***********************************************************************
48 * SetRectEmpty32 (USER32.500)
50 BOOL WINAPI SetRectEmpty( LPRECT rect )
52 rect->left = rect->right = rect->top = rect->bottom = 0;
53 return TRUE;
57 /***********************************************************************
58 * CopyRect16 (USER.74)
60 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
62 *dest = *src;
63 return TRUE;
67 /***********************************************************************
68 * CopyRect32 (USER32.62)
70 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
72 if (!dest || !src)
73 return FALSE;
74 *dest = *src;
75 return TRUE;
79 /***********************************************************************
80 * IsRectEmpty16 (USER.75)
82 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
84 return ((rect->left == rect->right) || (rect->top == rect->bottom));
88 /***********************************************************************
89 * IsRectEmpty32 (USER32.347)
91 BOOL WINAPI IsRectEmpty( const RECT *rect )
93 return ((rect->left == rect->right) || (rect->top == rect->bottom));
97 /***********************************************************************
98 * PtInRect16 (USER.76)
100 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
102 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
103 (pt.y >= rect->top) && (pt.y < rect->bottom));
107 /***********************************************************************
108 * PtInRect32 (USER32.424)
110 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
112 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
113 (pt.y >= rect->top) && (pt.y < rect->bottom));
117 /***********************************************************************
118 * OffsetRect16 (USER.77)
120 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
122 rect->left += x;
123 rect->right += x;
124 rect->top += y;
125 rect->bottom += y;
129 /***********************************************************************
130 * OffsetRect32 (USER32.406)
132 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
134 rect->left += x;
135 rect->right += x;
136 rect->top += y;
137 rect->bottom += y;
138 return TRUE;
142 /***********************************************************************
143 * InflateRect16 (USER.78)
145 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
147 rect->left -= x;
148 rect->top -= y;
149 rect->right += x;
150 rect->bottom += y;
154 /***********************************************************************
155 * InflateRect32 (USER32.321)
157 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
159 rect->left -= x;
160 rect->top -= y;
161 rect->right += x;
162 rect->bottom += y;
163 return TRUE;
167 /***********************************************************************
168 * IntersectRect16 (USER.79)
170 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
171 const RECT16 *src2 )
173 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
174 (src1->left >= src2->right) || (src2->left >= src1->right) ||
175 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
177 SetRectEmpty16( dest );
178 return FALSE;
180 dest->left = MAX( src1->left, src2->left );
181 dest->right = MIN( src1->right, src2->right );
182 dest->top = MAX( src1->top, src2->top );
183 dest->bottom = MIN( src1->bottom, src2->bottom );
184 return TRUE;
188 /***********************************************************************
189 * IntersectRect32 (USER32.327)
191 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
192 const RECT *src2 )
194 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
195 (src1->left >= src2->right) || (src2->left >= src1->right) ||
196 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
198 SetRectEmpty( dest );
199 return FALSE;
201 dest->left = MAX( src1->left, src2->left );
202 dest->right = MIN( src1->right, src2->right );
203 dest->top = MAX( src1->top, src2->top );
204 dest->bottom = MIN( src1->bottom, src2->bottom );
205 return TRUE;
209 /***********************************************************************
210 * UnionRect16 (USER.80)
212 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
213 const RECT16 *src2 )
215 if (IsRectEmpty16(src1))
217 if (IsRectEmpty16(src2))
219 SetRectEmpty16( dest );
220 return FALSE;
222 else *dest = *src2;
224 else
226 if (IsRectEmpty16(src2)) *dest = *src1;
227 else
229 dest->left = MIN( src1->left, src2->left );
230 dest->right = MAX( src1->right, src2->right );
231 dest->top = MIN( src1->top, src2->top );
232 dest->bottom = MAX( src1->bottom, src2->bottom );
235 return TRUE;
239 /***********************************************************************
240 * UnionRect32 (USER32.559)
242 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
243 const RECT *src2 )
245 if (IsRectEmpty(src1))
247 if (IsRectEmpty(src2))
249 SetRectEmpty( dest );
250 return FALSE;
252 else *dest = *src2;
254 else
256 if (IsRectEmpty(src2)) *dest = *src1;
257 else
259 dest->left = MIN( src1->left, src2->left );
260 dest->right = MAX( src1->right, src2->right );
261 dest->top = MIN( src1->top, src2->top );
262 dest->bottom = MAX( src1->bottom, src2->bottom );
265 return TRUE;
269 /***********************************************************************
270 * EqualRect16 (USER.244)
272 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
274 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
275 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
279 /***********************************************************************
280 * EqualRect32 (USER32.194)
282 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
284 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
285 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
289 /***********************************************************************
290 * SubtractRect16 (USER.373)
292 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
293 const RECT16 *src2 )
295 RECT16 tmp;
297 if (IsRectEmpty16( src1 ))
299 SetRectEmpty16( dest );
300 return FALSE;
302 *dest = *src1;
303 if (IntersectRect16( &tmp, src1, src2 ))
305 if (EqualRect16( &tmp, dest ))
307 SetRectEmpty16( dest );
308 return FALSE;
310 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
312 if (tmp.left == dest->left) dest->left = tmp.right;
313 else if (tmp.right == dest->right) dest->right = tmp.left;
315 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
317 if (tmp.top == dest->top) dest->top = tmp.bottom;
318 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
321 return TRUE;
325 /***********************************************************************
326 * SubtractRect32 (USER32.536)
328 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
329 const RECT *src2 )
331 RECT tmp;
333 if (IsRectEmpty( src1 ))
335 SetRectEmpty( dest );
336 return FALSE;
338 *dest = *src1;
339 if (IntersectRect( &tmp, src1, src2 ))
341 if (EqualRect( &tmp, dest ))
343 SetRectEmpty( dest );
344 return FALSE;
346 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
348 if (tmp.left == dest->left) dest->left = tmp.right;
349 else if (tmp.right == dest->right) dest->right = tmp.left;
351 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
353 if (tmp.top == dest->top) dest->top = tmp.bottom;
354 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
357 return TRUE;