2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
8 #include "wine/winuser16.h"
11 /***********************************************************************
14 void WINAPI
SetRect16( LPRECT16 rect
, INT16 left
, INT16 top
,
15 INT16 right
, INT16 bottom
)
20 rect
->bottom
= bottom
;
24 /***********************************************************************
25 * SetRect32 (USER32.499)
27 BOOL WINAPI
SetRect( LPRECT rect
, INT left
, INT top
,
28 INT right
, INT bottom
)
33 rect
->bottom
= bottom
;
38 /***********************************************************************
39 * SetRectEmpty16 (USER.73)
41 void WINAPI
SetRectEmpty16( LPRECT16 rect
)
43 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
47 /***********************************************************************
48 * SetRectEmpty32 (USER32.500)
50 BOOL WINAPI
SetRectEmpty( LPRECT rect
)
52 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
57 /***********************************************************************
58 * CopyRect16 (USER.74)
60 BOOL16 WINAPI
CopyRect16( RECT16
*dest
, const RECT16
*src
)
67 /***********************************************************************
68 * CopyRect32 (USER32.62)
70 BOOL WINAPI
CopyRect( RECT
*dest
, const RECT
*src
)
79 /***********************************************************************
80 * IsRectEmpty16 (USER.75)
82 BOOL16 WINAPI
IsRectEmpty16( const RECT16
*rect
)
84 return ((rect
->left
== rect
->right
) || (rect
->top
== rect
->bottom
));
88 /***********************************************************************
89 * IsRectEmpty32 (USER32.347)
91 BOOL WINAPI
IsRectEmpty( const RECT
*rect
)
93 return ((rect
->left
== rect
->right
) || (rect
->top
== rect
->bottom
));
97 /***********************************************************************
98 * PtInRect16 (USER.76)
100 BOOL16 WINAPI
PtInRect16( const RECT16
*rect
, POINT16 pt
)
102 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
103 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
107 /***********************************************************************
108 * PtInRect32 (USER32.424)
110 BOOL WINAPI
PtInRect( const RECT
*rect
, POINT pt
)
112 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
113 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
117 /***********************************************************************
118 * OffsetRect16 (USER.77)
120 void WINAPI
OffsetRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
129 /***********************************************************************
130 * OffsetRect32 (USER32.406)
132 BOOL WINAPI
OffsetRect( LPRECT rect
, INT x
, INT y
)
142 /***********************************************************************
143 * InflateRect16 (USER.78)
145 void WINAPI
InflateRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
154 /***********************************************************************
155 * InflateRect32 (USER32.321)
157 BOOL WINAPI
InflateRect( LPRECT rect
, INT x
, INT y
)
167 /***********************************************************************
168 * IntersectRect16 (USER.79)
170 BOOL16 WINAPI
IntersectRect16( LPRECT16 dest
, const RECT16
*src1
,
173 if (IsRectEmpty16(src1
) || IsRectEmpty16(src2
) ||
174 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
175 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
177 SetRectEmpty16( dest
);
180 dest
->left
= MAX( src1
->left
, src2
->left
);
181 dest
->right
= MIN( src1
->right
, src2
->right
);
182 dest
->top
= MAX( src1
->top
, src2
->top
);
183 dest
->bottom
= MIN( src1
->bottom
, src2
->bottom
);
188 /***********************************************************************
189 * IntersectRect32 (USER32.327)
191 BOOL WINAPI
IntersectRect( LPRECT dest
, const RECT
*src1
,
194 if (IsRectEmpty(src1
) || IsRectEmpty(src2
) ||
195 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
196 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
198 SetRectEmpty( dest
);
201 dest
->left
= MAX( src1
->left
, src2
->left
);
202 dest
->right
= MIN( src1
->right
, src2
->right
);
203 dest
->top
= MAX( src1
->top
, src2
->top
);
204 dest
->bottom
= MIN( src1
->bottom
, src2
->bottom
);
209 /***********************************************************************
210 * UnionRect16 (USER.80)
212 BOOL16 WINAPI
UnionRect16( LPRECT16 dest
, const RECT16
*src1
,
215 if (IsRectEmpty16(src1
))
217 if (IsRectEmpty16(src2
))
219 SetRectEmpty16( dest
);
226 if (IsRectEmpty16(src2
)) *dest
= *src1
;
229 dest
->left
= MIN( src1
->left
, src2
->left
);
230 dest
->right
= MAX( src1
->right
, src2
->right
);
231 dest
->top
= MIN( src1
->top
, src2
->top
);
232 dest
->bottom
= MAX( src1
->bottom
, src2
->bottom
);
239 /***********************************************************************
240 * UnionRect32 (USER32.559)
242 BOOL WINAPI
UnionRect( LPRECT dest
, const RECT
*src1
,
245 if (IsRectEmpty(src1
))
247 if (IsRectEmpty(src2
))
249 SetRectEmpty( dest
);
256 if (IsRectEmpty(src2
)) *dest
= *src1
;
259 dest
->left
= MIN( src1
->left
, src2
->left
);
260 dest
->right
= MAX( src1
->right
, src2
->right
);
261 dest
->top
= MIN( src1
->top
, src2
->top
);
262 dest
->bottom
= MAX( src1
->bottom
, src2
->bottom
);
269 /***********************************************************************
270 * EqualRect16 (USER.244)
272 BOOL16 WINAPI
EqualRect16( const RECT16
* rect1
, const RECT16
* rect2
)
274 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
275 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
279 /***********************************************************************
280 * EqualRect32 (USER32.194)
282 BOOL WINAPI
EqualRect( const RECT
* rect1
, const RECT
* rect2
)
284 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
285 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
289 /***********************************************************************
290 * SubtractRect16 (USER.373)
292 BOOL16 WINAPI
SubtractRect16( LPRECT16 dest
, const RECT16
*src1
,
297 if (IsRectEmpty16( src1
))
299 SetRectEmpty16( dest
);
303 if (IntersectRect16( &tmp
, src1
, src2
))
305 if (EqualRect16( &tmp
, dest
))
307 SetRectEmpty16( dest
);
310 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
312 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
313 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
315 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
317 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
318 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;
325 /***********************************************************************
326 * SubtractRect32 (USER32.536)
328 BOOL WINAPI
SubtractRect( LPRECT dest
, const RECT
*src1
,
333 if (IsRectEmpty( src1
))
335 SetRectEmpty( dest
);
339 if (IntersectRect( &tmp
, src1
, src2
))
341 if (EqualRect( &tmp
, dest
))
343 SetRectEmpty( dest
);
346 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
348 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
349 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
351 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
353 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
354 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;