1093582a88488632aa821df57abb1b402a2cb666
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: rect.c,v 1.15 2004/05/14 17:02:40 navaraf Exp $
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
35 /* FUNCTIONS *****************************************************************/
41 CopyRect(LPRECT lprcDst
, CONST RECT
*lprcSrc
)
43 if(lprcDst
== NULL
|| lprcSrc
== NULL
)
59 if (lprc1
== NULL
|| lprc2
== NULL
)
62 return (lprc1
->left
== lprc2
->left
) && (lprc1
->top
== lprc2
->top
) &&
63 (lprc1
->right
== lprc2
->right
) && (lprc1
->bottom
== lprc2
->bottom
);
71 InflateRect(LPRECT rect
, int dx
, int dy
)
85 IntersectRect(LPRECT lprcDst
,
89 if (IsRectEmpty(lprcSrc1
) || IsRectEmpty(lprcSrc2
) ||
90 lprcSrc1
->left
>= lprcSrc2
->right
||
91 lprcSrc2
->left
>= lprcSrc1
->right
||
92 lprcSrc1
->top
>= lprcSrc2
->bottom
||
93 lprcSrc2
->top
>= lprcSrc1
->bottom
)
95 SetRectEmpty(lprcDst
);
98 lprcDst
->left
= max(lprcSrc1
->left
, lprcSrc2
->left
);
99 lprcDst
->right
= min(lprcSrc1
->right
, lprcSrc2
->right
);
100 lprcDst
->top
= max(lprcSrc1
->top
, lprcSrc2
->top
);
101 lprcDst
->bottom
= min(lprcSrc1
->bottom
, lprcSrc2
->bottom
);
110 IsRectEmpty(CONST RECT
*lprc
)
112 return((lprc
->left
>= lprc
->right
) || (lprc
->top
>= lprc
->bottom
));
120 OffsetRect(LPRECT rect
, int dx
, int dy
)
137 PtInRect(CONST RECT
*lprc
, POINT pt
)
139 return((pt
.x
>= lprc
->left
) && (pt
.x
< lprc
->right
) &&
140 (pt
.y
>= lprc
->top
) && (pt
.y
< lprc
->bottom
));
144 SetRect(LPRECT lprc
, int xLeft
, int yTop
, int xRight
, int yBottom
)
148 lprc
->right
= xRight
;
149 lprc
->bottom
= yBottom
;
158 SetRectEmpty(LPRECT lprc
)
160 lprc
->left
= lprc
->right
= lprc
->top
= lprc
->bottom
= 0;
169 SubtractRect(LPRECT lprcDst
, CONST RECT
*lprcSrc1
, CONST RECT
*lprcSrc2
)
173 if(lprcDst
== NULL
|| lprcSrc1
== NULL
|| lprcSrc2
== NULL
)
176 CopyRect(lprcDst
, lprcSrc1
);
178 if(!IntersectRect(&tempRect
, lprcSrc1
, lprcSrc2
))
181 if (EqualRect(&tempRect
, lprcDst
))
183 SetRectEmpty(lprcDst
);
186 if(lprcDst
->top
== tempRect
.top
&& lprcDst
->bottom
== tempRect
.bottom
)
188 if(lprcDst
->left
== tempRect
.left
)
189 lprcDst
->left
= tempRect
.right
;
190 else if(lprcDst
->right
== tempRect
.right
)
191 lprcDst
->right
= tempRect
.left
;
193 else if(lprcDst
->left
== tempRect
.left
&& lprcDst
->right
== tempRect
.right
)
195 if(lprcDst
->top
== tempRect
.top
)
196 lprcDst
->top
= tempRect
.bottom
;
197 else if(lprcDst
->right
== tempRect
.right
)
198 lprcDst
->right
= tempRect
.left
;
209 UnionRect(LPRECT lprcDst
, CONST RECT
*lprcSrc1
, CONST RECT
*lprcSrc2
)
211 if (IsRectEmpty(lprcSrc1
))
213 if (IsRectEmpty(lprcSrc2
))
215 SetRectEmpty(lprcDst
);
220 *lprcDst
= *lprcSrc2
;
225 if (IsRectEmpty(lprcSrc2
))
227 *lprcDst
= *lprcSrc1
;
231 lprcDst
->left
= min(lprcSrc1
->left
, lprcSrc2
->left
);
232 lprcDst
->top
= min(lprcSrc1
->top
, lprcSrc2
->top
);
233 lprcDst
->right
= max(lprcSrc1
->right
, lprcSrc2
->right
);
234 lprcDst
->bottom
= max(lprcSrc1
->bottom
, lprcSrc2
->bottom
);