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
35 #include "ntgdi_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
41 /***********************************************************************
42 * null driver fallback implementations
45 BOOL CDECL
nulldrv_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
47 DC
*dc
= get_physdev_dc( dev
);
48 INT x1
= GDI_ROUND( x
+ cos( start
* M_PI
/ 180 ) * radius
);
49 INT y1
= GDI_ROUND( y
- sin( start
* M_PI
/ 180 ) * radius
);
50 INT x2
= GDI_ROUND( x
+ cos( (start
+ sweep
) * M_PI
/ 180) * radius
);
51 INT y2
= GDI_ROUND( y
- sin( (start
+ sweep
) * M_PI
/ 180) * radius
);
52 INT arcdir
= dc
->attr
->arc_direction
;
54 dc
->attr
->arc_direction
= sweep
>= 0 ? AD_COUNTERCLOCKWISE
: AD_CLOCKWISE
;
55 ret
= NtGdiArcInternal( NtGdiArcTo
, dev
->hdc
, x
- radius
, y
- radius
, x
+ radius
, y
+ radius
,
57 dc
->attr
->arc_direction
= arcdir
;
61 BOOL CDECL
nulldrv_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
62 INT xstart
, INT ystart
, INT xend
, INT yend
)
64 INT width
= abs( right
- left
);
65 INT height
= abs( bottom
- top
);
66 double xradius
= width
/ 2.0;
67 double yradius
= height
/ 2.0;
68 double xcenter
= right
> left
? left
+ xradius
: right
+ xradius
;
69 double ycenter
= bottom
> top
? top
+ yradius
: bottom
+ yradius
;
72 if (!height
|| !width
) return FALSE
;
73 /* draw a line from the current position to the starting point of the arc, then draw the arc */
74 angle
= atan2( (ystart
- ycenter
) / height
, (xstart
- xcenter
) / width
);
75 NtGdiLineTo( dev
->hdc
, GDI_ROUND( xcenter
+ cos(angle
) * xradius
),
76 GDI_ROUND( ycenter
+ sin(angle
) * yradius
));
77 return NtGdiArcInternal( NtGdiArc
, dev
->hdc
, left
, top
, right
, bottom
,
78 xstart
, ystart
, xend
, yend
);
81 BOOL CDECL
nulldrv_FillRgn( PHYSDEV dev
, HRGN rgn
, HBRUSH brush
)
86 if ((prev
= NtGdiSelectBrush( dev
->hdc
, brush
)))
88 PHYSDEV physdev
= GET_DC_PHYSDEV( get_physdev_dc( dev
), pPaintRgn
);
89 ret
= physdev
->funcs
->pPaintRgn( physdev
, rgn
);
90 NtGdiSelectBrush( dev
->hdc
, prev
);
95 BOOL CDECL
nulldrv_FrameRgn( PHYSDEV dev
, HRGN rgn
, HBRUSH brush
, INT width
, INT height
)
98 HRGN tmp
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
102 if (REGION_FrameRgn( tmp
, rgn
, width
, height
))
103 ret
= NtGdiFillRgn( dev
->hdc
, tmp
, brush
);
104 NtGdiDeleteObjectApp( tmp
);
109 BOOL CDECL
nulldrv_InvertRgn( PHYSDEV dev
, HRGN rgn
)
111 DC
*dc
= get_physdev_dc( dev
);
112 INT prev_rop
= dc
->attr
->rop_mode
;
114 dc
->attr
->rop_mode
= R2_NOT
;
115 ret
= NtGdiFillRgn( dev
->hdc
, rgn
, GetStockObject(BLACK_BRUSH
) );
116 dc
->attr
->rop_mode
= prev_rop
;
120 static BOOL
polyline( HDC hdc
, const POINT
*points
, ULONG count
)
122 return NtGdiPolyPolyDraw( hdc
, points
, &count
, 1, NtGdiPolyPolyline
);
125 BOOL CDECL
nulldrv_PolyBezier( PHYSDEV dev
, const POINT
*points
, DWORD count
)
131 if ((pts
= GDI_Bezier( points
, count
, &n
)))
133 ret
= polyline( dev
->hdc
, pts
, n
);
139 BOOL CDECL
nulldrv_PolyBezierTo( PHYSDEV dev
, const POINT
*points
, DWORD count
)
141 DC
*dc
= get_nulldrv_dc( dev
);
143 POINT
*pts
= malloc( sizeof(POINT
) * (count
+ 1) );
147 pts
[0] = dc
->attr
->cur_pos
;
148 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
150 ret
= NtGdiPolyPolyDraw( dev
->hdc
, pts
, &count
, 1, NtGdiPolyBezier
);
156 BOOL CDECL
nulldrv_PolyDraw( PHYSDEV dev
, const POINT
*points
, const BYTE
*types
, DWORD count
)
158 DC
*dc
= get_nulldrv_dc( dev
);
159 POINT
*line_pts
= NULL
, *new_line_pts
, *bzr_pts
= NULL
, bzr
[4];
161 INT num_pts
, num_bzr_pts
, space
, size
;
163 /* check for valid point types */
164 for (i
= 0; i
< count
; i
++)
169 case PT_LINETO
| PT_CLOSEFIGURE
:
173 if (i
+ 2 >= count
) return FALSE
;
174 if (types
[i
+ 1] != PT_BEZIERTO
) return FALSE
;
175 if ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) return FALSE
;
184 line_pts
= malloc( space
* sizeof(POINT
) );
185 if (!line_pts
) return FALSE
;
188 line_pts
[0] = dc
->attr
->cur_pos
;
189 for (i
= 0; i
< count
; i
++)
194 if (num_pts
>= 2) polyline( dev
->hdc
, line_pts
, num_pts
);
196 line_pts
[num_pts
++] = points
[i
];
199 case (PT_LINETO
| PT_CLOSEFIGURE
):
200 line_pts
[num_pts
++] = points
[i
];
203 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
204 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
205 memcpy( &bzr
[1], &points
[i
], 3 * sizeof(POINT
) );
207 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
209 size
= num_pts
+ (count
- i
) + num_bzr_pts
;
213 new_line_pts
= realloc( line_pts
, space
* sizeof(POINT
) );
220 line_pts
= new_line_pts
;
222 memcpy( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
223 num_pts
+= num_bzr_pts
- 1;
229 if (types
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
232 if (num_pts
>= 2) polyline( dev
->hdc
, line_pts
, num_pts
);
237 BOOL CDECL
nulldrv_PolylineTo( PHYSDEV dev
, const POINT
*points
, INT count
)
239 DC
*dc
= get_nulldrv_dc( dev
);
243 if (!count
) return FALSE
;
244 if ((pts
= malloc( sizeof(POINT
) * (count
+ 1) )))
246 pts
[0] = dc
->attr
->cur_pos
;
247 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
248 ret
= polyline( dev
->hdc
, pts
, count
+ 1 );
254 /***********************************************************************
255 * NtGdiLineTo (win32u.@)
257 BOOL WINAPI
NtGdiLineTo( HDC hdc
, INT x
, INT y
)
259 DC
* dc
= get_dc_ptr( hdc
);
263 if(!dc
) return FALSE
;
266 physdev
= GET_DC_PHYSDEV( dc
, pLineTo
);
267 ret
= physdev
->funcs
->pLineTo( physdev
, x
, y
);
271 dc
->attr
->cur_pos
.x
= x
;
272 dc
->attr
->cur_pos
.y
= y
;
274 release_dc_ptr( dc
);
279 /***********************************************************************
280 * NtGdiMoveTo (win32u.@)
282 BOOL WINAPI
NtGdiMoveTo( HDC hdc
, INT x
, INT y
, POINT
*pt
)
286 DC
* dc
= get_dc_ptr( hdc
);
288 if(!dc
) return FALSE
;
291 *pt
= dc
->attr
->cur_pos
;
293 dc
->attr
->cur_pos
.x
= x
;
294 dc
->attr
->cur_pos
.y
= y
;
296 physdev
= GET_DC_PHYSDEV( dc
, pMoveTo
);
297 ret
= physdev
->funcs
->pMoveTo( physdev
, x
, y
);
298 release_dc_ptr( dc
);
303 /***********************************************************************
304 * NtGdiArcInternal (win32u.@)
306 BOOL WINAPI
NtGdiArcInternal( UINT type
, HDC hdc
, INT left
, INT top
, INT right
,
307 INT bottom
, INT xstart
, INT ystart
, INT xend
, INT yend
)
313 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
319 physdev
= GET_DC_PHYSDEV( dc
, pArc
);
320 ret
= physdev
->funcs
->pArc( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
325 double width
= abs( right
- left
);
326 double height
= abs( bottom
- top
);
327 double xradius
= width
/ 2;
328 double yradius
= height
/ 2;
329 double xcenter
= right
> left
? left
+ xradius
: right
+ xradius
;
330 double ycenter
= bottom
> top
? top
+ yradius
: bottom
+ yradius
;
332 physdev
= GET_DC_PHYSDEV( dc
, pArcTo
);
333 ret
= physdev
->funcs
->pArcTo( physdev
, left
, top
, right
, bottom
,
334 xstart
, ystart
, xend
, yend
);
337 double angle
= atan2(((yend
- ycenter
) / height
),
338 ((xend
- xcenter
) / width
));
339 dc
->attr
->cur_pos
.x
= GDI_ROUND( xcenter
+ (cos( angle
) * xradius
) );
340 dc
->attr
->cur_pos
.y
= GDI_ROUND( ycenter
+ (sin( angle
) * yradius
) );
346 physdev
= GET_DC_PHYSDEV( dc
, pChord
);
347 ret
= physdev
->funcs
->pChord( physdev
, left
, top
, right
, bottom
,
348 xstart
, ystart
, xend
, yend
);
352 physdev
= GET_DC_PHYSDEV( dc
, pPie
);
353 ret
= physdev
->funcs
->pPie( physdev
, left
, top
, right
, bottom
,
354 xstart
, ystart
, xend
, yend
);
358 WARN( "invalid arc type %u\n", type
);
362 release_dc_ptr( dc
);
367 /***********************************************************************
368 * NtGdiEllipse (win32u.@)
370 BOOL WINAPI
NtGdiEllipse( HDC hdc
, INT left
, INT top
, INT right
, INT bottom
)
374 DC
* dc
= get_dc_ptr( hdc
);
376 if (!dc
) return FALSE
;
378 physdev
= GET_DC_PHYSDEV( dc
, pEllipse
);
379 ret
= physdev
->funcs
->pEllipse( physdev
, left
, top
, right
, bottom
);
380 release_dc_ptr( dc
);
385 /***********************************************************************
386 * NtGdiRectangle (win32u.@)
388 BOOL WINAPI
NtGdiRectangle( HDC hdc
, INT left
, INT top
, INT right
, INT bottom
)
392 DC
* dc
= get_dc_ptr( hdc
);
394 if (!dc
) return FALSE
;
396 physdev
= GET_DC_PHYSDEV( dc
, pRectangle
);
397 ret
= physdev
->funcs
->pRectangle( physdev
, left
, top
, right
, bottom
);
398 release_dc_ptr( dc
);
403 /***********************************************************************
404 * NtGdiRoundRect (win32u.@)
406 BOOL WINAPI
NtGdiRoundRect( HDC hdc
, INT left
, INT top
, INT right
,
407 INT bottom
, INT ell_width
, INT ell_height
)
411 DC
*dc
= get_dc_ptr( hdc
);
413 if (!dc
) return FALSE
;
415 physdev
= GET_DC_PHYSDEV( dc
, pRoundRect
);
416 ret
= physdev
->funcs
->pRoundRect( physdev
, left
, top
, right
, bottom
, ell_width
, ell_height
);
417 release_dc_ptr( dc
);
421 /***********************************************************************
422 * NtGdiSetPixel (win32u.@)
424 COLORREF WINAPI
NtGdiSetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
428 DC
* dc
= get_dc_ptr( hdc
);
430 if (!dc
) return CLR_INVALID
;
432 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
433 ret
= physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
434 release_dc_ptr( dc
);
438 /***********************************************************************
439 * NtGdiGetPixel (win32u.@)
441 COLORREF WINAPI
NtGdiGetPixel( HDC hdc
, INT x
, INT y
)
445 DC
* dc
= get_dc_ptr( hdc
);
447 if (!dc
) return CLR_INVALID
;
449 physdev
= GET_DC_PHYSDEV( dc
, pGetPixel
);
450 ret
= physdev
->funcs
->pGetPixel( physdev
, x
, y
);
451 release_dc_ptr( dc
);
456 /******************************************************************************
457 * NtGdiSetPixelFormat (win32u.@)
459 * Probably not the correct semantics, it's supposed to be an internal backend for SetPixelFormat.
461 BOOL WINAPI
NtGdiSetPixelFormat( HDC hdc
, INT format
)
466 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
468 if (!dc
->pixel_format
) dc
->pixel_format
= format
;
469 else ret
= (dc
->pixel_format
== format
);
470 release_dc_ptr( dc
);
475 /******************************************************************************
476 * NtGdiDescribePixelFormat (win32u.@)
478 INT WINAPI
NtGdiDescribePixelFormat( HDC hdc
, INT format
, UINT size
, PIXELFORMATDESCRIPTOR
*descr
)
480 FIXME( "(%p,%d,%d,%p): stub\n", hdc
, format
, size
, descr
);
485 /******************************************************************************
486 * NtGdiSwapBuffers (win32u.@)
488 BOOL WINAPI
NtGdiSwapBuffers( HDC hdc
)
490 FIXME( "(%p): stub\n", hdc
);
495 /***********************************************************************
496 * NtGdiFillRgn (win32u.@)
498 BOOL WINAPI
NtGdiFillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
502 DC
* dc
= get_dc_ptr( hdc
);
504 if (!dc
) return FALSE
;
506 physdev
= GET_DC_PHYSDEV( dc
, pFillRgn
);
507 retval
= physdev
->funcs
->pFillRgn( physdev
, hrgn
, hbrush
);
508 release_dc_ptr( dc
);
513 /***********************************************************************
514 * NtGdiFrameRgn (win32u.@)
516 BOOL WINAPI
NtGdiFrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
520 DC
*dc
= get_dc_ptr( hdc
);
522 if (!dc
) return FALSE
;
524 physdev
= GET_DC_PHYSDEV( dc
, pFrameRgn
);
525 ret
= physdev
->funcs
->pFrameRgn( physdev
, hrgn
, hbrush
, width
, height
);
526 release_dc_ptr( dc
);
531 /***********************************************************************
532 * NtGdiInvertRgn (win32u.@)
534 BOOL WINAPI
NtGdiInvertRgn( HDC hdc
, HRGN hrgn
)
538 DC
*dc
= get_dc_ptr( hdc
);
540 if (!dc
) return FALSE
;
542 physdev
= GET_DC_PHYSDEV( dc
, pInvertRgn
);
543 ret
= physdev
->funcs
->pInvertRgn( physdev
, hrgn
);
544 release_dc_ptr( dc
);
549 /**********************************************************************
550 * NtGdiPolyPolyDraw (win32u.@)
552 ULONG WINAPI
NtGdiPolyPolyDraw( HDC hdc
, const POINT
*points
, const ULONG
*counts
,
553 DWORD count
, UINT function
)
559 if (function
== NtGdiPolyPolygonRgn
)
560 return HandleToULong( create_polypolygon_region( points
, (const INT
*)counts
, count
,
561 HandleToULong(hdc
), NULL
));
563 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
568 case NtGdiPolyPolygon
:
569 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolygon
);
570 ret
= physdev
->funcs
->pPolyPolygon( physdev
, points
, (const INT
*)counts
, count
);
573 case NtGdiPolyPolyline
:
574 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolyline
);
575 ret
= physdev
->funcs
->pPolyPolyline( physdev
, points
, (const DWORD
*)counts
, count
);
578 case NtGdiPolyBezier
:
579 /* *counts must be 3 * n + 1 (where n >= 1) */
580 if (count
== 1 && *counts
!= 1 && *counts
% 3 == 1)
582 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezier
);
583 ret
= physdev
->funcs
->pPolyBezier( physdev
, points
, *counts
);
584 if (ret
) dc
->attr
->cur_pos
= points
[*counts
- 1];
589 case NtGdiPolyBezierTo
:
590 if (count
== 1 && *counts
&& *counts
% 3 == 0)
592 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezierTo
);
593 ret
= physdev
->funcs
->pPolyBezierTo( physdev
, points
, *counts
);
594 if (ret
) dc
->attr
->cur_pos
= points
[*counts
- 1];
599 case NtGdiPolylineTo
:
602 physdev
= GET_DC_PHYSDEV( dc
, pPolylineTo
);
603 ret
= physdev
->funcs
->pPolylineTo( physdev
, points
, *counts
);
604 if (ret
&& *counts
) dc
->attr
->cur_pos
= points
[*counts
- 1];
610 WARN( "invalid function %u\n", function
);
615 release_dc_ptr( dc
);
619 /**********************************************************************
620 * NtGdiExtFloodFill (win32u.@)
622 BOOL WINAPI
NtGdiExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
, UINT fill_type
)
626 DC
* dc
= get_dc_ptr( hdc
);
628 if (!dc
) return FALSE
;
630 physdev
= GET_DC_PHYSDEV( dc
, pExtFloodFill
);
631 ret
= physdev
->funcs
->pExtFloodFill( physdev
, x
, y
, color
, fill_type
);
632 release_dc_ptr( dc
);
637 /***********************************************************************
638 * NtGdiAngleArc (win32u.@)
640 BOOL WINAPI
NtGdiAngleArc( HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
646 if( (signed int)dwRadius
< 0 )
649 dc
= get_dc_ptr( hdc
);
650 if(!dc
) return FALSE
;
653 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
654 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
658 dc
->attr
->cur_pos
.x
= GDI_ROUND( x
+ cos( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
659 dc
->attr
->cur_pos
.y
= GDI_ROUND( y
- sin( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
661 release_dc_ptr( dc
);
665 /***********************************************************************
666 * NtGdiPolyDraw (win32u.@)
668 BOOL WINAPI
NtGdiPolyDraw( HDC hdc
, const POINT
*points
, const BYTE
*types
, DWORD count
)
670 DC
*dc
= get_dc_ptr( hdc
);
674 if(!dc
) return FALSE
;
677 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
678 result
= physdev
->funcs
->pPolyDraw( physdev
, points
, types
, count
);
680 dc
->attr
->cur_pos
= points
[count
- 1];
682 release_dc_ptr( dc
);
687 /******************************************************************
689 * *Very* simple bezier drawing code,
691 * It uses a recursive algorithm to divide the curve in a series
692 * of straight line segments. Not ideal but sufficient for me.
693 * If you are in need for something better look for some incremental
696 * 7 July 1998 Rein Klazes
700 * some macro definitions for bezier drawing
702 * to avoid truncation errors the coordinates are
703 * shifted upwards. When used in drawing they are
704 * shifted down again, including correct rounding
705 * and avoiding floating point arithmetic
706 * 4 bits should allow 27 bits coordinates which I saw
707 * somewhere in the win32 doc's
711 #define BEZIERSHIFTBITS 4
712 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
713 #define BEZIERPIXEL BEZIERSHIFTUP(1)
714 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
715 /* maximum depth of recursion */
716 #define BEZIERMAXDEPTH 8
718 /* size of array to store points on */
719 /* enough for one curve */
720 #define BEZIER_INITBUFSIZE (150)
722 /* calculate Bezier average, in this case the middle
723 * correctly rounded...
726 #define BEZIERMIDDLE(Mid, P1, P2) \
727 (Mid).x=((P1).x+(P2).x + 1)/2;\
728 (Mid).y=((P1).y+(P2).y + 1)/2;
730 /**********************************************************
731 * BezierCheck helper function to check
732 * that recursion can be terminated
733 * Points[0] and Points[3] are begin and endpoint
734 * Points[1] and Points[2] are control points
735 * level is the recursion depth
736 * returns true if the recursion can be terminated
738 static BOOL
BezierCheck( int level
, POINT
*Points
)
741 dx
=Points
[3].x
-Points
[0].x
;
742 dy
=Points
[3].y
-Points
[0].y
;
743 if(abs(dy
)<=abs(dx
)){/* shallow line */
744 /* check that control points are between begin and end */
745 if(Points
[1].x
< Points
[0].x
){
746 if(Points
[1].x
< Points
[3].x
)
749 if(Points
[1].x
> Points
[3].x
)
751 if(Points
[2].x
< Points
[0].x
){
752 if(Points
[2].x
< Points
[3].x
)
755 if(Points
[2].x
> Points
[3].x
)
757 dx
=BEZIERSHIFTDOWN(dx
);
759 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
760 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
761 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
762 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
766 }else{ /* steep line */
767 /* check that control points are between begin and end */
768 if(Points
[1].y
< Points
[0].y
){
769 if(Points
[1].y
< Points
[3].y
)
772 if(Points
[1].y
> Points
[3].y
)
774 if(Points
[2].y
< Points
[0].y
){
775 if(Points
[2].y
< Points
[3].y
)
778 if(Points
[2].y
> Points
[3].y
)
780 dy
=BEZIERSHIFTDOWN(dy
);
782 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
783 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
784 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
785 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
792 /* Helper for GDI_Bezier.
793 * Just handles one Bezier, so Points should point to four POINTs
795 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
796 INT
*nPtsOut
, INT level
)
798 if(*nPtsOut
== *dwOut
) {
800 *PtsOut
= realloc( *PtsOut
, *dwOut
* sizeof(POINT
) );
803 if(!level
|| BezierCheck(level
, Points
)) {
805 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
806 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
809 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
810 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
813 POINT Points2
[4]; /* for the second recursive call */
814 Points2
[3]=Points
[3];
815 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
816 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
817 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
819 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
820 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
821 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
823 Points2
[0]=Points
[3];
825 /* do the two halves */
826 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
827 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
833 /***********************************************************************
834 * GDI_Bezier [INTERNAL]
835 * Calculate line segments that approximate -what microsoft calls- a bezier
837 * The routine recursively divides the curve in two parts until a straight
842 * Points [I] Ptr to count POINTs which are the end and control points
843 * of the set of Bezier curves to flatten.
844 * count [I] Number of Points. Must be 3n+1.
845 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
850 * Ptr to an array of POINTs that contain the lines that approximate the
851 * Beziers. The array is allocated on the process heap and it is the caller's
852 * responsibility to free it. [this is not a particularly nice interface
853 * but since we can't know in advance how many points we will generate, the
854 * alternative would be to call the function twice, once to determine the size
855 * and a second time to do the work - I decided this was too much of a pain].
857 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
860 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
862 if (count
== 1 || (count
- 1) % 3 != 0) {
863 ERR("Invalid no. of points %d\n", count
);
867 out
= malloc( dwOut
* sizeof(POINT
) );
868 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
870 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
871 for(i
= 0; i
< 4; i
++) {
872 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
873 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
875 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
877 TRACE("Produced %d points\n", *nPtsOut
);
881 /******************************************************************************
882 * NtGdiGdiGradientFill (win32u.@)
884 BOOL WINAPI
NtGdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
885 void *grad_array
, ULONG ngrad
, ULONG mode
)
892 if (!vert_array
|| !nvert
|| !grad_array
|| !ngrad
|| mode
> GRADIENT_FILL_TRIANGLE
)
894 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
897 for (i
= 0; i
< ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2); i
++)
898 if (((ULONG
*)grad_array
)[i
] >= nvert
) return FALSE
;
900 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
902 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
903 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
904 release_dc_ptr( dc
);
908 /******************************************************************************
909 * NtGdiDrawStream (win32u.@)
911 BOOL WINAPI
NtGdiDrawStream( HDC hdc
, ULONG in
, void *pvin
)
913 FIXME("stub: %p, %d, %p\n", hdc
, in
, pvin
);
917 /*************************************************************************
918 * NtUserScrollDC (win32u.@)
920 BOOL WINAPI
NtUserScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
921 HRGN ret_update_rgn
, RECT
*update_rect
)
924 HRGN update_rgn
= ret_update_rgn
;
925 RECT src_rect
, clip_rect
, offset
;
927 HRGN dstrgn
, cliprgn
, visrgn
;
932 TRACE( "dx,dy %d,%d scroll %s clip %s update %p rect %p\n",
933 dx
, dy
, wine_dbgstr_rect(scroll
), wine_dbgstr_rect(clip
), ret_update_rgn
, update_rect
);
935 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
936 org
.x
= dc
->attr
->vis_rect
.left
;
937 org
.y
= dc
->attr
->vis_rect
.top
;
938 release_dc_ptr( dc
);
940 /* get the visible region */
941 visrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
942 NtGdiGetRandomRgn( hdc
, visrgn
, SYSRGN
);
943 if (!is_win9x()) NtGdiOffsetRgn( visrgn
, -org
.x
, -org
.y
);
945 /* intersect with the clipping region if the DC has one */
946 cliprgn
= NtGdiCreateRectRgn( 0, 0, 0, 0);
947 if (NtGdiGetRandomRgn( hdc
, cliprgn
, NTGDI_RGN_MIRROR_RTL
| 1 ) != 1)
949 NtGdiDeleteObjectApp( cliprgn
);
952 else NtGdiCombineRgn( visrgn
, visrgn
, cliprgn
, RGN_AND
);
954 /* only those pixels in the scroll rectangle that remain in the clipping
955 * rect are scrolled. */
959 NtGdiGetAppClipBox( hdc
, &clip_rect
);
960 src_rect
= clip_rect
;
961 OffsetRect( &clip_rect
, -dx
, -dy
);
962 intersect_rect( &src_rect
, &src_rect
, &clip_rect
);
964 /* if an scroll rectangle is specified, only the pixels within that
965 * rectangle are scrolled */
966 if (scroll
) intersect_rect( &src_rect
, &src_rect
, scroll
);
968 /* now convert to device coordinates */
969 NtGdiTransformPoints( hdc
, (POINT
*)&src_rect
, (POINT
*)&src_rect
, 2, NtGdiLPtoDP
);
970 TRACE( "source rect: %s\n", wine_dbgstr_rect(&src_rect
) );
972 SetRect( &offset
, 0, 0, dx
, dy
);
973 NtGdiTransformPoints( hdc
, (POINT
*)&offset
, (POINT
*)&offset
, 2, NtGdiLPtoDP
);
974 dxdev
= offset
.right
- offset
.left
;
975 dydev
= offset
.bottom
- offset
.top
;
977 /* now intersect with the visible region to get the pixels that will actually scroll */
978 dstrgn
= NtGdiCreateRectRgn( src_rect
.left
, src_rect
.top
, src_rect
.right
, src_rect
.bottom
);
979 NtGdiCombineRgn( dstrgn
, dstrgn
, visrgn
, RGN_AND
);
980 NtGdiOffsetRgn( dstrgn
, dxdev
, dydev
);
981 NtGdiExtSelectClipRgn( hdc
, dstrgn
, RGN_AND
);
983 /* compute the update areas. This is the combined clip rectangle
984 * minus the scrolled region, and intersected with the visible region. */
985 if (ret_update_rgn
|| update_rect
)
987 /* intersect clip and scroll rectangles, allowing NULL values */
991 intersect_rect( &clip_rect
, clip
, scroll
);
998 NtGdiGetAppClipBox( hdc
, &clip_rect
);
1000 /* Convert the combined clip rectangle to device coordinates */
1001 NtGdiTransformPoints( hdc
, (POINT
*)&clip_rect
, (POINT
*)&clip_rect
, 2, NtGdiLPtoDP
);
1003 NtGdiSetRectRgn( update_rgn
, clip_rect
.left
, clip_rect
.top
,
1004 clip_rect
.right
, clip_rect
.bottom
);
1006 update_rgn
= NtGdiCreateRectRgn( clip_rect
.left
, clip_rect
.top
,
1007 clip_rect
.right
, clip_rect
.bottom
);
1009 NtGdiCombineRgn( update_rgn
, update_rgn
, visrgn
, RGN_AND
);
1010 NtGdiCombineRgn( update_rgn
, update_rgn
, dstrgn
, RGN_DIFF
);
1013 ret
= user_driver
->pScrollDC( hdc
, dx
, dy
, update_rgn
);
1015 if (ret
&& update_rect
)
1017 NtGdiGetRgnBox( update_rgn
, update_rect
);
1018 NtGdiTransformPoints( hdc
, (POINT
*)&update_rect
, (POINT
*)&update_rect
, 2, NtGdiDPtoLP
);
1019 TRACE( "returning update_rect %s\n", wine_dbgstr_rect(update_rect
) );
1021 if (!ret_update_rgn
) NtGdiDeleteObjectApp( update_rgn
);
1022 NtGdiExtSelectClipRgn( hdc
, cliprgn
, RGN_COPY
);
1023 if (cliprgn
) NtGdiDeleteObjectApp( cliprgn
);
1024 NtGdiDeleteObjectApp( visrgn
);
1025 NtGdiDeleteObjectApp( dstrgn
);