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
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
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
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
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
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
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
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
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
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
, DWORD start_angle
, DWORD sweep_angle
)
642 FLOAT eStartAngle
= *(FLOAT
*)&start_angle
;
643 FLOAT eSweepAngle
= *(FLOAT
*)&sweep_angle
;
648 if( (signed int)dwRadius
< 0 )
651 dc
= get_dc_ptr( hdc
);
652 if(!dc
) return FALSE
;
655 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
656 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
660 dc
->attr
->cur_pos
.x
= GDI_ROUND( x
+ cos( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
661 dc
->attr
->cur_pos
.y
= GDI_ROUND( y
- sin( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
663 release_dc_ptr( dc
);
667 /***********************************************************************
668 * NtGdiPolyDraw (win32u.@)
670 BOOL WINAPI
NtGdiPolyDraw( HDC hdc
, const POINT
*points
, const BYTE
*types
, DWORD count
)
672 DC
*dc
= get_dc_ptr( hdc
);
676 if(!dc
) return FALSE
;
679 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
680 result
= physdev
->funcs
->pPolyDraw( physdev
, points
, types
, count
);
682 dc
->attr
->cur_pos
= points
[count
- 1];
684 release_dc_ptr( dc
);
689 /******************************************************************
691 * *Very* simple bezier drawing code,
693 * It uses a recursive algorithm to divide the curve in a series
694 * of straight line segments. Not ideal but sufficient for me.
695 * If you are in need for something better look for some incremental
698 * 7 July 1998 Rein Klazes
702 * some macro definitions for bezier drawing
704 * to avoid truncation errors the coordinates are
705 * shifted upwards. When used in drawing they are
706 * shifted down again, including correct rounding
707 * and avoiding floating point arithmetic
708 * 4 bits should allow 27 bits coordinates which I saw
709 * somewhere in the win32 doc's
713 #define BEZIERSHIFTBITS 4
714 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
715 #define BEZIERPIXEL BEZIERSHIFTUP(1)
716 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
717 /* maximum depth of recursion */
718 #define BEZIERMAXDEPTH 8
720 /* size of array to store points on */
721 /* enough for one curve */
722 #define BEZIER_INITBUFSIZE (150)
724 /* calculate Bezier average, in this case the middle
725 * correctly rounded...
728 #define BEZIERMIDDLE(Mid, P1, P2) \
729 (Mid).x=((P1).x+(P2).x + 1)/2;\
730 (Mid).y=((P1).y+(P2).y + 1)/2;
732 /**********************************************************
733 * BezierCheck helper function to check
734 * that recursion can be terminated
735 * Points[0] and Points[3] are begin and endpoint
736 * Points[1] and Points[2] are control points
737 * level is the recursion depth
738 * returns true if the recursion can be terminated
740 static BOOL
BezierCheck( int level
, POINT
*Points
)
743 dx
=Points
[3].x
-Points
[0].x
;
744 dy
=Points
[3].y
-Points
[0].y
;
745 if(abs(dy
)<=abs(dx
)){/* shallow line */
746 /* check that control points are between begin and end */
747 if(Points
[1].x
< Points
[0].x
){
748 if(Points
[1].x
< Points
[3].x
)
751 if(Points
[1].x
> Points
[3].x
)
753 if(Points
[2].x
< Points
[0].x
){
754 if(Points
[2].x
< Points
[3].x
)
757 if(Points
[2].x
> Points
[3].x
)
759 dx
=BEZIERSHIFTDOWN(dx
);
761 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
762 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
763 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
764 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
768 }else{ /* steep line */
769 /* check that control points are between begin and end */
770 if(Points
[1].y
< Points
[0].y
){
771 if(Points
[1].y
< Points
[3].y
)
774 if(Points
[1].y
> Points
[3].y
)
776 if(Points
[2].y
< Points
[0].y
){
777 if(Points
[2].y
< Points
[3].y
)
780 if(Points
[2].y
> Points
[3].y
)
782 dy
=BEZIERSHIFTDOWN(dy
);
784 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
785 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
786 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
787 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
794 /* Helper for GDI_Bezier.
795 * Just handles one Bezier, so Points should point to four POINTs
797 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
798 INT
*nPtsOut
, INT level
)
800 if(*nPtsOut
== *dwOut
) {
802 *PtsOut
= realloc( *PtsOut
, *dwOut
* sizeof(POINT
) );
805 if(!level
|| BezierCheck(level
, Points
)) {
807 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
808 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
811 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
812 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
815 POINT Points2
[4]; /* for the second recursive call */
816 Points2
[3]=Points
[3];
817 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
818 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
819 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
821 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
822 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
823 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
825 Points2
[0]=Points
[3];
827 /* do the two halves */
828 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
829 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
835 /***********************************************************************
836 * GDI_Bezier [INTERNAL]
837 * Calculate line segments that approximate -what microsoft calls- a bezier
839 * The routine recursively divides the curve in two parts until a straight
844 * Points [I] Ptr to count POINTs which are the end and control points
845 * of the set of Bezier curves to flatten.
846 * count [I] Number of Points. Must be 3n+1.
847 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
852 * Ptr to an array of POINTs that contain the lines that approximate the
853 * Beziers. The array is allocated on the process heap and it is the caller's
854 * responsibility to free it. [this is not a particularly nice interface
855 * but since we can't know in advance how many points we will generate, the
856 * alternative would be to call the function twice, once to determine the size
857 * and a second time to do the work - I decided this was too much of a pain].
859 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
862 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
864 if (count
== 1 || (count
- 1) % 3 != 0) {
865 ERR("Invalid no. of points %d\n", count
);
869 out
= malloc( dwOut
* sizeof(POINT
) );
870 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
872 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
873 for(i
= 0; i
< 4; i
++) {
874 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
875 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
877 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
879 TRACE("Produced %d points\n", *nPtsOut
);
883 /******************************************************************************
884 * NtGdiGdiGradientFill (win32u.@)
886 BOOL WINAPI
NtGdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
887 void *grad_array
, ULONG ngrad
, ULONG mode
)
894 if (!vert_array
|| !nvert
|| !grad_array
|| !ngrad
|| mode
> GRADIENT_FILL_TRIANGLE
)
896 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
899 for (i
= 0; i
< ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2); i
++)
900 if (((ULONG
*)grad_array
)[i
] >= nvert
) return FALSE
;
902 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
904 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
905 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
906 release_dc_ptr( dc
);
910 /******************************************************************************
911 * NtGdiDrawStream (win32u.@)
913 BOOL WINAPI
NtGdiDrawStream( HDC hdc
, ULONG in
, void *pvin
)
915 FIXME("stub: %p, %d, %p\n", hdc
, (int)in
, pvin
);
919 /*************************************************************************
920 * NtUserScrollDC (win32u.@)
922 BOOL WINAPI
NtUserScrollDC( HDC hdc
, INT dx
, INT dy
, const RECT
*scroll
, const RECT
*clip
,
923 HRGN ret_update_rgn
, RECT
*update_rect
)
926 HRGN update_rgn
= ret_update_rgn
;
927 RECT src_rect
, clip_rect
, offset
;
929 HRGN dstrgn
, cliprgn
, visrgn
;
934 TRACE( "dx,dy %d,%d scroll %s clip %s update %p rect %p\n",
935 dx
, dy
, wine_dbgstr_rect(scroll
), wine_dbgstr_rect(clip
), ret_update_rgn
, update_rect
);
937 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
938 org
.x
= dc
->attr
->vis_rect
.left
;
939 org
.y
= dc
->attr
->vis_rect
.top
;
940 release_dc_ptr( dc
);
942 /* get the visible region */
943 visrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
944 NtGdiGetRandomRgn( hdc
, visrgn
, SYSRGN
);
945 if (!is_win9x()) NtGdiOffsetRgn( visrgn
, -org
.x
, -org
.y
);
947 /* intersect with the clipping region if the DC has one */
948 cliprgn
= NtGdiCreateRectRgn( 0, 0, 0, 0);
949 if (NtGdiGetRandomRgn( hdc
, cliprgn
, NTGDI_RGN_MIRROR_RTL
| 1 ) != 1)
951 NtGdiDeleteObjectApp( cliprgn
);
954 else NtGdiCombineRgn( visrgn
, visrgn
, cliprgn
, RGN_AND
);
956 /* only those pixels in the scroll rectangle that remain in the clipping
957 * rect are scrolled. */
961 NtGdiGetAppClipBox( hdc
, &clip_rect
);
962 src_rect
= clip_rect
;
963 OffsetRect( &clip_rect
, -dx
, -dy
);
964 intersect_rect( &src_rect
, &src_rect
, &clip_rect
);
966 /* if an scroll rectangle is specified, only the pixels within that
967 * rectangle are scrolled */
968 if (scroll
) intersect_rect( &src_rect
, &src_rect
, scroll
);
970 /* now convert to device coordinates */
971 NtGdiTransformPoints( hdc
, (POINT
*)&src_rect
, (POINT
*)&src_rect
, 2, NtGdiLPtoDP
);
972 TRACE( "source rect: %s\n", wine_dbgstr_rect(&src_rect
) );
974 SetRect( &offset
, 0, 0, dx
, dy
);
975 NtGdiTransformPoints( hdc
, (POINT
*)&offset
, (POINT
*)&offset
, 2, NtGdiLPtoDP
);
976 dxdev
= offset
.right
- offset
.left
;
977 dydev
= offset
.bottom
- offset
.top
;
979 /* now intersect with the visible region to get the pixels that will actually scroll */
980 dstrgn
= NtGdiCreateRectRgn( src_rect
.left
, src_rect
.top
, src_rect
.right
, src_rect
.bottom
);
981 NtGdiCombineRgn( dstrgn
, dstrgn
, visrgn
, RGN_AND
);
982 NtGdiOffsetRgn( dstrgn
, dxdev
, dydev
);
983 NtGdiExtSelectClipRgn( hdc
, dstrgn
, RGN_AND
);
985 /* compute the update areas. This is the combined clip rectangle
986 * minus the scrolled region, and intersected with the visible region. */
987 if (ret_update_rgn
|| update_rect
)
989 /* intersect clip and scroll rectangles, allowing NULL values */
993 intersect_rect( &clip_rect
, clip
, scroll
);
1000 NtGdiGetAppClipBox( hdc
, &clip_rect
);
1002 /* Convert the combined clip rectangle to device coordinates */
1003 NtGdiTransformPoints( hdc
, (POINT
*)&clip_rect
, (POINT
*)&clip_rect
, 2, NtGdiLPtoDP
);
1005 NtGdiSetRectRgn( update_rgn
, clip_rect
.left
, clip_rect
.top
,
1006 clip_rect
.right
, clip_rect
.bottom
);
1008 update_rgn
= NtGdiCreateRectRgn( clip_rect
.left
, clip_rect
.top
,
1009 clip_rect
.right
, clip_rect
.bottom
);
1011 NtGdiCombineRgn( update_rgn
, update_rgn
, visrgn
, RGN_AND
);
1012 NtGdiCombineRgn( update_rgn
, update_rgn
, dstrgn
, RGN_DIFF
);
1015 ret
= user_driver
->pScrollDC( hdc
, dx
, dy
, update_rgn
);
1017 if (ret
&& update_rect
)
1019 NtGdiGetRgnBox( update_rgn
, update_rect
);
1020 NtGdiTransformPoints( hdc
, (POINT
*)&update_rect
, (POINT
*)&update_rect
, 2, NtGdiDPtoLP
);
1021 TRACE( "returning update_rect %s\n", wine_dbgstr_rect(update_rect
) );
1023 if (!ret_update_rgn
) NtGdiDeleteObjectApp( update_rgn
);
1024 NtGdiExtSelectClipRgn( hdc
, cliprgn
, RGN_COPY
);
1025 if (cliprgn
) NtGdiDeleteObjectApp( cliprgn
);
1026 NtGdiDeleteObjectApp( visrgn
);
1027 NtGdiDeleteObjectApp( dstrgn
);