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 TRACE( "%p, (%d, %d)\n", hdc
, x
, y
);
242 if(!dc
) return FALSE
;
245 physdev
= GET_DC_PHYSDEV( dc
, pLineTo
);
246 ret
= physdev
->funcs
->pLineTo( physdev
, x
, y
);
253 release_dc_ptr( dc
);
258 /***********************************************************************
261 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
265 DC
* dc
= get_dc_ptr( hdc
);
267 TRACE( "%p, (%d, %d), %p\n", hdc
, x
, y
, pt
);
269 if(!dc
) return FALSE
;
277 physdev
= GET_DC_PHYSDEV( dc
, pMoveTo
);
278 ret
= physdev
->funcs
->pMoveTo( physdev
, x
, y
);
279 release_dc_ptr( dc
);
284 /***********************************************************************
287 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
288 INT bottom
, INT xstart
, INT ystart
,
293 DC
* dc
= get_dc_ptr( hdc
);
295 TRACE( "%p, (%d, %d)-(%d, %d), (%d, %d), (%d, %d)\n", hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
297 if (!dc
) return FALSE
;
299 physdev
= GET_DC_PHYSDEV( dc
, pArc
);
300 ret
= physdev
->funcs
->pArc( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
301 release_dc_ptr( dc
);
305 /***********************************************************************
308 BOOL WINAPI
ArcTo( HDC hdc
,
310 INT right
, INT bottom
,
311 INT xstart
, INT ystart
,
314 double width
= abs( right
- left
),
315 height
= abs( bottom
- top
),
318 xcenter
= right
> left
? left
+xradius
: right
+xradius
,
319 ycenter
= bottom
> top
? top
+yradius
: bottom
+yradius
,
323 DC
* dc
= get_dc_ptr( hdc
);
325 TRACE( "%p, (%d, %d)-(%d, %d), (%d, %d), (%d, %d)\n", hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
327 if(!dc
) return FALSE
;
329 physdev
= GET_DC_PHYSDEV( dc
, pArcTo
);
330 result
= physdev
->funcs
->pArcTo( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
334 angle
= atan2(((yend
-ycenter
)/height
),
335 ((xend
-xcenter
)/width
));
336 dc
->cur_pos
.x
= GDI_ROUND( xcenter
+ (cos( angle
) * xradius
) );
337 dc
->cur_pos
.y
= GDI_ROUND( ycenter
+ (sin( angle
) * yradius
) );
339 release_dc_ptr( dc
);
344 /***********************************************************************
347 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
348 INT right
, INT bottom
, INT xstart
, INT ystart
,
353 DC
* dc
= get_dc_ptr( hdc
);
355 TRACE( "%p, (%d, %d)-(%d, %d), (%d, %d), (%d, %d)\n", hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
357 if (!dc
) return FALSE
;
359 physdev
= GET_DC_PHYSDEV( dc
, pPie
);
360 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
,
375 DC
* dc
= get_dc_ptr( hdc
);
377 TRACE( "%p, (%d, %d)-(%d, %d), (%d, %d), (%d, %d)\n", hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
379 if (!dc
) return FALSE
;
381 physdev
= GET_DC_PHYSDEV( dc
, pChord
);
382 ret
= physdev
->funcs
->pChord( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
383 release_dc_ptr( dc
);
388 /***********************************************************************
391 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
392 INT right
, INT bottom
)
396 DC
* dc
= get_dc_ptr( hdc
);
398 TRACE( "%p, (%d, %d)-(%d, %d)\n", hdc
, left
, top
, right
, bottom
);
400 if (!dc
) return FALSE
;
402 physdev
= GET_DC_PHYSDEV( dc
, pEllipse
);
403 ret
= physdev
->funcs
->pEllipse( physdev
, left
, top
, right
, bottom
);
404 release_dc_ptr( dc
);
409 /***********************************************************************
410 * Rectangle (GDI32.@)
412 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
413 INT right
, INT bottom
)
417 DC
* dc
= get_dc_ptr( hdc
);
419 TRACE( "%p, (%d, %d)-(%d, %d)\n", hdc
, left
, top
, right
, bottom
);
421 if (!dc
) return FALSE
;
423 physdev
= GET_DC_PHYSDEV( dc
, pRectangle
);
424 ret
= physdev
->funcs
->pRectangle( physdev
, left
, top
, right
, bottom
);
425 release_dc_ptr( dc
);
430 /***********************************************************************
431 * RoundRect (GDI32.@)
433 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
434 INT bottom
, INT ell_width
, INT ell_height
)
438 DC
*dc
= get_dc_ptr( hdc
);
440 TRACE( "%p, (%d, %d)-(%d, %d), %dx%d\n", hdc
, left
, top
, right
, bottom
, ell_width
, ell_height
);
442 if (!dc
) return FALSE
;
444 physdev
= GET_DC_PHYSDEV( dc
, pRoundRect
);
445 ret
= physdev
->funcs
->pRoundRect( physdev
, left
, top
, right
, bottom
, ell_width
, ell_height
);
446 release_dc_ptr( dc
);
450 /***********************************************************************
453 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
457 DC
* dc
= get_dc_ptr( hdc
);
461 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
462 ret
= physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
463 release_dc_ptr( dc
);
467 /***********************************************************************
468 * SetPixelV (GDI32.@)
470 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
473 DC
* dc
= get_dc_ptr( hdc
);
475 if (!dc
) return FALSE
;
477 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
478 physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
479 release_dc_ptr( dc
);
483 /***********************************************************************
486 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
490 DC
* dc
= get_dc_ptr( hdc
);
492 if (!dc
) return CLR_INVALID
;
494 physdev
= GET_DC_PHYSDEV( dc
, pGetPixel
);
495 ret
= physdev
->funcs
->pGetPixel( physdev
, x
, y
);
496 release_dc_ptr( dc
);
501 /******************************************************************************
502 * GdiSetPixelFormat [GDI32.@]
504 * Probably not the correct semantics, it's supposed to be an internal backend for SetPixelFormat.
506 BOOL WINAPI
GdiSetPixelFormat( HDC hdc
, INT format
, const PIXELFORMATDESCRIPTOR
*descr
)
511 TRACE("(%p,%d,%p)\n", hdc
, format
, descr
);
513 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
515 if (!dc
->pixel_format
) dc
->pixel_format
= format
;
516 else ret
= (dc
->pixel_format
== format
);
517 release_dc_ptr( dc
);
522 /******************************************************************************
523 * GdiDescribePixelFormat [GDI32.@]
525 * Probably not the correct semantics, it's supposed to be an internal backend for DescribePixelFormat.
527 INT WINAPI
GdiDescribePixelFormat( HDC hdc
, INT format
, UINT size
, PIXELFORMATDESCRIPTOR
*descr
)
529 FIXME( "(%p,%d,%d,%p): stub\n", hdc
, format
, size
, descr
);
534 /******************************************************************************
535 * GdiSwapBuffers [GDI32.@]
537 * Probably not the correct semantics, it's supposed to be an internal backend for SwapBuffers.
539 BOOL WINAPI
GdiSwapBuffers( HDC hdc
)
541 FIXME( "(%p): stub\n", hdc
);
546 /***********************************************************************
549 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
553 DC
* dc
= get_dc_ptr( hdc
);
555 TRACE( "%p, %p\n", hdc
, hrgn
);
557 if (!dc
) return FALSE
;
559 physdev
= GET_DC_PHYSDEV( dc
, pPaintRgn
);
560 ret
= physdev
->funcs
->pPaintRgn( physdev
, hrgn
);
561 release_dc_ptr( dc
);
566 /***********************************************************************
569 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
573 DC
* dc
= get_dc_ptr( hdc
);
575 TRACE( "%p, %p, %p\n", hdc
, hrgn
, hbrush
);
577 if (!dc
) return FALSE
;
579 physdev
= GET_DC_PHYSDEV( dc
, pFillRgn
);
580 retval
= physdev
->funcs
->pFillRgn( physdev
, hrgn
, hbrush
);
581 release_dc_ptr( dc
);
586 /***********************************************************************
589 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
590 INT nWidth
, INT nHeight
)
594 DC
*dc
= get_dc_ptr( hdc
);
596 TRACE( "%p, %p, %p, %dx%d\n", hdc
, hrgn
, hbrush
, nWidth
, nHeight
);
598 if (!dc
) return FALSE
;
600 physdev
= GET_DC_PHYSDEV( dc
, pFrameRgn
);
601 ret
= physdev
->funcs
->pFrameRgn( physdev
, hrgn
, hbrush
, nWidth
, nHeight
);
602 release_dc_ptr( dc
);
607 /***********************************************************************
608 * InvertRgn (GDI32.@)
610 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
614 DC
*dc
= get_dc_ptr( hdc
);
616 TRACE( "%p, %p\n", hdc
, hrgn
);
618 if (!dc
) return FALSE
;
620 physdev
= GET_DC_PHYSDEV( dc
, pInvertRgn
);
621 ret
= physdev
->funcs
->pInvertRgn( physdev
, hrgn
);
622 release_dc_ptr( dc
);
627 /**********************************************************************
630 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
634 DC
* dc
= get_dc_ptr( hdc
);
636 TRACE( "%p, %p, %d\n", hdc
, pt
, count
);
638 if (!dc
) return FALSE
;
640 physdev
= GET_DC_PHYSDEV( dc
, pPolyline
);
641 ret
= physdev
->funcs
->pPolyline( physdev
, pt
, count
);
642 release_dc_ptr( dc
);
646 /**********************************************************************
647 * PolylineTo (GDI32.@)
649 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
651 DC
* dc
= get_dc_ptr( hdc
);
655 TRACE( "%p, %p, %u\n", hdc
, pt
, cCount
);
657 if(!dc
) return FALSE
;
660 physdev
= GET_DC_PHYSDEV( dc
, pPolylineTo
);
661 ret
= physdev
->funcs
->pPolylineTo( physdev
, pt
, cCount
);
664 dc
->cur_pos
= pt
[cCount
- 1];
666 release_dc_ptr( dc
);
671 /**********************************************************************
674 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
678 DC
* dc
= get_dc_ptr( hdc
);
680 TRACE( "%p, %p, %d\n", hdc
, pt
, count
);
682 if (!dc
) return FALSE
;
684 physdev
= GET_DC_PHYSDEV( dc
, pPolygon
);
685 ret
= physdev
->funcs
->pPolygon( physdev
, pt
, count
);
686 release_dc_ptr( dc
);
691 /**********************************************************************
692 * PolyPolygon (GDI32.@)
694 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
699 DC
* dc
= get_dc_ptr( hdc
);
701 TRACE( "%p, %p, %p, %u\n", hdc
, pt
, counts
, polygons
);
703 if (!dc
) return FALSE
;
705 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolygon
);
706 ret
= physdev
->funcs
->pPolyPolygon( physdev
, pt
, counts
, polygons
);
707 release_dc_ptr( dc
);
711 /**********************************************************************
712 * PolyPolyline (GDI32.@)
714 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
719 DC
* dc
= get_dc_ptr( hdc
);
721 TRACE( "%p, %p, %p, %u\n", hdc
, pt
, counts
, polylines
);
723 if (!dc
) return FALSE
;
725 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolyline
);
726 ret
= physdev
->funcs
->pPolyPolyline( physdev
, pt
, counts
, polylines
);
727 release_dc_ptr( dc
);
731 /**********************************************************************
732 * ExtFloodFill (GDI32.@)
734 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
739 DC
* dc
= get_dc_ptr( hdc
);
741 TRACE( "%p, (%d, %d), %08x, %x\n", hdc
, x
, y
, color
, fillType
);
743 if (!dc
) return FALSE
;
745 physdev
= GET_DC_PHYSDEV( dc
, pExtFloodFill
);
746 ret
= physdev
->funcs
->pExtFloodFill( physdev
, x
, y
, color
, fillType
);
747 release_dc_ptr( dc
);
752 /**********************************************************************
753 * FloodFill (GDI32.@)
755 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
757 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
761 /******************************************************************************
762 * PolyBezier [GDI32.@]
763 * Draws one or more Bezier curves
766 * hDc [I] Handle to device context
767 * lppt [I] Pointer to endpoints and control points
768 * cPoints [I] Count of endpoints and control points
774 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
780 TRACE( "%p, %p, %u\n", hdc
, lppt
, cPoints
);
782 /* cPoints must be 3 * n + 1 (where n>=1) */
783 if (cPoints
== 1 || (cPoints
% 3) != 1) return FALSE
;
785 dc
= get_dc_ptr( hdc
);
786 if(!dc
) return FALSE
;
789 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezier
);
790 ret
= physdev
->funcs
->pPolyBezier( physdev
, lppt
, cPoints
);
791 release_dc_ptr( dc
);
795 /******************************************************************************
796 * PolyBezierTo [GDI32.@]
797 * Draws one or more Bezier curves
800 * hDc [I] Handle to device context
801 * lppt [I] Pointer to endpoints and control points
802 * cPoints [I] Count of endpoints and control points
808 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
814 TRACE( "%p, %p, %u\n", hdc
, lppt
, cPoints
);
816 /* cbPoints must be 3 * n (where n>=1) */
817 if (!cPoints
|| (cPoints
% 3) != 0) return FALSE
;
819 dc
= get_dc_ptr( hdc
);
820 if(!dc
) return FALSE
;
823 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezierTo
);
824 ret
= physdev
->funcs
->pPolyBezierTo( physdev
, lppt
, cPoints
);
827 dc
->cur_pos
= lppt
[cPoints
- 1];
829 release_dc_ptr( dc
);
833 /***********************************************************************
836 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
842 TRACE( "%p, (%d, %d), %u, %f, %f\n", hdc
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
844 if( (signed int)dwRadius
< 0 )
847 dc
= get_dc_ptr( hdc
);
848 if(!dc
) return FALSE
;
851 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
852 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
856 dc
->cur_pos
.x
= GDI_ROUND( x
+ cos( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
857 dc
->cur_pos
.y
= GDI_ROUND( y
- sin( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
859 release_dc_ptr( dc
);
863 /***********************************************************************
866 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
869 DC
*dc
= get_dc_ptr( hdc
);
873 TRACE( "%p, %p, %p, %u\n", hdc
, lppt
, lpbTypes
, cCount
);
875 if(!dc
) return FALSE
;
878 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
879 result
= physdev
->funcs
->pPolyDraw( physdev
, lppt
, lpbTypes
, cCount
);
880 if (result
&& cCount
)
881 dc
->cur_pos
= lppt
[cCount
- 1];
883 release_dc_ptr( dc
);
888 /**********************************************************************
891 BOOL WINAPI
LineDDA(INT nXStart
, INT nYStart
, INT nXEnd
, INT nYEnd
,
892 LINEDDAPROC callback
, LPARAM lParam
)
894 INT xadd
= 1, yadd
= 1;
897 INT dx
= nXEnd
- nXStart
;
898 INT dy
= nYEnd
- nYStart
;
900 TRACE( "(%d, %d), (%d, %d), %p, %lx\n", nXStart
, nYStart
, nXEnd
, nYEnd
, callback
, lParam
);
912 if (dx
> dy
) /* line is "more horizontal" */
914 err
= 2*dy
- dx
; erradd
= 2*dy
- 2*dx
;
915 for(cnt
= 0;cnt
< dx
; cnt
++)
917 callback(nXStart
,nYStart
,lParam
);
927 else /* line is "more vertical" */
929 err
= 2*dx
- dy
; erradd
= 2*dx
- 2*dy
;
930 for(cnt
= 0;cnt
< dy
; cnt
++)
932 callback(nXStart
,nYStart
,lParam
);
946 /******************************************************************
948 * *Very* simple bezier drawing code,
950 * It uses a recursive algorithm to divide the curve in a series
951 * of straight line segments. Not ideal but sufficient for me.
952 * If you are in need for something better look for some incremental
955 * 7 July 1998 Rein Klazes
959 * some macro definitions for bezier drawing
961 * to avoid truncation errors the coordinates are
962 * shifted upwards. When used in drawing they are
963 * shifted down again, including correct rounding
964 * and avoiding floating point arithmetic
965 * 4 bits should allow 27 bits coordinates which I saw
966 * somewhere in the win32 doc's
970 #define BEZIERSHIFTBITS 4
971 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
972 #define BEZIERPIXEL BEZIERSHIFTUP(1)
973 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
974 /* maximum depth of recursion */
975 #define BEZIERMAXDEPTH 8
977 /* size of array to store points on */
978 /* enough for one curve */
979 #define BEZIER_INITBUFSIZE (150)
981 /* calculate Bezier average, in this case the middle
982 * correctly rounded...
985 #define BEZIERMIDDLE(Mid, P1, P2) \
986 (Mid).x=((P1).x+(P2).x + 1)/2;\
987 (Mid).y=((P1).y+(P2).y + 1)/2;
989 /**********************************************************
990 * BezierCheck helper function to check
991 * that recursion can be terminated
992 * Points[0] and Points[3] are begin and endpoint
993 * Points[1] and Points[2] are control points
994 * level is the recursion depth
995 * returns true if the recursion can be terminated
997 static BOOL
BezierCheck( int level
, POINT
*Points
)
1000 dx
=Points
[3].x
-Points
[0].x
;
1001 dy
=Points
[3].y
-Points
[0].y
;
1002 if(abs(dy
)<=abs(dx
)){/* shallow line */
1003 /* check that control points are between begin and end */
1004 if(Points
[1].x
< Points
[0].x
){
1005 if(Points
[1].x
< Points
[3].x
)
1008 if(Points
[1].x
> Points
[3].x
)
1010 if(Points
[2].x
< Points
[0].x
){
1011 if(Points
[2].x
< Points
[3].x
)
1014 if(Points
[2].x
> Points
[3].x
)
1016 dx
=BEZIERSHIFTDOWN(dx
);
1017 if(!dx
) return TRUE
;
1018 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
1019 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
1020 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
1021 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
1025 }else{ /* steep line */
1026 /* check that control points are between begin and end */
1027 if(Points
[1].y
< Points
[0].y
){
1028 if(Points
[1].y
< Points
[3].y
)
1031 if(Points
[1].y
> Points
[3].y
)
1033 if(Points
[2].y
< Points
[0].y
){
1034 if(Points
[2].y
< Points
[3].y
)
1037 if(Points
[2].y
> Points
[3].y
)
1039 dy
=BEZIERSHIFTDOWN(dy
);
1040 if(!dy
) return TRUE
;
1041 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
1042 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
1043 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
1044 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1051 /* Helper for GDI_Bezier.
1052 * Just handles one Bezier, so Points should point to four POINTs
1054 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
1055 INT
*nPtsOut
, INT level
)
1057 if(*nPtsOut
== *dwOut
) {
1059 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
1060 *dwOut
* sizeof(POINT
) );
1063 if(!level
|| BezierCheck(level
, Points
)) {
1065 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1066 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1069 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1070 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1073 POINT Points2
[4]; /* for the second recursive call */
1074 Points2
[3]=Points
[3];
1075 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1076 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1077 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1079 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1080 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1081 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1083 Points2
[0]=Points
[3];
1085 /* do the two halves */
1086 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1087 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1093 /***********************************************************************
1094 * GDI_Bezier [INTERNAL]
1095 * Calculate line segments that approximate -what microsoft calls- a bezier
1097 * The routine recursively divides the curve in two parts until a straight
1102 * Points [I] Ptr to count POINTs which are the end and control points
1103 * of the set of Bezier curves to flatten.
1104 * count [I] Number of Points. Must be 3n+1.
1105 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1110 * Ptr to an array of POINTs that contain the lines that approximate the
1111 * Beziers. The array is allocated on the process heap and it is the caller's
1112 * responsibility to HeapFree it. [this is not a particularly nice interface
1113 * but since we can't know in advance how many points we will generate, the
1114 * alternative would be to call the function twice, once to determine the size
1115 * and a second time to do the work - I decided this was too much of a pain].
1117 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1120 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1122 if (count
== 1 || (count
- 1) % 3 != 0) {
1123 ERR("Invalid no. of points %d\n", count
);
1127 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1128 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1130 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1131 for(i
= 0; i
< 4; i
++) {
1132 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1133 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1135 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1137 TRACE("Produced %d points\n", *nPtsOut
);
1141 /******************************************************************************
1142 * GdiGradientFill (GDI32.@)
1144 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1145 void *grad_array
, ULONG ngrad
, ULONG mode
)
1152 TRACE("%p vert_array:%p nvert:%d grad_array:%p ngrad:%d\n", hdc
, vert_array
, nvert
, grad_array
, ngrad
);
1154 if (!vert_array
|| !nvert
|| !grad_array
|| !ngrad
|| mode
> GRADIENT_FILL_TRIANGLE
)
1156 SetLastError( ERROR_INVALID_PARAMETER
);
1159 for (i
= 0; i
< ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2); i
++)
1160 if (((ULONG
*)grad_array
)[i
] >= nvert
) return FALSE
;
1162 if (!(dc
= get_dc_ptr( hdc
)))
1164 SetLastError( ERROR_INVALID_PARAMETER
);
1168 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
1169 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
1170 release_dc_ptr( dc
);
1174 /******************************************************************************
1175 * GdiDrawStream (GDI32.@)
1178 BOOL WINAPI
GdiDrawStream( HDC hdc
, ULONG in
, void * pvin
)
1180 FIXME("stub: %p, %d, %p\n", hdc
, in
, pvin
);