2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
8 #include "wine/winuser16.h"
11 /***********************************************************************
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15 INT16 right, INT16 bottom )
20 rect->bottom = bottom;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
28 INT right, INT bottom )
33 rect->bottom = bottom;
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;
57 /***********************************************************************
58 * CopyRect16 (USER.74)
60 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
67 /***********************************************************************
68 * CopyRect32 (USER32.62)
70 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
77 /***********************************************************************
78 * IsRectEmpty16 (USER.75)
80 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
82 return ((rect->left == rect->right) || (rect->top == rect->bottom));
86 /***********************************************************************
87 * IsRectEmpty32 (USER32.347)
89 BOOL WINAPI IsRectEmpty( const RECT *rect )
91 return ((rect->left == rect->right) || (rect->top == rect->bottom));
95 /***********************************************************************
96 * PtInRect16 (USER.76)
98 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
100 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
101 (pt.y >= rect->top) && (pt.y < rect->bottom));
105 /***********************************************************************
106 * PtInRect32 (USER32.424)
108 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
110 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
111 (pt.y >= rect->top) && (pt.y < rect->bottom));
115 /***********************************************************************
116 * OffsetRect16 (USER.77)
118 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
127 /***********************************************************************
128 * OffsetRect32 (USER32.406)
130 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
140 /***********************************************************************
141 * InflateRect16 (USER.78)
143 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
152 /***********************************************************************
153 * InflateRect32 (USER32.321)
155 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
165 /***********************************************************************
166 * IntersectRect16 (USER.79)
168 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
171 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
172 (src1->left >= src2->right) || (src2->left >= src1->right) ||
173 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
175 SetRectEmpty16( dest );
178 dest->left = MAX( src1->left, src2->left );
179 dest->right = MIN( src1->right, src2->right );
180 dest->top = MAX( src1->top, src2->top );
181 dest->bottom = MIN( src1->bottom, src2->bottom );
186 /***********************************************************************
187 * IntersectRect32 (USER32.327)
189 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
192 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
193 (src1->left >= src2->right) || (src2->left >= src1->right) ||
194 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
196 SetRectEmpty( dest );
199 dest->left = MAX( src1->left, src2->left );
200 dest->right = MIN( src1->right, src2->right );
201 dest->top = MAX( src1->top, src2->top );
202 dest->bottom = MIN( src1->bottom, src2->bottom );
207 /***********************************************************************
208 * UnionRect16 (USER.80)
210 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
213 if (IsRectEmpty16(src1))
215 if (IsRectEmpty16(src2))
217 SetRectEmpty16( dest );
224 if (IsRectEmpty16(src2)) *dest = *src1;
227 dest->left = MIN( src1->left, src2->left );
228 dest->right = MAX( src1->right, src2->right );
229 dest->top = MIN( src1->top, src2->top );
230 dest->bottom = MAX( src1->bottom, src2->bottom );
237 /***********************************************************************
238 * UnionRect32 (USER32.559)
240 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
243 if (IsRectEmpty(src1))
245 if (IsRectEmpty(src2))
247 SetRectEmpty( dest );
254 if (IsRectEmpty(src2)) *dest = *src1;
257 dest->left = MIN( src1->left, src2->left );
258 dest->right = MAX( src1->right, src2->right );
259 dest->top = MIN( src1->top, src2->top );
260 dest->bottom = MAX( src1->bottom, src2->bottom );
267 /***********************************************************************
268 * EqualRect16 (USER.244)
270 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
272 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
273 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
277 /***********************************************************************
278 * EqualRect32 (USER32.194)
280 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
282 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
283 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
287 /***********************************************************************
288 * SubtractRect16 (USER.373)
290 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
295 if (IsRectEmpty16( src1 ))
297 SetRectEmpty16( dest );
301 if (IntersectRect16( &tmp, src1, src2 ))
303 if (EqualRect16( &tmp, dest ))
305 SetRectEmpty16( dest );
308 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
310 if (tmp.left == dest->left) dest->left = tmp.right;
311 else if (tmp.right == dest->right) dest->right = tmp.left;
313 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
315 if (tmp.top == dest->top) dest->top = tmp.bottom;
316 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
323 /***********************************************************************
324 * SubtractRect32 (USER32.536)
326 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
331 if (IsRectEmpty( src1 ))
333 SetRectEmpty( dest );
337 if (IntersectRect( &tmp, src1, src2 ))
339 if (EqualRect( &tmp, dest ))
341 SetRectEmpty( dest );
344 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
346 if (tmp.left == dest->left) dest->left = tmp.right;
347 else if (tmp.right == dest->right) dest->right = tmp.left;
349 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
351 if (tmp.top == dest->top) dest->top = tmp.bottom;
352 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;