2 * GDI drawing functions.
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 1997 Bertho A. Stultiens
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
38 /***********************************************************************
41 BOOL16 WINAPI
LineTo16( HDC16 hdc
, INT16 x
, INT16 y
)
43 return LineTo( hdc
, x
, y
);
47 /***********************************************************************
50 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
52 DC
* dc
= DC_GetDCUpdate( hdc
);
57 if(PATH_IsPathOpen(dc
->path
))
58 ret
= PATH_LineTo(dc
, x
, y
);
60 ret
= dc
->funcs
->pLineTo
&& dc
->funcs
->pLineTo(dc
->physDev
,x
,y
);
65 GDI_ReleaseObj( hdc
);
70 /***********************************************************************
73 DWORD WINAPI
MoveTo16( HDC16 hdc
, INT16 x
, INT16 y
)
77 if (!MoveToEx( (HDC
)hdc
, x
, y
, &pt
)) return 0;
78 return MAKELONG(pt
.x
,pt
.y
);
82 /***********************************************************************
85 BOOL16 WINAPI
MoveToEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
89 if (!MoveToEx( (HDC
)hdc
, (INT
)x
, (INT
)y
, &pt32
)) return FALSE
;
90 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
95 /***********************************************************************
98 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
101 DC
* dc
= DC_GetDCPtr( hdc
);
103 if(!dc
) return FALSE
;
106 pt
->x
= dc
->CursPosX
;
107 pt
->y
= dc
->CursPosY
;
112 if(PATH_IsPathOpen(dc
->path
)) ret
= PATH_MoveTo(dc
);
113 else if (dc
->funcs
->pMoveTo
) ret
= dc
->funcs
->pMoveTo(dc
->physDev
,x
,y
);
114 GDI_ReleaseObj( hdc
);
119 /***********************************************************************
122 BOOL16 WINAPI
Arc16( HDC16 hdc
, INT16 left
, INT16 top
, INT16 right
,
123 INT16 bottom
, INT16 xstart
, INT16 ystart
,
124 INT16 xend
, INT16 yend
)
126 return Arc( (HDC
)hdc
, (INT
)left
, (INT
)top
, (INT
)right
,
127 (INT
)bottom
, (INT
)xstart
, (INT
)ystart
, (INT
)xend
,
132 /***********************************************************************
135 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
136 INT bottom
, INT xstart
, INT ystart
,
140 DC
* dc
= DC_GetDCUpdate( hdc
);
143 if(PATH_IsPathOpen(dc
->path
))
144 ret
= PATH_Arc(dc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,0);
145 else if (dc
->funcs
->pArc
)
146 ret
= dc
->funcs
->pArc(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
147 GDI_ReleaseObj( hdc
);
152 /***********************************************************************
155 BOOL WINAPI
ArcTo( HDC hdc
,
157 INT right
, INT bottom
,
158 INT xstart
, INT ystart
,
162 DC
* dc
= DC_GetDCUpdate( hdc
);
163 if(!dc
) return FALSE
;
165 if(dc
->funcs
->pArcTo
)
167 result
= dc
->funcs
->pArcTo( dc
->physDev
, left
, top
, right
, bottom
,
168 xstart
, ystart
, xend
, yend
);
169 GDI_ReleaseObj( hdc
);
172 GDI_ReleaseObj( hdc
);
175 * According to the documentation, a line is drawn from the current
176 * position to the starting point of the arc.
178 LineTo(hdc
, xstart
, ystart
);
180 * Then the arc is drawn.
182 result
= Arc(hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
184 * If no error occurred, the current position is moved to the ending
187 if (result
) MoveToEx(hdc
, xend
, yend
, NULL
);
191 /***********************************************************************
194 BOOL16 WINAPI
Pie16( HDC16 hdc
, INT16 left
, INT16 top
,
195 INT16 right
, INT16 bottom
, INT16 xstart
, INT16 ystart
,
196 INT16 xend
, INT16 yend
)
198 return Pie( (HDC
)hdc
, (INT
)left
, (INT
)top
, (INT
)right
,
199 (INT
)bottom
, (INT
)xstart
, (INT
)ystart
, (INT
)xend
,
204 /***********************************************************************
207 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
208 INT right
, INT bottom
, INT xstart
, INT ystart
,
212 DC
* dc
= DC_GetDCUpdate( hdc
);
213 if (!dc
) return FALSE
;
215 if(PATH_IsPathOpen(dc
->path
))
216 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,2);
217 else if(dc
->funcs
->pPie
)
218 ret
= dc
->funcs
->pPie(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
220 GDI_ReleaseObj( hdc
);
225 /***********************************************************************
228 BOOL16 WINAPI
Chord16( HDC16 hdc
, INT16 left
, INT16 top
,
229 INT16 right
, INT16 bottom
, INT16 xstart
, INT16 ystart
,
230 INT16 xend
, INT16 yend
)
232 return Chord( hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
236 /***********************************************************************
239 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
240 INT right
, INT bottom
, INT xstart
, INT ystart
,
244 DC
* dc
= DC_GetDCUpdate( hdc
);
245 if (!dc
) return FALSE
;
247 if(PATH_IsPathOpen(dc
->path
))
248 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,1);
249 else if(dc
->funcs
->pChord
)
250 ret
= dc
->funcs
->pChord(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
252 GDI_ReleaseObj( hdc
);
257 /***********************************************************************
260 BOOL16 WINAPI
Ellipse16( HDC16 hdc
, INT16 left
, INT16 top
,
261 INT16 right
, INT16 bottom
)
263 return Ellipse( hdc
, left
, top
, right
, bottom
);
267 /***********************************************************************
270 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
271 INT right
, INT bottom
)
274 DC
* dc
= DC_GetDCUpdate( hdc
);
275 if (!dc
) return FALSE
;
277 if(PATH_IsPathOpen(dc
->path
))
278 ret
= PATH_Ellipse(dc
,left
,top
,right
,bottom
);
279 else if (dc
->funcs
->pEllipse
)
280 ret
= dc
->funcs
->pEllipse(dc
->physDev
,left
,top
,right
,bottom
);
282 GDI_ReleaseObj( hdc
);
287 /***********************************************************************
290 BOOL16 WINAPI
Rectangle16( HDC16 hdc
, INT16 left
, INT16 top
,
291 INT16 right
, INT16 bottom
)
293 return Rectangle( hdc
, left
, top
, right
, bottom
);
297 /***********************************************************************
298 * Rectangle (GDI32.@)
300 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
301 INT right
, INT bottom
)
304 DC
* dc
= DC_GetDCUpdate( hdc
);
307 if(PATH_IsPathOpen(dc
->path
))
308 ret
= PATH_Rectangle(dc
, left
, top
, right
, bottom
);
309 else if (dc
->funcs
->pRectangle
)
310 ret
= dc
->funcs
->pRectangle(dc
->physDev
,left
,top
,right
,bottom
);
311 GDI_ReleaseObj( hdc
);
317 /***********************************************************************
320 BOOL16 WINAPI
RoundRect16( HDC16 hdc
, INT16 left
, INT16 top
, INT16 right
,
321 INT16 bottom
, INT16 ell_width
, INT16 ell_height
)
323 return RoundRect( hdc
, left
, top
, right
, bottom
, ell_width
, ell_height
);
327 /***********************************************************************
328 * RoundRect (GDI32.@)
330 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
331 INT bottom
, INT ell_width
, INT ell_height
)
334 DC
*dc
= DC_GetDCUpdate( hdc
);
338 if(PATH_IsPathOpen(dc
->path
))
339 ret
= PATH_RoundRect(dc
,left
,top
,right
,bottom
,ell_width
,ell_height
);
340 else if (dc
->funcs
->pRoundRect
)
341 ret
= dc
->funcs
->pRoundRect(dc
->physDev
,left
,top
,right
,bottom
,ell_width
,ell_height
);
342 GDI_ReleaseObj( hdc
);
347 /***********************************************************************
350 COLORREF WINAPI
SetPixel16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
)
352 return SetPixel( hdc
, x
, y
, color
);
356 /***********************************************************************
359 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
362 DC
* dc
= DC_GetDCUpdate( hdc
);
365 if (dc
->funcs
->pSetPixel
) ret
= dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
366 GDI_ReleaseObj( hdc
);
371 /***********************************************************************
372 * SetPixelV (GDI32.@)
374 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
377 DC
* dc
= DC_GetDCUpdate( hdc
);
380 if (dc
->funcs
->pSetPixel
)
382 dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
385 GDI_ReleaseObj( hdc
);
390 /***********************************************************************
393 COLORREF WINAPI
GetPixel16( HDC16 hdc
, INT16 x
, INT16 y
)
395 return GetPixel( hdc
, x
, y
);
399 /***********************************************************************
402 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
404 COLORREF ret
= CLR_INVALID
;
405 DC
* dc
= DC_GetDCUpdate( hdc
);
409 /* FIXME: should this be in the graphics driver? */
410 if (PtVisible( hdc
, x
, y
))
412 if (dc
->funcs
->pGetPixel
) ret
= dc
->funcs
->pGetPixel(dc
->physDev
,x
,y
);
414 GDI_ReleaseObj( hdc
);
420 /******************************************************************************
421 * ChoosePixelFormat [GDI32.@]
422 * Matches a pixel format to given format
425 * hdc [I] Device context to search for best pixel match
426 * ppfd [I] Pixel format for which a match is sought
429 * Success: Pixel format index closest to given format
432 INT WINAPI
ChoosePixelFormat( HDC hdc
, const LPPIXELFORMATDESCRIPTOR ppfd
)
435 DC
* dc
= DC_GetDCPtr( hdc
);
437 TRACE("(%08x,%p)\n",hdc
,ppfd
);
441 if (!dc
->funcs
->pChoosePixelFormat
) FIXME(" :stub\n");
442 else ret
= dc
->funcs
->pChoosePixelFormat(dc
->physDev
,ppfd
);
444 GDI_ReleaseObj( hdc
);
449 /******************************************************************************
450 * SetPixelFormat [GDI32.@]
451 * Sets pixel format of device context
454 * hdc [I] Device context to search for best pixel match
455 * iPixelFormat [I] Pixel format index
456 * ppfd [I] Pixel format for which a match is sought
460 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT iPixelFormat
,
461 const PIXELFORMATDESCRIPTOR
*ppfd
)
464 DC
* dc
= DC_GetDCPtr( hdc
);
466 TRACE("(%d,%d,%p)\n",hdc
,iPixelFormat
,ppfd
);
470 if (!dc
->funcs
->pSetPixelFormat
) FIXME(" :stub\n");
471 else bRet
= dc
->funcs
->pSetPixelFormat(dc
->physDev
,iPixelFormat
,ppfd
);
473 GDI_ReleaseObj( hdc
);
478 /******************************************************************************
479 * GetPixelFormat [GDI32.@]
480 * Gets index of pixel format of DC
483 * hdc [I] Device context whose pixel format index is sought
486 * Success: Currently selected pixel format
489 INT WINAPI
GetPixelFormat( HDC hdc
)
492 DC
* dc
= DC_GetDCPtr( hdc
);
494 TRACE("(%08x)\n",hdc
);
498 if (!dc
->funcs
->pGetPixelFormat
) FIXME(" :stub\n");
499 else ret
= dc
->funcs
->pGetPixelFormat(dc
->physDev
);
501 GDI_ReleaseObj( hdc
);
506 /******************************************************************************
507 * DescribePixelFormat [GDI32.@]
508 * Gets info about pixel format from DC
511 * hdc [I] Device context
512 * iPixelFormat [I] Pixel format selector
513 * nBytes [I] Size of buffer
514 * ppfd [O] Pointer to structure to receive pixel format data
517 * Success: Maximum pixel format index of the device context
520 INT WINAPI
DescribePixelFormat( HDC hdc
, INT iPixelFormat
, UINT nBytes
,
521 LPPIXELFORMATDESCRIPTOR ppfd
)
524 DC
* dc
= DC_GetDCPtr( hdc
);
526 TRACE("(%08x,%d,%d,%p): stub\n",hdc
,iPixelFormat
,nBytes
,ppfd
);
530 if (!dc
->funcs
->pDescribePixelFormat
)
533 ppfd
->nSize
= nBytes
;
537 else ret
= dc
->funcs
->pDescribePixelFormat(dc
->physDev
,iPixelFormat
,nBytes
,ppfd
);
539 GDI_ReleaseObj( hdc
);
544 /******************************************************************************
545 * SwapBuffers [GDI32.@]
546 * Exchanges front and back buffers of window
549 * hdc [I] Device context whose buffers get swapped
553 BOOL WINAPI
SwapBuffers( HDC hdc
)
556 DC
* dc
= DC_GetDCPtr( hdc
);
558 TRACE("(%08x)\n",hdc
);
560 if (!dc
) return TRUE
;
562 if (!dc
->funcs
->pSwapBuffers
)
567 else bRet
= dc
->funcs
->pSwapBuffers(dc
->physDev
);
569 GDI_ReleaseObj( hdc
);
574 /***********************************************************************
577 BOOL16 WINAPI
PaintRgn16( HDC16 hdc
, HRGN16 hrgn
)
579 return PaintRgn( hdc
, hrgn
);
583 /***********************************************************************
586 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
589 DC
* dc
= DC_GetDCUpdate( hdc
);
592 if (dc
->funcs
->pPaintRgn
) ret
= dc
->funcs
->pPaintRgn(dc
->physDev
,hrgn
);
593 GDI_ReleaseObj( hdc
);
599 /***********************************************************************
602 BOOL16 WINAPI
FillRgn16( HDC16 hdc
, HRGN16 hrgn
, HBRUSH16 hbrush
)
604 return FillRgn( hdc
, hrgn
, hbrush
);
608 /***********************************************************************
611 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
615 DC
* dc
= DC_GetDCUpdate( hdc
);
617 if (!dc
) return FALSE
;
618 if(dc
->funcs
->pFillRgn
)
619 retval
= dc
->funcs
->pFillRgn(dc
->physDev
, hrgn
, hbrush
);
620 else if ((prevBrush
= SelectObject( hdc
, hbrush
)))
622 retval
= PaintRgn( hdc
, hrgn
);
623 SelectObject( hdc
, prevBrush
);
625 GDI_ReleaseObj( hdc
);
630 /***********************************************************************
633 BOOL16 WINAPI
FrameRgn16( HDC16 hdc
, HRGN16 hrgn
, HBRUSH16 hbrush
,
634 INT16 nWidth
, INT16 nHeight
)
636 return FrameRgn( hdc
, hrgn
, hbrush
, nWidth
, nHeight
);
640 /***********************************************************************
643 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
644 INT nWidth
, INT nHeight
)
647 DC
*dc
= DC_GetDCUpdate( hdc
);
649 if (!dc
) return FALSE
;
650 if(dc
->funcs
->pFrameRgn
)
651 ret
= dc
->funcs
->pFrameRgn( dc
->physDev
, hrgn
, hbrush
, nWidth
, nHeight
);
654 HRGN tmp
= CreateRectRgn( 0, 0, 0, 0 );
657 if (REGION_FrameRgn( tmp
, hrgn
, nWidth
, nHeight
))
659 FillRgn( hdc
, tmp
, hbrush
);
665 GDI_ReleaseObj( hdc
);
670 /***********************************************************************
673 BOOL16 WINAPI
InvertRgn16( HDC16 hdc
, HRGN16 hrgn
)
675 return InvertRgn( hdc
, hrgn
);
679 /***********************************************************************
680 * InvertRgn (GDI32.@)
682 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
687 DC
*dc
= DC_GetDCUpdate( hdc
);
688 if (!dc
) return FALSE
;
690 if(dc
->funcs
->pInvertRgn
)
691 retval
= dc
->funcs
->pInvertRgn( dc
->physDev
, hrgn
);
694 prevBrush
= SelectObject( hdc
, GetStockObject(BLACK_BRUSH
) );
695 prevROP
= SetROP2( hdc
, R2_NOT
);
696 retval
= PaintRgn( hdc
, hrgn
);
697 SelectObject( hdc
, prevBrush
);
698 SetROP2( hdc
, prevROP
);
700 GDI_ReleaseObj( hdc
);
704 /**********************************************************************
707 BOOL16 WINAPI
Polyline16( HDC16 hdc
, const POINT16
* pt
, INT16 count
)
711 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
712 count
*sizeof(POINT
) );
714 if (!pt32
) return FALSE
;
715 for (i
=count
;i
--;) CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
716 ret
= Polyline(hdc
,pt32
,count
);
717 HeapFree( GetProcessHeap(), 0, pt32
);
722 /**********************************************************************
725 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
728 DC
* dc
= DC_GetDCUpdate( hdc
);
731 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polyline(dc
, pt
, count
);
732 else if (dc
->funcs
->pPolyline
) ret
= dc
->funcs
->pPolyline(dc
->physDev
,pt
,count
);
733 GDI_ReleaseObj( hdc
);
738 /**********************************************************************
739 * PolylineTo (GDI32.@)
741 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
743 DC
* dc
= DC_GetDCUpdate( hdc
);
746 if(!dc
) return FALSE
;
748 if(PATH_IsPathOpen(dc
->path
))
749 ret
= PATH_PolylineTo(dc
, pt
, cCount
);
751 else if(dc
->funcs
->pPolylineTo
)
752 ret
= dc
->funcs
->pPolylineTo(dc
->physDev
, pt
, cCount
);
754 else { /* do it using Polyline */
755 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
756 sizeof(POINT
) * (cCount
+ 1) );
759 pts
[0].x
= dc
->CursPosX
;
760 pts
[0].y
= dc
->CursPosY
;
761 memcpy( pts
+ 1, pt
, sizeof(POINT
) * cCount
);
762 ret
= Polyline( hdc
, pts
, cCount
+ 1 );
763 HeapFree( GetProcessHeap(), 0, pts
);
767 dc
->CursPosX
= pt
[cCount
-1].x
;
768 dc
->CursPosY
= pt
[cCount
-1].y
;
770 GDI_ReleaseObj( hdc
);
774 /**********************************************************************
777 BOOL16 WINAPI
Polygon16( HDC16 hdc
, const POINT16
* pt
, INT16 count
)
781 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
782 count
*sizeof(POINT
) );
784 if (!pt32
) return FALSE
;
785 for (i
=count
;i
--;) CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
786 ret
= Polygon(hdc
,pt32
,count
);
787 HeapFree( GetProcessHeap(), 0, pt32
);
792 /**********************************************************************
795 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
798 DC
* dc
= DC_GetDCUpdate( hdc
);
801 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polygon(dc
, pt
, count
);
802 else if (dc
->funcs
->pPolygon
) ret
= dc
->funcs
->pPolygon(dc
->physDev
,pt
,count
);
803 GDI_ReleaseObj( hdc
);
809 /**********************************************************************
810 * PolyPolygon (GDI.450)
812 BOOL16 WINAPI
PolyPolygon16( HDC16 hdc
, const POINT16
* pt
, const INT16
* counts
,
821 for (i
=polygons
;i
--;)
823 pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
)*nrpts
);
824 if(pt32
== NULL
) return FALSE
;
826 CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
827 counts32
= (LPINT
)HeapAlloc( GetProcessHeap(), 0, polygons
*sizeof(INT
) );
828 if(counts32
== NULL
) {
829 HeapFree( GetProcessHeap(), 0, pt32
);
832 for (i
=polygons
;i
--;) counts32
[i
]=counts
[i
];
834 ret
= PolyPolygon(hdc
,pt32
,counts32
,polygons
);
835 HeapFree( GetProcessHeap(), 0, counts32
);
836 HeapFree( GetProcessHeap(), 0, pt32
);
840 /**********************************************************************
841 * PolyPolygon (GDI32.@)
843 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
847 DC
* dc
= DC_GetDCUpdate( hdc
);
850 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolygon(dc
, pt
, counts
, polygons
);
851 else if (dc
->funcs
->pPolyPolygon
) ret
= dc
->funcs
->pPolyPolygon(dc
->physDev
,pt
,counts
,polygons
);
852 GDI_ReleaseObj( hdc
);
857 /**********************************************************************
858 * PolyPolyline (GDI32.@)
860 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
864 DC
* dc
= DC_GetDCUpdate( hdc
);
867 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolyline(dc
, pt
, counts
, polylines
);
868 else if (dc
->funcs
->pPolyPolyline
) ret
= dc
->funcs
->pPolyPolyline(dc
->physDev
,pt
,counts
,polylines
);
869 GDI_ReleaseObj( hdc
);
874 /**********************************************************************
875 * ExtFloodFill (GDI.372)
877 BOOL16 WINAPI
ExtFloodFill16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
,
880 return ExtFloodFill( hdc
, x
, y
, color
, fillType
);
884 /**********************************************************************
885 * ExtFloodFill (GDI32.@)
887 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
891 DC
* dc
= DC_GetDCUpdate( hdc
);
894 if (dc
->funcs
->pExtFloodFill
) ret
= dc
->funcs
->pExtFloodFill(dc
->physDev
,x
,y
,color
,fillType
);
895 GDI_ReleaseObj( hdc
);
901 /**********************************************************************
904 BOOL16 WINAPI
FloodFill16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
)
906 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
910 /**********************************************************************
911 * FloodFill (GDI32.@)
913 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
915 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
919 /******************************************************************************
920 * PolyBezier [GDI.502]
922 BOOL16 WINAPI
PolyBezier16( HDC16 hDc
, const POINT16
* lppt
, INT16 cPoints
)
926 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
927 cPoints
*sizeof(POINT
) );
928 if(!pt32
) return FALSE
;
929 for (i
=cPoints
;i
--;) CONV_POINT16TO32(&(lppt
[i
]),&(pt32
[i
]));
930 ret
= PolyBezier(hDc
, pt32
, cPoints
);
931 HeapFree( GetProcessHeap(), 0, pt32
);
935 /******************************************************************************
936 * PolyBezierTo [GDI.503]
938 BOOL16 WINAPI
PolyBezierTo16( HDC16 hDc
, const POINT16
* lppt
, INT16 cPoints
)
942 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
943 cPoints
*sizeof(POINT
) );
944 if(!pt32
) return FALSE
;
945 for (i
=cPoints
;i
--;) CONV_POINT16TO32(&(lppt
[i
]),&(pt32
[i
]));
946 ret
= PolyBezierTo(hDc
, pt32
, cPoints
);
947 HeapFree( GetProcessHeap(), 0, pt32
);
951 /******************************************************************************
952 * PolyBezier [GDI32.@]
953 * Draws one or more Bezier curves
956 * hDc [I] Handle to device context
957 * lppt [I] Pointer to endpoints and control points
958 * cPoints [I] Count of endpoints and control points
962 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
965 DC
* dc
= DC_GetDCUpdate( hdc
);
967 if(!dc
) return FALSE
;
969 if(PATH_IsPathOpen(dc
->path
))
970 ret
= PATH_PolyBezier(dc
, lppt
, cPoints
);
971 else if (dc
->funcs
->pPolyBezier
)
972 ret
= dc
->funcs
->pPolyBezier(dc
->physDev
, lppt
, cPoints
);
973 else /* We'll convert it into line segments and draw them using Polyline */
978 if ((Pts
= GDI_Bezier( lppt
, cPoints
, &nOut
)))
980 TRACE("Pts = %p, no = %d\n", Pts
, nOut
);
981 ret
= Polyline( dc
->hSelf
, Pts
, nOut
);
982 HeapFree( GetProcessHeap(), 0, Pts
);
986 GDI_ReleaseObj( hdc
);
990 /******************************************************************************
991 * PolyBezierTo [GDI32.@]
992 * Draws one or more Bezier curves
995 * hDc [I] Handle to device context
996 * lppt [I] Pointer to endpoints and control points
997 * cPoints [I] Count of endpoints and control points
1001 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
1003 DC
* dc
= DC_GetDCUpdate( hdc
);
1006 if(!dc
) return FALSE
;
1008 if(PATH_IsPathOpen(dc
->path
))
1009 ret
= PATH_PolyBezierTo(dc
, lppt
, cPoints
);
1010 else if(dc
->funcs
->pPolyBezierTo
)
1011 ret
= dc
->funcs
->pPolyBezierTo(dc
->physDev
, lppt
, cPoints
);
1012 else { /* We'll do it using PolyBezier */
1014 pt
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (cPoints
+ 1) );
1015 if(!pt
) return FALSE
;
1016 pt
[0].x
= dc
->CursPosX
;
1017 pt
[0].y
= dc
->CursPosY
;
1018 memcpy(pt
+ 1, lppt
, sizeof(POINT
) * cPoints
);
1019 ret
= PolyBezier(dc
->hSelf
, pt
, cPoints
+1);
1020 HeapFree( GetProcessHeap(), 0, pt
);
1023 dc
->CursPosX
= lppt
[cPoints
-1].x
;
1024 dc
->CursPosY
= lppt
[cPoints
-1].y
;
1026 GDI_ReleaseObj( hdc
);
1030 /***********************************************************************
1031 * AngleArc (GDI32.@)
1033 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
1035 INT x1
,y1
,x2
,y2
, arcdir
;
1039 if( (signed int)dwRadius
< 0 )
1042 dc
= DC_GetDCUpdate( hdc
);
1043 if(!dc
) return FALSE
;
1045 if(dc
->funcs
->pAngleArc
)
1047 result
= dc
->funcs
->pAngleArc( dc
->physDev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
1049 GDI_ReleaseObj( hdc
);
1052 GDI_ReleaseObj( hdc
);
1054 /* AngleArc always works counterclockwise */
1055 arcdir
= GetArcDirection( hdc
);
1056 SetArcDirection( hdc
, AD_COUNTERCLOCKWISE
);
1058 x1
= x
+ cos(eStartAngle
*M_PI
/180) * dwRadius
;
1059 y1
= y
- sin(eStartAngle
*M_PI
/180) * dwRadius
;
1060 x2
= x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
1061 y2
= x
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
1063 LineTo( hdc
, x1
, y1
);
1064 if( eSweepAngle
>= 0 )
1065 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
1068 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
1071 if( result
) MoveToEx( hdc
, x2
, y2
, NULL
);
1072 SetArcDirection( hdc
, arcdir
);
1076 /***********************************************************************
1077 * PolyDraw (GDI32.@)
1079 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
1087 dc
= DC_GetDCUpdate( hdc
);
1088 if(!dc
) return FALSE
;
1090 if(dc
->funcs
->pPolyDraw
)
1092 result
= dc
->funcs
->pPolyDraw( dc
->physDev
, lppt
, lpbTypes
, cCount
);
1093 GDI_ReleaseObj( hdc
);
1096 GDI_ReleaseObj( hdc
);
1098 /* check for each bezierto if there are two more points */
1099 for( i
= 0; i
< cCount
; i
++ )
1100 if( lpbTypes
[i
] != PT_MOVETO
&&
1101 lpbTypes
[i
] & PT_BEZIERTO
)
1109 /* if no moveto occurs, we will close the figure here */
1110 lastmove
.x
= dc
->CursPosX
;
1111 lastmove
.y
= dc
->CursPosY
;
1113 /* now let's draw */
1114 for( i
= 0; i
< cCount
; i
++ )
1116 if( lpbTypes
[i
] == PT_MOVETO
)
1118 MoveToEx( hdc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
1119 lastmove
.x
= dc
->CursPosX
;
1120 lastmove
.y
= dc
->CursPosY
;
1122 else if( lpbTypes
[i
] & PT_LINETO
)
1123 LineTo( hdc
, lppt
[i
].x
, lppt
[i
].y
);
1124 else if( lpbTypes
[i
] & PT_BEZIERTO
)
1126 PolyBezierTo( hdc
, &lppt
[i
], 3 );
1132 if( lpbTypes
[i
] & PT_CLOSEFIGURE
)
1134 if( PATH_IsPathOpen( dc
->path
) )
1137 LineTo( hdc
, lastmove
.x
, lastmove
.y
);
1144 /******************************************************************
1146 * *Very* simple bezier drawing code,
1148 * It uses a recursive algorithm to divide the curve in a series
1149 * of straight line segements. Not ideal but for me sufficient.
1150 * If you are in need for something better look for some incremental
1153 * 7 July 1998 Rein Klazes
1157 * some macro definitions for bezier drawing
1159 * to avoid trucation errors the coordinates are
1160 * shifted upwards. When used in drawing they are
1161 * shifted down again, including correct rounding
1162 * and avoiding floating point arithmatic
1163 * 4 bits should allow 27 bits coordinates which I saw
1164 * somewere in the win32 doc's
1168 #define BEZIERSHIFTBITS 4
1169 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
1170 #define BEZIERPIXEL BEZIERSHIFTUP(1)
1171 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
1172 /* maximum depth of recursion */
1173 #define BEZIERMAXDEPTH 8
1175 /* size of array to store points on */
1176 /* enough for one curve */
1177 #define BEZIER_INITBUFSIZE (150)
1179 /* calculate Bezier average, in this case the middle
1180 * correctly rounded...
1183 #define BEZIERMIDDLE(Mid, P1, P2) \
1184 (Mid).x=((P1).x+(P2).x + 1)/2;\
1185 (Mid).y=((P1).y+(P2).y + 1)/2;
1187 /**********************************************************
1188 * BezierCheck helper function to check
1189 * that recursion can be terminated
1190 * Points[0] and Points[3] are begin and endpoint
1191 * Points[1] and Points[2] are control points
1192 * level is the recursion depth
1193 * returns true if the recusion can be terminated
1195 static BOOL
BezierCheck( int level
, POINT
*Points
)
1198 dx
=Points
[3].x
-Points
[0].x
;
1199 dy
=Points
[3].y
-Points
[0].y
;
1200 if(abs(dy
)<=abs(dx
)){/* shallow line */
1201 /* check that control points are between begin and end */
1202 if(Points
[1].x
< Points
[0].x
){
1203 if(Points
[1].x
< Points
[3].x
)
1206 if(Points
[1].x
> Points
[3].x
)
1208 if(Points
[2].x
< Points
[0].x
){
1209 if(Points
[2].x
< Points
[3].x
)
1212 if(Points
[2].x
> Points
[3].x
)
1214 dx
=BEZIERSHIFTDOWN(dx
);
1215 if(!dx
) return TRUE
;
1216 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
1217 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
1218 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
1219 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
1223 }else{ /* steep line */
1224 /* check that control points are between begin and end */
1225 if(Points
[1].y
< Points
[0].y
){
1226 if(Points
[1].y
< Points
[3].y
)
1229 if(Points
[1].y
> Points
[3].y
)
1231 if(Points
[2].y
< Points
[0].y
){
1232 if(Points
[2].y
< Points
[3].y
)
1235 if(Points
[2].y
> Points
[3].y
)
1237 dy
=BEZIERSHIFTDOWN(dy
);
1238 if(!dy
) return TRUE
;
1239 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
1240 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
1241 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
1242 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1249 /* Helper for GDI_Bezier.
1250 * Just handles one Bezier, so Points should point to four POINTs
1252 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
1253 INT
*nPtsOut
, INT level
)
1255 if(*nPtsOut
== *dwOut
) {
1257 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
1258 *dwOut
* sizeof(POINT
) );
1261 if(!level
|| BezierCheck(level
, Points
)) {
1263 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1264 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1267 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1268 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1271 POINT Points2
[4]; /* for the second recursive call */
1272 Points2
[3]=Points
[3];
1273 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1274 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1275 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1277 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1278 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1279 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1281 Points2
[0]=Points
[3];
1283 /* do the two halves */
1284 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1285 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1291 /***********************************************************************
1292 * GDI_Bezier [INTERNAL]
1293 * Calculate line segments that approximate -what microsoft calls- a bezier
1295 * The routine recursively divides the curve in two parts until a straight
1300 * Points [I] Ptr to count POINTs which are the end and control points
1301 * of the set of Bezier curves to flatten.
1302 * count [I] Number of Points. Must be 3n+1.
1303 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1308 * Ptr to an array of POINTs that contain the lines that approximinate the
1309 * Beziers. The array is allocated on the process heap and it is the caller's
1310 * responsibility to HeapFree it. [this is not a particularly nice interface
1311 * but since we can't know in advance how many points will generate, the
1312 * alternative would be to call the function twice, once to determine the size
1313 * and a second time to do the work - I decided this was too much of a pain].
1315 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1318 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1320 if((count
- 1) % 3 != 0) {
1321 ERR("Invalid no. of points\n");
1325 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1326 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1328 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1329 for(i
= 0; i
< 4; i
++) {
1330 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1331 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1333 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1335 TRACE("Produced %d points\n", *nPtsOut
);