2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
9 #include "wine/winuser16.h"
12 /***********************************************************************
15 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
16 INT16 right, INT16 bottom )
21 rect->bottom = bottom;
25 /***********************************************************************
26 * SetRect32 (USER32.499)
28 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
29 INT right, INT bottom )
34 rect->bottom = bottom;
39 /***********************************************************************
40 * SetRectEmpty16 (USER.73)
42 void WINAPI SetRectEmpty16( LPRECT16 rect )
44 rect->left = rect->right = rect->top = rect->bottom = 0;
48 /***********************************************************************
49 * SetRectEmpty32 (USER32.500)
51 BOOL WINAPI SetRectEmpty( LPRECT rect )
53 rect->left = rect->right = rect->top = rect->bottom = 0;
58 /***********************************************************************
59 * CopyRect16 (USER.74)
61 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
68 /***********************************************************************
69 * CopyRect32 (USER32.62)
71 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
78 /***********************************************************************
79 * IsRectEmpty16 (USER.75)
81 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
83 return ((rect->left == rect->right) || (rect->top == rect->bottom));
87 /***********************************************************************
88 * IsRectEmpty32 (USER32.347)
90 BOOL WINAPI IsRectEmpty( const RECT *rect )
92 return ((rect->left == rect->right) || (rect->top == rect->bottom));
96 /***********************************************************************
97 * PtInRect16 (USER.76)
99 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
101 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
102 (pt.y >= rect->top) && (pt.y < rect->bottom));
106 /***********************************************************************
107 * PtInRect32 (USER32.424)
109 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
111 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
112 (pt.y >= rect->top) && (pt.y < rect->bottom));
116 /***********************************************************************
117 * OffsetRect16 (USER.77)
119 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
128 /***********************************************************************
129 * OffsetRect32 (USER32.406)
131 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
141 /***********************************************************************
142 * InflateRect16 (USER.78)
144 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
153 /***********************************************************************
154 * InflateRect32 (USER32.321)
156 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
166 /***********************************************************************
167 * IntersectRect16 (USER.79)
169 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
172 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
173 (src1->left >= src2->right) || (src2->left >= src1->right) ||
174 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
176 SetRectEmpty16( dest );
179 dest->left = MAX( src1->left, src2->left );
180 dest->right = MIN( src1->right, src2->right );
181 dest->top = MAX( src1->top, src2->top );
182 dest->bottom = MIN( src1->bottom, src2->bottom );
187 /***********************************************************************
188 * IntersectRect32 (USER32.327)
190 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
193 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
194 (src1->left >= src2->right) || (src2->left >= src1->right) ||
195 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
197 SetRectEmpty( dest );
200 dest->left = MAX( src1->left, src2->left );
201 dest->right = MIN( src1->right, src2->right );
202 dest->top = MAX( src1->top, src2->top );
203 dest->bottom = MIN( src1->bottom, src2->bottom );
208 /***********************************************************************
209 * UnionRect16 (USER.80)
211 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
214 if (IsRectEmpty16(src1))
216 if (IsRectEmpty16(src2))
218 SetRectEmpty16( dest );
225 if (IsRectEmpty16(src2)) *dest = *src1;
228 dest->left = MIN( src1->left, src2->left );
229 dest->right = MAX( src1->right, src2->right );
230 dest->top = MIN( src1->top, src2->top );
231 dest->bottom = MAX( src1->bottom, src2->bottom );
238 /***********************************************************************
239 * UnionRect32 (USER32.559)
241 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
244 if (IsRectEmpty(src1))
246 if (IsRectEmpty(src2))
248 SetRectEmpty( dest );
255 if (IsRectEmpty(src2)) *dest = *src1;
258 dest->left = MIN( src1->left, src2->left );
259 dest->right = MAX( src1->right, src2->right );
260 dest->top = MIN( src1->top, src2->top );
261 dest->bottom = MAX( src1->bottom, src2->bottom );
268 /***********************************************************************
269 * EqualRect16 (USER.244)
271 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
273 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
274 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
278 /***********************************************************************
279 * EqualRect32 (USER32.194)
281 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
283 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
284 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
288 /***********************************************************************
289 * SubtractRect16 (USER.373)
291 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
296 if (IsRectEmpty16( src1 ))
298 SetRectEmpty16( dest );
302 if (IntersectRect16( &tmp, src1, src2 ))
304 if (EqualRect16( &tmp, dest ))
306 SetRectEmpty16( dest );
309 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
311 if (tmp.left == dest->left) dest->left = tmp.right;
312 else if (tmp.right == dest->right) dest->right = tmp.left;
314 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
316 if (tmp.top == dest->top) dest->top = tmp.bottom;
317 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
324 /***********************************************************************
325 * SubtractRect32 (USER32.536)
327 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
332 if (IsRectEmpty( src1 ))
334 SetRectEmpty( dest );
338 if (IntersectRect( &tmp, src1, src2 ))
340 if (EqualRect( &tmp, dest ))
342 SetRectEmpty( dest );
345 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
347 if (tmp.left == dest->left) dest->left = tmp.right;
348 else if (tmp.right == dest->right) dest->right = tmp.left;
350 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
352 if (tmp.top == dest->top) dest->top = tmp.bottom;
353 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;