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
)
127 DC
*dc
= get_nulldrv_dc( dev
);
129 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (count
+ 1) );
133 pts
[0] = dc
->cur_pos
;
134 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
135 ret
= PolyBezier( dev
->hdc
, pts
, count
+ 1 );
136 HeapFree( GetProcessHeap(), 0, pts
);
141 BOOL
nulldrv_PolyDraw( PHYSDEV dev
, const POINT
*points
, const BYTE
*types
, DWORD count
)
143 DC
*dc
= get_nulldrv_dc( dev
);
144 POINT
*line_pts
= NULL
, *bzr_pts
= NULL
, bzr
[4];
146 INT num_pts
, num_bzr_pts
, space
, size
;
148 /* check for valid point types */
149 for (i
= 0; i
< count
; i
++)
154 case PT_LINETO
| PT_CLOSEFIGURE
:
158 if (i
+ 2 >= count
) return FALSE
;
159 if (types
[i
+ 1] != PT_BEZIERTO
) return FALSE
;
160 if ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) return FALSE
;
169 line_pts
= HeapAlloc( GetProcessHeap(), 0, space
* sizeof(POINT
) );
172 line_pts
[0] = dc
->cur_pos
;
173 for (i
= 0; i
< count
; i
++)
178 if (num_pts
>= 2) Polyline( dev
->hdc
, line_pts
, num_pts
);
180 line_pts
[num_pts
++] = points
[i
];
183 case (PT_LINETO
| PT_CLOSEFIGURE
):
184 line_pts
[num_pts
++] = points
[i
];
187 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
188 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
189 memcpy( &bzr
[1], &points
[i
], 3 * sizeof(POINT
) );
191 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
193 size
= num_pts
+ (count
- i
) + num_bzr_pts
;
197 line_pts
= HeapReAlloc( GetProcessHeap(), 0, line_pts
, space
* sizeof(POINT
) );
199 memcpy( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
200 num_pts
+= num_bzr_pts
- 1;
201 HeapFree( GetProcessHeap(), 0, bzr_pts
);
206 if (types
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
209 if (num_pts
>= 2) Polyline( dev
->hdc
, line_pts
, num_pts
);
210 HeapFree( GetProcessHeap(), 0, line_pts
);
214 BOOL
nulldrv_PolylineTo( PHYSDEV dev
, const POINT
*points
, INT count
)
216 DC
*dc
= get_nulldrv_dc( dev
);
220 if (!count
) return FALSE
;
221 if ((pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (count
+ 1) )))
223 pts
[0] = dc
->cur_pos
;
224 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
225 ret
= Polyline( dev
->hdc
, pts
, count
+ 1 );
226 HeapFree( GetProcessHeap(), 0, pts
);
231 /***********************************************************************
234 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
236 DC
* dc
= get_dc_ptr( hdc
);
240 if(!dc
) return FALSE
;
243 physdev
= GET_DC_PHYSDEV( dc
, pLineTo
);
244 ret
= physdev
->funcs
->pLineTo( physdev
, x
, y
);
251 release_dc_ptr( dc
);
256 /***********************************************************************
259 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
263 DC
* dc
= get_dc_ptr( hdc
);
265 if(!dc
) return FALSE
;
273 physdev
= GET_DC_PHYSDEV( dc
, pMoveTo
);
274 ret
= physdev
->funcs
->pMoveTo( physdev
, x
, y
);
275 release_dc_ptr( dc
);
280 /***********************************************************************
283 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
284 INT bottom
, INT xstart
, INT ystart
,
289 DC
* dc
= get_dc_ptr( hdc
);
291 if (!dc
) return FALSE
;
293 physdev
= GET_DC_PHYSDEV( dc
, pArc
);
294 ret
= physdev
->funcs
->pArc( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
295 release_dc_ptr( dc
);
299 /***********************************************************************
302 BOOL WINAPI
ArcTo( HDC hdc
,
304 INT right
, INT bottom
,
305 INT xstart
, INT ystart
,
308 double width
= abs( right
- left
),
309 height
= abs( bottom
- top
),
312 xcenter
= right
> left
? left
+xradius
: right
+xradius
,
313 ycenter
= bottom
> top
? top
+yradius
: bottom
+yradius
,
317 DC
* dc
= get_dc_ptr( hdc
);
318 if(!dc
) return FALSE
;
321 physdev
= GET_DC_PHYSDEV( dc
, pArcTo
);
322 result
= physdev
->funcs
->pArcTo( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
326 angle
= atan2(((yend
-ycenter
)/height
),
327 ((xend
-xcenter
)/width
));
328 dc
->cur_pos
.x
= GDI_ROUND( xcenter
+ (cos( angle
) * xradius
) );
329 dc
->cur_pos
.y
= GDI_ROUND( ycenter
+ (sin( angle
) * yradius
) );
331 release_dc_ptr( dc
);
336 /***********************************************************************
339 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
340 INT right
, INT bottom
, INT xstart
, INT ystart
,
345 DC
* dc
= get_dc_ptr( hdc
);
346 if (!dc
) return FALSE
;
349 physdev
= GET_DC_PHYSDEV( dc
, pPie
);
350 ret
= physdev
->funcs
->pPie( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
351 release_dc_ptr( dc
);
356 /***********************************************************************
359 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
360 INT right
, INT bottom
, INT xstart
, INT ystart
,
365 DC
* dc
= get_dc_ptr( hdc
);
366 if (!dc
) return FALSE
;
369 physdev
= GET_DC_PHYSDEV( dc
, pChord
);
370 ret
= physdev
->funcs
->pChord( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
371 release_dc_ptr( dc
);
376 /***********************************************************************
379 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
380 INT right
, INT bottom
)
384 DC
* dc
= get_dc_ptr( hdc
);
385 if (!dc
) return FALSE
;
388 physdev
= GET_DC_PHYSDEV( dc
, pEllipse
);
389 ret
= physdev
->funcs
->pEllipse( physdev
, left
, top
, right
, bottom
);
390 release_dc_ptr( dc
);
395 /***********************************************************************
396 * Rectangle (GDI32.@)
398 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
399 INT right
, INT bottom
)
403 DC
* dc
= get_dc_ptr( hdc
);
405 if (!dc
) return FALSE
;
407 physdev
= GET_DC_PHYSDEV( dc
, pRectangle
);
408 ret
= physdev
->funcs
->pRectangle( physdev
, left
, top
, right
, bottom
);
409 release_dc_ptr( dc
);
414 /***********************************************************************
415 * RoundRect (GDI32.@)
417 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
418 INT bottom
, INT ell_width
, INT ell_height
)
422 DC
*dc
= get_dc_ptr( hdc
);
424 if (!dc
) return FALSE
;
426 physdev
= GET_DC_PHYSDEV( dc
, pRoundRect
);
427 ret
= physdev
->funcs
->pRoundRect( physdev
, left
, top
, right
, bottom
, ell_width
, ell_height
);
428 release_dc_ptr( dc
);
432 /***********************************************************************
435 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
439 DC
* dc
= get_dc_ptr( hdc
);
443 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
444 ret
= physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
445 release_dc_ptr( dc
);
449 /***********************************************************************
450 * SetPixelV (GDI32.@)
452 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
455 DC
* dc
= get_dc_ptr( hdc
);
457 if (!dc
) return FALSE
;
459 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
460 physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
461 release_dc_ptr( dc
);
465 /***********************************************************************
468 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
472 DC
* dc
= get_dc_ptr( hdc
);
474 if (!dc
) return CLR_INVALID
;
476 physdev
= GET_DC_PHYSDEV( dc
, pGetPixel
);
477 ret
= physdev
->funcs
->pGetPixel( physdev
, x
, y
);
478 release_dc_ptr( dc
);
483 /******************************************************************************
484 * GdiSetPixelFormat [GDI32.@]
486 * Probably not the correct semantics, it's supposed to be an internal backend for SetPixelFormat.
488 BOOL WINAPI
GdiSetPixelFormat( HDC hdc
, INT format
, const PIXELFORMATDESCRIPTOR
*descr
)
493 TRACE("(%p,%d,%p)\n", hdc
, format
, descr
);
495 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
497 if (!dc
->pixel_format
) dc
->pixel_format
= format
;
498 else ret
= (dc
->pixel_format
== format
);
499 release_dc_ptr( dc
);
504 /******************************************************************************
505 * GdiDescribePixelFormat [GDI32.@]
507 * Probably not the correct semantics, it's supposed to be an internal backend for DescribePixelFormat.
509 INT WINAPI
GdiDescribePixelFormat( HDC hdc
, INT format
, UINT size
, PIXELFORMATDESCRIPTOR
*descr
)
511 FIXME( "(%p,%d,%d,%p): stub\n", hdc
, format
, size
, descr
);
516 /******************************************************************************
517 * GdiSwapBuffers [GDI32.@]
519 * Probably not the correct semantics, it's supposed to be an internal backend for SwapBuffers.
521 BOOL WINAPI
GdiSwapBuffers( HDC hdc
)
523 FIXME( "(%p): stub\n", hdc
);
528 /***********************************************************************
531 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
535 DC
* dc
= get_dc_ptr( hdc
);
537 if (!dc
) return FALSE
;
539 physdev
= GET_DC_PHYSDEV( dc
, pPaintRgn
);
540 ret
= physdev
->funcs
->pPaintRgn( physdev
, hrgn
);
541 release_dc_ptr( dc
);
546 /***********************************************************************
549 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
553 DC
* dc
= get_dc_ptr( hdc
);
555 if (!dc
) return FALSE
;
557 physdev
= GET_DC_PHYSDEV( dc
, pFillRgn
);
558 retval
= physdev
->funcs
->pFillRgn( physdev
, hrgn
, hbrush
);
559 release_dc_ptr( dc
);
564 /***********************************************************************
567 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
568 INT nWidth
, INT nHeight
)
572 DC
*dc
= get_dc_ptr( hdc
);
574 if (!dc
) return FALSE
;
576 physdev
= GET_DC_PHYSDEV( dc
, pFrameRgn
);
577 ret
= physdev
->funcs
->pFrameRgn( physdev
, hrgn
, hbrush
, nWidth
, nHeight
);
578 release_dc_ptr( dc
);
583 /***********************************************************************
584 * InvertRgn (GDI32.@)
586 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
590 DC
*dc
= get_dc_ptr( hdc
);
592 if (!dc
) return FALSE
;
594 physdev
= GET_DC_PHYSDEV( dc
, pInvertRgn
);
595 ret
= physdev
->funcs
->pInvertRgn( physdev
, hrgn
);
596 release_dc_ptr( dc
);
601 /**********************************************************************
604 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
608 DC
* dc
= get_dc_ptr( hdc
);
610 if (!dc
) return FALSE
;
612 physdev
= GET_DC_PHYSDEV( dc
, pPolyline
);
613 ret
= physdev
->funcs
->pPolyline( physdev
, pt
, count
);
614 release_dc_ptr( dc
);
618 /**********************************************************************
619 * PolylineTo (GDI32.@)
621 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
623 DC
* dc
= get_dc_ptr( hdc
);
627 if(!dc
) return FALSE
;
630 physdev
= GET_DC_PHYSDEV( dc
, pPolylineTo
);
631 ret
= physdev
->funcs
->pPolylineTo( physdev
, pt
, cCount
);
634 dc
->cur_pos
= pt
[cCount
- 1];
636 release_dc_ptr( dc
);
641 /**********************************************************************
644 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
648 DC
* dc
= get_dc_ptr( hdc
);
650 if (!dc
) return FALSE
;
652 physdev
= GET_DC_PHYSDEV( dc
, pPolygon
);
653 ret
= physdev
->funcs
->pPolygon( physdev
, pt
, count
);
654 release_dc_ptr( dc
);
659 /**********************************************************************
660 * PolyPolygon (GDI32.@)
662 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
667 DC
* dc
= get_dc_ptr( hdc
);
669 if (!dc
) return FALSE
;
671 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolygon
);
672 ret
= physdev
->funcs
->pPolyPolygon( physdev
, pt
, counts
, polygons
);
673 release_dc_ptr( dc
);
677 /**********************************************************************
678 * PolyPolyline (GDI32.@)
680 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
685 DC
* dc
= get_dc_ptr( hdc
);
687 if (!dc
) return FALSE
;
689 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolyline
);
690 ret
= physdev
->funcs
->pPolyPolyline( physdev
, pt
, counts
, polylines
);
691 release_dc_ptr( dc
);
695 /**********************************************************************
696 * ExtFloodFill (GDI32.@)
698 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
703 DC
* dc
= get_dc_ptr( hdc
);
705 if (!dc
) return FALSE
;
707 physdev
= GET_DC_PHYSDEV( dc
, pExtFloodFill
);
708 ret
= physdev
->funcs
->pExtFloodFill( physdev
, x
, y
, color
, fillType
);
709 release_dc_ptr( dc
);
714 /**********************************************************************
715 * FloodFill (GDI32.@)
717 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
719 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
723 /******************************************************************************
724 * PolyBezier [GDI32.@]
725 * Draws one or more Bezier curves
728 * hDc [I] Handle to device context
729 * lppt [I] Pointer to endpoints and control points
730 * cPoints [I] Count of endpoints and control points
736 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
742 /* cPoints must be 3 * n + 1 (where n>=1) */
743 if (cPoints
== 1 || (cPoints
% 3) != 1) return FALSE
;
745 dc
= get_dc_ptr( hdc
);
746 if(!dc
) return FALSE
;
749 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezier
);
750 ret
= physdev
->funcs
->pPolyBezier( physdev
, lppt
, cPoints
);
751 release_dc_ptr( dc
);
755 /******************************************************************************
756 * PolyBezierTo [GDI32.@]
757 * Draws one or more Bezier curves
760 * hDc [I] Handle to device context
761 * lppt [I] Pointer to endpoints and control points
762 * cPoints [I] Count of endpoints and control points
768 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
774 /* cbPoints must be 3 * n (where n>=1) */
775 if (!cPoints
|| (cPoints
% 3) != 0) return FALSE
;
777 dc
= get_dc_ptr( hdc
);
778 if(!dc
) return FALSE
;
781 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezierTo
);
782 ret
= physdev
->funcs
->pPolyBezierTo( physdev
, lppt
, cPoints
);
785 dc
->cur_pos
= lppt
[cPoints
- 1];
787 release_dc_ptr( dc
);
791 /***********************************************************************
794 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
800 if( (signed int)dwRadius
< 0 )
803 dc
= get_dc_ptr( hdc
);
804 if(!dc
) return FALSE
;
807 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
808 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
812 dc
->cur_pos
.x
= GDI_ROUND( x
+ cos( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
813 dc
->cur_pos
.y
= GDI_ROUND( y
- sin( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
815 release_dc_ptr( dc
);
819 /***********************************************************************
822 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
825 DC
*dc
= get_dc_ptr( hdc
);
829 if(!dc
) return FALSE
;
832 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
833 result
= physdev
->funcs
->pPolyDraw( physdev
, lppt
, lpbTypes
, cCount
);
834 if (result
&& cCount
)
835 dc
->cur_pos
= lppt
[cCount
- 1];
837 release_dc_ptr( dc
);
842 /**********************************************************************
845 BOOL WINAPI
LineDDA(INT nXStart
, INT nYStart
, INT nXEnd
, INT nYEnd
,
846 LINEDDAPROC callback
, LPARAM lParam
)
848 INT xadd
= 1, yadd
= 1;
851 INT dx
= nXEnd
- nXStart
;
852 INT dy
= nYEnd
- nYStart
;
864 if (dx
> dy
) /* line is "more horizontal" */
866 err
= 2*dy
- dx
; erradd
= 2*dy
- 2*dx
;
867 for(cnt
= 0;cnt
< dx
; cnt
++)
869 callback(nXStart
,nYStart
,lParam
);
879 else /* line is "more vertical" */
881 err
= 2*dx
- dy
; erradd
= 2*dx
- 2*dy
;
882 for(cnt
= 0;cnt
< dy
; cnt
++)
884 callback(nXStart
,nYStart
,lParam
);
898 /******************************************************************
900 * *Very* simple bezier drawing code,
902 * It uses a recursive algorithm to divide the curve in a series
903 * of straight line segments. Not ideal but sufficient for me.
904 * If you are in need for something better look for some incremental
907 * 7 July 1998 Rein Klazes
911 * some macro definitions for bezier drawing
913 * to avoid truncation errors the coordinates are
914 * shifted upwards. When used in drawing they are
915 * shifted down again, including correct rounding
916 * and avoiding floating point arithmetic
917 * 4 bits should allow 27 bits coordinates which I saw
918 * somewhere in the win32 doc's
922 #define BEZIERSHIFTBITS 4
923 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
924 #define BEZIERPIXEL BEZIERSHIFTUP(1)
925 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
926 /* maximum depth of recursion */
927 #define BEZIERMAXDEPTH 8
929 /* size of array to store points on */
930 /* enough for one curve */
931 #define BEZIER_INITBUFSIZE (150)
933 /* calculate Bezier average, in this case the middle
934 * correctly rounded...
937 #define BEZIERMIDDLE(Mid, P1, P2) \
938 (Mid).x=((P1).x+(P2).x + 1)/2;\
939 (Mid).y=((P1).y+(P2).y + 1)/2;
941 /**********************************************************
942 * BezierCheck helper function to check
943 * that recursion can be terminated
944 * Points[0] and Points[3] are begin and endpoint
945 * Points[1] and Points[2] are control points
946 * level is the recursion depth
947 * returns true if the recursion can be terminated
949 static BOOL
BezierCheck( int level
, POINT
*Points
)
952 dx
=Points
[3].x
-Points
[0].x
;
953 dy
=Points
[3].y
-Points
[0].y
;
954 if(abs(dy
)<=abs(dx
)){/* shallow line */
955 /* check that control points are between begin and end */
956 if(Points
[1].x
< Points
[0].x
){
957 if(Points
[1].x
< Points
[3].x
)
960 if(Points
[1].x
> Points
[3].x
)
962 if(Points
[2].x
< Points
[0].x
){
963 if(Points
[2].x
< Points
[3].x
)
966 if(Points
[2].x
> Points
[3].x
)
968 dx
=BEZIERSHIFTDOWN(dx
);
970 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
971 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
972 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
973 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
977 }else{ /* steep line */
978 /* check that control points are between begin and end */
979 if(Points
[1].y
< Points
[0].y
){
980 if(Points
[1].y
< Points
[3].y
)
983 if(Points
[1].y
> Points
[3].y
)
985 if(Points
[2].y
< Points
[0].y
){
986 if(Points
[2].y
< Points
[3].y
)
989 if(Points
[2].y
> Points
[3].y
)
991 dy
=BEZIERSHIFTDOWN(dy
);
993 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
994 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
995 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
996 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1003 /* Helper for GDI_Bezier.
1004 * Just handles one Bezier, so Points should point to four POINTs
1006 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
1007 INT
*nPtsOut
, INT level
)
1009 if(*nPtsOut
== *dwOut
) {
1011 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
1012 *dwOut
* sizeof(POINT
) );
1015 if(!level
|| BezierCheck(level
, Points
)) {
1017 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1018 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1021 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1022 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1025 POINT Points2
[4]; /* for the second recursive call */
1026 Points2
[3]=Points
[3];
1027 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1028 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1029 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1031 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1032 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1033 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1035 Points2
[0]=Points
[3];
1037 /* do the two halves */
1038 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1039 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1045 /***********************************************************************
1046 * GDI_Bezier [INTERNAL]
1047 * Calculate line segments that approximate -what microsoft calls- a bezier
1049 * The routine recursively divides the curve in two parts until a straight
1054 * Points [I] Ptr to count POINTs which are the end and control points
1055 * of the set of Bezier curves to flatten.
1056 * count [I] Number of Points. Must be 3n+1.
1057 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1062 * Ptr to an array of POINTs that contain the lines that approximate the
1063 * Beziers. The array is allocated on the process heap and it is the caller's
1064 * responsibility to HeapFree it. [this is not a particularly nice interface
1065 * but since we can't know in advance how many points we will generate, the
1066 * alternative would be to call the function twice, once to determine the size
1067 * and a second time to do the work - I decided this was too much of a pain].
1069 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1072 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1074 if (count
== 1 || (count
- 1) % 3 != 0) {
1075 ERR("Invalid no. of points %d\n", count
);
1079 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1080 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1082 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1083 for(i
= 0; i
< 4; i
++) {
1084 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1085 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1087 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1089 TRACE("Produced %d points\n", *nPtsOut
);
1093 /******************************************************************************
1094 * GdiGradientFill (GDI32.@)
1096 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1097 void *grad_array
, ULONG ngrad
, ULONG mode
)
1104 TRACE("%p vert_array:%p nvert:%d grad_array:%p ngrad:%d\n", hdc
, vert_array
, nvert
, grad_array
, ngrad
);
1106 if (!vert_array
|| !nvert
|| !grad_array
|| !ngrad
|| mode
> GRADIENT_FILL_TRIANGLE
)
1108 SetLastError( ERROR_INVALID_PARAMETER
);
1111 for (i
= 0; i
< ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2); i
++)
1112 if (((ULONG
*)grad_array
)[i
] >= nvert
) return FALSE
;
1114 if (!(dc
= get_dc_ptr( hdc
)))
1116 SetLastError( ERROR_INVALID_PARAMETER
);
1120 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
1121 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
1122 release_dc_ptr( dc
);
1126 /******************************************************************************
1127 * GdiDrawStream (GDI32.@)
1130 BOOL WINAPI
GdiDrawStream( HDC hdc
, ULONG in
, void * pvin
)
1132 FIXME("stub: %p, %d, %p\n", hdc
, in
, pvin
);