Tranlation of English README to Portuguese.
[wine/wine64.git] / windows / rect.c
blobbba18ef19b990af73b8b42c142aebeae25bfb8e8
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 "windef.h"
22 #include "wingdi.h"
23 #include "wine/winuser16.h"
24 #include "winuser.h"
26 /***********************************************************************
27 * SetRect (USER.72)
29 void WINAPI SetRect16( LPRECT16 rect, INT16 left, INT16 top,
30 INT16 right, INT16 bottom )
32 rect->left = left;
33 rect->right = right;
34 rect->top = top;
35 rect->bottom = bottom;
39 /***********************************************************************
40 * SetRect (USER32.@)
42 BOOL WINAPI SetRect( LPRECT rect, INT left, INT top,
43 INT right, INT bottom )
45 if (!rect) return FALSE;
46 rect->left = left;
47 rect->right = right;
48 rect->top = top;
49 rect->bottom = bottom;
50 return TRUE;
54 /***********************************************************************
55 * SetRectEmpty (USER.73)
57 void WINAPI SetRectEmpty16( LPRECT16 rect )
59 rect->left = rect->right = rect->top = rect->bottom = 0;
63 /***********************************************************************
64 * SetRectEmpty (USER32.@)
66 BOOL WINAPI SetRectEmpty( LPRECT rect )
68 if (!rect) return FALSE;
69 rect->left = rect->right = rect->top = rect->bottom = 0;
70 return TRUE;
74 /***********************************************************************
75 * CopyRect (USER.74)
77 BOOL16 WINAPI CopyRect16( RECT16 *dest, const RECT16 *src )
79 *dest = *src;
80 return TRUE;
84 /***********************************************************************
85 * CopyRect (USER32.@)
87 BOOL WINAPI CopyRect( RECT *dest, const RECT *src )
89 if (!dest || !src)
90 return FALSE;
91 *dest = *src;
92 return TRUE;
96 /***********************************************************************
97 * IsRectEmpty (USER.75)
99 * Bug compat: Windows checks for 0 or negative width/height.
101 BOOL16 WINAPI IsRectEmpty16( const RECT16 *rect )
103 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
107 /***********************************************************************
108 * IsRectEmpty (USER32.@)
110 * Bug compat: Windows checks for 0 or negative width/height.
112 BOOL WINAPI IsRectEmpty( const RECT *rect )
114 if (!rect) return TRUE;
115 return ((rect->left >= rect->right) || (rect->top >= rect->bottom));
119 /***********************************************************************
120 * PtInRect (USER.76)
122 BOOL16 WINAPI PtInRect16( const RECT16 *rect, POINT16 pt )
124 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
125 (pt.y >= rect->top) && (pt.y < rect->bottom));
129 /***********************************************************************
130 * PtInRect (USER32.@)
132 BOOL WINAPI PtInRect( const RECT *rect, POINT pt )
134 if (!rect) return FALSE;
135 return ((pt.x >= rect->left) && (pt.x < rect->right) &&
136 (pt.y >= rect->top) && (pt.y < rect->bottom));
140 /***********************************************************************
141 * OffsetRect (USER.77)
143 void WINAPI OffsetRect16( LPRECT16 rect, INT16 x, INT16 y )
145 rect->left += x;
146 rect->right += x;
147 rect->top += y;
148 rect->bottom += y;
152 /***********************************************************************
153 * OffsetRect (USER32.@)
155 BOOL WINAPI OffsetRect( LPRECT rect, INT x, INT y )
157 if (!rect) return FALSE;
158 rect->left += x;
159 rect->right += x;
160 rect->top += y;
161 rect->bottom += y;
162 return TRUE;
166 /***********************************************************************
167 * InflateRect (USER.78)
169 void WINAPI InflateRect16( LPRECT16 rect, INT16 x, INT16 y )
171 rect->left -= x;
172 rect->top -= y;
173 rect->right += x;
174 rect->bottom += y;
178 /***********************************************************************
179 * InflateRect (USER32.@)
181 BOOL WINAPI InflateRect( LPRECT rect, INT x, INT y )
183 if (!rect) return FALSE;
184 rect->left -= x;
185 rect->top -= y;
186 rect->right += x;
187 rect->bottom += y;
188 return TRUE;
192 /***********************************************************************
193 * IntersectRect (USER.79)
195 BOOL16 WINAPI IntersectRect16( LPRECT16 dest, const RECT16 *src1,
196 const RECT16 *src2 )
198 if (IsRectEmpty16(src1) || IsRectEmpty16(src2) ||
199 (src1->left >= src2->right) || (src2->left >= src1->right) ||
200 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
202 SetRectEmpty16( dest );
203 return FALSE;
205 dest->left = max( src1->left, src2->left );
206 dest->right = min( src1->right, src2->right );
207 dest->top = max( src1->top, src2->top );
208 dest->bottom = min( src1->bottom, src2->bottom );
209 return TRUE;
213 /***********************************************************************
214 * IntersectRect (USER32.@)
216 BOOL WINAPI IntersectRect( LPRECT dest, const RECT *src1,
217 const RECT *src2 )
219 if (!dest || !src1 || !src2) return FALSE;
220 if (IsRectEmpty(src1) || IsRectEmpty(src2) ||
221 (src1->left >= src2->right) || (src2->left >= src1->right) ||
222 (src1->top >= src2->bottom) || (src2->top >= src1->bottom))
224 SetRectEmpty( dest );
225 return FALSE;
227 dest->left = max( src1->left, src2->left );
228 dest->right = min( src1->right, src2->right );
229 dest->top = max( src1->top, src2->top );
230 dest->bottom = min( src1->bottom, src2->bottom );
231 return TRUE;
235 /***********************************************************************
236 * UnionRect (USER.80)
238 BOOL16 WINAPI UnionRect16( LPRECT16 dest, const RECT16 *src1,
239 const RECT16 *src2 )
241 if (IsRectEmpty16(src1))
243 if (IsRectEmpty16(src2))
245 SetRectEmpty16( dest );
246 return FALSE;
248 else *dest = *src2;
250 else
252 if (IsRectEmpty16(src2)) *dest = *src1;
253 else
255 dest->left = min( src1->left, src2->left );
256 dest->right = max( src1->right, src2->right );
257 dest->top = min( src1->top, src2->top );
258 dest->bottom = max( src1->bottom, src2->bottom );
261 return TRUE;
265 /***********************************************************************
266 * UnionRect (USER32.@)
268 BOOL WINAPI UnionRect( LPRECT dest, const RECT *src1,
269 const RECT *src2 )
271 if (!dest) return FALSE;
272 if (IsRectEmpty(src1))
274 if (IsRectEmpty(src2))
276 SetRectEmpty( dest );
277 return FALSE;
279 else *dest = *src2;
281 else
283 if (IsRectEmpty(src2)) *dest = *src1;
284 else
286 dest->left = min( src1->left, src2->left );
287 dest->right = max( src1->right, src2->right );
288 dest->top = min( src1->top, src2->top );
289 dest->bottom = max( src1->bottom, src2->bottom );
292 return TRUE;
296 /***********************************************************************
297 * EqualRect (USER.244)
299 BOOL16 WINAPI EqualRect16( const RECT16* rect1, const RECT16* rect2 )
301 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
302 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
306 /***********************************************************************
307 * EqualRect (USER32.@)
309 BOOL WINAPI EqualRect( const RECT* rect1, const RECT* rect2 )
311 if (!rect1 || !rect2) return FALSE;
312 return ((rect1->left == rect2->left) && (rect1->right == rect2->right) &&
313 (rect1->top == rect2->top) && (rect1->bottom == rect2->bottom));
317 /***********************************************************************
318 * SubtractRect (USER.373)
320 BOOL16 WINAPI SubtractRect16( LPRECT16 dest, const RECT16 *src1,
321 const RECT16 *src2 )
323 RECT16 tmp;
325 if (IsRectEmpty16( src1 ))
327 SetRectEmpty16( dest );
328 return FALSE;
330 *dest = *src1;
331 if (IntersectRect16( &tmp, src1, src2 ))
333 if (EqualRect16( &tmp, dest ))
335 SetRectEmpty16( dest );
336 return FALSE;
338 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
340 if (tmp.left == dest->left) dest->left = tmp.right;
341 else if (tmp.right == dest->right) dest->right = tmp.left;
343 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
345 if (tmp.top == dest->top) dest->top = tmp.bottom;
346 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
349 return TRUE;
353 /***********************************************************************
354 * SubtractRect (USER32.@)
356 BOOL WINAPI SubtractRect( LPRECT dest, const RECT *src1,
357 const RECT *src2 )
359 RECT tmp;
361 if (!dest) return FALSE;
362 if (IsRectEmpty( src1 ))
364 SetRectEmpty( dest );
365 return FALSE;
367 *dest = *src1;
368 if (IntersectRect( &tmp, src1, src2 ))
370 if (EqualRect( &tmp, dest ))
372 SetRectEmpty( dest );
373 return FALSE;
375 if ((tmp.top == dest->top) && (tmp.bottom == dest->bottom))
377 if (tmp.left == dest->left) dest->left = tmp.right;
378 else if (tmp.right == dest->right) dest->right = tmp.left;
380 else if ((tmp.left == dest->left) && (tmp.right == dest->right))
382 if (tmp.top == dest->top) dest->top = tmp.bottom;
383 else if (tmp.bottom == dest->bottom) dest->bottom = tmp.top;
386 return TRUE;