Changed some functions prototypes (were returning void).
[wine] / windows / rect.c
1 /*
2  * Rectangle-related functions
3  *
4  * Copyright 1993, 1996 Alexandre Julliard
5  *
6  */
7
8 #include "windows.h"
9
10
11 /***********************************************************************
12  *           SetRect16    (USER.72)
13  */
14 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
15                        INT16 right, INT16 bottom )
16 {
17     rect->left   = left;
18     rect->right  = right;
19     rect->top    = top;
20     rect->bottom = bottom;
21 }
22
23
24 /***********************************************************************
25  *           SetRect32    (USER32.499)
26  */
27 BOOL32 WINAPI SetRect32( LPRECT32 rect, INT32 left, INT32 top,
28                        INT32 right, INT32 bottom )
29 {
30     rect->left   = left;
31     rect->right  = right;
32     rect->top    = top;
33     rect->bottom = bottom;
34     return TRUE;
35 }
36
37
38 /***********************************************************************
39  *           SetRectEmpty16    (USER.73)
40  */
41 void WINAPI SetRectEmpty16( LPRECT16 rect )
42 {
43     rect->left = rect->right = rect->top = rect->bottom = 0;
44 }
45
46
47 /***********************************************************************
48  *           SetRectEmpty32    (USER32.500)
49  */
50 BOOL32 WINAPI SetRectEmpty32( LPRECT32 rect )
51 {
52     rect->left = rect->right = rect->top = rect->bottom = 0;
53     return TRUE;
54 }
55
56
57 /***********************************************************************
58  *           CopyRect16    (USER.74)
59  */
60 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
61 {
62     *dest = *src;
63     return TRUE;
64 }
65
66
67 /***********************************************************************
68  *           CopyRect32    (USER32.62)
69  */
70 BOOL32 WINAPI CopyRect32( RECT32 *dest, const RECT32 *src )
71 {
72     *dest = *src;
73     return TRUE;
74 }
75
76
77 /***********************************************************************
78  *           IsRectEmpty16    (USER.75)
79  */
80 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
81 {
82     return ((rect->left == rect->right) || (rect->top == rect->bottom));
83 }
84
85
86 /***********************************************************************
87  *           IsRectEmpty32    (USER32.347)
88  */
89 BOOL32 WINAPI IsRectEmpty32( const RECT32 *rect )
90 {
91     return ((rect->left == rect->right) || (rect->top == rect->bottom));
92 }
93
94
95 /***********************************************************************
96  *           PtInRect16    (USER.76)
97  */
98 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
99 {
100     return ((pt.x >= rect->left) && (pt.x < rect->right) &&
101             (pt.y >= rect->top) && (pt.y < rect->bottom));
102 }
103
104
105 /***********************************************************************
106  *           PtInRect32    (USER32.424)
107  */
108 BOOL32 WINAPI PtInRect32( const RECT32 *rect, POINT32 pt )
109 {
110     return ((pt.x >= rect->left) && (pt.x < rect->right) &&
111             (pt.y >= rect->top) && (pt.y < rect->bottom));
112 }
113
114
115 /***********************************************************************
116  *           OffsetRect16    (USER.77)
117  */
118 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
119 {
120     rect->left   += x;
121     rect->right  += x;
122     rect->top    += y;
123     rect->bottom += y;    
124 }
125
126
127 /***********************************************************************
128  *           OffsetRect32    (USER32.406)
129  */
130 BOOL32 WINAPI OffsetRect32( LPRECT32 rect, INT32 x, INT32 y )
131 {
132     rect->left   += x;
133     rect->right  += x;
134     rect->top    += y;
135     rect->bottom += y;    
136     return TRUE;
137 }
138
139
140 /***********************************************************************
141  *           InflateRect16    (USER.78)
142  */
143 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
144 {
145     rect->left   -= x;
146     rect->top    -= y;
147     rect->right  += x;
148     rect->bottom += y;
149 }
150
151
152 /***********************************************************************
153  *           InflateRect32    (USER32.321)
154  */
155 BOOL32 WINAPI InflateRect32( LPRECT32 rect, INT32 x, INT32 y )
156 {
157     rect->left   -= x;
158     rect->top    -= y;
159     rect->right  += x;
160     rect->bottom += y;
161     return TRUE;
162 }
163
164
165 /***********************************************************************
166  *           IntersectRect16    (USER.79)
167  */
168 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
169                                const RECT16 *src2 )
170 {
171     if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
172         (src1->left >= src2->right) || (src2->left >= src1->right) ||
173         (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
174     {
175         SetRectEmpty16( dest );
176         return FALSE;
177     }
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 );
182     return TRUE;
183 }
184
185
186 /***********************************************************************
187  *           IntersectRect32    (USER32.327)
188  */
189 BOOL32 WINAPI IntersectRect32( LPRECT32 dest, const RECT32 *src1,
190                                const RECT32 *src2 )
191 {
192     if (IsRectEmpty32(src1) || IsRectEmpty32(src2) ||
193         (src1->left >= src2->right) || (src2->left >= src1->right) ||
194         (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
195     {
196         SetRectEmpty32( dest );
197         return FALSE;
198     }
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 );
203     return TRUE;
204 }
205
206
207 /***********************************************************************
208  *           UnionRect16    (USER.80)
209  */
210 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
211                            const RECT16 *src2 )
212 {
213     if (IsRectEmpty16(src1))
214     {
215         if (IsRectEmpty16(src2))
216         {
217             SetRectEmpty16( dest );
218             return FALSE;
219         }
220         else *dest = *src2;
221     }
222     else
223     {
224         if (IsRectEmpty16(src2)) *dest = *src1;
225         else
226         {
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 );       
231         }
232     }
233     return TRUE;
234 }
235
236
237 /***********************************************************************
238  *           UnionRect32    (USER32.559)
239  */
240 BOOL32 WINAPI UnionRect32( LPRECT32 dest, const RECT32 *src1,
241                            const RECT32 *src2 )
242 {
243     if (IsRectEmpty32(src1))
244     {
245         if (IsRectEmpty32(src2))
246         {
247             SetRectEmpty32( dest );
248             return FALSE;
249         }
250         else *dest = *src2;
251     }
252     else
253     {
254         if (IsRectEmpty32(src2)) *dest = *src1;
255         else
256         {
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 );       
261         }
262     }
263     return TRUE;
264 }
265
266
267 /***********************************************************************
268  *           EqualRect16    (USER.244)
269  */
270 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
271 {
272     return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
273             (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
274 }
275
276
277 /***********************************************************************
278  *           EqualRect32    (USER32.194)
279  */
280 BOOL32 WINAPI EqualRect32( const RECT32* rect1, const RECT32* rect2 )
281 {
282     return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
283             (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
284 }
285
286
287 /***********************************************************************
288  *           SubtractRect16    (USER.373)
289  */
290 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
291                               const RECT16 *src2 )
292 {
293     RECT16 tmp;
294
295     if (IsRectEmpty16( src1 ))
296     {
297         SetRectEmpty16( dest );
298         return FALSE;
299     }
300     *dest = *src1;
301     if (IntersectRect16( &tmp, src1, src2 ))
302     {
303         if (EqualRect16( &tmp, dest ))
304         {
305             SetRectEmpty16( dest );
306             return FALSE;
307         }
308         if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
309         {
310             if (tmp.left == dest->left) dest->left = tmp.right;
311             else if (tmp.right == dest->right) dest->right = tmp.left;
312         }
313         else if ((tmp.left == dest->left) && (tmp.right == dest->right))
314         {
315             if (tmp.top == dest->top) dest->top = tmp.bottom;
316             else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
317         }
318     }
319     return TRUE;
320 }
321
322
323 /***********************************************************************
324  *           SubtractRect32    (USER32.536)
325  */
326 BOOL32 WINAPI SubtractRect32( LPRECT32 dest, const RECT32 *src1,
327                               const RECT32 *src2 )
328 {
329     RECT32 tmp;
330
331     if (IsRectEmpty32( src1 ))
332     {
333         SetRectEmpty32( dest );
334         return FALSE;
335     }
336     *dest = *src1;
337     if (IntersectRect32( &tmp, src1, src2 ))
338     {
339         if (EqualRect32( &tmp, dest ))
340         {
341             SetRectEmpty32( dest );
342             return FALSE;
343         }
344         if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
345         {
346             if (tmp.left == dest->left) dest->left = tmp.right;
347             else if (tmp.right == dest->right) dest->right = tmp.left;
348         }
349         else if ((tmp.left == dest->left) && (tmp.right == dest->right))
350         {
351             if (tmp.top == dest->top) dest->top = tmp.bottom;
352             else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
353         }
354     }
355     return TRUE;
356 }