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
23 #include "wine/winuser16.h"
26 /***********************************************************************
29 void WINAPI
SetRect16( LPRECT16 rect
, INT16 left
, INT16 top
,
30 INT16 right
, INT16 bottom
)
35 rect
->bottom
= bottom
;
39 /***********************************************************************
42 BOOL WINAPI
SetRect( LPRECT rect
, INT left
, INT top
,
43 INT right
, INT bottom
)
45 if (!rect
) return FALSE
;
49 rect
->bottom
= bottom
;
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;
74 /***********************************************************************
77 BOOL16 WINAPI
CopyRect16( RECT16
*dest
, const RECT16
*src
)
84 /***********************************************************************
87 BOOL WINAPI
CopyRect( RECT
*dest
, const RECT
*src
)
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 /***********************************************************************
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
)
152 /***********************************************************************
153 * OffsetRect (USER32.@)
155 BOOL WINAPI
OffsetRect( LPRECT rect
, INT x
, INT y
)
157 if (!rect
) return FALSE
;
166 /***********************************************************************
167 * InflateRect (USER.78)
169 void WINAPI
InflateRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
178 /***********************************************************************
179 * InflateRect (USER32.@)
181 BOOL WINAPI
InflateRect( LPRECT rect
, INT x
, INT y
)
183 if (!rect
) return FALSE
;
192 /***********************************************************************
193 * IntersectRect (USER.79)
195 BOOL16 WINAPI
IntersectRect16( LPRECT16 dest
, const RECT16
*src1
,
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
);
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
);
213 /***********************************************************************
214 * IntersectRect (USER32.@)
216 BOOL WINAPI
IntersectRect( LPRECT dest
, const RECT
*src1
,
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
);
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
);
235 /***********************************************************************
236 * UnionRect (USER.80)
238 BOOL16 WINAPI
UnionRect16( LPRECT16 dest
, const RECT16
*src1
,
241 if (IsRectEmpty16(src1
))
243 if (IsRectEmpty16(src2
))
245 SetRectEmpty16( dest
);
252 if (IsRectEmpty16(src2
)) *dest
= *src1
;
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
);
265 /***********************************************************************
266 * UnionRect (USER32.@)
268 BOOL WINAPI
UnionRect( LPRECT dest
, const RECT
*src1
,
271 if (!dest
) return FALSE
;
272 if (IsRectEmpty(src1
))
274 if (IsRectEmpty(src2
))
276 SetRectEmpty( dest
);
283 if (IsRectEmpty(src2
)) *dest
= *src1
;
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
);
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
,
325 if (IsRectEmpty16( src1
))
327 SetRectEmpty16( dest
);
331 if (IntersectRect16( &tmp
, src1
, src2
))
333 if (EqualRect16( &tmp
, dest
))
335 SetRectEmpty16( dest
);
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
;
353 /***********************************************************************
354 * SubtractRect (USER32.@)
356 BOOL WINAPI
SubtractRect( LPRECT dest
, const RECT
*src1
,
361 if (!dest
) return FALSE
;
362 if (IsRectEmpty( src1
))
364 SetRectEmpty( dest
);
368 if (IntersectRect( &tmp
, src1
, src2
))
370 if (EqualRect( &tmp
, dest
))
372 SetRectEmpty( dest
);
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
;