ReAlloc should be able to move memory blocks if necessary. This fixes
[reactos.git] / reactos / include / win32k / float.h
1 #ifndef __WIN32K_FLOAT_H
2 #define __WIN32K_FLOAT_H
3
4 #include <win32k/math.h>
5 #include <win32k/dc.h>
6 #include <ft2build.h>
7 #include FT_FREETYPE_H
8
9 typedef struct tagFLOAT_POINT
10 {
11 FLOAT x, y;
12 } FLOAT_POINT;
13
14 /* Rounds a floating point number to integer. The world-to-viewport
15 * transformation process is done in floating point internally. This function
16 * is then used to round these coordinates to integer values.
17 */
18 static __inline INT GDI_ROUND(FLOAT val)
19 {
20 return (int)floor(val + 0.5);
21 }
22
23 /* Performs a world-to-viewport transformation on the specified point (which
24 * is in floating point format).
25 */
26 static __inline void INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
27 {
28 FLOAT x, y;
29
30 /* Perform the transformation */
31 x = point->x;
32 y = point->y;
33 point->x = x * dc->w.xformWorld2Vport.eM11 +
34 y * dc->w.xformWorld2Vport.eM21 +
35 dc->w.xformWorld2Vport.eDx;
36 point->y = x * dc->w.xformWorld2Vport.eM12 +
37 y * dc->w.xformWorld2Vport.eM22 +
38 dc->w.xformWorld2Vport.eDy;
39 }
40
41 /* Performs a viewport-to-world transformation on the specified point (which
42 * is in integer format). Returns TRUE if successful, else FALSE.
43 */
44 #if 0
45 static __inline BOOL INTERNAL_DPTOLP(DC *dc, LPPOINT point)
46 {
47 FLOAT_POINT floatPoint;
48
49 /* Perform operation with floating point */
50 floatPoint.x=(FLOAT)point->x;
51 floatPoint.y=(FLOAT)point->y;
52 if (!INTERNAL_DPTOLP_FLOAT(dc, &floatPoint))
53 return FALSE;
54
55 /* Round to integers */
56 point->x = GDI_ROUND(floatPoint.x);
57 point->y = GDI_ROUND(floatPoint.y);
58
59 return TRUE;
60 }
61
62 /* Performs a world-to-viewport transformation on the specified point (which
63 * is in integer format).
64 */
65 static __inline void INTERNAL_LPTODP(DC *dc, LPPOINT point)
66 {
67 FLOAT_POINT floatPoint;
68
69 /* Perform operation with floating point */
70 floatPoint.x=(FLOAT)point->x;
71 floatPoint.y=(FLOAT)point->y;
72 INTERNAL_LPTODP_FLOAT(dc, &floatPoint);
73
74 /* Round to integers */
75 point->x = GDI_ROUND(floatPoint.x);
76 point->y = GDI_ROUND(floatPoint.y);
77 }
78
79 #endif
80
81 #define MulDiv( x, y, z ) EngMulDiv( x, y, z )
82
83 #define XDPTOLP(dc,x) \
84 (MulDiv(((x)-(dc)->vportOrgX), (dc)->wndExtX, (dc)->vportExtX) + (dc)->wndOrgX)
85 #define YDPTOLP(dc,y) \
86 (MulDiv(((y)-(dc)->vportOrgY), (dc)->wndExtY, (dc)->vportExtY) + (dc)->wndOrgY)
87 #define XLPTODP(dc,x) \
88 (MulDiv(((x)-(dc)->wndOrgX), (dc)->vportExtX, (dc)->wndExtX) + (dc)->vportOrgX)
89 #define YLPTODP(dc,y) \
90 (MulDiv(((y)-(dc)->wndOrgY), (dc)->vportExtY, (dc)->wndExtY) + (dc)->vportOrgY)
91
92 /* Device <-> logical size conversion */
93
94 #define XDSTOLS(dc,x) \
95 MulDiv((x), (dc)->wndExtX, (dc)->vportExtX)
96 #define YDSTOLS(dc,y) \
97 MulDiv((y), (dc)->wndExtY, (dc)->vportExtY)
98 #define XLSTODS(dc,x) \
99 MulDiv((x), (dc)->vportExtX, (dc)->wndExtX)
100 #define YLSTODS(dc,y) \
101 MulDiv((y), (dc)->vportExtY, (dc)->wndExtY)
102
103 #endif