Release 970415
[wine/multimedia.git] / windows / rect.c
blob61d76c2cc3ae48cae24efa21f604de76e6d4c180
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "windows.h"
11 /***********************************************************************
12 * SetRect16 (USER.72)
14 void SetRect16(LPRECT16 rect, INT16 left, INT16 top, INT16 right, INT16 bottom)
16 rect->left = left;
17 rect->right = right;
18 rect->top = top;
19 rect->bottom = bottom;
23 /***********************************************************************
24 * SetRect32 (USER32.498)
26 void SetRect32(LPRECT32 rect, INT32 left, INT32 top, INT32 right, INT32 bottom)
28 rect->left = left;
29 rect->right = right;
30 rect->top = top;
31 rect->bottom = bottom;
35 /***********************************************************************
36 * SetRectEmpty16 (USER.73)
38 void SetRectEmpty16( LPRECT16 rect )
40 rect->left = rect->right = rect->top = rect->bottom = 0;
44 /***********************************************************************
45 * SetRectEmpty32 (USER32.499)
47 void SetRectEmpty32( LPRECT32 rect )
49 rect->left = rect->right = rect->top = rect->bottom = 0;
53 /***********************************************************************
54 * CopyRect16 (USER.74)
56 BOOL16 CopyRect16( RECT16 *dest, const RECT16 *src )
58 *dest = *src;
59 return TRUE;
63 /***********************************************************************
64 * CopyRect32 (USER32.61)
66 BOOL32 CopyRect32( RECT32 *dest, const RECT32 *src )
68 *dest = *src;
69 return TRUE;
73 /***********************************************************************
74 * IsRectEmpty16 (USER.75)
76 BOOL16 IsRectEmpty16( const RECT16 *rect )
78 return ((rect->left == rect->right) || (rect->top == rect->bottom));
82 /***********************************************************************
83 * IsRectEmpty32 (USER32.346)
85 BOOL32 IsRectEmpty32( const RECT32 *rect )
87 return ((rect->left == rect->right) || (rect->top == rect->bottom));
91 /***********************************************************************
92 * PtInRect16 (USER.76)
94 BOOL16 PtInRect16( const RECT16 *rect, POINT16 pt )
96 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
97 (pt.y >= rect->top) && (pt.y < rect->bottom));
101 /***********************************************************************
102 * PtInRect32 (USER32.423)
104 BOOL32 PtInRect32( const RECT32 *rect, POINT32 pt )
106 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
107 (pt.y >= rect->top) && (pt.y < rect->bottom));
111 /***********************************************************************
112 * OffsetRect16 (USER.77)
114 void OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
116 rect->left += x;
117 rect->right += x;
118 rect->top += y;
119 rect->bottom += y;
123 /***********************************************************************
124 * OffsetRect32 (USER32.405)
126 void OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
128 rect->left += x;
129 rect->right += x;
130 rect->top += y;
131 rect->bottom += y;
135 /***********************************************************************
136 * InflateRect16 (USER.78)
138 void InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
140 rect->left -= x;
141 rect->top -= y;
142 rect->right += x;
143 rect->bottom += y;
147 /***********************************************************************
148 * InflateRect32 (USER32.320)
150 void InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
152 rect->left -= x;
153 rect->top -= y;
154 rect->right += x;
155 rect->bottom += y;
159 /***********************************************************************
160 * IntersectRect16 (USER.79)
162 BOOL16 IntersectRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
164 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
165 (src1->left >= src2->right) || (src2->left >= src1->right) ||
166 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
168 SetRectEmpty16( dest );
169 return FALSE;
171 dest->left = MAX( src1->left, src2->left );
172 dest->right = MIN( src1->right, src2->right );
173 dest->top = MAX( src1->top, src2->top );
174 dest->bottom = MIN( src1->bottom, src2->bottom );
175 return TRUE;
179 /***********************************************************************
180 * IntersectRect32 (USER32.326)
182 BOOL32 IntersectRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
184 if (IsRectEmpty32(src1) || IsRectEmpty32(src2) ||
185 (src1->left >= src2->right) || (src2->left >= src1->right) ||
186 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
188 SetRectEmpty32( dest );
189 return FALSE;
191 dest->left = MAX( src1->left, src2->left );
192 dest->right = MIN( src1->right, src2->right );
193 dest->top = MAX( src1->top, src2->top );
194 dest->bottom = MIN( src1->bottom, src2->bottom );
195 return TRUE;
199 /***********************************************************************
200 * UnionRect16 (USER.80)
202 BOOL16 UnionRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
204 if (IsRectEmpty16(src1))
206 if (IsRectEmpty16(src2))
208 SetRectEmpty16( dest );
209 return FALSE;
211 else *dest = *src2;
213 else
215 if (IsRectEmpty16(src2)) *dest = *src1;
216 else
218 dest->left = MIN( src1->left, src2->left );
219 dest->right = MAX( src1->right, src2->right );
220 dest->top = MIN( src1->top, src2->top );
221 dest->bottom = MAX( src1->bottom, src2->bottom );
224 return TRUE;
228 /***********************************************************************
229 * UnionRect32 (USER32.558)
231 BOOL32 UnionRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
233 if (IsRectEmpty32(src1))
235 if (IsRectEmpty32(src2))
237 SetRectEmpty32( dest );
238 return FALSE;
240 else *dest = *src2;
242 else
244 if (IsRectEmpty32(src2)) *dest = *src1;
245 else
247 dest->left = MIN( src1->left, src2->left );
248 dest->right = MAX( src1->right, src2->right );
249 dest->top = MIN( src1->top, src2->top );
250 dest->bottom = MAX( src1->bottom, src2->bottom );
253 return TRUE;
257 /***********************************************************************
258 * EqualRect16 (USER.244)
260 BOOL16 EqualRect16( const RECT16* rect1, const RECT16* rect2 )
262 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
263 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
267 /***********************************************************************
268 * EqualRect32 (USER32.193)
270 BOOL32 EqualRect32( const RECT32* rect1, const RECT32* rect2 )
272 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
273 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
277 /***********************************************************************
278 * SubtractRect16 (USER.373)
280 BOOL16 SubtractRect16( LPRECT16 dest, const RECT16 *src1, const RECT16 *src2 )
282 RECT16 tmp;
284 if (IsRectEmpty16( src1 ))
286 SetRectEmpty16( dest );
287 return FALSE;
289 *dest = *src1;
290 if (IntersectRect16( &tmp, src1, src2 ))
292 if (EqualRect16( &tmp, dest ))
294 SetRectEmpty16( dest );
295 return FALSE;
297 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
299 if (tmp.left == dest->left) dest->left = tmp.right;
300 else if (tmp.right == dest->right) dest->right = tmp.left;
302 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
304 if (tmp.top == dest->top) dest->top = tmp.bottom;
305 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
308 return TRUE;
312 /***********************************************************************
313 * SubtractRect32 (USER32.535)
315 BOOL32 SubtractRect32( LPRECT32 dest, const RECT32 *src1, const RECT32 *src2 )
317 RECT32 tmp;
319 if (IsRectEmpty32( src1 ))
321 SetRectEmpty32( dest );
322 return FALSE;
324 *dest = *src1;
325 if (IntersectRect32( &tmp, src1, src2 ))
327 if (EqualRect32( &tmp, dest ))
329 SetRectEmpty32( dest );
330 return FALSE;
332 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
334 if (tmp.left == dest->left) dest->left = tmp.right;
335 else if (tmp.right == dest->right) dest->right = tmp.left;
337 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
339 if (tmp.top == dest->top) dest->top = tmp.bottom;
340 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
343 return TRUE;