2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
13 /***********************************************************************
16 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
17 INT16 right, INT16 bottom )
22 rect->bottom = bottom;
26 /***********************************************************************
27 * SetRect32 (USER32.499)
29 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
30 INT right, INT bottom )
35 rect->bottom = bottom;
40 /***********************************************************************
41 * SetRectEmpty16 (USER.73)
43 void WINAPI SetRectEmpty16( LPRECT16 rect )
45 rect->left = rect->right = rect->top = rect->bottom = 0;
49 /***********************************************************************
50 * SetRectEmpty32 (USER32.500)
52 BOOL WINAPI SetRectEmpty( LPRECT rect )
54 rect->left = rect->right = rect->top = rect->bottom = 0;
59 /***********************************************************************
60 * CopyRect16 (USER.74)
62 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
69 /***********************************************************************
70 * CopyRect32 (USER32.62)
72 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
81 /***********************************************************************
82 * IsRectEmpty16 (USER.75)
84 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
86 return ((rect->left == rect->right) || (rect->top == rect->bottom));
90 /***********************************************************************
91 * IsRectEmpty32 (USER32.347)
93 BOOL WINAPI IsRectEmpty( const RECT *rect )
95 return ((rect->left == rect->right) || (rect->top == rect->bottom));
99 /***********************************************************************
100 * PtInRect16 (USER.76)
102 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
104 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
105 (pt.y >= rect->top) && (pt.y < rect->bottom));
109 /***********************************************************************
110 * PtInRect32 (USER32.424)
112 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
114 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
115 (pt.y >= rect->top) && (pt.y < rect->bottom));
119 /***********************************************************************
120 * OffsetRect16 (USER.77)
122 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
131 /***********************************************************************
132 * OffsetRect32 (USER32.406)
134 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
144 /***********************************************************************
145 * InflateRect16 (USER.78)
147 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
156 /***********************************************************************
157 * InflateRect32 (USER32.321)
159 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
169 /***********************************************************************
170 * IntersectRect16 (USER.79)
172 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
175 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
176 (src1->left >= src2->right) || (src2->left >= src1->right) ||
177 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
179 SetRectEmpty16( dest );
182 dest->left = MAX( src1->left, src2->left );
183 dest->right = MIN( src1->right, src2->right );
184 dest->top = MAX( src1->top, src2->top );
185 dest->bottom = MIN( src1->bottom, src2->bottom );
190 /***********************************************************************
191 * IntersectRect32 (USER32.327)
193 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
196 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
197 (src1->left >= src2->right) || (src2->left >= src1->right) ||
198 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
200 SetRectEmpty( dest );
203 dest->left = MAX( src1->left, src2->left );
204 dest->right = MIN( src1->right, src2->right );
205 dest->top = MAX( src1->top, src2->top );
206 dest->bottom = MIN( src1->bottom, src2->bottom );
211 /***********************************************************************
212 * UnionRect16 (USER.80)
214 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
217 if (IsRectEmpty16(src1))
219 if (IsRectEmpty16(src2))
221 SetRectEmpty16( dest );
228 if (IsRectEmpty16(src2)) *dest = *src1;
231 dest->left = MIN( src1->left, src2->left );
232 dest->right = MAX( src1->right, src2->right );
233 dest->top = MIN( src1->top, src2->top );
234 dest->bottom = MAX( src1->bottom, src2->bottom );
241 /***********************************************************************
242 * UnionRect32 (USER32.559)
244 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
247 if (IsRectEmpty(src1))
249 if (IsRectEmpty(src2))
251 SetRectEmpty( dest );
258 if (IsRectEmpty(src2)) *dest = *src1;
261 dest->left = MIN( src1->left, src2->left );
262 dest->right = MAX( src1->right, src2->right );
263 dest->top = MIN( src1->top, src2->top );
264 dest->bottom = MAX( src1->bottom, src2->bottom );
271 /***********************************************************************
272 * EqualRect16 (USER.244)
274 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
276 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
277 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
281 /***********************************************************************
282 * EqualRect32 (USER32.194)
284 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
286 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
287 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
291 /***********************************************************************
292 * SubtractRect16 (USER.373)
294 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
299 if (IsRectEmpty16( src1 ))
301 SetRectEmpty16( dest );
305 if (IntersectRect16( &tmp, src1, src2 ))
307 if (EqualRect16( &tmp, dest ))
309 SetRectEmpty16( dest );
312 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
314 if (tmp.left == dest->left) dest->left = tmp.right;
315 else if (tmp.right == dest->right) dest->right = tmp.left;
317 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
319 if (tmp.top == dest->top) dest->top = tmp.bottom;
320 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
327 /***********************************************************************
328 * SubtractRect32 (USER32.536)
330 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
335 if (IsRectEmpty( src1 ))
337 SetRectEmpty( dest );
341 if (IntersectRect( &tmp, src1, src2 ))
343 if (EqualRect( &tmp, dest ))
345 SetRectEmpty( dest );
348 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
350 if (tmp.left == dest->left) dest->left = tmp.right;
351 else if (tmp.right == dest->right) dest->right = tmp.left;
353 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
355 if (tmp.top == dest->top) dest->top = tmp.bottom;
356 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;