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 BOOL
nulldrv_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
230 void * grad_array
, ULONG ngrad
, ULONG mode
)
236 case GRADIENT_FILL_RECT_H
:
237 for(i
= 0; i
< ngrad
; i
++)
239 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
240 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
241 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
242 int y1
= v1
->y
< v2
->y
? v1
->y
: v2
->y
;
243 int y2
= v2
->y
> v1
->y
? v2
->y
: v1
->y
;
252 for (x
= 0; x
< dx
; x
++)
257 hPen
= CreatePen( PS_SOLID
, 1, RGB(
258 (v1
->Red
* (dx
- x
) + v2
->Red
* x
) / dx
>> 8,
259 (v1
->Green
* (dx
- x
) + v2
->Green
* x
) / dx
>> 8,
260 (v1
->Blue
* (dx
- x
) + v2
->Blue
* x
) / dx
>> 8));
261 hOldPen
= SelectObject( dev
->hdc
, hPen
);
262 pts
[0].x
= v1
->x
+ x
;
264 pts
[1].x
= v1
->x
+ x
;
266 Polyline( dev
->hdc
, &pts
[0], 2 );
267 DeleteObject( SelectObject(dev
->hdc
, hOldPen
) );
271 case GRADIENT_FILL_RECT_V
:
272 for(i
= 0; i
< ngrad
; i
++)
274 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
275 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
276 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
277 int x1
= v1
->x
< v2
->x
? v1
->x
: v2
->x
;
278 int x2
= v2
->x
> v1
->x
? v2
->x
: v1
->x
;
287 for (y
= 0; y
< dy
; y
++)
292 hPen
= CreatePen( PS_SOLID
, 1, RGB(
293 (v1
->Red
* (dy
- y
) + v2
->Red
* y
) / dy
>> 8,
294 (v1
->Green
* (dy
- y
) + v2
->Green
* y
) / dy
>> 8,
295 (v1
->Blue
* (dy
- y
) + v2
->Blue
* y
) / dy
>> 8));
296 hOldPen
= SelectObject( dev
->hdc
, hPen
);
298 pts
[0].y
= v1
->y
+ y
;
300 pts
[1].y
= v1
->y
+ y
;
301 Polyline( dev
->hdc
, &pts
[0], 2 );
302 DeleteObject( SelectObject(dev
->hdc
, hOldPen
) );
306 case GRADIENT_FILL_TRIANGLE
:
307 for (i
= 0; i
< ngrad
; i
++)
309 GRADIENT_TRIANGLE
*tri
= ((GRADIENT_TRIANGLE
*)grad_array
) + i
;
310 TRIVERTEX
*v1
= vert_array
+ tri
->Vertex1
;
311 TRIVERTEX
*v2
= vert_array
+ tri
->Vertex2
;
312 TRIVERTEX
*v3
= vert_array
+ tri
->Vertex3
;
316 { TRIVERTEX
*t
= v1
; v1
= v2
; v2
= t
; }
319 TRIVERTEX
*t
= v2
; v2
= v3
; v3
= t
;
321 { t
= v1
; v1
= v2
; v2
= t
; }
323 /* v1->y <= v2->y <= v3->y */
326 for (y
= 0; y
< dy
; y
++)
328 /* v1->y <= y < v3->y */
329 TRIVERTEX
*v
= y
< (v2
->y
- v1
->y
) ? v1
: v3
;
330 /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */
331 int dy2
= v2
->y
- v
->y
;
332 int y2
= y
+ v1
->y
- v
->y
;
334 int x1
= (v3
->x
* y
+ v1
->x
* (dy
- y
)) / dy
;
335 int x2
= (v2
->x
* y2
+ v
-> x
* (dy2
- y2
)) / dy2
;
336 int r1
= (v3
->Red
* y
+ v1
->Red
* (dy
- y
)) / dy
;
337 int r2
= (v2
->Red
* y2
+ v
-> Red
* (dy2
- y2
)) / dy2
;
338 int g1
= (v3
->Green
* y
+ v1
->Green
* (dy
- y
)) / dy
;
339 int g2
= (v2
->Green
* y2
+ v
-> Green
* (dy2
- y2
)) / dy2
;
340 int b1
= (v3
->Blue
* y
+ v1
->Blue
* (dy
- y
)) / dy
;
341 int b2
= (v2
->Blue
* y2
+ v
-> Blue
* (dy2
- y2
)) / dy2
;
347 for (x
= 0; x
< dx
; x
++)
348 SetPixel (dev
->hdc
, x
+ x1
, y
+ v1
->y
, RGB(
349 (r1
* (dx
- x
) + r2
* x
) / dx
>> 8,
350 (g1
* (dx
- x
) + g2
* x
) / dx
>> 8,
351 (b1
* (dx
- x
) + b2
* x
) / dx
>> 8));
356 for (x
= 0; x
< dx
; x
++)
357 SetPixel (dev
->hdc
, x
+ x2
, y
+ v1
->y
, RGB(
358 (r2
* (dx
- x
) + r1
* x
) / dx
>> 8,
359 (g2
* (dx
- x
) + g1
* x
) / dx
>> 8,
360 (b2
* (dx
- x
) + b1
* x
) / dx
>> 8));
372 /***********************************************************************
375 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
377 DC
* dc
= get_dc_ptr( hdc
);
381 if(!dc
) return FALSE
;
384 physdev
= GET_DC_PHYSDEV( dc
, pLineTo
);
385 ret
= physdev
->funcs
->pLineTo( physdev
, x
, y
);
391 release_dc_ptr( dc
);
396 /***********************************************************************
399 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
403 DC
* dc
= get_dc_ptr( hdc
);
405 if(!dc
) return FALSE
;
408 pt
->x
= dc
->CursPosX
;
409 pt
->y
= dc
->CursPosY
;
414 physdev
= GET_DC_PHYSDEV( dc
, pMoveTo
);
415 ret
= physdev
->funcs
->pMoveTo( physdev
, x
, y
);
416 release_dc_ptr( dc
);
421 /***********************************************************************
424 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
425 INT bottom
, INT xstart
, INT ystart
,
429 DC
* dc
= get_dc_ptr( hdc
);
433 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pArc
);
435 ret
= physdev
->funcs
->pArc( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
436 release_dc_ptr( dc
);
441 /***********************************************************************
444 BOOL WINAPI
ArcTo( HDC hdc
,
446 INT right
, INT bottom
,
447 INT xstart
, INT ystart
,
450 double width
= fabs(right
-left
),
451 height
= fabs(bottom
-top
),
454 xcenter
= right
> left
? left
+xradius
: right
+xradius
,
455 ycenter
= bottom
> top
? top
+yradius
: bottom
+yradius
,
459 DC
* dc
= get_dc_ptr( hdc
);
460 if(!dc
) return FALSE
;
463 physdev
= GET_DC_PHYSDEV( dc
, pArcTo
);
464 result
= physdev
->funcs
->pArcTo( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
467 angle
= atan2(((yend
-ycenter
)/height
),
468 ((xend
-xcenter
)/width
));
469 dc
->CursPosX
= GDI_ROUND(xcenter
+(cos(angle
)*xradius
));
470 dc
->CursPosY
= GDI_ROUND(ycenter
+(sin(angle
)*yradius
));
472 release_dc_ptr( dc
);
477 /***********************************************************************
480 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
481 INT right
, INT bottom
, INT xstart
, INT ystart
,
486 DC
* dc
= get_dc_ptr( hdc
);
487 if (!dc
) return FALSE
;
490 physdev
= GET_DC_PHYSDEV( dc
, pPie
);
491 ret
= physdev
->funcs
->pPie( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
492 release_dc_ptr( dc
);
497 /***********************************************************************
500 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
501 INT right
, INT bottom
, INT xstart
, INT ystart
,
506 DC
* dc
= get_dc_ptr( hdc
);
507 if (!dc
) return FALSE
;
510 physdev
= GET_DC_PHYSDEV( dc
, pChord
);
511 ret
= physdev
->funcs
->pChord( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
512 release_dc_ptr( dc
);
517 /***********************************************************************
520 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
521 INT right
, INT bottom
)
525 DC
* dc
= get_dc_ptr( hdc
);
526 if (!dc
) return FALSE
;
529 physdev
= GET_DC_PHYSDEV( dc
, pEllipse
);
530 ret
= physdev
->funcs
->pEllipse( physdev
, left
, top
, right
, bottom
);
531 release_dc_ptr( dc
);
536 /***********************************************************************
537 * Rectangle (GDI32.@)
539 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
540 INT right
, INT bottom
)
543 DC
* dc
= get_dc_ptr( hdc
);
547 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRectangle
);
549 ret
= physdev
->funcs
->pRectangle( physdev
, left
, top
, right
, bottom
);
550 release_dc_ptr( dc
);
556 /***********************************************************************
557 * RoundRect (GDI32.@)
559 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
560 INT bottom
, INT ell_width
, INT ell_height
)
563 DC
*dc
= get_dc_ptr( hdc
);
567 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRoundRect
);
569 ret
= physdev
->funcs
->pRoundRect( physdev
, left
, top
, right
, bottom
, ell_width
, ell_height
);
570 release_dc_ptr( dc
);
575 /***********************************************************************
578 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
581 DC
* dc
= get_dc_ptr( hdc
);
585 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
587 ret
= physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
588 release_dc_ptr( dc
);
593 /***********************************************************************
594 * SetPixelV (GDI32.@)
596 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
599 DC
* dc
= get_dc_ptr( hdc
);
603 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
605 physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
607 release_dc_ptr( dc
);
612 /***********************************************************************
615 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
617 COLORREF ret
= CLR_INVALID
;
618 DC
* dc
= get_dc_ptr( hdc
);
623 /* FIXME: should this be in the graphics driver? */
624 if (PtVisible( hdc
, x
, y
))
626 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetPixel
);
627 ret
= physdev
->funcs
->pGetPixel( physdev
, x
, y
);
629 release_dc_ptr( dc
);
635 /******************************************************************************
636 * ChoosePixelFormat [GDI32.@]
637 * Matches a pixel format to given format
640 * hdc [I] Device context to search for best pixel match
641 * ppfd [I] Pixel format for which a match is sought
644 * Success: Pixel format index closest to given format
647 INT WINAPI
ChoosePixelFormat( HDC hdc
, const PIXELFORMATDESCRIPTOR
* ppfd
)
650 DC
* dc
= get_dc_ptr( hdc
);
652 TRACE("(%p,%p)\n",hdc
,ppfd
);
656 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pChoosePixelFormat
);
657 ret
= physdev
->funcs
->pChoosePixelFormat( physdev
, ppfd
);
658 release_dc_ptr( dc
);
664 /******************************************************************************
665 * SetPixelFormat [GDI32.@]
666 * Sets pixel format of device context
669 * hdc [I] Device context to search for best pixel match
670 * iPixelFormat [I] Pixel format index
671 * ppfd [I] Pixel format for which a match is sought
677 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT iPixelFormat
,
678 const PIXELFORMATDESCRIPTOR
*ppfd
)
681 DC
* dc
= get_dc_ptr( hdc
);
683 TRACE("(%p,%d,%p)\n",hdc
,iPixelFormat
,ppfd
);
687 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPixelFormat
);
689 bRet
= physdev
->funcs
->pSetPixelFormat( physdev
, iPixelFormat
, ppfd
);
690 release_dc_ptr( dc
);
696 /******************************************************************************
697 * GetPixelFormat [GDI32.@]
698 * Gets index of pixel format of DC
701 * hdc [I] Device context whose pixel format index is sought
704 * Success: Currently selected pixel format
707 INT WINAPI
GetPixelFormat( HDC hdc
)
710 DC
* dc
= get_dc_ptr( hdc
);
716 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetPixelFormat
);
718 ret
= physdev
->funcs
->pGetPixelFormat( physdev
);
719 release_dc_ptr( dc
);
725 /******************************************************************************
726 * DescribePixelFormat [GDI32.@]
727 * Gets info about pixel format from DC
730 * hdc [I] Device context
731 * iPixelFormat [I] Pixel format selector
732 * nBytes [I] Size of buffer
733 * ppfd [O] Pointer to structure to receive pixel format data
736 * Success: Maximum pixel format index of the device context
739 INT WINAPI
DescribePixelFormat( HDC hdc
, INT iPixelFormat
, UINT nBytes
,
740 LPPIXELFORMATDESCRIPTOR ppfd
)
743 DC
* dc
= get_dc_ptr( hdc
);
745 TRACE("(%p,%d,%d,%p): stub\n",hdc
,iPixelFormat
,nBytes
,ppfd
);
749 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pDescribePixelFormat
);
751 ret
= physdev
->funcs
->pDescribePixelFormat( physdev
, iPixelFormat
, nBytes
, ppfd
);
752 release_dc_ptr( dc
);
758 /******************************************************************************
759 * SwapBuffers [GDI32.@]
760 * Exchanges front and back buffers of window
763 * hdc [I] Device context whose buffers get swapped
769 BOOL WINAPI
SwapBuffers( HDC hdc
)
772 DC
* dc
= get_dc_ptr( hdc
);
778 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSwapBuffers
);
780 bRet
= physdev
->funcs
->pSwapBuffers( physdev
);
781 release_dc_ptr( dc
);
787 /***********************************************************************
790 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
793 DC
* dc
= get_dc_ptr( hdc
);
797 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pPaintRgn
);
799 ret
= physdev
->funcs
->pPaintRgn( physdev
, hrgn
);
800 release_dc_ptr( dc
);
806 /***********************************************************************
809 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
812 DC
* dc
= get_dc_ptr( hdc
);
816 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pFillRgn
);
818 retval
= physdev
->funcs
->pFillRgn( physdev
, hrgn
, hbrush
);
819 release_dc_ptr( dc
);
825 /***********************************************************************
828 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
829 INT nWidth
, INT nHeight
)
832 DC
*dc
= get_dc_ptr( hdc
);
836 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pFrameRgn
);
838 ret
= physdev
->funcs
->pFrameRgn( physdev
, hrgn
, hbrush
, nWidth
, nHeight
);
839 release_dc_ptr( dc
);
845 /***********************************************************************
846 * InvertRgn (GDI32.@)
848 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
851 DC
*dc
= get_dc_ptr( hdc
);
855 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pInvertRgn
);
857 ret
= physdev
->funcs
->pInvertRgn( physdev
, hrgn
);
858 release_dc_ptr( dc
);
864 /**********************************************************************
867 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
870 DC
* dc
= get_dc_ptr( hdc
);
874 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pPolyline
);
876 ret
= physdev
->funcs
->pPolyline( physdev
, pt
, count
);
877 release_dc_ptr( dc
);
882 /**********************************************************************
883 * PolylineTo (GDI32.@)
885 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
887 DC
* dc
= get_dc_ptr( hdc
);
891 if(!dc
) return FALSE
;
894 physdev
= GET_DC_PHYSDEV( dc
, pPolylineTo
);
895 ret
= physdev
->funcs
->pPolylineTo( physdev
, pt
, cCount
);
899 dc
->CursPosX
= pt
[cCount
-1].x
;
900 dc
->CursPosY
= pt
[cCount
-1].y
;
902 release_dc_ptr( dc
);
907 /**********************************************************************
910 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
913 DC
* dc
= get_dc_ptr( hdc
);
917 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pPolygon
);
919 ret
= physdev
->funcs
->pPolygon( physdev
, pt
, count
);
920 release_dc_ptr( dc
);
926 /**********************************************************************
927 * PolyPolygon (GDI32.@)
929 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
933 DC
* dc
= get_dc_ptr( hdc
);
937 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pPolyPolygon
);
939 ret
= physdev
->funcs
->pPolyPolygon( physdev
, pt
, counts
, polygons
);
940 release_dc_ptr( dc
);
945 /**********************************************************************
946 * PolyPolyline (GDI32.@)
948 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
952 DC
* dc
= get_dc_ptr( hdc
);
956 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pPolyPolyline
);
958 ret
= physdev
->funcs
->pPolyPolyline( physdev
, pt
, counts
, polylines
);
959 release_dc_ptr( dc
);
964 /**********************************************************************
965 * ExtFloodFill (GDI32.@)
967 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
971 DC
* dc
= get_dc_ptr( hdc
);
975 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pExtFloodFill
);
978 ret
= physdev
->funcs
->pExtFloodFill( physdev
, x
, y
, color
, fillType
);
979 release_dc_ptr( dc
);
985 /**********************************************************************
986 * FloodFill (GDI32.@)
988 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
990 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
994 /******************************************************************************
995 * PolyBezier [GDI32.@]
996 * Draws one or more Bezier curves
999 * hDc [I] Handle to device context
1000 * lppt [I] Pointer to endpoints and control points
1001 * cPoints [I] Count of endpoints and control points
1007 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
1013 /* cPoints must be 3 * n + 1 (where n>=1) */
1014 if (cPoints
== 1 || (cPoints
% 3) != 1) return FALSE
;
1016 dc
= get_dc_ptr( hdc
);
1017 if(!dc
) return FALSE
;
1020 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezier
);
1021 ret
= physdev
->funcs
->pPolyBezier( physdev
, lppt
, cPoints
);
1022 release_dc_ptr( dc
);
1026 /******************************************************************************
1027 * PolyBezierTo [GDI32.@]
1028 * Draws one or more Bezier curves
1031 * hDc [I] Handle to device context
1032 * lppt [I] Pointer to endpoints and control points
1033 * cPoints [I] Count of endpoints and control points
1039 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
1045 /* cbPoints must be 3 * n (where n>=1) */
1046 if (!cPoints
|| (cPoints
% 3) != 0) return FALSE
;
1048 dc
= get_dc_ptr( hdc
);
1049 if(!dc
) return FALSE
;
1052 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezierTo
);
1053 ret
= physdev
->funcs
->pPolyBezierTo( physdev
, lppt
, cPoints
);
1056 dc
->CursPosX
= lppt
[cPoints
-1].x
;
1057 dc
->CursPosY
= lppt
[cPoints
-1].y
;
1059 release_dc_ptr( dc
);
1063 /***********************************************************************
1064 * AngleArc (GDI32.@)
1066 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
1072 if( (signed int)dwRadius
< 0 )
1075 dc
= get_dc_ptr( hdc
);
1076 if(!dc
) return FALSE
;
1079 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
1080 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
1083 dc
->CursPosX
= GDI_ROUND( x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
);
1084 dc
->CursPosY
= GDI_ROUND( y
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
);
1086 release_dc_ptr( dc
);
1090 /***********************************************************************
1091 * PolyDraw (GDI32.@)
1093 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
1096 DC
*dc
= get_dc_ptr( hdc
);
1100 if(!dc
) return FALSE
;
1103 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
1104 result
= physdev
->funcs
->pPolyDraw( physdev
, lppt
, lpbTypes
, cCount
);
1105 release_dc_ptr( dc
);
1110 /**********************************************************************
1113 BOOL WINAPI
LineDDA(INT nXStart
, INT nYStart
, INT nXEnd
, INT nYEnd
,
1114 LINEDDAPROC callback
, LPARAM lParam
)
1116 INT xadd
= 1, yadd
= 1;
1119 INT dx
= nXEnd
- nXStart
;
1120 INT dy
= nYEnd
- nYStart
;
1132 if (dx
> dy
) /* line is "more horizontal" */
1134 err
= 2*dy
- dx
; erradd
= 2*dy
- 2*dx
;
1135 for(cnt
= 0;cnt
< dx
; cnt
++)
1137 callback(nXStart
,nYStart
,lParam
);
1147 else /* line is "more vertical" */
1149 err
= 2*dx
- dy
; erradd
= 2*dx
- 2*dy
;
1150 for(cnt
= 0;cnt
< dy
; cnt
++)
1152 callback(nXStart
,nYStart
,lParam
);
1166 /******************************************************************
1168 * *Very* simple bezier drawing code,
1170 * It uses a recursive algorithm to divide the curve in a series
1171 * of straight line segments. Not ideal but sufficient for me.
1172 * If you are in need for something better look for some incremental
1175 * 7 July 1998 Rein Klazes
1179 * some macro definitions for bezier drawing
1181 * to avoid truncation errors the coordinates are
1182 * shifted upwards. When used in drawing they are
1183 * shifted down again, including correct rounding
1184 * and avoiding floating point arithmetic
1185 * 4 bits should allow 27 bits coordinates which I saw
1186 * somewhere in the win32 doc's
1190 #define BEZIERSHIFTBITS 4
1191 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
1192 #define BEZIERPIXEL BEZIERSHIFTUP(1)
1193 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
1194 /* maximum depth of recursion */
1195 #define BEZIERMAXDEPTH 8
1197 /* size of array to store points on */
1198 /* enough for one curve */
1199 #define BEZIER_INITBUFSIZE (150)
1201 /* calculate Bezier average, in this case the middle
1202 * correctly rounded...
1205 #define BEZIERMIDDLE(Mid, P1, P2) \
1206 (Mid).x=((P1).x+(P2).x + 1)/2;\
1207 (Mid).y=((P1).y+(P2).y + 1)/2;
1209 /**********************************************************
1210 * BezierCheck helper function to check
1211 * that recursion can be terminated
1212 * Points[0] and Points[3] are begin and endpoint
1213 * Points[1] and Points[2] are control points
1214 * level is the recursion depth
1215 * returns true if the recursion can be terminated
1217 static BOOL
BezierCheck( int level
, POINT
*Points
)
1220 dx
=Points
[3].x
-Points
[0].x
;
1221 dy
=Points
[3].y
-Points
[0].y
;
1222 if(abs(dy
)<=abs(dx
)){/* shallow line */
1223 /* check that control points are between begin and end */
1224 if(Points
[1].x
< Points
[0].x
){
1225 if(Points
[1].x
< Points
[3].x
)
1228 if(Points
[1].x
> Points
[3].x
)
1230 if(Points
[2].x
< Points
[0].x
){
1231 if(Points
[2].x
< Points
[3].x
)
1234 if(Points
[2].x
> Points
[3].x
)
1236 dx
=BEZIERSHIFTDOWN(dx
);
1237 if(!dx
) return TRUE
;
1238 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
1239 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
1240 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
1241 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
1245 }else{ /* steep line */
1246 /* check that control points are between begin and end */
1247 if(Points
[1].y
< Points
[0].y
){
1248 if(Points
[1].y
< Points
[3].y
)
1251 if(Points
[1].y
> Points
[3].y
)
1253 if(Points
[2].y
< Points
[0].y
){
1254 if(Points
[2].y
< Points
[3].y
)
1257 if(Points
[2].y
> Points
[3].y
)
1259 dy
=BEZIERSHIFTDOWN(dy
);
1260 if(!dy
) return TRUE
;
1261 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
1262 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
1263 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
1264 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1271 /* Helper for GDI_Bezier.
1272 * Just handles one Bezier, so Points should point to four POINTs
1274 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
1275 INT
*nPtsOut
, INT level
)
1277 if(*nPtsOut
== *dwOut
) {
1279 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
1280 *dwOut
* sizeof(POINT
) );
1283 if(!level
|| BezierCheck(level
, Points
)) {
1285 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1286 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1289 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1290 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1293 POINT Points2
[4]; /* for the second recursive call */
1294 Points2
[3]=Points
[3];
1295 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1296 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1297 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1299 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1300 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1301 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1303 Points2
[0]=Points
[3];
1305 /* do the two halves */
1306 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1307 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1313 /***********************************************************************
1314 * GDI_Bezier [INTERNAL]
1315 * Calculate line segments that approximate -what microsoft calls- a bezier
1317 * The routine recursively divides the curve in two parts until a straight
1322 * Points [I] Ptr to count POINTs which are the end and control points
1323 * of the set of Bezier curves to flatten.
1324 * count [I] Number of Points. Must be 3n+1.
1325 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1330 * Ptr to an array of POINTs that contain the lines that approximate the
1331 * Beziers. The array is allocated on the process heap and it is the caller's
1332 * responsibility to HeapFree it. [this is not a particularly nice interface
1333 * but since we can't know in advance how many points we will generate, the
1334 * alternative would be to call the function twice, once to determine the size
1335 * and a second time to do the work - I decided this was too much of a pain].
1337 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1340 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1342 if (count
== 1 || (count
- 1) % 3 != 0) {
1343 ERR("Invalid no. of points %d\n", count
);
1347 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1348 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1350 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1351 for(i
= 0; i
< 4; i
++) {
1352 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1353 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1355 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1357 TRACE("Produced %d points\n", *nPtsOut
);
1361 /******************************************************************************
1362 * GdiGradientFill (GDI32.@)
1364 * FIXME: we don't support the Alpha channel properly
1366 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1367 void * grad_array
, ULONG ngrad
, ULONG mode
)
1369 DC
*dc
= get_dc_ptr( hdc
);
1373 TRACE("%p vert_array:%p nvert:%d grad_array:%p ngrad:%d\n", hdc
, vert_array
, nvert
, grad_array
, ngrad
);
1375 if (!dc
) return FALSE
;
1378 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
1379 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
1380 release_dc_ptr( dc
);
1384 /******************************************************************************
1385 * GdiDrawStream (GDI32.@)
1388 BOOL WINAPI
GdiDrawStream( HDC hdc
, ULONG in
, void * pvin
)
1390 FIXME("stub: %p, %d, %p\n", hdc
, in
, pvin
);