Release 20040914.
[wine/multimedia.git] / windows / rect.c
blob40bcaaa59f910b2ebf59496a3f60273ae735017e
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "wine/winuser16.h"
27 #include "winuser.h"
29 /***********************************************************************
30 * SetRect (USER.72)
32 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
33 INT16 right, INT16 bottom )
35 rect->left = left;
36 rect->right = right;
37 rect->top = top;
38 rect->bottom = bottom;
42 /***********************************************************************
43 * SetRect (USER32.@)
45 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
46 INT right, INT bottom )
48 if (!rect) return FALSE;
49 rect->left = left;
50 rect->right = right;
51 rect->top = top;
52 rect->bottom = bottom;
53 return TRUE;
57 /***********************************************************************
58 * SetRectEmpty (USER.73)
60 void WINAPI SetRectEmpty16( LPRECT16 rect )
62 rect->left = rect->right = rect->top = rect->bottom = 0;
66 /***********************************************************************
67 * SetRectEmpty (USER32.@)
69 BOOL WINAPI SetRectEmpty( LPRECT rect )
71 if (!rect) return FALSE;
72 rect->left = rect->right = rect->top = rect->bottom = 0;
73 return TRUE;
77 /***********************************************************************
78 * CopyRect (USER.74)
80 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
82 *dest = *src;
83 return TRUE;
87 /***********************************************************************
88 * CopyRect (USER32.@)
90 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
92 if (!dest || !src)
93 return FALSE;
94 *dest = *src;
95 return TRUE;
99 /***********************************************************************
100 * IsRectEmpty (USER.75)
102 * Bug compat: Windows checks for 0 or negative width/height.
104 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
106 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
110 /***********************************************************************
111 * IsRectEmpty (USER32.@)
113 * Bug compat: Windows checks for 0 or negative width/height.
115 BOOL WINAPI IsRectEmpty( const RECT *rect )
117 if (!rect) return TRUE;
118 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
122 /***********************************************************************
123 * PtInRect (USER.76)
125 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
127 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
128 (pt.y >= rect->top) && (pt.y < rect->bottom));
132 /***********************************************************************
133 * PtInRect (USER32.@)
135 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
137 if (!rect) return FALSE;
138 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
139 (pt.y >= rect->top) && (pt.y < rect->bottom));
143 /***********************************************************************
144 * OffsetRect (USER.77)
146 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
148 rect->left += x;
149 rect->right += x;
150 rect->top += y;
151 rect->bottom += y;
155 /***********************************************************************
156 * OffsetRect (USER32.@)
158 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
160 if (!rect) return FALSE;
161 rect->left += x;
162 rect->right += x;
163 rect->top += y;
164 rect->bottom += y;
165 return TRUE;
169 /***********************************************************************
170 * InflateRect (USER.78)
172 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
174 rect->left -= x;
175 rect->top -= y;
176 rect->right += x;
177 rect->bottom += y;
181 /***********************************************************************
182 * InflateRect (USER32.@)
184 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
186 if (!rect) return FALSE;
187 rect->left -= x;
188 rect->top -= y;
189 rect->right += x;
190 rect->bottom += y;
191 return TRUE;
195 /***********************************************************************
196 * IntersectRect (USER.79)
198 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
199 const RECT16 *src2 )
201 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
202 (src1->left >= src2->right) || (src2->left >= src1->right) ||
203 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
205 SetRectEmpty16( dest );
206 return FALSE;
208 dest->left = max( src1->left, src2->left );
209 dest->right = min( src1->right, src2->right );
210 dest->top = max( src1->top, src2->top );
211 dest->bottom = min( src1->bottom, src2->bottom );
212 return TRUE;
216 /***********************************************************************
217 * IntersectRect (USER32.@)
219 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
220 const RECT *src2 )
222 if (!dest || !src1 || !src2) return FALSE;
223 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
224 (src1->left >= src2->right) || (src2->left >= src1->right) ||
225 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
227 SetRectEmpty( dest );
228 return FALSE;
230 dest->left = max( src1->left, src2->left );
231 dest->right = min( src1->right, src2->right );
232 dest->top = max( src1->top, src2->top );
233 dest->bottom = min( src1->bottom, src2->bottom );
234 return TRUE;
238 /***********************************************************************
239 * UnionRect (USER.80)
241 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
242 const RECT16 *src2 )
244 if (IsRectEmpty16(src1))
246 if (IsRectEmpty16(src2))
248 SetRectEmpty16( dest );
249 return FALSE;
251 else *dest = *src2;
253 else
255 if (IsRectEmpty16(src2)) *dest = *src1;
256 else
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 );
264 return TRUE;
268 /***********************************************************************
269 * UnionRect (USER32.@)
271 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
272 const RECT *src2 )
274 if (!dest) return FALSE;
275 if (IsRectEmpty(src1))
277 if (IsRectEmpty(src2))
279 SetRectEmpty( dest );
280 return FALSE;
282 else *dest = *src2;
284 else
286 if (IsRectEmpty(src2)) *dest = *src1;
287 else
289 dest->left = min( src1->left, src2->left );
290 dest->right = max( src1->right, src2->right );
291 dest->top = min( src1->top, src2->top );
292 dest->bottom = max( src1->bottom, src2->bottom );
295 return TRUE;
299 /***********************************************************************
300 * EqualRect (USER.244)
302 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
304 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
305 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
309 /***********************************************************************
310 * EqualRect (USER32.@)
312 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
314 if (!rect1 || !rect2) return FALSE;
315 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
316 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
320 /***********************************************************************
321 * SubtractRect (USER.373)
323 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
324 const RECT16 *src2 )
326 RECT16 tmp;
328 if (IsRectEmpty16( src1 ))
330 SetRectEmpty16( dest );
331 return FALSE;
333 *dest = *src1;
334 if (IntersectRect16( &tmp, src1, src2 ))
336 if (EqualRect16( &tmp, dest ))
338 SetRectEmpty16( dest );
339 return FALSE;
341 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
343 if (tmp.left == dest->left) dest->left = tmp.right;
344 else if (tmp.right == dest->right) dest->right = tmp.left;
346 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
348 if (tmp.top == dest->top) dest->top = tmp.bottom;
349 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
352 return TRUE;
356 /***********************************************************************
357 * SubtractRect (USER32.@)
359 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
360 const RECT *src2 )
362 RECT tmp;
364 if (!dest) return FALSE;
365 if (IsRectEmpty( src1 ))
367 SetRectEmpty( dest );
368 return FALSE;
370 *dest = *src1;
371 if (IntersectRect( &tmp, src1, src2 ))
373 if (EqualRect( &tmp, dest ))
375 SetRectEmpty( dest );
376 return FALSE;
378 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
380 if (tmp.left == dest->left) dest->left = tmp.right;
381 else if (tmp.right == dest->right) dest->right = tmp.left;
383 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
385 if (tmp.top == dest->top) dest->top = tmp.bottom;
386 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
389 return TRUE;