ReactOS 0.4.15-dev-7674-gc0b4db1
rect.c File Reference
#include <user32.h>
Include dependency graph for rect.c:

Go to the source code of this file.

Functions

BOOL WINAPI CopyRect (LPRECT lprcDst, CONST RECT *lprcSrc)
 
BOOL WINAPI EqualRect (CONST RECT *lprc1, CONST RECT *lprc2)
 
BOOL WINAPI InflateRect (LPRECT rect, int dx, int dy)
 
BOOL WINAPI IntersectRect (LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
 
BOOL WINAPI IsRectEmpty (CONST RECT *lprc)
 
BOOL WINAPI OffsetRect (LPRECT rect, int dx, int dy)
 
BOOL WINAPI PtInRect (CONST RECT *lprc, POINT pt)
 
BOOL WINAPI SetRect (LPRECT lprc, int xLeft, int yTop, int xRight, int yBottom)
 
BOOL WINAPI SetRectEmpty (LPRECT lprc)
 
BOOL WINAPI SubtractRect (LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
 
BOOL WINAPI UnionRect (LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
 

Function Documentation

◆ CopyRect()

BOOL WINAPI CopyRect ( LPRECT  lprcDst,
CONST RECT lprcSrc 
)

Definition at line 35 of file rect.c.

37{
38 if (lprcDst == NULL || lprcSrc == NULL)
39 return FALSE;
40
41 *lprcDst = *lprcSrc;
42
43 return TRUE;
44}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

◆ EqualRect()

BOOL WINAPI EqualRect ( CONST RECT lprc1,
CONST RECT lprc2 
)

Definition at line 52 of file rect.c.

54{
55 if (lprc1 == NULL || lprc2 == NULL)
56 return FALSE;
57
58 return (lprc1->left == lprc2->left) && (lprc1->top == lprc2->top) &&
59 (lprc1->right == lprc2->right) && (lprc1->bottom == lprc2->bottom);
60}

Referenced by SubtractRect().

◆ InflateRect()

BOOL WINAPI InflateRect ( LPRECT  rect,
int  dx,
int  dy 
)

Definition at line 68 of file rect.c.

71{
72 if (rect == NULL)
73 return FALSE;
74
75 rect->left -= dx;
76 rect->top -= dy;
77 rect->right += dx;
78 rect->bottom += dy;
79
80 return TRUE;
81}
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
& rect
Definition: startmenu.cpp:1413

◆ IntersectRect()

BOOL WINAPI IntersectRect ( LPRECT  lprcDst,
CONST RECT lprcSrc1,
CONST RECT lprcSrc2 
)

Definition at line 89 of file rect.c.

92{
93 if (lprcDst == NULL || lprcSrc1 == NULL || lprcSrc2 == NULL)
94 return FALSE;
95
96 if (IsRectEmpty(lprcSrc1) || IsRectEmpty(lprcSrc2) ||
97 lprcSrc1->left >= lprcSrc2->right ||
98 lprcSrc2->left >= lprcSrc1->right ||
99 lprcSrc1->top >= lprcSrc2->bottom ||
100 lprcSrc2->top >= lprcSrc1->bottom)
101 {
102 SetRectEmpty(lprcDst);
103 return FALSE;
104 }
105
106 lprcDst->left = max(lprcSrc1->left, lprcSrc2->left);
107 lprcDst->right = min(lprcSrc1->right, lprcSrc2->right);
108 lprcDst->top = max(lprcSrc1->top, lprcSrc2->top);
109 lprcDst->bottom = min(lprcSrc1->bottom, lprcSrc2->bottom);
110
111 return TRUE;
112}
#define min(a, b)
Definition: monoChain.cc:55
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define max(a, b)
Definition: svc.c:63
BOOL WINAPI SetRectEmpty(LPRECT lprc)
Definition: rect.c:190
BOOL WINAPI IsRectEmpty(CONST RECT *lprc)
Definition: rect.c:120

Referenced by SubtractRect().

◆ IsRectEmpty()

BOOL WINAPI IsRectEmpty ( CONST RECT lprc)

Definition at line 120 of file rect.c.

121{
122 if (lprc == NULL)
123 return TRUE;
124
125 return ((lprc->left >= lprc->right) || (lprc->top >= lprc->bottom));
126}
_In_ int _Inout_ LPRECT lprc
Definition: winuser.h:4465

Referenced by IntersectRect(), and UnionRect().

◆ OffsetRect()

BOOL WINAPI OffsetRect ( LPRECT  rect,
int  dx,
int  dy 
)

Definition at line 134 of file rect.c.

137{
138 if (rect == NULL)
139 return FALSE;
140
141 rect->left += dx;
142 rect->top += dy;
143 rect->right += dx;
144 rect->bottom += dy;
145
146 return TRUE;
147}

◆ PtInRect()

BOOL WINAPI PtInRect ( CONST RECT lprc,
POINT  pt 
)

Definition at line 155 of file rect.c.

157{
158 if (lprc == NULL)
159 return FALSE;
160
161 return((pt.x >= lprc->left) && (pt.x < lprc->right) &&
162 (pt.y >= lprc->top) && (pt.y < lprc->bottom));
163}
#define pt(x, y)
Definition: drawing.c:79

◆ SetRect()

BOOL WINAPI SetRect ( LPRECT  lprc,
int  xLeft,
int  yTop,
int  xRight,
int  yBottom 
)

Definition at line 167 of file rect.c.

172{
173 if (lprc == NULL)
174 return FALSE;
175
176 lprc->left = xLeft;
177 lprc->top = yTop;
178 lprc->right = xRight;
179 lprc->bottom = yBottom;
180
181 return TRUE;
182}

◆ SetRectEmpty()

BOOL WINAPI SetRectEmpty ( LPRECT  lprc)

Definition at line 190 of file rect.c.

191{
192 if (lprc == NULL)
193 return FALSE;
194
195 lprc->left = lprc->right = lprc->top = lprc->bottom = 0;
196
197 return TRUE;
198}

Referenced by IntersectRect(), SubtractRect(), and UnionRect().

◆ SubtractRect()

BOOL WINAPI SubtractRect ( LPRECT  lprcDst,
CONST RECT lprcSrc1,
CONST RECT lprcSrc2 
)

Definition at line 206 of file rect.c.

209{
210 RECT tempRect;
211
212 if (lprcDst == NULL || lprcSrc1 == NULL || lprcSrc2 == NULL)
213 return FALSE;
214
215 if (!IntersectRect(&tempRect, lprcSrc1, lprcSrc2))
216 {
217 *lprcDst = *lprcSrc1;
218 return TRUE;
219 }
220
221 if (EqualRect(&tempRect, lprcSrc1))
222 {
223 SetRectEmpty(lprcDst);
224 return FALSE;
225 }
226
227 *lprcDst = *lprcSrc1;
228
229 if (lprcDst->top == tempRect.top && lprcDst->bottom == tempRect.bottom)
230 {
231 if (lprcDst->left == tempRect.left)
232 lprcDst->left = tempRect.right;
233 else if (lprcDst->right == tempRect.right)
234 lprcDst->right = tempRect.left;
235 }
236 else if (lprcDst->left == tempRect.left && lprcDst->right == tempRect.right)
237 {
238 if (lprcDst->top == tempRect.top)
239 lprcDst->top = tempRect.bottom;
240 else if (lprcDst->bottom == tempRect.bottom)
241 lprcDst->bottom = tempRect.top;
242 }
243
244 return TRUE;
245}
BOOL WINAPI EqualRect(CONST RECT *lprc1, CONST RECT *lprc2)
Definition: rect.c:52
BOOL WINAPI IntersectRect(LPRECT lprcDst, CONST RECT *lprcSrc1, CONST RECT *lprcSrc2)
Definition: rect.c:89

◆ UnionRect()

BOOL WINAPI UnionRect ( LPRECT  lprcDst,
CONST RECT lprcSrc1,
CONST RECT lprcSrc2 
)

Definition at line 253 of file rect.c.

256{
257 if (lprcDst == NULL || lprcSrc1 == NULL || lprcSrc2 == NULL)
258 return FALSE;
259
260 if (IsRectEmpty(lprcSrc1))
261 {
262 if (IsRectEmpty(lprcSrc2))
263 {
264 SetRectEmpty(lprcDst);
265 return FALSE;
266 }
267 else
268 {
269 *lprcDst = *lprcSrc2;
270 }
271 }
272 else
273 {
274 if (IsRectEmpty(lprcSrc2))
275 {
276 *lprcDst = *lprcSrc1;
277 }
278 else
279 {
280 lprcDst->left = min(lprcSrc1->left, lprcSrc2->left);
281 lprcDst->top = min(lprcSrc1->top, lprcSrc2->top);
282 lprcDst->right = max(lprcSrc1->right, lprcSrc2->right);
283 lprcDst->bottom = max(lprcSrc1->bottom, lprcSrc2->bottom);
284 }
285 }
286
287 return TRUE;
288}