2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
10 #include "wine/winuser16.h"
13 /***********************************************************************
16 void WINAPI
SetRect16( LPRECT16 rect
, INT16 left
, INT16 top
,
17 INT16 right
, INT16 bottom
)
22 rect
->bottom
= bottom
;
26 /***********************************************************************
29 BOOL WINAPI
SetRect( LPRECT rect
, INT left
, INT top
,
30 INT right
, INT bottom
)
35 rect
->bottom
= bottom
;
40 /***********************************************************************
41 * SetRectEmpty (USER.73)
43 void WINAPI
SetRectEmpty16( LPRECT16 rect
)
45 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
49 /***********************************************************************
50 * SetRectEmpty (USER32.@)
52 BOOL WINAPI
SetRectEmpty( LPRECT rect
)
54 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
59 /***********************************************************************
62 BOOL16 WINAPI
CopyRect16( RECT16
*dest
, const RECT16
*src
)
69 /***********************************************************************
72 BOOL WINAPI
CopyRect( RECT
*dest
, const RECT
*src
)
81 /***********************************************************************
82 * IsRectEmpty (USER.75)
84 * Bug compat: Windows checks for 0 or negative width/height.
86 BOOL16 WINAPI
IsRectEmpty16( const RECT16
*rect
)
88 return ((rect
->left
>= rect
->right
) || (rect
->top
>= rect
->bottom
));
92 /***********************************************************************
93 * IsRectEmpty (USER32.@)
95 * Bug compat: Windows checks for 0 or negative width/height.
97 BOOL WINAPI
IsRectEmpty( const RECT
*rect
)
99 return ((rect
->left
>= rect
->right
) || (rect
->top
>= rect
->bottom
));
103 /***********************************************************************
106 BOOL16 WINAPI
PtInRect16( const RECT16
*rect
, POINT16 pt
)
108 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
109 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
113 /***********************************************************************
114 * PtInRect (USER32.@)
116 BOOL WINAPI
PtInRect( const RECT
*rect
, POINT pt
)
118 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
119 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
123 /***********************************************************************
124 * OffsetRect (USER.77)
126 void WINAPI
OffsetRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
135 /***********************************************************************
136 * OffsetRect (USER32.@)
138 BOOL WINAPI
OffsetRect( LPRECT rect
, INT x
, INT y
)
148 /***********************************************************************
149 * InflateRect (USER.78)
151 void WINAPI
InflateRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
160 /***********************************************************************
161 * InflateRect (USER32.@)
163 BOOL WINAPI
InflateRect( LPRECT rect
, INT x
, INT y
)
173 /***********************************************************************
174 * IntersectRect (USER.79)
176 BOOL16 WINAPI
IntersectRect16( LPRECT16 dest
, const RECT16
*src1
,
179 if (IsRectEmpty16(src1
) || IsRectEmpty16(src2
) ||
180 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
181 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
183 SetRectEmpty16( dest
);
186 dest
->left
= max( src1
->left
, src2
->left
);
187 dest
->right
= min( src1
->right
, src2
->right
);
188 dest
->top
= max( src1
->top
, src2
->top
);
189 dest
->bottom
= min( src1
->bottom
, src2
->bottom
);
194 /***********************************************************************
195 * IntersectRect (USER32.@)
197 BOOL WINAPI
IntersectRect( LPRECT dest
, const RECT
*src1
,
200 if (IsRectEmpty(src1
) || IsRectEmpty(src2
) ||
201 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
202 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
204 SetRectEmpty( dest
);
207 dest
->left
= max( src1
->left
, src2
->left
);
208 dest
->right
= min( src1
->right
, src2
->right
);
209 dest
->top
= max( src1
->top
, src2
->top
);
210 dest
->bottom
= min( src1
->bottom
, src2
->bottom
);
215 /***********************************************************************
216 * UnionRect (USER.80)
218 BOOL16 WINAPI
UnionRect16( LPRECT16 dest
, const RECT16
*src1
,
221 if (IsRectEmpty16(src1
))
223 if (IsRectEmpty16(src2
))
225 SetRectEmpty16( dest
);
232 if (IsRectEmpty16(src2
)) *dest
= *src1
;
235 dest
->left
= min( src1
->left
, src2
->left
);
236 dest
->right
= max( src1
->right
, src2
->right
);
237 dest
->top
= min( src1
->top
, src2
->top
);
238 dest
->bottom
= max( src1
->bottom
, src2
->bottom
);
245 /***********************************************************************
246 * UnionRect (USER32.@)
248 BOOL WINAPI
UnionRect( LPRECT dest
, const RECT
*src1
,
251 if (IsRectEmpty(src1
))
253 if (IsRectEmpty(src2
))
255 SetRectEmpty( dest
);
262 if (IsRectEmpty(src2
)) *dest
= *src1
;
265 dest
->left
= min( src1
->left
, src2
->left
);
266 dest
->right
= max( src1
->right
, src2
->right
);
267 dest
->top
= min( src1
->top
, src2
->top
);
268 dest
->bottom
= max( src1
->bottom
, src2
->bottom
);
275 /***********************************************************************
276 * EqualRect (USER.244)
278 BOOL16 WINAPI
EqualRect16( const RECT16
* rect1
, const RECT16
* rect2
)
280 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
281 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
285 /***********************************************************************
286 * EqualRect (USER32.@)
288 BOOL WINAPI
EqualRect( const RECT
* rect1
, const RECT
* rect2
)
290 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
291 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
295 /***********************************************************************
296 * SubtractRect (USER.373)
298 BOOL16 WINAPI
SubtractRect16( LPRECT16 dest
, const RECT16
*src1
,
303 if (IsRectEmpty16( src1
))
305 SetRectEmpty16( dest
);
309 if (IntersectRect16( &tmp
, src1
, src2
))
311 if (EqualRect16( &tmp
, dest
))
313 SetRectEmpty16( dest
);
316 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
318 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
319 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
321 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
323 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
324 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;
331 /***********************************************************************
332 * SubtractRect (USER32.@)
334 BOOL WINAPI
SubtractRect( LPRECT dest
, const RECT
*src1
,
339 if (IsRectEmpty( src1
))
341 SetRectEmpty( dest
);
345 if (IntersectRect( &tmp
, src1
, src2
))
347 if (EqualRect( &tmp
, dest
))
349 SetRectEmpty( dest
);
352 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
354 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
355 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
357 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
359 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
360 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;