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
24 #include "wine/port.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
39 /***********************************************************************
42 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
44 DC
* dc
= DC_GetDCUpdate( hdc
);
49 if(PATH_IsPathOpen(dc
->path
))
50 ret
= PATH_LineTo(dc
, x
, y
);
52 ret
= dc
->funcs
->pLineTo
&& dc
->funcs
->pLineTo(dc
->physDev
,x
,y
);
57 GDI_ReleaseObj( hdc
);
62 /***********************************************************************
65 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
68 DC
* dc
= DC_GetDCPtr( hdc
);
79 if(PATH_IsPathOpen(dc
->path
)) ret
= PATH_MoveTo(dc
);
80 else if (dc
->funcs
->pMoveTo
) ret
= dc
->funcs
->pMoveTo(dc
->physDev
,x
,y
);
81 GDI_ReleaseObj( hdc
);
86 /***********************************************************************
89 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
90 INT bottom
, INT xstart
, INT ystart
,
94 DC
* dc
= DC_GetDCUpdate( hdc
);
97 if(PATH_IsPathOpen(dc
->path
))
98 ret
= PATH_Arc(dc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,0);
99 else if (dc
->funcs
->pArc
)
100 ret
= dc
->funcs
->pArc(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
101 GDI_ReleaseObj( hdc
);
106 /***********************************************************************
109 BOOL WINAPI
ArcTo( HDC hdc
,
111 INT right
, INT bottom
,
112 INT xstart
, INT ystart
,
116 DC
* dc
= DC_GetDCUpdate( hdc
);
117 if(!dc
) return FALSE
;
119 if(dc
->funcs
->pArcTo
)
121 result
= dc
->funcs
->pArcTo( dc
->physDev
, left
, top
, right
, bottom
,
122 xstart
, ystart
, xend
, yend
);
123 GDI_ReleaseObj( hdc
);
126 GDI_ReleaseObj( hdc
);
129 * According to the documentation, a line is drawn from the current
130 * position to the starting point of the arc.
132 LineTo(hdc
, xstart
, ystart
);
134 * Then the arc is drawn.
136 result
= Arc(hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
138 * If no error occurred, the current position is moved to the ending
141 if (result
) MoveToEx(hdc
, xend
, yend
, NULL
);
146 /***********************************************************************
149 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
150 INT right
, INT bottom
, INT xstart
, INT ystart
,
154 DC
* dc
= DC_GetDCUpdate( hdc
);
155 if (!dc
) return FALSE
;
157 if(PATH_IsPathOpen(dc
->path
))
158 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,2);
159 else if(dc
->funcs
->pPie
)
160 ret
= dc
->funcs
->pPie(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
162 GDI_ReleaseObj( hdc
);
167 /***********************************************************************
170 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
171 INT right
, INT bottom
, INT xstart
, INT ystart
,
175 DC
* dc
= DC_GetDCUpdate( hdc
);
176 if (!dc
) return FALSE
;
178 if(PATH_IsPathOpen(dc
->path
))
179 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,1);
180 else if(dc
->funcs
->pChord
)
181 ret
= dc
->funcs
->pChord(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
183 GDI_ReleaseObj( hdc
);
188 /***********************************************************************
191 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
192 INT right
, INT bottom
)
195 DC
* dc
= DC_GetDCUpdate( hdc
);
196 if (!dc
) return FALSE
;
198 if(PATH_IsPathOpen(dc
->path
))
199 ret
= PATH_Ellipse(dc
,left
,top
,right
,bottom
);
200 else if (dc
->funcs
->pEllipse
)
201 ret
= dc
->funcs
->pEllipse(dc
->physDev
,left
,top
,right
,bottom
);
203 GDI_ReleaseObj( hdc
);
208 /***********************************************************************
209 * Rectangle (GDI32.@)
211 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
212 INT right
, INT bottom
)
215 DC
* dc
= DC_GetDCUpdate( hdc
);
218 if(PATH_IsPathOpen(dc
->path
))
219 ret
= PATH_Rectangle(dc
, left
, top
, right
, bottom
);
220 else if (dc
->funcs
->pRectangle
)
221 ret
= dc
->funcs
->pRectangle(dc
->physDev
,left
,top
,right
,bottom
);
222 GDI_ReleaseObj( hdc
);
228 /***********************************************************************
229 * RoundRect (GDI32.@)
231 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
232 INT bottom
, INT ell_width
, INT ell_height
)
235 DC
*dc
= DC_GetDCUpdate( hdc
);
239 if(PATH_IsPathOpen(dc
->path
))
240 ret
= PATH_RoundRect(dc
,left
,top
,right
,bottom
,ell_width
,ell_height
);
241 else if (dc
->funcs
->pRoundRect
)
242 ret
= dc
->funcs
->pRoundRect(dc
->physDev
,left
,top
,right
,bottom
,ell_width
,ell_height
);
243 GDI_ReleaseObj( hdc
);
248 /***********************************************************************
251 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
254 DC
* dc
= DC_GetDCUpdate( hdc
);
257 if (dc
->funcs
->pSetPixel
) ret
= dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
258 GDI_ReleaseObj( hdc
);
263 /***********************************************************************
264 * SetPixelV (GDI32.@)
266 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
269 DC
* dc
= DC_GetDCUpdate( hdc
);
272 if (dc
->funcs
->pSetPixel
)
274 dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
277 GDI_ReleaseObj( hdc
);
282 /***********************************************************************
285 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
287 COLORREF ret
= CLR_INVALID
;
288 DC
* dc
= DC_GetDCUpdate( hdc
);
292 /* FIXME: should this be in the graphics driver? */
293 if (PtVisible( hdc
, x
, y
))
295 if (dc
->funcs
->pGetPixel
) ret
= dc
->funcs
->pGetPixel(dc
->physDev
,x
,y
);
297 GDI_ReleaseObj( hdc
);
303 /******************************************************************************
304 * ChoosePixelFormat [GDI32.@]
305 * Matches a pixel format to given format
308 * hdc [I] Device context to search for best pixel match
309 * ppfd [I] Pixel format for which a match is sought
312 * Success: Pixel format index closest to given format
315 INT WINAPI
ChoosePixelFormat( HDC hdc
, const LPPIXELFORMATDESCRIPTOR ppfd
)
318 DC
* dc
= DC_GetDCPtr( hdc
);
320 TRACE("(%p,%p)\n",hdc
,ppfd
);
324 if (!dc
->funcs
->pChoosePixelFormat
) FIXME(" :stub\n");
325 else ret
= dc
->funcs
->pChoosePixelFormat(dc
->physDev
,ppfd
);
327 GDI_ReleaseObj( hdc
);
332 /******************************************************************************
333 * SetPixelFormat [GDI32.@]
334 * Sets pixel format of device context
337 * hdc [I] Device context to search for best pixel match
338 * iPixelFormat [I] Pixel format index
339 * ppfd [I] Pixel format for which a match is sought
343 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT iPixelFormat
,
344 const PIXELFORMATDESCRIPTOR
*ppfd
)
347 DC
* dc
= DC_GetDCPtr( hdc
);
349 TRACE("(%p,%d,%p)\n",hdc
,iPixelFormat
,ppfd
);
353 if (!dc
->funcs
->pSetPixelFormat
) FIXME(" :stub\n");
354 else bRet
= dc
->funcs
->pSetPixelFormat(dc
->physDev
,iPixelFormat
,ppfd
);
356 GDI_ReleaseObj( hdc
);
361 /******************************************************************************
362 * GetPixelFormat [GDI32.@]
363 * Gets index of pixel format of DC
366 * hdc [I] Device context whose pixel format index is sought
369 * Success: Currently selected pixel format
372 INT WINAPI
GetPixelFormat( HDC hdc
)
375 DC
* dc
= DC_GetDCPtr( hdc
);
381 if (!dc
->funcs
->pGetPixelFormat
) FIXME(" :stub\n");
382 else ret
= dc
->funcs
->pGetPixelFormat(dc
->physDev
);
384 GDI_ReleaseObj( hdc
);
389 /******************************************************************************
390 * DescribePixelFormat [GDI32.@]
391 * Gets info about pixel format from DC
394 * hdc [I] Device context
395 * iPixelFormat [I] Pixel format selector
396 * nBytes [I] Size of buffer
397 * ppfd [O] Pointer to structure to receive pixel format data
400 * Success: Maximum pixel format index of the device context
403 INT WINAPI
DescribePixelFormat( HDC hdc
, INT iPixelFormat
, UINT nBytes
,
404 LPPIXELFORMATDESCRIPTOR ppfd
)
407 DC
* dc
= DC_GetDCPtr( hdc
);
409 TRACE("(%p,%d,%d,%p): stub\n",hdc
,iPixelFormat
,nBytes
,ppfd
);
413 if (!dc
->funcs
->pDescribePixelFormat
)
416 ppfd
->nSize
= nBytes
;
420 else ret
= dc
->funcs
->pDescribePixelFormat(dc
->physDev
,iPixelFormat
,nBytes
,ppfd
);
422 GDI_ReleaseObj( hdc
);
427 /******************************************************************************
428 * SwapBuffers [GDI32.@]
429 * Exchanges front and back buffers of window
432 * hdc [I] Device context whose buffers get swapped
436 BOOL WINAPI
SwapBuffers( HDC hdc
)
439 DC
* dc
= DC_GetDCPtr( hdc
);
443 if (!dc
) return TRUE
;
445 if (!dc
->funcs
->pSwapBuffers
)
450 else bRet
= dc
->funcs
->pSwapBuffers(dc
->physDev
);
452 GDI_ReleaseObj( hdc
);
457 /***********************************************************************
460 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
463 DC
* dc
= DC_GetDCUpdate( hdc
);
466 if (dc
->funcs
->pPaintRgn
) ret
= dc
->funcs
->pPaintRgn(dc
->physDev
,hrgn
);
467 GDI_ReleaseObj( hdc
);
473 /***********************************************************************
476 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
480 DC
* dc
= DC_GetDCUpdate( hdc
);
482 if (!dc
) return FALSE
;
483 if(dc
->funcs
->pFillRgn
)
484 retval
= dc
->funcs
->pFillRgn(dc
->physDev
, hrgn
, hbrush
);
485 else if ((prevBrush
= SelectObject( hdc
, hbrush
)))
487 retval
= PaintRgn( hdc
, hrgn
);
488 SelectObject( hdc
, prevBrush
);
490 GDI_ReleaseObj( hdc
);
495 /***********************************************************************
498 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
499 INT nWidth
, INT nHeight
)
502 DC
*dc
= DC_GetDCUpdate( hdc
);
504 if (!dc
) return FALSE
;
505 if(dc
->funcs
->pFrameRgn
)
506 ret
= dc
->funcs
->pFrameRgn( dc
->physDev
, hrgn
, hbrush
, nWidth
, nHeight
);
509 HRGN tmp
= CreateRectRgn( 0, 0, 0, 0 );
512 if (REGION_FrameRgn( tmp
, hrgn
, nWidth
, nHeight
))
514 FillRgn( hdc
, tmp
, hbrush
);
520 GDI_ReleaseObj( hdc
);
525 /***********************************************************************
526 * InvertRgn (GDI32.@)
528 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
533 DC
*dc
= DC_GetDCUpdate( hdc
);
534 if (!dc
) return FALSE
;
536 if(dc
->funcs
->pInvertRgn
)
537 retval
= dc
->funcs
->pInvertRgn( dc
->physDev
, hrgn
);
540 prevBrush
= SelectObject( hdc
, GetStockObject(BLACK_BRUSH
) );
541 prevROP
= SetROP2( hdc
, R2_NOT
);
542 retval
= PaintRgn( hdc
, hrgn
);
543 SelectObject( hdc
, prevBrush
);
544 SetROP2( hdc
, prevROP
);
546 GDI_ReleaseObj( hdc
);
551 /**********************************************************************
554 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
557 DC
* dc
= DC_GetDCUpdate( hdc
);
560 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polyline(dc
, pt
, count
);
561 else if (dc
->funcs
->pPolyline
) ret
= dc
->funcs
->pPolyline(dc
->physDev
,pt
,count
);
562 GDI_ReleaseObj( hdc
);
567 /**********************************************************************
568 * PolylineTo (GDI32.@)
570 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
572 DC
* dc
= DC_GetDCUpdate( hdc
);
575 if(!dc
) return FALSE
;
577 if(PATH_IsPathOpen(dc
->path
))
578 ret
= PATH_PolylineTo(dc
, pt
, cCount
);
580 else if(dc
->funcs
->pPolylineTo
)
581 ret
= dc
->funcs
->pPolylineTo(dc
->physDev
, pt
, cCount
);
583 else { /* do it using Polyline */
584 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
585 sizeof(POINT
) * (cCount
+ 1) );
588 pts
[0].x
= dc
->CursPosX
;
589 pts
[0].y
= dc
->CursPosY
;
590 memcpy( pts
+ 1, pt
, sizeof(POINT
) * cCount
);
591 ret
= Polyline( hdc
, pts
, cCount
+ 1 );
592 HeapFree( GetProcessHeap(), 0, pts
);
596 dc
->CursPosX
= pt
[cCount
-1].x
;
597 dc
->CursPosY
= pt
[cCount
-1].y
;
599 GDI_ReleaseObj( hdc
);
604 /**********************************************************************
607 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
610 DC
* dc
= DC_GetDCUpdate( hdc
);
613 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polygon(dc
, pt
, count
);
614 else if (dc
->funcs
->pPolygon
) ret
= dc
->funcs
->pPolygon(dc
->physDev
,pt
,count
);
615 GDI_ReleaseObj( hdc
);
621 /**********************************************************************
622 * PolyPolygon (GDI32.@)
624 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
628 DC
* dc
= DC_GetDCUpdate( hdc
);
631 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolygon(dc
, pt
, counts
, polygons
);
632 else if (dc
->funcs
->pPolyPolygon
) ret
= dc
->funcs
->pPolyPolygon(dc
->physDev
,pt
,counts
,polygons
);
633 GDI_ReleaseObj( hdc
);
638 /**********************************************************************
639 * PolyPolyline (GDI32.@)
641 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
645 DC
* dc
= DC_GetDCUpdate( hdc
);
648 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolyline(dc
, pt
, counts
, polylines
);
649 else if (dc
->funcs
->pPolyPolyline
) ret
= dc
->funcs
->pPolyPolyline(dc
->physDev
,pt
,counts
,polylines
);
650 GDI_ReleaseObj( hdc
);
655 /**********************************************************************
656 * ExtFloodFill (GDI32.@)
658 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
662 DC
* dc
= DC_GetDCUpdate( hdc
);
665 if (dc
->funcs
->pExtFloodFill
) ret
= dc
->funcs
->pExtFloodFill(dc
->physDev
,x
,y
,color
,fillType
);
666 GDI_ReleaseObj( hdc
);
672 /**********************************************************************
673 * FloodFill (GDI32.@)
675 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
677 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
681 /******************************************************************************
682 * PolyBezier [GDI32.@]
683 * Draws one or more Bezier curves
686 * hDc [I] Handle to device context
687 * lppt [I] Pointer to endpoints and control points
688 * cPoints [I] Count of endpoints and control points
692 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
695 DC
* dc
= DC_GetDCUpdate( hdc
);
697 if(!dc
) return FALSE
;
699 if(PATH_IsPathOpen(dc
->path
))
700 ret
= PATH_PolyBezier(dc
, lppt
, cPoints
);
701 else if (dc
->funcs
->pPolyBezier
)
702 ret
= dc
->funcs
->pPolyBezier(dc
->physDev
, lppt
, cPoints
);
703 else /* We'll convert it into line segments and draw them using Polyline */
708 if ((Pts
= GDI_Bezier( lppt
, cPoints
, &nOut
)))
710 TRACE("Pts = %p, no = %d\n", Pts
, nOut
);
711 ret
= Polyline( dc
->hSelf
, Pts
, nOut
);
712 HeapFree( GetProcessHeap(), 0, Pts
);
716 GDI_ReleaseObj( hdc
);
720 /******************************************************************************
721 * PolyBezierTo [GDI32.@]
722 * Draws one or more Bezier curves
725 * hDc [I] Handle to device context
726 * lppt [I] Pointer to endpoints and control points
727 * cPoints [I] Count of endpoints and control points
731 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
733 DC
* dc
= DC_GetDCUpdate( hdc
);
736 if(!dc
) return FALSE
;
738 if(PATH_IsPathOpen(dc
->path
))
739 ret
= PATH_PolyBezierTo(dc
, lppt
, cPoints
);
740 else if(dc
->funcs
->pPolyBezierTo
)
741 ret
= dc
->funcs
->pPolyBezierTo(dc
->physDev
, lppt
, cPoints
);
742 else { /* We'll do it using PolyBezier */
744 pt
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (cPoints
+ 1) );
745 if(!pt
) return FALSE
;
746 pt
[0].x
= dc
->CursPosX
;
747 pt
[0].y
= dc
->CursPosY
;
748 memcpy(pt
+ 1, lppt
, sizeof(POINT
) * cPoints
);
749 ret
= PolyBezier(dc
->hSelf
, pt
, cPoints
+1);
750 HeapFree( GetProcessHeap(), 0, pt
);
753 dc
->CursPosX
= lppt
[cPoints
-1].x
;
754 dc
->CursPosY
= lppt
[cPoints
-1].y
;
756 GDI_ReleaseObj( hdc
);
760 /***********************************************************************
763 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
765 INT x1
,y1
,x2
,y2
, arcdir
;
769 if( (signed int)dwRadius
< 0 )
772 dc
= DC_GetDCUpdate( hdc
);
773 if(!dc
) return FALSE
;
775 if(dc
->funcs
->pAngleArc
)
777 result
= dc
->funcs
->pAngleArc( dc
->physDev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
779 GDI_ReleaseObj( hdc
);
782 GDI_ReleaseObj( hdc
);
784 /* AngleArc always works counterclockwise */
785 arcdir
= GetArcDirection( hdc
);
786 SetArcDirection( hdc
, AD_COUNTERCLOCKWISE
);
788 x1
= x
+ cos(eStartAngle
*M_PI
/180) * dwRadius
;
789 y1
= y
- sin(eStartAngle
*M_PI
/180) * dwRadius
;
790 x2
= x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
791 y2
= x
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
793 LineTo( hdc
, x1
, y1
);
794 if( eSweepAngle
>= 0 )
795 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
798 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
801 if( result
) MoveToEx( hdc
, x2
, y2
, NULL
);
802 SetArcDirection( hdc
, arcdir
);
806 /***********************************************************************
809 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
817 dc
= DC_GetDCUpdate( hdc
);
818 if(!dc
) return FALSE
;
820 if(dc
->funcs
->pPolyDraw
)
822 result
= dc
->funcs
->pPolyDraw( dc
->physDev
, lppt
, lpbTypes
, cCount
);
823 GDI_ReleaseObj( hdc
);
826 GDI_ReleaseObj( hdc
);
828 /* check for each bezierto if there are two more points */
829 for( i
= 0; i
< cCount
; i
++ )
830 if( lpbTypes
[i
] != PT_MOVETO
&&
831 lpbTypes
[i
] & PT_BEZIERTO
)
839 /* if no moveto occurs, we will close the figure here */
840 lastmove
.x
= dc
->CursPosX
;
841 lastmove
.y
= dc
->CursPosY
;
844 for( i
= 0; i
< cCount
; i
++ )
846 if( lpbTypes
[i
] == PT_MOVETO
)
848 MoveToEx( hdc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
849 lastmove
.x
= dc
->CursPosX
;
850 lastmove
.y
= dc
->CursPosY
;
852 else if( lpbTypes
[i
] & PT_LINETO
)
853 LineTo( hdc
, lppt
[i
].x
, lppt
[i
].y
);
854 else if( lpbTypes
[i
] & PT_BEZIERTO
)
856 PolyBezierTo( hdc
, &lppt
[i
], 3 );
862 if( lpbTypes
[i
] & PT_CLOSEFIGURE
)
864 if( PATH_IsPathOpen( dc
->path
) )
867 LineTo( hdc
, lastmove
.x
, lastmove
.y
);
874 /******************************************************************
876 * *Very* simple bezier drawing code,
878 * It uses a recursive algorithm to divide the curve in a series
879 * of straight line segements. Not ideal but for me sufficient.
880 * If you are in need for something better look for some incremental
883 * 7 July 1998 Rein Klazes
887 * some macro definitions for bezier drawing
889 * to avoid truncation errors the coordinates are
890 * shifted upwards. When used in drawing they are
891 * shifted down again, including correct rounding
892 * and avoiding floating point arithmetic
893 * 4 bits should allow 27 bits coordinates which I saw
894 * somewhere in the win32 doc's
898 #define BEZIERSHIFTBITS 4
899 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
900 #define BEZIERPIXEL BEZIERSHIFTUP(1)
901 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
902 /* maximum depth of recursion */
903 #define BEZIERMAXDEPTH 8
905 /* size of array to store points on */
906 /* enough for one curve */
907 #define BEZIER_INITBUFSIZE (150)
909 /* calculate Bezier average, in this case the middle
910 * correctly rounded...
913 #define BEZIERMIDDLE(Mid, P1, P2) \
914 (Mid).x=((P1).x+(P2).x + 1)/2;\
915 (Mid).y=((P1).y+(P2).y + 1)/2;
917 /**********************************************************
918 * BezierCheck helper function to check
919 * that recursion can be terminated
920 * Points[0] and Points[3] are begin and endpoint
921 * Points[1] and Points[2] are control points
922 * level is the recursion depth
923 * returns true if the recusion can be terminated
925 static BOOL
BezierCheck( int level
, POINT
*Points
)
928 dx
=Points
[3].x
-Points
[0].x
;
929 dy
=Points
[3].y
-Points
[0].y
;
930 if(abs(dy
)<=abs(dx
)){/* shallow line */
931 /* check that control points are between begin and end */
932 if(Points
[1].x
< Points
[0].x
){
933 if(Points
[1].x
< Points
[3].x
)
936 if(Points
[1].x
> Points
[3].x
)
938 if(Points
[2].x
< Points
[0].x
){
939 if(Points
[2].x
< Points
[3].x
)
942 if(Points
[2].x
> Points
[3].x
)
944 dx
=BEZIERSHIFTDOWN(dx
);
946 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
947 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
948 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
949 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
953 }else{ /* steep line */
954 /* check that control points are between begin and end */
955 if(Points
[1].y
< Points
[0].y
){
956 if(Points
[1].y
< Points
[3].y
)
959 if(Points
[1].y
> Points
[3].y
)
961 if(Points
[2].y
< Points
[0].y
){
962 if(Points
[2].y
< Points
[3].y
)
965 if(Points
[2].y
> Points
[3].y
)
967 dy
=BEZIERSHIFTDOWN(dy
);
969 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
970 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
971 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
972 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
979 /* Helper for GDI_Bezier.
980 * Just handles one Bezier, so Points should point to four POINTs
982 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
983 INT
*nPtsOut
, INT level
)
985 if(*nPtsOut
== *dwOut
) {
987 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
988 *dwOut
* sizeof(POINT
) );
991 if(!level
|| BezierCheck(level
, Points
)) {
993 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
994 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
997 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
998 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1001 POINT Points2
[4]; /* for the second recursive call */
1002 Points2
[3]=Points
[3];
1003 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1004 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1005 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1007 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1008 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1009 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1011 Points2
[0]=Points
[3];
1013 /* do the two halves */
1014 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1015 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1021 /***********************************************************************
1022 * GDI_Bezier [INTERNAL]
1023 * Calculate line segments that approximate -what microsoft calls- a bezier
1025 * The routine recursively divides the curve in two parts until a straight
1030 * Points [I] Ptr to count POINTs which are the end and control points
1031 * of the set of Bezier curves to flatten.
1032 * count [I] Number of Points. Must be 3n+1.
1033 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1038 * Ptr to an array of POINTs that contain the lines that approximinate the
1039 * Beziers. The array is allocated on the process heap and it is the caller's
1040 * responsibility to HeapFree it. [this is not a particularly nice interface
1041 * but since we can't know in advance how many points will generate, the
1042 * alternative would be to call the function twice, once to determine the size
1043 * and a second time to do the work - I decided this was too much of a pain].
1045 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1048 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1050 if((count
- 1) % 3 != 0) {
1051 ERR("Invalid no. of points\n");
1055 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1056 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1058 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1059 for(i
= 0; i
< 4; i
++) {
1060 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1061 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1063 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1065 TRACE("Produced %d points\n", *nPtsOut
);
1069 /******************************************************************************
1070 * GradientFill (GDI32.@)
1072 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1073 void * grad_array
, ULONG ngrad
, ULONG mode
)
1077 TRACE("vert_array:0x%08lx nvert:%ld grad_array:0x%08lx ngrad:%ld\n",
1078 (long)vert_array
, nvert
, (long)grad_array
, ngrad
);
1082 case GRADIENT_FILL_RECT_H
:
1083 for(i
= 0; i
< ngrad
; i
++)
1085 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1086 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1087 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1088 int y1
= v1
->y
< v2
->y
? v1
->y
: v2
->y
;
1089 int y2
= v2
->y
> v1
->y
? v2
->y
: v1
->y
;
1098 for (x
= 0; x
< dx
; x
++)
1100 for (y
= y1
; y
< y2
; y
++)
1101 SetPixel (hdc
, x
+ v1
->x
, y
, RGB(
1102 (v1
->Red
* (dx
- x
) + v2
->Red
* x
) / dx
>> 8,
1103 (v1
->Green
* (dx
- x
) + v2
->Green
* x
) / dx
>> 8,
1104 (v1
->Blue
* (dx
- x
) + v2
->Blue
* x
) / dx
>> 8));
1108 case GRADIENT_FILL_RECT_V
:
1109 for(i
= 0; i
< ngrad
; i
++)
1111 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1112 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1113 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1114 int x1
= v1
->x
< v2
->x
? v1
->x
: v2
->x
;
1115 int x2
= v2
->x
> v1
->x
? v2
->x
: v1
->x
;
1124 for (y
= 0; y
< dy
; y
++)
1126 for (x
= x1
; x
< x2
; x
++)
1127 SetPixel (hdc
, x
, y
+ v1
->y
, RGB(
1128 (v1
->Red
* (dy
- y
) + v2
->Red
* y
) / dy
>> 8,
1129 (v1
->Green
* (dy
- y
) + v2
->Green
* y
) / dy
>> 8,
1130 (v1
->Blue
* (dy
- y
) + v2
->Blue
* y
) / dy
>> 8));
1134 case GRADIENT_FILL_TRIANGLE
:
1135 for (i
= 0; i
< ngrad
; i
++)
1137 GRADIENT_TRIANGLE
*tri
= ((GRADIENT_TRIANGLE
*)grad_array
) + i
;
1138 TRIVERTEX
*v1
= vert_array
+ tri
->Vertex1
;
1139 TRIVERTEX
*v2
= vert_array
+ tri
->Vertex2
;
1140 TRIVERTEX
*v3
= vert_array
+ tri
->Vertex3
;
1144 { TRIVERTEX
*t
= v1
; v1
= v2
; v2
= t
; }
1147 TRIVERTEX
*t
= v2
; v2
= v3
; v3
= t
;
1149 { t
= v1
; v1
= v2
; v2
= t
; }
1151 /* v1->y <= v2->y <= v3->y */
1154 for (y
= 0; y
< dy
; y
++)
1156 /* v1->y <= y < v3->y */
1157 TRIVERTEX
*v
= y
< (v2
->y
- v1
->y
) ? v1
: v3
;
1158 /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */
1159 int dy2
= v2
->y
- v
->y
;
1160 int y2
= y
+ v1
->y
- v
->y
;
1162 int x1
= (v3
->x
* y
+ v1
->x
* (dy
- y
)) / dy
;
1163 int x2
= (v2
->x
* y2
+ v
-> x
* (dy2
- y2
)) / dy2
;
1164 int r1
= (v3
->Red
* y
+ v1
->Red
* (dy
- y
)) / dy
;
1165 int r2
= (v2
->Red
* y2
+ v
-> Red
* (dy2
- y2
)) / dy2
;
1166 int g1
= (v3
->Green
* y
+ v1
->Green
* (dy
- y
)) / dy
;
1167 int g2
= (v2
->Green
* y2
+ v
-> Green
* (dy2
- y2
)) / dy2
;
1168 int b1
= (v3
->Blue
* y
+ v1
->Blue
* (dy
- y
)) / dy
;
1169 int b2
= (v2
->Blue
* y2
+ v
-> Blue
* (dy2
- y2
)) / dy2
;
1175 for (x
= 0; x
< dx
; x
++)
1176 SetPixel (hdc
, x
+ x1
, y
+ v1
->y
, RGB(
1177 (r1
* (dx
- x
) + r2
* x
) / dx
>> 8,
1178 (g1
* (dx
- x
) + g2
* x
) / dx
>> 8,
1179 (b1
* (dx
- x
) + b2
* x
) / dx
>> 8));
1184 for (x
= 0; x
< dx
; x
++)
1185 SetPixel (hdc
, x
+ x2
, y
+ v1
->y
, RGB(
1186 (r2
* (dx
- x
) + r1
* x
) / dx
>> 8,
1187 (g2
* (dx
- x
) + g1
* x
) / dx
>> 8,
1188 (b2
* (dx
- x
) + b1
* x
) / dx
>> 8));