2 * Rectangle-related functions
4 * Copyright 1993, 1996 Alexandre Julliard
11 /***********************************************************************
14 void SetRect16(LPRECT16 rect
, INT16 left
, INT16 top
, INT16 right
, INT16 bottom
)
19 rect
->bottom
= bottom
;
23 /***********************************************************************
24 * SetRect32 (USER32.498)
26 void SetRect32(LPRECT32 rect
, INT32 left
, INT32 top
, INT32 right
, INT32 bottom
)
31 rect
->bottom
= bottom
;
35 /***********************************************************************
36 * SetRectEmpty16 (USER.73)
38 void SetRectEmpty16( LPRECT16 rect
)
40 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
44 /***********************************************************************
45 * SetRectEmpty32 (USER32.499)
47 void SetRectEmpty32( LPRECT32 rect
)
49 rect
->left
= rect
->right
= rect
->top
= rect
->bottom
= 0;
53 /***********************************************************************
54 * CopyRect16 (USER.74)
56 BOOL16
CopyRect16( RECT16
*dest
, const RECT16
*src
)
63 /***********************************************************************
64 * CopyRect32 (USER32.61)
66 BOOL32
CopyRect32( RECT32
*dest
, const RECT32
*src
)
73 /***********************************************************************
74 * IsRectEmpty16 (USER.75)
76 BOOL16
IsRectEmpty16( const RECT16
*rect
)
78 return ((rect
->left
== rect
->right
) || (rect
->top
== rect
->bottom
));
82 /***********************************************************************
83 * IsRectEmpty32 (USER32.346)
85 BOOL32
IsRectEmpty32( const RECT32
*rect
)
87 return ((rect
->left
== rect
->right
) || (rect
->top
== rect
->bottom
));
91 /***********************************************************************
92 * PtInRect16 (USER.76)
94 BOOL16
PtInRect16( const RECT16
*rect
, POINT16 pt
)
96 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
97 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
101 /***********************************************************************
102 * PtInRect32 (USER32.423)
104 BOOL32
PtInRect32( const RECT32
*rect
, POINT32 pt
)
106 return ((pt
.x
>= rect
->left
) && (pt
.x
< rect
->right
) &&
107 (pt
.y
>= rect
->top
) && (pt
.y
< rect
->bottom
));
111 /***********************************************************************
112 * OffsetRect16 (USER.77)
114 void OffsetRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
123 /***********************************************************************
124 * OffsetRect32 (USER32.405)
126 void OffsetRect32( LPRECT32 rect
, INT32 x
, INT32 y
)
135 /***********************************************************************
136 * InflateRect16 (USER.78)
138 void InflateRect16( LPRECT16 rect
, INT16 x
, INT16 y
)
147 /***********************************************************************
148 * InflateRect32 (USER32.320)
150 void InflateRect32( LPRECT32 rect
, INT32 x
, INT32 y
)
159 /***********************************************************************
160 * IntersectRect16 (USER.79)
162 BOOL16
IntersectRect16( LPRECT16 dest
, const RECT16
*src1
, const RECT16
*src2
)
164 if (IsRectEmpty16(src1
) || IsRectEmpty16(src2
) ||
165 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
166 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
168 SetRectEmpty16( dest
);
171 dest
->left
= MAX( src1
->left
, src2
->left
);
172 dest
->right
= MIN( src1
->right
, src2
->right
);
173 dest
->top
= MAX( src1
->top
, src2
->top
);
174 dest
->bottom
= MIN( src1
->bottom
, src2
->bottom
);
179 /***********************************************************************
180 * IntersectRect32 (USER32.326)
182 BOOL32
IntersectRect32( LPRECT32 dest
, const RECT32
*src1
, const RECT32
*src2
)
184 if (IsRectEmpty32(src1
) || IsRectEmpty32(src2
) ||
185 (src1
->left
>= src2
->right
) || (src2
->left
>= src1
->right
) ||
186 (src1
->top
>= src2
->bottom
) || (src2
->top
>= src1
->bottom
))
188 SetRectEmpty32( dest
);
191 dest
->left
= MAX( src1
->left
, src2
->left
);
192 dest
->right
= MIN( src1
->right
, src2
->right
);
193 dest
->top
= MAX( src1
->top
, src2
->top
);
194 dest
->bottom
= MIN( src1
->bottom
, src2
->bottom
);
199 /***********************************************************************
200 * UnionRect16 (USER.80)
202 BOOL16
UnionRect16( LPRECT16 dest
, const RECT16
*src1
, const RECT16
*src2
)
204 if (IsRectEmpty16(src1
))
206 if (IsRectEmpty16(src2
))
208 SetRectEmpty16( dest
);
215 if (IsRectEmpty16(src2
)) *dest
= *src1
;
218 dest
->left
= MIN( src1
->left
, src2
->left
);
219 dest
->right
= MAX( src1
->right
, src2
->right
);
220 dest
->top
= MIN( src1
->top
, src2
->top
);
221 dest
->bottom
= MAX( src1
->bottom
, src2
->bottom
);
228 /***********************************************************************
229 * UnionRect32 (USER32.558)
231 BOOL32
UnionRect32( LPRECT32 dest
, const RECT32
*src1
, const RECT32
*src2
)
233 if (IsRectEmpty32(src1
))
235 if (IsRectEmpty32(src2
))
237 SetRectEmpty32( dest
);
244 if (IsRectEmpty32(src2
)) *dest
= *src1
;
247 dest
->left
= MIN( src1
->left
, src2
->left
);
248 dest
->right
= MAX( src1
->right
, src2
->right
);
249 dest
->top
= MIN( src1
->top
, src2
->top
);
250 dest
->bottom
= MAX( src1
->bottom
, src2
->bottom
);
257 /***********************************************************************
258 * EqualRect16 (USER.244)
260 BOOL16
EqualRect16( const RECT16
* rect1
, const RECT16
* rect2
)
262 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
263 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
267 /***********************************************************************
268 * EqualRect32 (USER32.193)
270 BOOL32
EqualRect32( const RECT32
* rect1
, const RECT32
* rect2
)
272 return ((rect1
->left
== rect2
->left
) && (rect1
->right
== rect2
->right
) &&
273 (rect1
->top
== rect2
->top
) && (rect1
->bottom
== rect2
->bottom
));
277 /***********************************************************************
278 * SubtractRect16 (USER.373)
280 BOOL16
SubtractRect16( LPRECT16 dest
, const RECT16
*src1
, const RECT16
*src2
)
284 if (IsRectEmpty16( src1
))
286 SetRectEmpty16( dest
);
290 if (IntersectRect16( &tmp
, src1
, src2
))
292 if (EqualRect16( &tmp
, dest
))
294 SetRectEmpty16( dest
);
297 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
299 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
300 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
302 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
304 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
305 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;
312 /***********************************************************************
313 * SubtractRect32 (USER32.535)
315 BOOL32
SubtractRect32( LPRECT32 dest
, const RECT32
*src1
, const RECT32
*src2
)
319 if (IsRectEmpty32( src1
))
321 SetRectEmpty32( dest
);
325 if (IntersectRect32( &tmp
, src1
, src2
))
327 if (EqualRect32( &tmp
, dest
))
329 SetRectEmpty32( dest
);
332 if ((tmp
.top
== dest
->top
) && (tmp
.bottom
== dest
->bottom
))
334 if (tmp
.left
== dest
->left
) dest
->left
= tmp
.right
;
335 else if (tmp
.right
== dest
->right
) dest
->right
= tmp
.left
;
337 else if ((tmp
.left
== dest
->left
) && (tmp
.right
== dest
->right
))
339 if (tmp
.top
== dest
->top
) dest
->top
= tmp
.bottom
;
340 else if (tmp
.bottom
== dest
->bottom
) dest
->bottom
= tmp
.top
;