Release 961222
[wine/multimedia.git] / graphics / mapping.c
blobe70c1e52bd158ffa28ba19d9c73f506eb9ea8aaa
1 /*
2 * GDI mapping mode functions
4 * Copyright 1993 Alexandre Julliard
5 */
7 #include <math.h>
8 #include "dc.h"
9 #include "stddebug.h"
10 #include "debug.h"
13 /***********************************************************************
14 * MAPPING_FixIsotropic
16 * Fix viewport extensions for isotropic mode.
18 void MAPPING_FixIsotropic( DC * dc )
20 double xdim = (double)dc->vportExtX * dc->w.devCaps->horzSize /
21 (dc->w.devCaps->horzRes * dc->wndExtX);
22 double ydim = (double)dc->vportExtY * dc->w.devCaps->vertSize /
23 (dc->w.devCaps->vertRes * dc->wndExtY);
24 if (xdim > ydim)
26 dc->vportExtX = dc->vportExtX * fabs( ydim / xdim );
27 if (!dc->vportExtX) dc->vportExtX = 1;
29 else
31 dc->vportExtY = dc->vportExtY * fabs( xdim / ydim );
32 if (!dc->vportExtY) dc->vportExtY = 1;
37 /***********************************************************************
38 * DPtoLP16 (GDI.67)
40 BOOL16 DPtoLP16( HDC16 hdc, LPPOINT16 points, INT16 count )
42 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
43 if (!dc) return FALSE;
45 while (count--)
47 points->x = XDPTOLP( dc, points->x );
48 points->y = YDPTOLP( dc, points->y );
49 points++;
51 return TRUE;
55 /***********************************************************************
56 * DPtoLP32 (GDI32.65)
58 BOOL32 DPtoLP32( HDC32 hdc, LPPOINT32 points, INT32 count )
60 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
61 if (!dc) return FALSE;
63 while (count--)
65 points->x = XDPTOLP( dc, points->x );
66 points->y = YDPTOLP( dc, points->y );
67 points++;
69 return TRUE;
73 /***********************************************************************
74 * LPtoDP16 (GDI.99)
76 BOOL16 LPtoDP16( HDC16 hdc, LPPOINT16 points, INT16 count )
78 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
79 if (!dc) return FALSE;
81 while (count--)
83 points->x = XLPTODP( dc, points->x );
84 points->y = YLPTODP( dc, points->y );
85 points++;
87 return TRUE;
91 /***********************************************************************
92 * LPtoDP32 (GDI32.247)
94 BOOL32 LPtoDP32( HDC32 hdc, LPPOINT32 points, INT32 count )
96 DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
97 if (!dc) return FALSE;
99 while (count--)
101 points->x = XLPTODP( dc, points->x );
102 points->y = YLPTODP( dc, points->y );
103 points++;
105 return TRUE;
109 /***********************************************************************
110 * SetMapMode16 (GDI.3)
112 INT16 SetMapMode16( HDC16 hdc, INT16 mode )
114 return SetMapMode32( hdc, mode );
118 /***********************************************************************
119 * SetMapMode32 (GDI32.321)
121 INT32 SetMapMode32( HDC32 hdc, INT32 mode )
123 INT32 prevMode;
124 DC * dc = DC_GetDCPtr( hdc );
125 if (!dc) return 0;
126 if (dc->funcs->pSetMapMode) return dc->funcs->pSetMapMode( dc, mode );
128 dprintf_gdi(stddeb, "SetMapMode: %04x %d\n", hdc, mode );
130 prevMode = dc->w.MapMode;
131 switch(mode)
133 case MM_TEXT:
134 dc->wndOrgX = dc->wndOrgY = 0;
135 dc->vportOrgX = dc->vportOrgY = 0;
136 dc->wndExtX = 1;
137 dc->wndExtY = 1;
138 dc->vportExtX = 1;
139 dc->vportExtY = 1;
140 break;
142 case MM_LOMETRIC:
143 case MM_ISOTROPIC:
144 dc->wndOrgX = dc->wndOrgY = 0;
145 dc->vportOrgX = dc->vportOrgY = 0;
146 dc->wndExtX = dc->w.devCaps->horzSize;
147 dc->wndExtY = dc->w.devCaps->vertSize;
148 dc->vportExtX = dc->w.devCaps->horzRes / 10;
149 dc->vportExtY = dc->w.devCaps->vertRes / -10;
150 break;
152 case MM_HIMETRIC:
153 dc->wndOrgX = dc->wndOrgY = 0;
154 dc->vportOrgX = dc->vportOrgY = 0;
155 dc->wndExtX = dc->w.devCaps->horzSize * 10;
156 dc->wndExtY = dc->w.devCaps->vertSize * 10;
157 dc->vportExtX = dc->w.devCaps->horzRes / 10;
158 dc->vportExtY = dc->w.devCaps->vertRes / -10;
159 break;
161 case MM_LOENGLISH:
162 dc->wndOrgX = dc->wndOrgY = 0;
163 dc->vportOrgX = dc->vportOrgY = 0;
164 dc->wndExtX = dc->w.devCaps->horzSize;
165 dc->wndExtY = dc->w.devCaps->vertSize;
166 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
167 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
168 break;
170 case MM_HIENGLISH:
171 dc->wndOrgX = dc->wndOrgY = 0;
172 dc->vportOrgX = dc->vportOrgY = 0;
173 dc->wndExtX = dc->w.devCaps->horzSize * 10;
174 dc->wndExtY = dc->w.devCaps->vertSize * 10;
175 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
176 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
177 break;
179 case MM_TWIPS:
180 dc->wndOrgX = dc->wndOrgY = 0;
181 dc->vportOrgX = dc->vportOrgY = 0;
182 dc->wndExtX = 144L * dc->w.devCaps->horzSize / 10;
183 dc->wndExtY = 144L * dc->w.devCaps->vertSize / 10;
184 dc->vportExtX = 254L * dc->w.devCaps->horzRes / 1000;
185 dc->vportExtY = -254L * dc->w.devCaps->vertRes / 1000;
186 break;
188 case MM_ANISOTROPIC:
189 break;
191 default:
192 return prevMode;
194 dc->w.MapMode = mode;
195 return prevMode;
199 /***********************************************************************
200 * SetViewportExt (GDI.14)
202 DWORD SetViewportExt( HDC16 hdc, INT16 x, INT16 y )
204 SIZE32 size;
205 if (!SetViewportExtEx32( hdc, x, y, &size )) return 0;
206 return MAKELONG( size.cx, size.cy );
210 /***********************************************************************
211 * SetViewportExtEx16 (GDI.479)
213 BOOL16 SetViewportExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
215 SIZE32 size32;
216 BOOL16 ret = SetViewportExtEx32( hdc, x, y, &size32 );
217 if (size) CONV_SIZE32TO16( &size32, size );
218 return ret;
222 /***********************************************************************
223 * SetViewportExtEx32 (GDI32.340)
225 BOOL32 SetViewportExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
227 DC * dc = DC_GetDCPtr( hdc );
228 if (!dc) return FALSE;
229 if (dc->funcs->pSetViewportExt)
230 return dc->funcs->pSetViewportExt( dc, x, y );
231 if (size)
233 size->cx = dc->vportExtX;
234 size->cy = dc->vportExtY;
236 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
237 return TRUE;
238 if (!x || !y) return FALSE;
239 dc->vportExtX = x;
240 dc->vportExtY = y;
241 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
242 return TRUE;
246 /***********************************************************************
247 * SetViewportOrg (GDI.13)
249 DWORD SetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
251 POINT32 pt;
252 if (!SetViewportOrgEx32( hdc, x, y, &pt )) return 0;
253 return MAKELONG( pt.x, pt.y );
257 /***********************************************************************
258 * SetViewportOrgEx16 (GDI.480)
260 BOOL16 SetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
262 POINT32 pt32;
263 BOOL16 ret = SetViewportOrgEx32( hdc, x, y, &pt32 );
264 if (pt) CONV_POINT32TO16( &pt32, pt );
265 return ret;
269 /***********************************************************************
270 * SetViewportOrgEx32 (GDI32.341)
272 BOOL32 SetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
274 DC * dc = DC_GetDCPtr( hdc );
275 if (!dc) return FALSE;
276 if (dc->funcs->pSetViewportOrg)
277 return dc->funcs->pSetViewportOrg( dc, x, y );
278 if (pt)
280 pt->x = dc->vportOrgX;
281 pt->y = dc->vportOrgY;
283 dc->vportOrgX = x;
284 dc->vportOrgY = y;
285 return TRUE;
289 /***********************************************************************
290 * SetWindowExt (GDI.12)
292 DWORD SetWindowExt( HDC16 hdc, INT16 x, INT16 y )
294 SIZE32 size;
295 if (!SetWindowExtEx32( hdc, x, y, &size )) return 0;
296 return MAKELONG( size.cx, size.cy );
300 /***********************************************************************
301 * SetWindowExtEx16 (GDI.481)
303 BOOL16 SetWindowExtEx16( HDC16 hdc, INT16 x, INT16 y, LPSIZE16 size )
305 SIZE32 size32;
306 BOOL16 ret = SetWindowExtEx32( hdc, x, y, &size32 );
307 if (size) CONV_SIZE32TO16( &size32, size );
308 return ret;
312 /***********************************************************************
313 * SetWindowExtEx32 (GDI32.344)
315 BOOL32 SetWindowExtEx32( HDC32 hdc, INT32 x, INT32 y, LPSIZE32 size )
317 DC * dc = DC_GetDCPtr( hdc );
318 if (!dc) return FALSE;
319 if (dc->funcs->pSetWindowExt) return dc->funcs->pSetWindowExt( dc, x, y );
320 if (size)
322 size->cx = dc->wndExtX;
323 size->cy = dc->wndExtY;
325 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
326 return TRUE;
327 if (!x || !y) return FALSE;
328 dc->wndExtX = x;
329 dc->wndExtY = y;
330 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
331 return TRUE;
335 /***********************************************************************
336 * SetWindowOrg (GDI.11)
338 DWORD SetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
340 POINT32 pt;
341 if (!SetWindowOrgEx32( hdc, x, y, &pt )) return 0;
342 return MAKELONG( pt.x, pt.y );
346 /***********************************************************************
347 * SetWindowOrgEx16 (GDI.482)
349 BOOL16 SetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
351 POINT32 pt32;
352 BOOL16 ret = SetWindowOrgEx32( hdc, x, y, &pt32 );
353 if (pt) CONV_POINT32TO16( &pt32, pt );
354 return ret;
358 /***********************************************************************
359 * SetWindowOrgEx32 (GDI32.345)
361 BOOL32 SetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
363 DC * dc = DC_GetDCPtr( hdc );
364 if (!dc) return FALSE;
365 if (dc->funcs->pSetWindowOrg) return dc->funcs->pSetWindowOrg( dc, x, y );
366 if (pt)
368 pt->x = dc->wndOrgX;
369 pt->y = dc->wndOrgY;
371 dc->wndOrgX = x;
372 dc->wndOrgY = y;
373 return TRUE;
377 /***********************************************************************
378 * OffsetViewportOrg (GDI.17)
380 DWORD OffsetViewportOrg( HDC16 hdc, INT16 x, INT16 y )
382 POINT32 pt;
383 if (!OffsetViewportOrgEx32( hdc, x, y, &pt )) return 0;
384 return MAKELONG( pt.x, pt.y );
388 /***********************************************************************
389 * OffsetViewportOrgEx16 (GDI.476)
391 BOOL16 OffsetViewportOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
393 POINT32 pt32;
394 BOOL16 ret = OffsetViewportOrgEx32( hdc, x, y, &pt32 );
395 if (pt) CONV_POINT32TO16( &pt32, pt );
396 return ret;
400 /***********************************************************************
401 * OffsetViewportOrgEx32 (GDI32.257)
403 BOOL32 OffsetViewportOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
405 DC * dc = DC_GetDCPtr( hdc );
406 if (!dc) return FALSE;
407 if (dc->funcs->pOffsetViewportOrg)
408 return dc->funcs->pOffsetViewportOrg( dc, x, y );
409 if (pt)
411 pt->x = dc->vportOrgX;
412 pt->y = dc->vportOrgY;
414 dc->vportOrgX += x;
415 dc->vportOrgY += y;
416 return TRUE;
420 /***********************************************************************
421 * OffsetWindowOrg (GDI.15)
423 DWORD OffsetWindowOrg( HDC16 hdc, INT16 x, INT16 y )
425 POINT32 pt;
426 if (!OffsetWindowOrgEx32( hdc, x, y, &pt )) return 0;
427 return MAKELONG( pt.x, pt.y );
431 /***********************************************************************
432 * OffsetWindowOrgEx16 (GDI.477)
434 BOOL16 OffsetWindowOrgEx16( HDC16 hdc, INT16 x, INT16 y, LPPOINT16 pt )
436 POINT32 pt32;
437 BOOL16 ret = OffsetWindowOrgEx32( hdc, x, y, &pt32 );
438 if (pt) CONV_POINT32TO16( &pt32, pt );
439 return ret;
443 /***********************************************************************
444 * OffsetWindowOrgEx32 (GDI32.258)
446 BOOL32 OffsetWindowOrgEx32( HDC32 hdc, INT32 x, INT32 y, LPPOINT32 pt )
448 DC * dc = DC_GetDCPtr( hdc );
449 if (!dc) return FALSE;
450 if (dc->funcs->pOffsetWindowOrg)
451 return dc->funcs->pOffsetWindowOrg( dc, x, y );
452 if (pt)
454 pt->x = dc->wndOrgX;
455 pt->y = dc->wndOrgY;
457 dc->wndOrgX += x;
458 dc->wndOrgY += y;
459 return TRUE;
463 /***********************************************************************
464 * ScaleViewportExt (GDI.18)
466 DWORD ScaleViewportExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
467 INT16 yNum, INT16 yDenom )
469 SIZE32 size;
470 if (!ScaleViewportExtEx32( hdc, xNum, xDenom, yNum, yDenom, &size ))
471 return FALSE;
472 return MAKELONG( size.cx, size.cy );
476 /***********************************************************************
477 * ScaleViewportExtEx16 (GDI.484)
479 BOOL16 ScaleViewportExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
480 INT16 yNum, INT16 yDenom, LPSIZE16 size )
482 SIZE32 size32;
483 BOOL16 ret = ScaleViewportExtEx32( hdc, xNum, xDenom, yNum, yDenom,
484 &size32 );
485 if (size) CONV_SIZE32TO16( &size32, size );
486 return ret;
490 /***********************************************************************
491 * ScaleViewportExtEx32 (GDI32.293)
493 BOOL32 ScaleViewportExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
494 INT32 yNum, INT32 yDenom, LPSIZE32 size )
496 DC * dc = DC_GetDCPtr( hdc );
497 if (!dc) return FALSE;
498 if (dc->funcs->pScaleViewportExt)
499 return dc->funcs->pScaleViewportExt( dc, xNum, xDenom, yNum, yDenom );
500 if (size)
502 size->cx = dc->vportExtX;
503 size->cy = dc->vportExtY;
505 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
506 return TRUE;
507 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
508 dc->vportExtX = (dc->vportExtX * xNum) / xDenom;
509 dc->vportExtY = (dc->vportExtY * yNum) / yDenom;
510 if (dc->vportExtX == 0) dc->vportExtX = 1;
511 if (dc->vportExtY == 0) dc->vportExtY = 1;
512 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
513 return TRUE;
517 /***********************************************************************
518 * ScaleWindowExt (GDI.16)
520 DWORD ScaleWindowExt( HDC16 hdc, INT16 xNum, INT16 xDenom,
521 INT16 yNum, INT16 yDenom )
523 SIZE32 size;
524 if (!ScaleWindowExtEx32( hdc, xNum, xDenom, yNum, yDenom, &size ))
525 return FALSE;
526 return MAKELONG( size.cx, size.cy );
530 /***********************************************************************
531 * ScaleWindowExtEx16 (GDI.485)
533 BOOL16 ScaleWindowExtEx16( HDC16 hdc, INT16 xNum, INT16 xDenom,
534 INT16 yNum, INT16 yDenom, LPSIZE16 size )
536 SIZE32 size32;
537 BOOL16 ret = ScaleWindowExtEx32( hdc, xNum, xDenom, yNum, yDenom,
538 &size32 );
539 if (size) CONV_SIZE32TO16( &size32, size );
540 return ret;
544 /***********************************************************************
545 * ScaleWindowExtEx32 (GDI32.294)
547 BOOL32 ScaleWindowExtEx32( HDC32 hdc, INT32 xNum, INT32 xDenom,
548 INT32 yNum, INT32 yDenom, LPSIZE32 size )
550 DC * dc = DC_GetDCPtr( hdc );
551 if (!dc) return FALSE;
552 if (dc->funcs->pScaleWindowExt)
553 return dc->funcs->pScaleWindowExt( dc, xNum, xDenom, yNum, yDenom );
554 if (size)
556 size->cx = dc->wndExtX;
557 size->cy = dc->wndExtY;
559 if ((dc->w.MapMode != MM_ISOTROPIC) && (dc->w.MapMode != MM_ANISOTROPIC))
560 return TRUE;
561 if (!xNum || !xDenom || !xNum || !yDenom) return FALSE;
562 dc->wndExtX = (dc->wndExtX * xNum) / xDenom;
563 dc->wndExtY = (dc->wndExtY * yNum) / yDenom;
564 if (dc->wndExtX == 0) dc->wndExtX = 1;
565 if (dc->wndExtY == 0) dc->wndExtY = 1;
566 if (dc->w.MapMode == MM_ISOTROPIC) MAPPING_FixIsotropic( dc );
567 return TRUE;