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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
34 #include "gdi_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
40 /***********************************************************************
41 * null driver fallback implementations
44 BOOL nulldrv_AngleArc( PHYSDEV dev, INT x, INT y, DWORD radius, FLOAT start, FLOAT sweep )
46 INT x1 = GDI_ROUND( x + cos( start * M_PI / 180 ) * radius );
47 INT y1 = GDI_ROUND( y - sin( start * M_PI / 180 ) * radius );
48 INT x2 = GDI_ROUND( x + cos( (start + sweep) * M_PI / 180) * radius );
49 INT y2 = GDI_ROUND( y - sin( (start + sweep) * M_PI / 180) * radius );
50 INT arcdir = SetArcDirection( dev->hdc, sweep >= 0 ? AD_COUNTERCLOCKWISE : AD_CLOCKWISE );
51 BOOL ret = ArcTo( dev->hdc, x - radius, y - radius, x + radius, y + radius, x1, y1, x2, y2 );
52 SetArcDirection( dev->hdc, arcdir );
56 BOOL nulldrv_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
57 INT xstart, INT ystart, INT xend, INT yend )
59 INT width = abs( right - left );
60 INT height = abs( bottom - top );
61 double xradius = width / 2.0;
62 double yradius = height / 2.0;
63 double xcenter = right > left ? left + xradius : right + xradius;
64 double ycenter = bottom > top ? top + yradius : bottom + yradius;
67 if (!height || !width) return FALSE;
68 /* draw a line from the current position to the starting point of the arc, then draw the arc */
69 angle = atan2( (ystart - ycenter) / height, (xstart - xcenter) / width );
70 LineTo( dev->hdc, GDI_ROUND( xcenter + cos(angle) * xradius ),
71 GDI_ROUND( ycenter + sin(angle) * yradius ));
72 return Arc( dev->hdc, left, top, right, bottom, xstart, ystart, xend, yend );
75 BOOL nulldrv_FillRgn( PHYSDEV dev, HRGN rgn, HBRUSH brush )
80 if ((prev = SelectObject( dev->hdc, brush )))
82 ret = PaintRgn( dev->hdc, rgn );
83 SelectObject( dev->hdc, prev );
88 BOOL nulldrv_FrameRgn( PHYSDEV dev, HRGN rgn, HBRUSH brush, INT width, INT height )
91 HRGN tmp = CreateRectRgn( 0, 0, 0, 0 );
95 if (REGION_FrameRgn( tmp, rgn, width, height )) ret = FillRgn( dev->hdc, tmp, brush );
101 BOOL nulldrv_InvertRgn( PHYSDEV dev, HRGN rgn )
103 HBRUSH prev_brush = SelectObject( dev->hdc, GetStockObject(BLACK_BRUSH) );
104 INT prev_rop = SetROP2( dev->hdc, R2_NOT );
105 BOOL ret = PaintRgn( dev->hdc, rgn );
106 SelectObject( dev->hdc, prev_brush );
107 SetROP2( dev->hdc, prev_rop );
111 BOOL nulldrv_PolyBezier( PHYSDEV dev, const POINT *points, DWORD count )
117 if ((pts = GDI_Bezier( points, count, &n )))
119 ret = Polyline( dev->hdc, pts, n );
120 HeapFree( GetProcessHeap(), 0, pts );
125 BOOL nulldrv_PolyBezierTo( PHYSDEV dev, const POINT *points, DWORD count )
128 POINT *pts = HeapAlloc( GetProcessHeap(), 0, sizeof(POINT) * (count + 1) );
132 GetCurrentPositionEx( dev->hdc, &pts[0] );
133 memcpy( pts + 1, points, sizeof(POINT) * count );
134 ret = PolyBezier( dev->hdc, pts, count + 1 );
135 HeapFree( GetProcessHeap(), 0, pts );
140 BOOL nulldrv_PolyDraw( PHYSDEV dev, const POINT *points, const BYTE *types, DWORD count )
142 POINT *line_pts = NULL, *bzr_pts = NULL, bzr[4];
143 INT i, num_pts, num_bzr_pts, space, size;
145 /* check for valid point types */
146 for (i = 0; i < count; i++)
151 case PT_LINETO | PT_CLOSEFIGURE:
155 if((i + 2 < count) && (types[i + 1] == PT_BEZIERTO) &&
156 ((types[i + 2] & ~PT_CLOSEFIGURE) == PT_BEZIERTO))
167 line_pts = HeapAlloc( GetProcessHeap(), 0, space * sizeof(POINT) );
170 GetCurrentPositionEx( dev->hdc, &line_pts[0] );
171 for (i = 0; i < count; i++)
176 if (num_pts >= 2) Polyline( dev->hdc, line_pts, num_pts );
178 line_pts[num_pts++] = points[i];
181 case (PT_LINETO | PT_CLOSEFIGURE):
182 line_pts[num_pts++] = points[i];
185 bzr[0].x = line_pts[num_pts - 1].x;
186 bzr[0].y = line_pts[num_pts - 1].y;
187 memcpy( &bzr[1], &points[i], 3 * sizeof(POINT) );
189 if ((bzr_pts = GDI_Bezier( bzr, 4, &num_bzr_pts )))
191 size = num_pts + (count - i) + num_bzr_pts;
195 line_pts = HeapReAlloc( GetProcessHeap(), 0, line_pts, space * sizeof(POINT) );
197 memcpy( &line_pts[num_pts], &bzr_pts[1], (num_bzr_pts - 1) * sizeof(POINT) );
198 num_pts += num_bzr_pts - 1;
199 HeapFree( GetProcessHeap(), 0, bzr_pts );
204 if (types[i] & PT_CLOSEFIGURE) line_pts[num_pts++] = line_pts[0];
207 if (num_pts >= 2) Polyline( dev->hdc, line_pts, num_pts );
208 MoveToEx( dev->hdc, line_pts[num_pts - 1].x, line_pts[num_pts - 1].y, NULL );
209 HeapFree( GetProcessHeap(), 0, line_pts );
213 BOOL nulldrv_PolylineTo( PHYSDEV dev, const POINT *points, INT count )
218 if (!count) return FALSE;
219 if ((pts = HeapAlloc( GetProcessHeap(), 0, sizeof(POINT) * (count + 1) )))
221 GetCurrentPositionEx( dev->hdc, &pts[0] );
222 memcpy( pts + 1, points, sizeof(POINT) * count );
223 ret = Polyline( dev->hdc, pts, count + 1 );
224 HeapFree( GetProcessHeap(), 0, pts );
229 /***********************************************************************
232 BOOL WINAPI LineTo( HDC hdc, INT x, INT y )
234 DC * dc = get_dc_ptr( hdc );
238 if(!dc) return FALSE;
241 physdev = GET_DC_PHYSDEV( dc, pLineTo );
242 ret = physdev->funcs->pLineTo( physdev, x, y );
248 release_dc_ptr( dc );
253 /***********************************************************************
256 BOOL WINAPI MoveToEx( HDC hdc, INT x, INT y, LPPOINT pt )
260 DC * dc = get_dc_ptr( hdc );
262 if(!dc) return FALSE;
265 pt->x = dc->CursPosX;
266 pt->y = dc->CursPosY;
271 physdev = GET_DC_PHYSDEV( dc, pMoveTo );
272 ret = physdev->funcs->pMoveTo( physdev, x, y );
273 release_dc_ptr( dc );
278 /***********************************************************************
281 BOOL WINAPI Arc( HDC hdc, INT left, INT top, INT right,
282 INT bottom, INT xstart, INT ystart,
286 DC * dc = get_dc_ptr( hdc );
291 if(PATH_IsPathOpen(dc->path))
292 ret = PATH_Arc(dc, left, top, right, bottom, xstart, ystart, xend, yend,0);
295 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pArc );
296 ret = physdev->funcs->pArc( physdev, left, top, right, bottom, xstart, ystart, xend, yend );
298 release_dc_ptr( dc );
303 /***********************************************************************
306 BOOL WINAPI ArcTo( HDC hdc,
308 INT right, INT bottom,
309 INT xstart, INT ystart,
312 double width = fabs(right-left),
313 height = fabs(bottom-top),
316 xcenter = right > left ? left+xradius : right+xradius,
317 ycenter = bottom > top ? top+yradius : bottom+yradius,
320 DC * dc = get_dc_ptr( hdc );
321 if(!dc) return FALSE;
324 if(PATH_IsPathOpen(dc->path))
325 result = PATH_Arc(dc,left,top,right,bottom,xstart,ystart,xend,yend,-1);
328 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pArcTo );
329 result = physdev->funcs->pArcTo( physdev, left, top, right, bottom, xstart, ystart, xend, yend );
332 angle = atan2(((yend-ycenter)/height),
333 ((xend-xcenter)/width));
334 dc->CursPosX = GDI_ROUND(xcenter+(cos(angle)*xradius));
335 dc->CursPosY = GDI_ROUND(ycenter+(sin(angle)*yradius));
337 release_dc_ptr( dc );
342 /***********************************************************************
345 BOOL WINAPI Pie( HDC hdc, INT left, INT top,
346 INT right, INT bottom, INT xstart, INT ystart,
350 DC * dc = get_dc_ptr( hdc );
351 if (!dc) return FALSE;
354 if(PATH_IsPathOpen(dc->path))
355 ret = PATH_Arc(dc,left,top,right,bottom,xstart,ystart,xend,yend,2);
358 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPie );
359 ret = physdev->funcs->pPie( physdev, left, top, right, bottom, xstart, ystart, xend, yend );
361 release_dc_ptr( dc );
366 /***********************************************************************
369 BOOL WINAPI Chord( HDC hdc, INT left, INT top,
370 INT right, INT bottom, INT xstart, INT ystart,
374 DC * dc = get_dc_ptr( hdc );
375 if (!dc) return FALSE;
378 if(PATH_IsPathOpen(dc->path))
379 ret = PATH_Arc(dc,left,top,right,bottom,xstart,ystart,xend,yend,1);
382 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pChord );
383 ret = physdev->funcs->pChord( physdev, left, top, right, bottom, xstart, ystart, xend, yend );
385 release_dc_ptr( dc );
390 /***********************************************************************
393 BOOL WINAPI Ellipse( HDC hdc, INT left, INT top,
394 INT right, INT bottom )
397 DC * dc = get_dc_ptr( hdc );
398 if (!dc) return FALSE;
401 if(PATH_IsPathOpen(dc->path))
402 ret = PATH_Ellipse(dc,left,top,right,bottom);
405 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pEllipse );
406 ret = physdev->funcs->pEllipse( physdev, left, top, right, bottom );
409 release_dc_ptr( dc );
414 /***********************************************************************
415 * Rectangle (GDI32.@)
417 BOOL WINAPI Rectangle( HDC hdc, INT left, INT top,
418 INT right, INT bottom )
421 DC * dc = get_dc_ptr( hdc );
425 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRectangle );
427 ret = physdev->funcs->pRectangle( physdev, left, top, right, bottom );
428 release_dc_ptr( dc );
434 /***********************************************************************
435 * RoundRect (GDI32.@)
437 BOOL WINAPI RoundRect( HDC hdc, INT left, INT top, INT right,
438 INT bottom, INT ell_width, INT ell_height )
441 DC *dc = get_dc_ptr( hdc );
445 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRoundRect );
447 ret = physdev->funcs->pRoundRect( physdev, left, top, right, bottom, ell_width, ell_height );
448 release_dc_ptr( dc );
453 /***********************************************************************
456 COLORREF WINAPI SetPixel( HDC hdc, INT x, INT y, COLORREF color )
459 DC * dc = get_dc_ptr( hdc );
463 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPixel );
465 ret = physdev->funcs->pSetPixel( physdev, x, y, color );
466 release_dc_ptr( dc );
471 /***********************************************************************
472 * SetPixelV (GDI32.@)
474 BOOL WINAPI SetPixelV( HDC hdc, INT x, INT y, COLORREF color )
477 DC * dc = get_dc_ptr( hdc );
481 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPixel );
483 physdev->funcs->pSetPixel( physdev, x, y, color );
485 release_dc_ptr( dc );
490 /***********************************************************************
493 COLORREF WINAPI GetPixel( HDC hdc, INT x, INT y )
495 COLORREF ret = CLR_INVALID;
496 DC * dc = get_dc_ptr( hdc );
501 /* FIXME: should this be in the graphics driver? */
502 if (PtVisible( hdc, x, y ))
504 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetPixel );
505 ret = physdev->funcs->pGetPixel( physdev, x, y );
507 release_dc_ptr( dc );
513 /******************************************************************************
514 * ChoosePixelFormat [GDI32.@]
515 * Matches a pixel format to given format
518 * hdc [I] Device context to search for best pixel match
519 * ppfd [I] Pixel format for which a match is sought
522 * Success: Pixel format index closest to given format
525 INT WINAPI ChoosePixelFormat( HDC hdc, const PIXELFORMATDESCRIPTOR* ppfd )
528 DC * dc = get_dc_ptr( hdc );
530 TRACE("(%p,%p)\n",hdc,ppfd);
534 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pChoosePixelFormat );
535 ret = physdev->funcs->pChoosePixelFormat( physdev, ppfd );
536 release_dc_ptr( dc );
542 /******************************************************************************
543 * SetPixelFormat [GDI32.@]
544 * Sets pixel format of device context
547 * hdc [I] Device context to search for best pixel match
548 * iPixelFormat [I] Pixel format index
549 * ppfd [I] Pixel format for which a match is sought
555 BOOL WINAPI SetPixelFormat( HDC hdc, INT iPixelFormat,
556 const PIXELFORMATDESCRIPTOR *ppfd)
559 DC * dc = get_dc_ptr( hdc );
561 TRACE("(%p,%d,%p)\n",hdc,iPixelFormat,ppfd);
565 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSetPixelFormat );
567 bRet = physdev->funcs->pSetPixelFormat( physdev, iPixelFormat, ppfd );
568 release_dc_ptr( dc );
574 /******************************************************************************
575 * GetPixelFormat [GDI32.@]
576 * Gets index of pixel format of DC
579 * hdc [I] Device context whose pixel format index is sought
582 * Success: Currently selected pixel format
585 INT WINAPI GetPixelFormat( HDC hdc )
588 DC * dc = get_dc_ptr( hdc );
594 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetPixelFormat );
596 ret = physdev->funcs->pGetPixelFormat( physdev );
597 release_dc_ptr( dc );
603 /******************************************************************************
604 * DescribePixelFormat [GDI32.@]
605 * Gets info about pixel format from DC
608 * hdc [I] Device context
609 * iPixelFormat [I] Pixel format selector
610 * nBytes [I] Size of buffer
611 * ppfd [O] Pointer to structure to receive pixel format data
614 * Success: Maximum pixel format index of the device context
617 INT WINAPI DescribePixelFormat( HDC hdc, INT iPixelFormat, UINT nBytes,
618 LPPIXELFORMATDESCRIPTOR ppfd )
621 DC * dc = get_dc_ptr( hdc );
623 TRACE("(%p,%d,%d,%p): stub\n",hdc,iPixelFormat,nBytes,ppfd);
627 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pDescribePixelFormat );
629 ret = physdev->funcs->pDescribePixelFormat( physdev, iPixelFormat, nBytes, ppfd );
630 release_dc_ptr( dc );
636 /******************************************************************************
637 * SwapBuffers [GDI32.@]
638 * Exchanges front and back buffers of window
641 * hdc [I] Device context whose buffers get swapped
647 BOOL WINAPI SwapBuffers( HDC hdc )
650 DC * dc = get_dc_ptr( hdc );
656 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSwapBuffers );
658 bRet = physdev->funcs->pSwapBuffers( physdev );
659 release_dc_ptr( dc );
665 /***********************************************************************
668 BOOL WINAPI PaintRgn( HDC hdc, HRGN hrgn )
671 DC * dc = get_dc_ptr( hdc );
675 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPaintRgn );
677 ret = physdev->funcs->pPaintRgn( physdev, hrgn );
678 release_dc_ptr( dc );
684 /***********************************************************************
687 BOOL WINAPI FillRgn( HDC hdc, HRGN hrgn, HBRUSH hbrush )
690 DC * dc = get_dc_ptr( hdc );
694 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pFillRgn );
696 retval = physdev->funcs->pFillRgn( physdev, hrgn, hbrush );
697 release_dc_ptr( dc );
703 /***********************************************************************
706 BOOL WINAPI FrameRgn( HDC hdc, HRGN hrgn, HBRUSH hbrush,
707 INT nWidth, INT nHeight )
710 DC *dc = get_dc_ptr( hdc );
714 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pFrameRgn );
716 ret = physdev->funcs->pFrameRgn( physdev, hrgn, hbrush, nWidth, nHeight );
717 release_dc_ptr( dc );
723 /***********************************************************************
724 * InvertRgn (GDI32.@)
726 BOOL WINAPI InvertRgn( HDC hdc, HRGN hrgn )
729 DC *dc = get_dc_ptr( hdc );
733 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pInvertRgn );
735 ret = physdev->funcs->pInvertRgn( physdev, hrgn );
736 release_dc_ptr( dc );
742 /**********************************************************************
745 BOOL WINAPI Polyline( HDC hdc, const POINT* pt, INT count )
748 DC * dc = get_dc_ptr( hdc );
753 if (PATH_IsPathOpen(dc->path)) ret = PATH_Polyline(dc, pt, count);
756 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyline );
757 ret = physdev->funcs->pPolyline( physdev, pt, count );
759 release_dc_ptr( dc );
764 /**********************************************************************
765 * PolylineTo (GDI32.@)
767 BOOL WINAPI PolylineTo( HDC hdc, const POINT* pt, DWORD cCount )
769 DC * dc = get_dc_ptr( hdc );
772 if(!dc) return FALSE;
775 if(PATH_IsPathOpen(dc->path)) ret = PATH_PolylineTo(dc, pt, cCount);
778 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolylineTo );
779 ret = physdev->funcs->pPolylineTo( physdev, pt, cCount );
783 dc->CursPosX = pt[cCount-1].x;
784 dc->CursPosY = pt[cCount-1].y;
786 release_dc_ptr( dc );
791 /**********************************************************************
794 BOOL WINAPI Polygon( HDC hdc, const POINT* pt, INT count )
797 DC * dc = get_dc_ptr( hdc );
802 if (PATH_IsPathOpen(dc->path)) ret = PATH_Polygon(dc, pt, count);
805 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolygon );
806 ret = physdev->funcs->pPolygon( physdev, pt, count );
808 release_dc_ptr( dc );
814 /**********************************************************************
815 * PolyPolygon (GDI32.@)
817 BOOL WINAPI PolyPolygon( HDC hdc, const POINT* pt, const INT* counts,
821 DC * dc = get_dc_ptr( hdc );
826 if (PATH_IsPathOpen(dc->path)) ret = PATH_PolyPolygon(dc, pt, counts, polygons);
829 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyPolygon );
830 ret = physdev->funcs->pPolyPolygon( physdev, pt, counts, polygons );
832 release_dc_ptr( dc );
837 /**********************************************************************
838 * PolyPolyline (GDI32.@)
840 BOOL WINAPI PolyPolyline( HDC hdc, const POINT* pt, const DWORD* counts,
844 DC * dc = get_dc_ptr( hdc );
849 if (PATH_IsPathOpen(dc->path)) ret = PATH_PolyPolyline(dc, pt, counts, polylines);
852 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyPolyline );
853 ret = physdev->funcs->pPolyPolyline( physdev, pt, counts, polylines );
855 release_dc_ptr( dc );
860 /**********************************************************************
861 * ExtFloodFill (GDI32.@)
863 BOOL WINAPI ExtFloodFill( HDC hdc, INT x, INT y, COLORREF color,
867 DC * dc = get_dc_ptr( hdc );
871 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pExtFloodFill );
874 ret = physdev->funcs->pExtFloodFill( physdev, x, y, color, fillType );
875 release_dc_ptr( dc );
881 /**********************************************************************
882 * FloodFill (GDI32.@)
884 BOOL WINAPI FloodFill( HDC hdc, INT x, INT y, COLORREF color )
886 return ExtFloodFill( hdc, x, y, color, FLOODFILLBORDER );
890 /******************************************************************************
891 * PolyBezier [GDI32.@]
892 * Draws one or more Bezier curves
895 * hDc [I] Handle to device context
896 * lppt [I] Pointer to endpoints and control points
897 * cPoints [I] Count of endpoints and control points
903 BOOL WINAPI PolyBezier( HDC hdc, const POINT* lppt, DWORD cPoints )
908 /* cPoints must be 3 * n + 1 (where n>=1) */
909 if (cPoints == 1 || (cPoints % 3) != 1) return FALSE;
911 dc = get_dc_ptr( hdc );
912 if(!dc) return FALSE;
915 if(PATH_IsPathOpen(dc->path)) ret = PATH_PolyBezier(dc, lppt, cPoints);
918 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyBezier );
919 ret = physdev->funcs->pPolyBezier( physdev, lppt, cPoints );
921 release_dc_ptr( dc );
925 /******************************************************************************
926 * PolyBezierTo [GDI32.@]
927 * Draws one or more Bezier curves
930 * hDc [I] Handle to device context
931 * lppt [I] Pointer to endpoints and control points
932 * cPoints [I] Count of endpoints and control points
938 BOOL WINAPI PolyBezierTo( HDC hdc, const POINT* lppt, DWORD cPoints )
943 /* cbPoints must be 3 * n (where n>=1) */
944 if (!cPoints || (cPoints % 3) != 0) return FALSE;
946 dc = get_dc_ptr( hdc );
947 if(!dc) return FALSE;
950 if(PATH_IsPathOpen(dc->path)) ret = PATH_PolyBezierTo(dc, lppt, cPoints);
953 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyBezierTo );
954 ret = physdev->funcs->pPolyBezierTo( physdev, lppt, cPoints );
957 dc->CursPosX = lppt[cPoints-1].x;
958 dc->CursPosY = lppt[cPoints-1].y;
960 release_dc_ptr( dc );
964 /***********************************************************************
967 BOOL WINAPI AngleArc(HDC hdc, INT x, INT y, DWORD dwRadius, FLOAT eStartAngle, FLOAT eSweepAngle)
969 INT x1,y1,x2,y2, arcdir;
973 if( (signed int)dwRadius < 0 )
976 dc = get_dc_ptr( hdc );
977 if(!dc) return FALSE;
979 /* Calculate the end point */
980 x2 = GDI_ROUND( x + cos((eStartAngle+eSweepAngle)*M_PI/180) * dwRadius );
981 y2 = GDI_ROUND( y - sin((eStartAngle+eSweepAngle)*M_PI/180) * dwRadius );
984 if(!PATH_IsPathOpen(dc->path))
986 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pAngleArc );
987 result = physdev->funcs->pAngleArc( physdev, x, y, dwRadius, eStartAngle, eSweepAngle );
989 else { /* do it using ArcTo */
990 x1 = GDI_ROUND( x + cos(eStartAngle*M_PI/180) * dwRadius );
991 y1 = GDI_ROUND( y - sin(eStartAngle*M_PI/180) * dwRadius );
993 arcdir = SetArcDirection( hdc, eSweepAngle >= 0 ? AD_COUNTERCLOCKWISE : AD_CLOCKWISE);
994 result = ArcTo( hdc, x-dwRadius, y-dwRadius, x+dwRadius, y+dwRadius,
996 SetArcDirection( hdc, arcdir );
1002 release_dc_ptr( dc );
1006 /***********************************************************************
1007 * PolyDraw (GDI32.@)
1009 BOOL WINAPI PolyDraw(HDC hdc, const POINT *lppt, const BYTE *lpbTypes,
1012 DC *dc = get_dc_ptr( hdc );
1013 BOOL result = FALSE;
1015 if(!dc) return FALSE;
1018 if( PATH_IsPathOpen( dc->path ) ) result = PATH_PolyDraw(dc, lppt, lpbTypes, cCount);
1021 PHYSDEV physdev = GET_DC_PHYSDEV( dc, pPolyDraw );
1022 result = physdev->funcs->pPolyDraw( physdev, lppt, lpbTypes, cCount );
1024 release_dc_ptr( dc );
1029 /**********************************************************************
1032 BOOL WINAPI LineDDA(INT nXStart, INT nYStart, INT nXEnd, INT nYEnd,
1033 LINEDDAPROC callback, LPARAM lParam )
1035 INT xadd = 1, yadd = 1;
1038 INT dx = nXEnd - nXStart;
1039 INT dy = nYEnd - nYStart;
1051 if (dx > dy) /* line is "more horizontal" */
1053 err = 2*dy - dx; erradd = 2*dy - 2*dx;
1054 for(cnt = 0;cnt < dx; cnt++)
1056 callback(nXStart,nYStart,lParam);
1066 else /* line is "more vertical" */
1068 err = 2*dx - dy; erradd = 2*dx - 2*dy;
1069 for(cnt = 0;cnt < dy; cnt++)
1071 callback(nXStart,nYStart,lParam);
1085 /******************************************************************
1087 * *Very* simple bezier drawing code,
1089 * It uses a recursive algorithm to divide the curve in a series
1090 * of straight line segments. Not ideal but sufficient for me.
1091 * If you are in need for something better look for some incremental
1094 * 7 July 1998 Rein Klazes
1098 * some macro definitions for bezier drawing
1100 * to avoid truncation errors the coordinates are
1101 * shifted upwards. When used in drawing they are
1102 * shifted down again, including correct rounding
1103 * and avoiding floating point arithmetic
1104 * 4 bits should allow 27 bits coordinates which I saw
1105 * somewhere in the win32 doc's
1109 #define BEZIERSHIFTBITS 4
1110 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
1111 #define BEZIERPIXEL BEZIERSHIFTUP(1)
1112 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
1113 /* maximum depth of recursion */
1114 #define BEZIERMAXDEPTH 8
1116 /* size of array to store points on */
1117 /* enough for one curve */
1118 #define BEZIER_INITBUFSIZE (150)
1120 /* calculate Bezier average, in this case the middle
1121 * correctly rounded...
1124 #define BEZIERMIDDLE(Mid, P1, P2) \
1125 (Mid).x=((P1).x+(P2).x + 1)/2;\
1126 (Mid).y=((P1).y+(P2).y + 1)/2;
1128 /**********************************************************
1129 * BezierCheck helper function to check
1130 * that recursion can be terminated
1131 * Points[0] and Points[3] are begin and endpoint
1132 * Points[1] and Points[2] are control points
1133 * level is the recursion depth
1134 * returns true if the recursion can be terminated
1136 static BOOL BezierCheck( int level, POINT *Points)
1139 dx=Points[3].x-Points[0].x;
1140 dy=Points[3].y-Points[0].y;
1141 if(abs(dy)<=abs(dx)){/* shallow line */
1142 /* check that control points are between begin and end */
1143 if(Points[1].x < Points[0].x){
1144 if(Points[1].x < Points[3].x)
1147 if(Points[1].x > Points[3].x)
1149 if(Points[2].x < Points[0].x){
1150 if(Points[2].x < Points[3].x)
1153 if(Points[2].x > Points[3].x)
1155 dx=BEZIERSHIFTDOWN(dx);
1156 if(!dx) return TRUE;
1157 if(abs(Points[1].y-Points[0].y-(dy/dx)*
1158 BEZIERSHIFTDOWN(Points[1].x-Points[0].x)) > BEZIERPIXEL ||
1159 abs(Points[2].y-Points[0].y-(dy/dx)*
1160 BEZIERSHIFTDOWN(Points[2].x-Points[0].x)) > BEZIERPIXEL )
1164 }else{ /* steep line */
1165 /* check that control points are between begin and end */
1166 if(Points[1].y < Points[0].y){
1167 if(Points[1].y < Points[3].y)
1170 if(Points[1].y > Points[3].y)
1172 if(Points[2].y < Points[0].y){
1173 if(Points[2].y < Points[3].y)
1176 if(Points[2].y > Points[3].y)
1178 dy=BEZIERSHIFTDOWN(dy);
1179 if(!dy) return TRUE;
1180 if(abs(Points[1].x-Points[0].x-(dx/dy)*
1181 BEZIERSHIFTDOWN(Points[1].y-Points[0].y)) > BEZIERPIXEL ||
1182 abs(Points[2].x-Points[0].x-(dx/dy)*
1183 BEZIERSHIFTDOWN(Points[2].y-Points[0].y)) > BEZIERPIXEL )
1190 /* Helper for GDI_Bezier.
1191 * Just handles one Bezier, so Points should point to four POINTs
1193 static void GDI_InternalBezier( POINT *Points, POINT **PtsOut, INT *dwOut,
1194 INT *nPtsOut, INT level )
1196 if(*nPtsOut == *dwOut) {
1198 *PtsOut = HeapReAlloc( GetProcessHeap(), 0, *PtsOut,
1199 *dwOut * sizeof(POINT) );
1202 if(!level || BezierCheck(level, Points)) {
1204 (*PtsOut)[0].x = BEZIERSHIFTDOWN(Points[0].x);
1205 (*PtsOut)[0].y = BEZIERSHIFTDOWN(Points[0].y);
1208 (*PtsOut)[*nPtsOut].x = BEZIERSHIFTDOWN(Points[3].x);
1209 (*PtsOut)[*nPtsOut].y = BEZIERSHIFTDOWN(Points[3].y);
1212 POINT Points2[4]; /* for the second recursive call */
1213 Points2[3]=Points[3];
1214 BEZIERMIDDLE(Points2[2], Points[2], Points[3]);
1215 BEZIERMIDDLE(Points2[0], Points[1], Points[2]);
1216 BEZIERMIDDLE(Points2[1],Points2[0],Points2[2]);
1218 BEZIERMIDDLE(Points[1], Points[0], Points[1]);
1219 BEZIERMIDDLE(Points[2], Points[1], Points2[0]);
1220 BEZIERMIDDLE(Points[3], Points[2], Points2[1]);
1222 Points2[0]=Points[3];
1224 /* do the two halves */
1225 GDI_InternalBezier(Points, PtsOut, dwOut, nPtsOut, level-1);
1226 GDI_InternalBezier(Points2, PtsOut, dwOut, nPtsOut, level-1);
1232 /***********************************************************************
1233 * GDI_Bezier [INTERNAL]
1234 * Calculate line segments that approximate -what microsoft calls- a bezier
1236 * The routine recursively divides the curve in two parts until a straight
1241 * Points [I] Ptr to count POINTs which are the end and control points
1242 * of the set of Bezier curves to flatten.
1243 * count [I] Number of Points. Must be 3n+1.
1244 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1249 * Ptr to an array of POINTs that contain the lines that approximate the
1250 * Beziers. The array is allocated on the process heap and it is the caller's
1251 * responsibility to HeapFree it. [this is not a particularly nice interface
1252 * but since we can't know in advance how many points we will generate, the
1253 * alternative would be to call the function twice, once to determine the size
1254 * and a second time to do the work - I decided this was too much of a pain].
1256 POINT *GDI_Bezier( const POINT *Points, INT count, INT *nPtsOut )
1259 INT Bezier, dwOut = BEZIER_INITBUFSIZE, i;
1261 if (count == 1 || (count - 1) % 3 != 0) {
1262 ERR("Invalid no. of points %d\n", count);
1266 out = HeapAlloc( GetProcessHeap(), 0, dwOut * sizeof(POINT));
1267 for(Bezier = 0; Bezier < (count-1)/3; Bezier++) {
1269 memcpy(ptBuf, Points + Bezier * 3, sizeof(POINT) * 4);
1270 for(i = 0; i < 4; i++) {
1271 ptBuf[i].x = BEZIERSHIFTUP(ptBuf[i].x);
1272 ptBuf[i].y = BEZIERSHIFTUP(ptBuf[i].y);
1274 GDI_InternalBezier( ptBuf, &out, &dwOut, nPtsOut, BEZIERMAXDEPTH );
1276 TRACE("Produced %d points\n", *nPtsOut);
1280 /******************************************************************************
1281 * GdiGradientFill (GDI32.@)
1283 * FIXME: we don't support the Alpha channel properly
1285 BOOL WINAPI GdiGradientFill( HDC hdc, TRIVERTEX *vert_array, ULONG nvert,
1286 void * grad_array, ULONG ngrad, ULONG mode )
1290 TRACE("vert_array:%p nvert:%d grad_array:%p ngrad:%d\n",
1291 vert_array, nvert, grad_array, ngrad);
1295 case GRADIENT_FILL_RECT_H:
1296 for(i = 0; i < ngrad; i++)
1298 GRADIENT_RECT *rect = ((GRADIENT_RECT *)grad_array) + i;
1299 TRIVERTEX *v1 = vert_array + rect->UpperLeft;
1300 TRIVERTEX *v2 = vert_array + rect->LowerRight;
1301 int y1 = v1->y < v2->y ? v1->y : v2->y;
1302 int y2 = v2->y > v1->y ? v2->y : v1->y;
1311 for (x = 0; x < dx; x++)
1316 hPen = CreatePen( PS_SOLID, 1, RGB(
1317 (v1->Red * (dx - x) + v2->Red * x) / dx >> 8,
1318 (v1->Green * (dx - x) + v2->Green * x) / dx >> 8,
1319 (v1->Blue * (dx - x) + v2->Blue * x) / dx >> 8));
1320 hOldPen = SelectObject( hdc, hPen );
1321 pts[0].x = v1->x + x;
1323 pts[1].x = v1->x + x;
1325 Polyline( hdc, &pts[0], 2 );
1326 DeleteObject( SelectObject(hdc, hOldPen ) );
1330 case GRADIENT_FILL_RECT_V:
1331 for(i = 0; i < ngrad; i++)
1333 GRADIENT_RECT *rect = ((GRADIENT_RECT *)grad_array) + i;
1334 TRIVERTEX *v1 = vert_array + rect->UpperLeft;
1335 TRIVERTEX *v2 = vert_array + rect->LowerRight;
1336 int x1 = v1->x < v2->x ? v1->x : v2->x;
1337 int x2 = v2->x > v1->x ? v2->x : v1->x;
1346 for (y = 0; y < dy; y++)
1351 hPen = CreatePen( PS_SOLID, 1, RGB(
1352 (v1->Red * (dy - y) + v2->Red * y) / dy >> 8,
1353 (v1->Green * (dy - y) + v2->Green * y) / dy >> 8,
1354 (v1->Blue * (dy - y) + v2->Blue * y) / dy >> 8));
1355 hOldPen = SelectObject( hdc, hPen );
1357 pts[0].y = v1->y + y;
1359 pts[1].y = v1->y + y;
1360 Polyline( hdc, &pts[0], 2 );
1361 DeleteObject( SelectObject(hdc, hOldPen ) );
1365 case GRADIENT_FILL_TRIANGLE:
1366 for (i = 0; i < ngrad; i++)
1368 GRADIENT_TRIANGLE *tri = ((GRADIENT_TRIANGLE *)grad_array) + i;
1369 TRIVERTEX *v1 = vert_array + tri->Vertex1;
1370 TRIVERTEX *v2 = vert_array + tri->Vertex2;
1371 TRIVERTEX *v3 = vert_array + tri->Vertex3;
1375 { TRIVERTEX *t = v1; v1 = v2; v2 = t; }
1378 TRIVERTEX *t = v2; v2 = v3; v3 = t;
1380 { t = v1; v1 = v2; v2 = t; }
1382 /* v1->y <= v2->y <= v3->y */
1385 for (y = 0; y < dy; y++)
1387 /* v1->y <= y < v3->y */
1388 TRIVERTEX *v = y < (v2->y - v1->y) ? v1 : v3;
1389 /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */
1390 int dy2 = v2->y - v->y;
1391 int y2 = y + v1->y - v->y;
1393 int x1 = (v3->x * y + v1->x * (dy - y )) / dy;
1394 int x2 = (v2->x * y2 + v-> x * (dy2 - y2)) / dy2;
1395 int r1 = (v3->Red * y + v1->Red * (dy - y )) / dy;
1396 int r2 = (v2->Red * y2 + v-> Red * (dy2 - y2)) / dy2;
1397 int g1 = (v3->Green * y + v1->Green * (dy - y )) / dy;
1398 int g2 = (v2->Green * y2 + v-> Green * (dy2 - y2)) / dy2;
1399 int b1 = (v3->Blue * y + v1->Blue * (dy - y )) / dy;
1400 int b2 = (v2->Blue * y2 + v-> Blue * (dy2 - y2)) / dy2;
1406 for (x = 0; x < dx; x++)
1407 SetPixel (hdc, x + x1, y + v1->y, RGB(
1408 (r1 * (dx - x) + r2 * x) / dx >> 8,
1409 (g1 * (dx - x) + g2 * x) / dx >> 8,
1410 (b1 * (dx - x) + b2 * x) / dx >> 8));
1415 for (x = 0; x < dx; x++)
1416 SetPixel (hdc, x + x2, y + v1->y, RGB(
1417 (r2 * (dx - x) + r1 * x) / dx >> 8,
1418 (g2 * (dx - x) + g1 * x) / dx >> 8,
1419 (b2 * (dx - x) + b1 * x) / dx >> 8));
1431 /******************************************************************************
1432 * GdiDrawStream (GDI32.@)
1435 BOOL WINAPI GdiDrawStream( HDC hdc, ULONG in, void * pvin )
1437 FIXME("stub: %p, %d, %p\n", hdc, in, pvin);