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
26 #include "wine/winuser16.h"
29 /***********************************************************************
32 void WINAPI
SetRect16( LPRECT16 rect
, INT16 left
, INT16 top
,
33 INT16 right
, INT16 bottom
)
38 rect
->bottom
= bottom
;
42 /***********************************************************************
45 BOOL WINAPI
SetRect( LPRECT rect
, INT left
, INT top
,
46 INT right
, INT bottom
)
48 if (!rect
) return FALSE
;
52 rect
->bottom
= bottom
;
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;
77 /***********************************************************************
80 BOOL16 WINAPI
CopyRect16( RECT16
*dest
, const RECT16
*src
)
87 /***********************************************************************
90 BOOL WINAPI
CopyRect( RECT
*dest
, const RECT
*src
)
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 /***********************************************************************
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
)
155 /***********************************************************************
156 * OffsetRect (USER32.@)
158 BOOL WINAPI
OffsetRect( LPRECT rect
, INT x
, INT y
)
160 if (!rect
) return FALSE
;
169 /***********************************************************************
170 * InflateRect (USER.78)
172 void WINAPI
InflateRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
181 /***********************************************************************
182 * InflateRect (USER32.@)
184 BOOL WINAPI
InflateRect( LPRECT rect
, INT x
, INT y
)
186 if (!rect
) return FALSE
;
195 /***********************************************************************
196 * IntersectRect (USER.79)
198 BOOL16 WINAPI
IntersectRect16( LPRECT16 dest
, const RECT16
*src1
,
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
);
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
);
216 /***********************************************************************
217 * IntersectRect (USER32.@)
219 BOOL WINAPI
IntersectRect( LPRECT dest
, const RECT
*src1
,
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
);
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
);
238 /***********************************************************************
239 * UnionRect (USER.80)
241 BOOL16 WINAPI
UnionRect16( LPRECT16 dest
, const RECT16
*src1
,
244 if (IsRectEmpty16(src1
))
246 if (IsRectEmpty16(src2
))
248 SetRectEmpty16( dest
);
255 if (IsRectEmpty16(src2
)) *dest
= *src1
;
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
);
268 /***********************************************************************
269 * UnionRect (USER32.@)
271 BOOL WINAPI
UnionRect( LPRECT dest
, const RECT
*src1
,
274 if (!dest
) return FALSE
;
275 if (IsRectEmpty(src1
))
277 if (IsRectEmpty(src2
))
279 SetRectEmpty( dest
);
286 if (IsRectEmpty(src2
)) *dest
= *src1
;
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
);
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
,
328 if (IsRectEmpty16( src1
))
330 SetRectEmpty16( dest
);
334 if (IntersectRect16( &tmp
, src1
, src2
))
336 if (EqualRect16( &tmp
, dest
))
338 SetRectEmpty16( dest
);
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
;
356 /***********************************************************************
357 * SubtractRect (USER32.@)
359 BOOL WINAPI
SubtractRect( LPRECT dest
, const RECT
*src1
,
364 if (!dest
) return FALSE
;
365 if (IsRectEmpty( src1
))
367 SetRectEmpty( dest
);
371 if (IntersectRect( &tmp
, src1
, src2
))
373 if (EqualRect( &tmp
, dest
))
375 SetRectEmpty( dest
);
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
;