Implemented Local32Info, stubs for Local32First/Next (KERNEL.444-446).
[wine/multimedia.git] / windows / rect.c
blobe783e854e32cbd6cc19d02000c5d4fae5a461ad9
1 /*
2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 */
8 #include "windows.h"
11 /***********************************************************************
12 * SetRect16 (USER.72)
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15 INT16 right, INT16 bottom )
17 rect->left = left;
18 rect->right = right;
19 rect->top = top;
20 rect->bottom = bottom;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 void WINAPI SetRect32( LPRECT32 rect, INT32 left, INT32 top,
28 INT32 right, INT32 bottom )
30 rect->left = left;
31 rect->right = right;
32 rect->top = top;
33 rect->bottom = bottom;
37 /***********************************************************************
38 * SetRectEmpty16 (USER.73)
40 void WINAPI SetRectEmpty16( LPRECT16 rect )
42 rect->left = rect->right = rect->top = rect->bottom = 0;
46 /***********************************************************************
47 * SetRectEmpty32 (USER32.500)
49 void WINAPI SetRectEmpty32( LPRECT32 rect )
51 rect->left = rect->right = rect->top = rect->bottom = 0;
55 /***********************************************************************
56 * CopyRect16 (USER.74)
58 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
60 *dest = *src;
61 return TRUE;
65 /***********************************************************************
66 * CopyRect32 (USER32.62)
68 BOOL32 WINAPI CopyRect32( RECT32 *dest, const RECT32 *src )
70 *dest = *src;
71 return TRUE;
75 /***********************************************************************
76 * IsRectEmpty16 (USER.75)
78 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
80 return ((rect->left == rect->right) || (rect->top == rect->bottom));
84 /***********************************************************************
85 * IsRectEmpty32 (USER32.347)
87 BOOL32 WINAPI IsRectEmpty32( const RECT32 *rect )
89 return ((rect->left == rect->right) || (rect->top == rect->bottom));
93 /***********************************************************************
94 * PtInRect16 (USER.76)
96 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
98 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
99 (pt.y >= rect->top) && (pt.y < rect->bottom));
103 /***********************************************************************
104 * PtInRect32 (USER32.424)
106 BOOL32 WINAPI PtInRect32( const RECT32 *rect, POINT32 pt )
108 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
109 (pt.y >= rect->top) && (pt.y < rect->bottom));
113 /***********************************************************************
114 * OffsetRect16 (USER.77)
116 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
118 rect->left += x;
119 rect->right += x;
120 rect->top += y;
121 rect->bottom += y;
125 /***********************************************************************
126 * OffsetRect32 (USER32.406)
128 void WINAPI OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
130 rect->left += x;
131 rect->right += x;
132 rect->top += y;
133 rect->bottom += y;
137 /***********************************************************************
138 * InflateRect16 (USER.78)
140 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
142 rect->left -= x;
143 rect->top -= y;
144 rect->right += x;
145 rect->bottom += y;
149 /***********************************************************************
150 * InflateRect32 (USER32.321)
152 void WINAPI InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
154 rect->left -= x;
155 rect->top -= y;
156 rect->right += x;
157 rect->bottom += y;
161 /***********************************************************************
162 * IntersectRect16 (USER.79)
164 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
165 const RECT16 *src2 )
167 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
168 (src1->left >= src2->right) || (src2->left >= src1->right) ||
169 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
171 SetRectEmpty16( dest );
172 return FALSE;
174 dest->left = MAX( src1->left, src2->left );
175 dest->right = MIN( src1->right, src2->right );
176 dest->top = MAX( src1->top, src2->top );
177 dest->bottom = MIN( src1->bottom, src2->bottom );
178 return TRUE;
182 /***********************************************************************
183 * IntersectRect32 (USER32.327)
185 BOOL32 WINAPI IntersectRect32( LPRECT32 dest, const RECT32 *src1,
186 const RECT32 *src2 )
188 if (IsRectEmpty32(src1) || IsRectEmpty32(src2) ||
189 (src1->left >= src2->right) || (src2->left >= src1->right) ||
190 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
192 SetRectEmpty32( dest );
193 return FALSE;
195 dest->left = MAX( src1->left, src2->left );
196 dest->right = MIN( src1->right, src2->right );
197 dest->top = MAX( src1->top, src2->top );
198 dest->bottom = MIN( src1->bottom, src2->bottom );
199 return TRUE;
203 /***********************************************************************
204 * UnionRect16 (USER.80)
206 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
207 const RECT16 *src2 )
209 if (IsRectEmpty16(src1))
211 if (IsRectEmpty16(src2))
213 SetRectEmpty16( dest );
214 return FALSE;
216 else *dest = *src2;
218 else
220 if (IsRectEmpty16(src2)) *dest = *src1;
221 else
223 dest->left = MIN( src1->left, src2->left );
224 dest->right = MAX( src1->right, src2->right );
225 dest->top = MIN( src1->top, src2->top );
226 dest->bottom = MAX( src1->bottom, src2->bottom );
229 return TRUE;
233 /***********************************************************************
234 * UnionRect32 (USER32.559)
236 BOOL32 WINAPI UnionRect32( LPRECT32 dest, const RECT32 *src1,
237 const RECT32 *src2 )
239 if (IsRectEmpty32(src1))
241 if (IsRectEmpty32(src2))
243 SetRectEmpty32( dest );
244 return FALSE;
246 else *dest = *src2;
248 else
250 if (IsRectEmpty32(src2)) *dest = *src1;
251 else
253 dest->left = MIN( src1->left, src2->left );
254 dest->right = MAX( src1->right, src2->right );
255 dest->top = MIN( src1->top, src2->top );
256 dest->bottom = MAX( src1->bottom, src2->bottom );
259 return TRUE;
263 /***********************************************************************
264 * EqualRect16 (USER.244)
266 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
268 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
269 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
273 /***********************************************************************
274 * EqualRect32 (USER32.194)
276 BOOL32 WINAPI EqualRect32( const RECT32* rect1, const RECT32* rect2 )
278 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
279 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
283 /***********************************************************************
284 * SubtractRect16 (USER.373)
286 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
287 const RECT16 *src2 )
289 RECT16 tmp;
291 if (IsRectEmpty16( src1 ))
293 SetRectEmpty16( dest );
294 return FALSE;
296 *dest = *src1;
297 if (IntersectRect16( &tmp, src1, src2 ))
299 if (EqualRect16( &tmp, dest ))
301 SetRectEmpty16( dest );
302 return FALSE;
304 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
306 if (tmp.left == dest->left) dest->left = tmp.right;
307 else if (tmp.right == dest->right) dest->right = tmp.left;
309 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
311 if (tmp.top == dest->top) dest->top = tmp.bottom;
312 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
315 return TRUE;
319 /***********************************************************************
320 * SubtractRect32 (USER32.536)
322 BOOL32 WINAPI SubtractRect32( LPRECT32 dest, const RECT32 *src1,
323 const RECT32 *src2 )
325 RECT32 tmp;
327 if (IsRectEmpty32( src1 ))
329 SetRectEmpty32( dest );
330 return FALSE;
332 *dest = *src1;
333 if (IntersectRect32( &tmp, src1, src2 ))
335 if (EqualRect32( &tmp, dest ))
337 SetRectEmpty32( dest );
338 return FALSE;
340 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
342 if (tmp.left == dest->left) dest->left = tmp.right;
343 else if (tmp.right == dest->right) dest->right = tmp.left;
345 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
347 if (tmp.top == dest->top) dest->top = tmp.bottom;
348 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
351 return TRUE;