xref: /reactos/win32ss/gdi/ntgdi/coord.h (revision 405ce532)
1c2c66affSColin Finck #pragma once
2c2c66affSColin Finck 
3c2c66affSColin Finck /* Maximum extend of coordinate space */
4c2c66affSColin Finck #define MIN_COORD (INT_MIN / 16)
5c2c66affSColin Finck #define MAX_COORD (INT_MAX / 16)
6c2c66affSColin Finck 
7*405ce532SJérôme Gardou /*
8*405ce532SJérôme Gardou  * Applies matrix (which is made of FLOATOBJs) to the points array, which are made of integers.
9*405ce532SJérôme Gardou  */
10*405ce532SJérôme Gardou static
11*405ce532SJérôme Gardou inline
12*405ce532SJérôme Gardou BOOLEAN
INTERNAL_APPLY_MATRIX(PMATRIX matrix,LPPOINT points,UINT count)13*405ce532SJérôme Gardou INTERNAL_APPLY_MATRIX(PMATRIX matrix, LPPOINT points, UINT count)
14*405ce532SJérôme Gardou {
15*405ce532SJérôme Gardou     while (count--)
16*405ce532SJérôme Gardou     {
17*405ce532SJérôme Gardou         FLOATOBJ x, y;
18*405ce532SJérôme Gardou         FLOATOBJ tmp;
19c2c66affSColin Finck 
20*405ce532SJérôme Gardou         /* x = x * matrix->efM11 + y * matrix->efM21 + matrix->efDx; */
21*405ce532SJérôme Gardou         FLOATOBJ_SetLong(&x, points[count].x);
22*405ce532SJérôme Gardou         FLOATOBJ_Mul(&x, &matrix->efM11);
23*405ce532SJérôme Gardou         tmp = matrix->efM21;
24*405ce532SJérôme Gardou         FLOATOBJ_MulLong(&tmp, points[count].y);
25*405ce532SJérôme Gardou         FLOATOBJ_Add(&x, &tmp);
26*405ce532SJérôme Gardou         FLOATOBJ_Add(&x, &matrix->efDx);
27*405ce532SJérôme Gardou 
28*405ce532SJérôme Gardou         /* y = x * matrix->efM12 + y * matrix->efM22 + matrix->efDy; */
29*405ce532SJérôme Gardou         FLOATOBJ_SetLong(&y, points[count].y);
30*405ce532SJérôme Gardou         FLOATOBJ_Mul(&y, &matrix->efM22);
31*405ce532SJérôme Gardou         tmp = matrix->efM12;
32*405ce532SJérôme Gardou         FLOATOBJ_MulLong(&tmp, points[count].x);
33*405ce532SJérôme Gardou         FLOATOBJ_Add(&y, &tmp);
34*405ce532SJérôme Gardou         FLOATOBJ_Add(&y, &matrix->efDy);
35*405ce532SJérôme Gardou 
36*405ce532SJérôme Gardou         if (!FLOATOBJ_bConvertToLong(&x, &points[count].x))
37*405ce532SJérôme Gardou             return FALSE;
38*405ce532SJérôme Gardou         if (!FLOATOBJ_bConvertToLong(&y, &points[count].y))
39*405ce532SJérôme Gardou             return FALSE;
40*405ce532SJérôme Gardou     }
41*405ce532SJérôme Gardou     return TRUE;
42*405ce532SJérôme Gardou }
43*405ce532SJérôme Gardou 
44*405ce532SJérôme Gardou static
45*405ce532SJérôme Gardou inline
46*405ce532SJérôme Gardou BOOLEAN
INTERNAL_LPTODP(DC * dc,LPPOINT points,UINT count)47*405ce532SJérôme Gardou INTERNAL_LPTODP(DC *dc, LPPOINT points, UINT count)
48*405ce532SJérôme Gardou {
49*405ce532SJérôme Gardou     return INTERNAL_APPLY_MATRIX(&dc->pdcattr->mxWorldToDevice, points, count);
50*405ce532SJérôme Gardou }
51*405ce532SJérôme Gardou 
52*405ce532SJérôme Gardou static
53*405ce532SJérôme Gardou inline
54*405ce532SJérôme Gardou BOOLEAN
INTERNAL_DPTOLP(DC * dc,LPPOINT points,UINT count)55*405ce532SJérôme Gardou INTERNAL_DPTOLP(DC *dc, LPPOINT points, UINT count)
56*405ce532SJérôme Gardou {
57*405ce532SJérôme Gardou     return INTERNAL_APPLY_MATRIX(&dc->pdcattr->mxDeviceToWorld, points, count);
58*405ce532SJérôme Gardou }
59c2c66affSColin Finck 
60c2c66affSColin Finck FORCEINLINE
61c2c66affSColin Finck void
XFormToMatrix(MATRIX * pmx,const XFORML * pxform)62c2c66affSColin Finck XFormToMatrix(
63c2c66affSColin Finck     MATRIX *pmx,
64c2c66affSColin Finck     const XFORML *pxform)
65c2c66affSColin Finck {
66c2c66affSColin Finck     XFORMOBJ xo;
67c2c66affSColin Finck     XFORMOBJ_vInit(&xo, pmx);
68c2c66affSColin Finck     XFORMOBJ_iSetXform(&xo, pxform);
69c2c66affSColin Finck }
70c2c66affSColin Finck 
71c2c66affSColin Finck FORCEINLINE
72c2c66affSColin Finck void
MatrixToXForm(XFORML * pxform,const MATRIX * pmx)73c2c66affSColin Finck MatrixToXForm(
74c2c66affSColin Finck     XFORML *pxform,
75c2c66affSColin Finck     const MATRIX *pmx)
76c2c66affSColin Finck {
77c2c66affSColin Finck     XFORMOBJ xo;
78c2c66affSColin Finck     XFORMOBJ_vInit(&xo, (MATRIX*)pmx);
79c2c66affSColin Finck     XFORMOBJ_iGetXform(&xo, pxform);
80c2c66affSColin Finck }
81c2c66affSColin Finck 
82c2c66affSColin Finck FORCEINLINE
83c2c66affSColin Finck void
InvertXform(XFORML * pxformDest,const XFORML * pxformSource)84c2c66affSColin Finck InvertXform(
85c2c66affSColin Finck     XFORML *pxformDest,
86c2c66affSColin Finck     const XFORML *pxformSource)
87c2c66affSColin Finck {
88c2c66affSColin Finck     XFORMOBJ xo;
89c2c66affSColin Finck     MATRIX mx;
90c2c66affSColin Finck 
91c2c66affSColin Finck     XFORMOBJ_vInit(&xo, &mx);
92c2c66affSColin Finck     XFORMOBJ_iSetXform(&xo, pxformSource);
93c2c66affSColin Finck     XFORMOBJ_iInverse(&xo, &xo);
94c2c66affSColin Finck     XFORMOBJ_iGetXform(&xo, pxformDest);
95c2c66affSColin Finck }
96c2c66affSColin Finck 
97c2c66affSColin Finck VOID
98c2c66affSColin Finck FASTCALL
99c2c66affSColin Finck DC_vFixIsotropicMapping(PDC pdc);
100c2c66affSColin Finck 
101c2c66affSColin Finck VOID
102c2c66affSColin Finck FASTCALL
103c2c66affSColin Finck DC_vUpdateWorldToDevice(PDC pdc);
104c2c66affSColin Finck 
105c2c66affSColin Finck VOID
106c2c66affSColin Finck FASTCALL
107c2c66affSColin Finck DC_vUpdateDeviceToWorld(PDC pdc);
108c2c66affSColin Finck 
109c2c66affSColin Finck FORCEINLINE
110c2c66affSColin Finck PSIZEL
DC_pszlViewportExt(PDC pdc)111c2c66affSColin Finck DC_pszlViewportExt(PDC pdc)
112c2c66affSColin Finck {
113c2c66affSColin Finck     PDC_ATTR pdcattr = pdc->pdcattr;
114c2c66affSColin Finck 
115c2c66affSColin Finck     /* Check if we need isotropic fixup */
116c2c66affSColin Finck     if ((pdcattr->flXform & PAGE_EXTENTS_CHANGED) &&
117c2c66affSColin Finck         (pdcattr->iMapMode == MM_ISOTROPIC))
118c2c66affSColin Finck     {
119c2c66affSColin Finck         /* Fixup viewport extension */
120c2c66affSColin Finck         DC_vFixIsotropicMapping(pdc);
121c2c66affSColin Finck     }
122c2c66affSColin Finck 
123c2c66affSColin Finck     return &pdcattr->szlViewportExt;
124c2c66affSColin Finck }
125c2c66affSColin Finck 
126c2c66affSColin Finck FORCEINLINE
127c2c66affSColin Finck PMATRIX
DC_pmxWorldToPage(PDC pdc)128c2c66affSColin Finck DC_pmxWorldToPage(PDC pdc)
129c2c66affSColin Finck {
130c2c66affSColin Finck     return &pdc->pdcattr->mxWorldToPage;
131c2c66affSColin Finck }
132c2c66affSColin Finck 
133c2c66affSColin Finck FORCEINLINE
134c2c66affSColin Finck PMATRIX
DC_pmxWorldToDevice(PDC pdc)135c2c66affSColin Finck DC_pmxWorldToDevice(PDC pdc)
136c2c66affSColin Finck {
137c2c66affSColin Finck     /* Check if world or page xform was changed */
138c2c66affSColin Finck     if (pdc->pdcattr->flXform & (PAGE_XLATE_CHANGED|PAGE_EXTENTS_CHANGED|WORLD_XFORM_CHANGED))
139c2c66affSColin Finck     {
140c2c66affSColin Finck         /* Update the world-to-device xform */
141c2c66affSColin Finck          DC_vUpdateWorldToDevice(pdc);
142c2c66affSColin Finck     }
143c2c66affSColin Finck 
144c2c66affSColin Finck     return &pdc->pdcattr->mxWorldToDevice;
145c2c66affSColin Finck }
146c2c66affSColin Finck 
147c2c66affSColin Finck FORCEINLINE
148c2c66affSColin Finck PMATRIX
DC_pmxDeviceToWorld(PDC pdc)149c2c66affSColin Finck DC_pmxDeviceToWorld(PDC pdc)
150c2c66affSColin Finck {
151c2c66affSColin Finck     /* Check if the device-to-world xform is invalid */
152c2c66affSColin Finck     if (pdc->pdcattr->flXform & DEVICE_TO_WORLD_INVALID)
153c2c66affSColin Finck     {
154c2c66affSColin Finck         /* Update the world-to-device xform */
155c2c66affSColin Finck          DC_vUpdateDeviceToWorld(pdc);
156c2c66affSColin Finck     }
157c2c66affSColin Finck 
158c2c66affSColin Finck     return &pdc->pdcattr->mxDeviceToWorld;
159c2c66affSColin Finck }
160c2c66affSColin Finck 
161c2c66affSColin Finck BOOL
162c2c66affSColin Finck NTAPI
163c2c66affSColin Finck GreModifyWorldTransform(
164c2c66affSColin Finck     PDC pdc,
165c2c66affSColin Finck     const XFORML *pXForm,
166c2c66affSColin Finck     DWORD dwMode);
167c2c66affSColin Finck 
168c2c66affSColin Finck VOID FASTCALL IntMirrorWindowOrg(PDC);
169c2c66affSColin Finck int APIENTRY IntGdiSetMapMode(PDC, int);
170c2c66affSColin Finck BOOL FASTCALL GreLPtoDP(HDC, LPPOINT, INT);
171c2c66affSColin Finck BOOL FASTCALL GreDPtoLP(HDC, LPPOINT, INT);
172c2c66affSColin Finck BOOL APIENTRY GreGetDCPoint(HDC,UINT,PPOINTL);
173c2c66affSColin Finck BOOL WINAPI GreGetWindowExtEx( _In_ HDC hdc, _Out_ LPSIZE lpSize);
174c2c66affSColin Finck BOOL WINAPI GreGetViewportExtEx( _In_ HDC hdc, _Out_ LPSIZE lpSize);
175c2c66affSColin Finck BOOL FASTCALL GreSetViewportOrgEx(HDC,int,int,LPPOINT);
176c2c66affSColin Finck BOOL WINAPI GreGetDCOrgEx(_In_ HDC, _Out_ PPOINTL, _Out_ PRECTL);
177c2c66affSColin Finck BOOL WINAPI GreSetDCOrg(_In_  HDC, _In_ LONG, _In_ LONG, _In_opt_ PRECTL);
178*405ce532SJérôme Gardou 
179*405ce532SJérôme Gardou static
180*405ce532SJérôme Gardou inline
181*405ce532SJérôme Gardou BOOLEAN
IntLPtoDP(DC * pdc,PPOINTL ppt,UINT count)182*405ce532SJérôme Gardou IntLPtoDP(DC* pdc, PPOINTL ppt, UINT count)
183*405ce532SJérôme Gardou {
184*405ce532SJérôme Gardou     DC_vUpdateWorldToDevice(pdc);
185*405ce532SJérôme Gardou     return INTERNAL_LPTODP(pdc, (LPPOINT)ppt, count);
186*405ce532SJérôme Gardou }
187*405ce532SJérôme Gardou #define CoordLPtoDP(pdc, ppt) INTERNAL_LPTODP(pdc, ppt, 1)
188*405ce532SJérôme Gardou 
189*405ce532SJérôme Gardou static
190*405ce532SJérôme Gardou inline
191*405ce532SJérôme Gardou BOOLEAN
IntDPtoLP(DC * pdc,PPOINTL ppt,UINT count)192*405ce532SJérôme Gardou IntDPtoLP(DC* pdc, PPOINTL ppt, UINT count)
193*405ce532SJérôme Gardou {
194*405ce532SJérôme Gardou     DC_vUpdateDeviceToWorld(pdc);
195*405ce532SJérôme Gardou     return INTERNAL_DPTOLP(pdc, (LPPOINT)ppt, count);
196*405ce532SJérôme Gardou }
197*405ce532SJérôme Gardou #define CoordDPtoLP(pdc, ppt) INTERNAL_DPTOLP(pdc, ppt, 1)
198*405ce532SJérôme Gardou 
199*405ce532SJérôme Gardou #define XForm2MatrixS(m, x) XFormToMatrix(m, (XFORML*)x)
200*405ce532SJérôme Gardou #define MatrixS2XForm(x, m) MatrixToXForm((XFORML*)x, m)
201