:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / subsys / win32k / objects / coord.c
1 /* $Id$
2  *
3  * COPYRIGHT:        See COPYING in the top level directory
4  * PROJECT:          ReactOS kernel
5  * PURPOSE:          Coordinate systems
6  * FILE:             subsys/win32k/objects/coord.c
7  * PROGRAMER:        Unknown
8  */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <windows.h>
13 #include <ddk/ntddk.h>
14 #include <win32k/coord.h>
15 #include <win32k/dc.h>
16
17 //#define NDEBUG
18 #include <win32k/debug1.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 BOOL STDCALL W32kCombineTransform(LPXFORM  XFormResult,
23                            CONST LPXFORM  xform1,
24                            CONST LPXFORM  xform2)
25 {
26   XFORM  xformTemp;
27
28   /* Check for illegal parameters */
29   if (!XFormResult || !xform1 || !xform2)
30   {
31     return  FALSE;
32   }
33   /* Create the result in a temporary XFORM, since xformResult may be
34    * equal to xform1 or xform2 */
35   xformTemp.eM11 = xform1->eM11 * xform2->eM11 + xform1->eM12 * xform2->eM21;
36   xformTemp.eM12 = xform1->eM11 * xform2->eM12 + xform1->eM12 * xform2->eM22;
37   xformTemp.eM21 = xform1->eM21 * xform2->eM11 + xform1->eM22 * xform2->eM21;
38   xformTemp.eM22 = xform1->eM21 * xform2->eM12 + xform1->eM22 * xform2->eM22;
39   xformTemp.eDx  = xform1->eDx  * xform2->eM11 + xform1->eDy  * xform2->eM21 + xform2->eDx;
40   xformTemp.eDy  = xform1->eDx  * xform2->eM12 + xform1->eDy  * xform2->eM22 + xform2->eDy;
41
42   /* Copy the result to xformResult */
43   *XFormResult = xformTemp;
44
45   return  TRUE;
46 }
47
48 VOID STATIC
49 CoordDPtoLP(PDC Dc, LPPOINT Point)
50 {
51 FLOAT x, y;
52   x = (FLOAT)Point->x;
53   y = (FLOAT)Point->y;
54   Point->x = x * Dc->w.xformVport2World.eM11 +
55     y * Dc->w.xformVport2World.eM21 + Dc->w.xformVport2World.eDx;
56   Point->y = x * Dc->w.xformVport2World.eM12 +
57     y * Dc->w.xformVport2World.eM22 + Dc->w.xformVport2World.eDy;
58 }
59
60 BOOL STDCALL
61 W32kDPtoLP(HDC  hDC,
62            LPPOINT  Points,
63            int  Count)
64 {
65   PDC Dc;
66   ULONG i;
67
68   Dc = DC_HandleToPtr (hDC);
69   if (Dc == NULL || !Dc->w.vport2WorldValid)
70     {
71       return(FALSE);
72     }
73
74   for (i = 0; i < Count; i++)
75     {
76       CoordDPtoLP(Dc, &Points[i]);
77     }
78   DC_ReleasePtr( hDC );
79   return(TRUE);
80 }
81
82 int
83 STDCALL
84 W32kGetGraphicsMode(HDC  hDC)
85 {
86   PDC  dc;
87   int  GraphicsMode;
88
89   dc = DC_HandleToPtr (hDC);
90   if (!dc)
91   {
92     return  0;
93   }
94
95   GraphicsMode = dc->w.GraphicsMode;
96   DC_ReleasePtr( hDC );
97   return  GraphicsMode;
98 }
99
100 BOOL
101 STDCALL
102 W32kGetWorldTransform(HDC  hDC,
103                       LPXFORM  XForm)
104 {
105   PDC  dc;
106
107   dc = DC_HandleToPtr (hDC);
108   if (!dc)
109   {
110     return  FALSE;
111   }
112   if (!XForm)
113   {
114     return  FALSE;
115   }
116   *XForm = dc->w.xformWorld2Wnd;
117   DC_ReleasePtr( hDC );
118   return  TRUE;
119 }
120
121 VOID STATIC
122 CoordLPtoDP(PDC Dc, LPPOINT Point)
123 {
124   FLOAT x, y;
125   x = (FLOAT)Point->x;
126   y = (FLOAT)Point->y;
127   Point->x = x * Dc->w.xformWorld2Vport.eM11 +
128     y * Dc->w.xformWorld2Vport.eM21 + Dc->w.xformWorld2Vport.eDx;
129   Point->y = x * Dc->w.xformWorld2Vport.eM12 +
130     y * Dc->w.xformWorld2Vport.eM22 + Dc->w.xformWorld2Vport.eDy;
131 }
132
133 BOOL STDCALL
134 W32kLPtoDP(HDC hDC, LPPOINT Points, INT Count)
135 {
136   PDC Dc;
137   ULONG i;
138
139   Dc = DC_HandleToPtr (hDC);
140   if (Dc == NULL)
141     {
142       return(FALSE);
143     }
144
145   for (i = 0; i < Count; i++)
146     {
147       CoordLPtoDP(Dc, &Points[i]);
148     }
149   DC_ReleasePtr( hDC );
150   return(TRUE);
151 }
152
153 BOOL
154 STDCALL
155 W32kModifyWorldTransform(HDC  hDC,
156                                CONST LPXFORM  XForm,
157                                DWORD  Mode)
158 {
159   PDC  dc;
160
161   dc = DC_HandleToPtr (hDC);
162   if (!dc)
163   {
164 //    SetLastError( ERROR_INVALID_HANDLE );
165     return  FALSE;
166   }
167   if (!XForm)
168   {
169     return FALSE;
170   }
171
172   /* Check that graphics mode is GM_ADVANCED */
173   if (dc->w.GraphicsMode!=GM_ADVANCED)
174   {
175     return FALSE;
176   }
177   switch (Mode)
178   {
179     case MWT_IDENTITY:
180       dc->w.xformWorld2Wnd.eM11 = 1.0f;
181       dc->w.xformWorld2Wnd.eM12 = 0.0f;
182       dc->w.xformWorld2Wnd.eM21 = 0.0f;
183       dc->w.xformWorld2Wnd.eM22 = 1.0f;
184       dc->w.xformWorld2Wnd.eDx  = 0.0f;
185       dc->w.xformWorld2Wnd.eDy  = 0.0f;
186       break;
187
188     case MWT_LEFTMULTIPLY:
189       W32kCombineTransform(&dc->w.xformWorld2Wnd, XForm, &dc->w.xformWorld2Wnd );
190       break;
191
192     case MWT_RIGHTMULTIPLY:
193       W32kCombineTransform(&dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd, XForm);
194       break;
195
196     default:
197           DC_ReleasePtr( hDC );
198       return FALSE;
199   }
200   DC_UpdateXforms (dc);
201   DC_ReleasePtr( hDC );
202   return  TRUE;
203 }
204
205 BOOL
206 STDCALL
207 W32kOffsetViewportOrgEx(HDC  hDC,
208                               int  XOffset,
209                               int  YOffset,
210                               LPPOINT  Point)
211 {
212   UNIMPLEMENTED;
213 }
214
215 BOOL
216 STDCALL
217 W32kOffsetWindowOrgEx(HDC  hDC,
218                             int  XOffset,
219                             int  YOffset,
220                             LPPOINT  Point)
221 {
222   UNIMPLEMENTED;
223 }
224
225 BOOL
226 STDCALL
227 W32kScaleViewportExtEx(HDC  hDC,
228                              int  Xnum,
229                              int  Xdenom,
230                              int  Ynum,
231                              int  Ydenom,
232                              LPSIZE  Size)
233 {
234   UNIMPLEMENTED;
235 }
236
237 BOOL
238 STDCALL
239 W32kScaleWindowExtEx(HDC  hDC,
240                            int  Xnum,
241                            int  Xdenom,
242                            int  Ynum,
243                            int  Ydenom,
244                            LPSIZE  Size)
245 {
246   UNIMPLEMENTED;
247 }
248
249 int
250 STDCALL
251 W32kSetGraphicsMode(HDC  hDC,
252                          int  Mode)
253 {
254   INT ret;
255   DC *dc;
256
257   dc = DC_HandleToPtr (hDC);
258   if (!dc)
259   {
260     return 0;
261   }
262
263   /* One would think that setting the graphics mode to GM_COMPATIBLE
264    * would also reset the world transformation matrix to the unity
265    * matrix. However, in Windows, this is not the case. This doesn't
266    * make a lot of sense to me, but that's the way it is.
267    */
268
269   if ((Mode != GM_COMPATIBLE) && (Mode != GM_ADVANCED))
270   {
271         DC_ReleasePtr( hDC );
272     return 0;
273   }
274   ret = dc->w.GraphicsMode;
275   dc->w.GraphicsMode = Mode;
276   DC_ReleasePtr( hDC );
277   return  ret;
278 }
279
280 int
281 STDCALL
282 W32kSetMapMode(HDC  hDC,
283                     int  MapMode)
284 {
285   UNIMPLEMENTED;
286 }
287
288 BOOL
289 STDCALL
290 W32kSetViewportExtEx(HDC  hDC,
291                            int  XExtent,
292                            int  YExtent,
293                            LPSIZE  Size)
294 {
295   UNIMPLEMENTED;
296 }
297
298 BOOL
299 STDCALL
300 W32kSetViewportOrgEx(HDC  hDC,
301                            int  X,
302                            int  Y,
303                            LPPOINT  Point)
304 {
305   UNIMPLEMENTED;
306 }
307
308 BOOL
309 STDCALL
310 W32kSetWindowExtEx(HDC  hDC,
311                          int  XExtent,
312                          int  YExtent,
313                          LPSIZE  Size)
314 {
315   UNIMPLEMENTED;
316 }
317
318 BOOL
319 STDCALL
320 W32kSetWindowOrgEx(HDC  hDC,
321                          int  X,
322                          int  Y,
323                          LPPOINT  Point)
324 {
325   UNIMPLEMENTED;
326 }
327
328 BOOL
329 STDCALL
330 W32kSetWorldTransform(HDC  hDC,
331                             CONST LPXFORM  XForm)
332 {
333   PDC  dc;
334
335   dc = DC_HandleToPtr (hDC);
336   if (!dc)
337   {
338     return  FALSE;
339   }
340   if (!XForm)
341   {
342         DC_ReleasePtr( hDC );
343     return  FALSE;
344   }
345
346   /* Check that graphics mode is GM_ADVANCED */
347   if (dc->w.GraphicsMode != GM_ADVANCED)
348   {
349         DC_ReleasePtr( hDC );
350     return  FALSE;
351   }
352   dc->w.xformWorld2Wnd = *XForm;
353   DC_UpdateXforms (dc);
354   DC_ReleasePtr( hDC );
355   return  TRUE;
356 }
357
358