xref: /reactos/win32ss/gdi/ntgdi/rect.c (revision 8a978a17)
1 /*
2  * PROJECT:         ReactOS win32 kernel mode subsystem
3  * LICENSE:         GPL - See COPYING in the top level directory
4  * FILE:            win32ss/gdi/ntgdi/rect.c
5  * PURPOSE:         Rect functions
6  * PROGRAMMER:      Timo Kreuzer
7  */
8 
9 #include <win32k.h>
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 /* FUNCTIONS *****************************************************************/
15 
16 BOOL
17 FASTCALL
18 RECTL_bUnionRect(
19     _Out_ RECTL *prclDst,
20     _In_ const RECTL *prcl1,
21     _In_ const RECTL *prcl2)
22 {
23     if (RECTL_bIsEmptyRect(prcl1))
24     {
25         if (RECTL_bIsEmptyRect(prcl2))
26 	    {
27 	        RECTL_vSetEmptyRect(prclDst);
28 	        return FALSE;
29 	    }
30         else
31 	    {
32 	        *prclDst = *prcl2;
33 	    }
34     }
35     else
36     {
37         if (RECTL_bIsEmptyRect(prcl2))
38 	    {
39 	        *prclDst = *prcl1;
40 	    }
41         else
42 	    {
43 	        prclDst->left = min(prcl1->left, prcl2->left);
44 	        prclDst->top = min(prcl1->top, prcl2->top);
45 	        prclDst->right = max(prcl1->right, prcl2->right);
46 	        prclDst->bottom = max(prcl1->bottom, prcl2->bottom);
47 	    }
48     }
49 
50     return TRUE;
51 }
52 
53 BOOL
54 FASTCALL
55 RECTL_bIntersectRect(
56     _Out_ RECTL* prclDst,
57     _In_ const RECTL* prcl1,
58     _In_ const RECTL* prcl2)
59 {
60     prclDst->left  = max(prcl1->left, prcl2->left);
61     prclDst->right = min(prcl1->right, prcl2->right);
62 
63     if (prclDst->left < prclDst->right)
64     {
65         prclDst->top    = max(prcl1->top, prcl2->top);
66         prclDst->bottom = min(prcl1->bottom, prcl2->bottom);
67 
68         if (prclDst->top < prclDst->bottom)
69         {
70             return TRUE;
71         }
72     }
73 
74     RECTL_vSetEmptyRect(prclDst);
75 
76     return FALSE;
77 }
78 
79 VOID
80 FASTCALL
81 RECTL_vMakeWellOrdered(
82     _Inout_ RECTL *prcl)
83 {
84     LONG lTmp;
85     if (prcl->left > prcl->right)
86     {
87         lTmp = prcl->left;
88         prcl->left = prcl->right;
89         prcl->right = lTmp;
90     }
91     if (prcl->top > prcl->bottom)
92     {
93         lTmp = prcl->top;
94         prcl->top = prcl->bottom;
95         prcl->bottom = lTmp;
96     }
97 }
98 
99 VOID
100 FASTCALL
101 RECTL_vInflateRect(
102     _Inout_ RECTL *rect,
103     _In_ INT dx,
104     _In_ INT dy)
105 {
106     rect->left -= dx;
107     rect->top -= dy;
108     rect->right += dx;
109     rect->bottom += dy;
110 }
111 
112 /* EOF */
113