2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 Alexandre Julliard
8 * FIXME: none of these functions obey the GM_ADVANCED
14 #ifndef X_DISPLAY_MISSING
16 #include <X11/Intrinsic.h>
43 #include "debugtools.h"
46 DEFAULT_DEBUG_CHANNEL(graphics
)
48 #define ABS(x) ((x)<0?(-(x)):(x))
50 /* ROP code to GC function conversion */
51 const int X11DRV_XROPfunction
[16] =
53 GXclear
, /* R2_BLACK */
54 GXnor
, /* R2_NOTMERGEPEN */
55 GXandInverted
, /* R2_MASKNOTPEN */
56 GXcopyInverted
, /* R2_NOTCOPYPEN */
57 GXandReverse
, /* R2_MASKPENNOT */
58 GXinvert
, /* R2_NOT */
59 GXxor
, /* R2_XORPEN */
60 GXnand
, /* R2_NOTMASKPEN */
61 GXand
, /* R2_MASKPEN */
62 GXequiv
, /* R2_NOTXORPEN */
64 GXorInverted
, /* R2_MERGENOTPEN */
65 GXcopy
, /* R2_COPYPEN */
66 GXorReverse
, /* R2_MERGEPENNOT */
67 GXor
, /* R2_MERGEPEN */
72 /***********************************************************************
73 * X11DRV_SetupGCForPatBlt
75 * Setup the GC for a PatBlt operation using current brush.
76 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
77 * Return FALSE if brush is BS_NULL, TRUE otherwise.
79 BOOL
X11DRV_SetupGCForPatBlt( DC
* dc
, GC gc
, BOOL fMapColors
)
84 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
86 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
87 if (physDev
->brush
.pixel
== -1)
89 /* Special case used for monochrome pattern brushes.
90 * We need to swap foreground and background because
91 * Windows does it the wrong way...
93 val
.foreground
= physDev
->backgroundPixel
;
94 val
.background
= physDev
->textPixel
;
98 val
.foreground
= physDev
->brush
.pixel
;
99 val
.background
= physDev
->backgroundPixel
;
101 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
103 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
104 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
107 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
109 val
.function
= X11DRV_XROPfunction
[dc
->w
.ROPmode
-1];
111 ** Let's replace GXinvert by GXxor with (black xor white)
112 ** This solves the selection color and leak problems in excel
113 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
115 if (val
.function
== GXinvert
)
117 val
.foreground
= BlackPixelOfScreen(X11DRV_GetXScreen()) ^ WhitePixelOfScreen(X11DRV_GetXScreen());
118 val
.function
= GXxor
;
120 val
.fill_style
= physDev
->brush
.fillStyle
;
121 switch(val
.fill_style
)
124 case FillOpaqueStippled
:
125 if (dc
->w
.backgroundMode
==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
126 val
.stipple
= physDev
->brush
.pixmap
;
131 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
135 EnterCriticalSection( &X11DRV_CritSection
);
136 pixmap
= XCreatePixmap( display
,
137 X11DRV_GetXRootWindow(),
139 MONITOR_GetDepth(&MONITOR_PrimaryMonitor
) );
140 image
= XGetImage( display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
141 AllPlanes
, ZPixmap
);
142 for (y
= 0; y
< 8; y
++)
143 for (x
= 0; x
< 8; x
++)
144 XPutPixel( image
, x
, y
,
145 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
146 XPutImage( display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
147 XDestroyImage( image
);
148 LeaveCriticalSection( &X11DRV_CritSection
);
151 else val
.tile
= physDev
->brush
.pixmap
;
159 val
.ts_x_origin
= dc
->w
.DCOrgX
+ dc
->w
.brushOrgX
;
160 val
.ts_y_origin
= dc
->w
.DCOrgY
+ dc
->w
.brushOrgY
;
161 val
.fill_rule
= (dc
->w
.polyFillMode
==WINDING
) ? WindingRule
: EvenOddRule
;
162 TSXChangeGC( display
, gc
,
163 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
164 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
166 if (pixmap
) TSXFreePixmap( display
, pixmap
);
171 /***********************************************************************
172 * X11DRV_SetupGCForBrush
174 * Setup physDev->gc for drawing operations using current brush.
175 * Return FALSE if brush is BS_NULL, TRUE otherwise.
177 BOOL
X11DRV_SetupGCForBrush( DC
* dc
)
179 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
180 return X11DRV_SetupGCForPatBlt( dc
, physDev
->gc
, FALSE
);
184 /***********************************************************************
185 * X11DRV_SetupGCForPen
187 * Setup physDev->gc for drawing operations using current pen.
188 * Return FALSE if pen is PS_NULL, TRUE otherwise.
190 BOOL
X11DRV_SetupGCForPen( DC
* dc
)
193 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
195 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
197 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
199 switch (dc
->w
.ROPmode
)
202 val
.foreground
= BlackPixelOfScreen( X11DRV_GetXScreen() );
203 val
.function
= GXcopy
;
206 val
.foreground
= WhitePixelOfScreen( X11DRV_GetXScreen() );
207 val
.function
= GXcopy
;
210 val
.foreground
= physDev
->pen
.pixel
;
211 /* It is very unlikely someone wants to XOR with 0 */
212 /* This fixes the rubber-drawings in paintbrush */
213 if (val
.foreground
== 0)
214 val
.foreground
= BlackPixelOfScreen( X11DRV_GetXScreen() )
215 ^ WhitePixelOfScreen( X11DRV_GetXScreen() );
216 val
.function
= GXxor
;
219 val
.foreground
= physDev
->pen
.pixel
;
220 val
.function
= X11DRV_XROPfunction
[dc
->w
.ROPmode
-1];
222 val
.background
= physDev
->backgroundPixel
;
223 val
.fill_style
= FillSolid
;
224 if ((physDev
->pen
.width
<= 1) &&
225 (physDev
->pen
.style
!= PS_SOLID
) &&
226 (physDev
->pen
.style
!= PS_INSIDEFRAME
))
228 TSXSetDashes( display
, physDev
->gc
, 0, physDev
->pen
.dashes
,
229 physDev
->pen
.dash_len
);
230 val
.line_style
= (dc
->w
.backgroundMode
== OPAQUE
) ?
231 LineDoubleDash
: LineOnOffDash
;
233 else val
.line_style
= LineSolid
;
234 val
.line_width
= physDev
->pen
.width
;
235 if (val
.line_width
<= 1) {
236 val
.cap_style
= CapNotLast
;
238 switch (physDev
->pen
.endcap
)
240 case PS_ENDCAP_SQUARE
:
241 val
.cap_style
= CapProjecting
;
244 val
.cap_style
= CapButt
;
246 case PS_ENDCAP_ROUND
:
248 val
.cap_style
= CapRound
;
251 switch (physDev
->pen
.linejoin
)
254 val
.join_style
= JoinBevel
;
257 val
.join_style
= JoinMiter
;
261 val
.join_style
= JoinRound
;
263 TSXChangeGC( display
, physDev
->gc
,
264 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
265 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
270 /***********************************************************************
271 * X11DRV_SetupGCForText
273 * Setup physDev->gc for text drawing operations.
274 * Return FALSE if the font is null, TRUE otherwise.
276 BOOL
X11DRV_SetupGCForText( DC
* dc
)
278 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
279 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
285 if (dc
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion(dc
);
287 val
.function
= GXcopy
; /* Text is always GXcopy */
288 val
.foreground
= physDev
->textPixel
;
289 val
.background
= physDev
->backgroundPixel
;
290 val
.fill_style
= FillSolid
;
293 TSXChangeGC( display
, physDev
->gc
,
294 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
298 WARN("Physical font failure\n" );
303 /**********************************************************************
307 X11DRV_MoveToEx(DC
*dc
,INT x
,INT y
,LPPOINT pt
) {
310 pt
->x
= dc
->w
.CursPosX
;
311 pt
->y
= dc
->w
.CursPosY
;
318 /***********************************************************************
322 X11DRV_LineTo( DC
*dc
, INT x
, INT y
)
324 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
326 if (X11DRV_SetupGCForPen( dc
))
327 TSXDrawLine(display
, physDev
->drawable
, physDev
->gc
,
328 dc
->w
.DCOrgX
+ XLPTODP( dc
, dc
->w
.CursPosX
),
329 dc
->w
.DCOrgY
+ YLPTODP( dc
, dc
->w
.CursPosY
),
330 dc
->w
.DCOrgX
+ XLPTODP( dc
, x
),
331 dc
->w
.DCOrgY
+ YLPTODP( dc
, y
) );
339 /***********************************************************************
342 * Helper functions for Arc(), Chord() and Pie().
343 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
347 X11DRV_DrawArc( DC
*dc
, INT left
, INT top
, INT right
,
348 INT bottom
, INT xstart
, INT ystart
,
349 INT xend
, INT yend
, INT lines
)
351 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
352 INT width
, oldwidth
, oldendcap
;
353 double start_angle
, end_angle
;
355 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
357 left
= XLPTODP( dc
, left
);
358 top
= YLPTODP( dc
, top
);
359 right
= XLPTODP( dc
, right
);
360 bottom
= YLPTODP( dc
, bottom
);
361 xstart
= XLPTODP( dc
, xstart
);
362 ystart
= YLPTODP( dc
, ystart
);
363 xend
= XLPTODP( dc
, xend
);
364 yend
= YLPTODP( dc
, yend
);
366 if (right
< left
) { INT tmp
= right
; right
= left
; left
= tmp
; }
367 if (bottom
< top
) { INT tmp
= bottom
; bottom
= top
; top
= tmp
; }
368 if ((left
== right
) || (top
== bottom
)
369 ||(lines
&& ((right
-left
==1)||(bottom
-top
==1)))) return TRUE
;
371 oldwidth
= width
= physDev
->pen
.width
;
372 oldendcap
= physDev
->pen
.endcap
;
373 if (!width
) width
= 1;
374 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
376 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
378 if (2*width
> (right
-left
)) width
=(right
-left
+ 1)/2;
379 if (2*width
> (bottom
-top
)) width
=(bottom
-top
+ 1)/2;
381 right
-= (width
- 1) / 2;
383 bottom
-= (width
- 1) / 2;
385 if(width
== 0) width
= 1; /* more accurate */
386 physDev
->pen
.width
= width
;
387 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
389 xcenter
= (right
+ left
) / 2;
390 ycenter
= (bottom
+ top
) / 2;
391 start_angle
= atan2( (double)(ycenter
-ystart
)*(right
-left
),
392 (double)(xstart
-xcenter
)*(bottom
-top
) );
393 end_angle
= atan2( (double)(ycenter
-yend
)*(right
-left
),
394 (double)(xend
-xcenter
)*(bottom
-top
) );
395 if ((xstart
==xend
)&&(ystart
==yend
))
396 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
400 else /* notorious cases */
401 if ((start_angle
== PI
)&&( end_angle
<0))
404 if ((end_angle
== PI
)&&( start_angle
<0))
406 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
407 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
408 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
410 /* Fill arc with brush if Chord() or Pie() */
412 if ((lines
> 0) && X11DRV_SetupGCForBrush( dc
)) {
413 TSXSetArcMode( display
, physDev
->gc
,
414 (lines
==1) ? ArcChord
: ArcPieSlice
);
415 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
416 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
417 right
-left
-1, bottom
-top
-1, istart_angle
, idiff_angle
);
420 /* Draw arc and lines */
422 if (X11DRV_SetupGCForPen( dc
)){
423 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
424 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
425 right
-left
-1, bottom
-top
-1, istart_angle
, idiff_angle
);
427 /* use the truncated values */
428 start_angle
=(double)istart_angle
*PI
/64./180.;
429 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
430 /* calculate the endpoints and round correctly */
431 points
[0].x
= (int) floor(dc
->w
.DCOrgX
+ (right
+left
)/2.0 +
432 cos(start_angle
) * (right
-left
-width
*2+2) / 2. + 0.5);
433 points
[0].y
= (int) floor(dc
->w
.DCOrgY
+ (top
+bottom
)/2.0 -
434 sin(start_angle
) * (bottom
-top
-width
*2+2) / 2. + 0.5);
435 points
[1].x
= (int) floor(dc
->w
.DCOrgX
+ (right
+left
)/2.0 +
436 cos(end_angle
) * (right
-left
-width
*2+2) / 2. + 0.5);
437 points
[1].y
= (int) floor(dc
->w
.DCOrgY
+ (top
+bottom
)/2.0 -
438 sin(end_angle
) * (bottom
-top
-width
*2+2) / 2. + 0.5);
440 /* OK this stuff is optimized for Xfree86
441 * which is probably the most used server by
442 * wine users. Other X servers will not
443 * display correctly. (eXceed for instance)
444 * so if you feel you must change make sure that
445 * you either use Xfree86 or seperate your changes
446 * from these (compile switch or whatever)
450 points
[3] = points
[1];
451 points
[1].x
= dc
->w
.DCOrgX
+ xcenter
;
452 points
[1].y
= dc
->w
.DCOrgY
+ ycenter
;
453 points
[2] = points
[1];
454 dx1
=points
[1].x
-points
[0].x
;
455 dy1
=points
[1].y
-points
[0].y
;
456 if(((top
-bottom
) | -2) == -2)
457 if(dy1
>0) points
[1].y
--;
459 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
460 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
461 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
463 if(dy1
< 0) points
[0].y
--;
464 if(((right
-left
) | -2) == -2) points
[1].x
--;
466 dx1
=points
[3].x
-points
[2].x
;
467 dy1
=points
[3].y
-points
[2].y
;
468 if(((top
-bottom
) | -2 ) == -2)
469 if(dy1
< 0) points
[2].y
--;
471 if( dy1
>0) points
[3].y
--;
472 if(((right
-left
) | -2) == -2 ) points
[2].x
--;
475 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
479 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
480 points
, lines
+1, CoordModeOrigin
);
483 physDev
->pen
.width
= oldwidth
;
484 physDev
->pen
.endcap
= oldendcap
;
489 /***********************************************************************
493 X11DRV_Arc( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
494 INT xstart
, INT ystart
, INT xend
, INT yend
)
496 return X11DRV_DrawArc( dc
, left
, top
, right
, bottom
,
497 xstart
, ystart
, xend
, yend
, 0 );
501 /***********************************************************************
505 X11DRV_Pie( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
506 INT xstart
, INT ystart
, INT xend
, INT yend
)
508 return X11DRV_DrawArc( dc
, left
, top
, right
, bottom
,
509 xstart
, ystart
, xend
, yend
, 2 );
512 /***********************************************************************
516 X11DRV_Chord( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
,
517 INT xstart
, INT ystart
, INT xend
, INT yend
)
519 return X11DRV_DrawArc( dc
, left
, top
, right
, bottom
,
520 xstart
, ystart
, xend
, yend
, 1 );
524 /***********************************************************************
528 X11DRV_Ellipse( DC
*dc
, INT left
, INT top
, INT right
, INT bottom
)
531 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
533 left
= XLPTODP( dc
, left
);
534 top
= YLPTODP( dc
, top
);
535 right
= XLPTODP( dc
, right
);
536 bottom
= YLPTODP( dc
, bottom
);
537 if ((left
== right
) || (top
== bottom
)) return TRUE
;
539 if (right
< left
) { INT tmp
= right
; right
= left
; left
= tmp
; }
540 if (bottom
< top
) { INT tmp
= bottom
; bottom
= top
; top
= tmp
; }
542 oldwidth
= width
= physDev
->pen
.width
;
543 if (!width
) width
= 1;
544 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
546 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
548 if (2*width
> (right
-left
)) width
=(right
-left
+ 1)/2;
549 if (2*width
> (bottom
-top
)) width
=(bottom
-top
+ 1)/2;
551 right
-= (width
- 1) / 2;
553 bottom
-= (width
- 1) / 2;
555 if(width
== 0) width
= 1; /* more accurate */
556 physDev
->pen
.width
= width
;
558 if (X11DRV_SetupGCForBrush( dc
))
559 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
560 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
561 right
-left
-1, bottom
-top
-1, 0, 360*64 );
562 if (X11DRV_SetupGCForPen( dc
))
563 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
564 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
565 right
-left
-1, bottom
-top
-1, 0, 360*64 );
566 physDev
->pen
.width
= oldwidth
;
571 /***********************************************************************
575 X11DRV_Rectangle(DC
*dc
, INT left
, INT top
, INT right
, INT bottom
)
577 INT width
, oldwidth
, oldjoinstyle
;
578 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
580 TRACE("(%d %d %d %d)\n",
581 left
, top
, right
, bottom
);
583 left
= XLPTODP( dc
, left
);
584 top
= YLPTODP( dc
, top
);
585 right
= XLPTODP( dc
, right
);
586 bottom
= YLPTODP( dc
, bottom
);
588 if ((left
== right
) || (top
== bottom
)) return TRUE
;
590 if (right
< left
) { INT tmp
= right
; right
= left
; left
= tmp
; }
591 if (bottom
< top
) { INT tmp
= bottom
; bottom
= top
; top
= tmp
; }
593 oldwidth
= width
= physDev
->pen
.width
;
594 if (!width
) width
= 1;
595 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
597 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
599 if (2*width
> (right
-left
)) width
=(right
-left
+ 1)/2;
600 if (2*width
> (bottom
-top
)) width
=(bottom
-top
+ 1)/2;
602 right
-= (width
- 1) / 2;
604 bottom
-= (width
- 1) / 2;
606 if(width
== 1) width
= 0;
607 physDev
->pen
.width
= width
;
608 oldjoinstyle
= physDev
->pen
.linejoin
;
609 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
610 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
612 if ((right
> left
+ width
) && (bottom
> top
+ width
))
614 if (X11DRV_SetupGCForBrush( dc
))
615 TSXFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
616 dc
->w
.DCOrgX
+ left
+ (width
+ 1) / 2,
617 dc
->w
.DCOrgY
+ top
+ (width
+ 1) / 2,
618 right
-left
-width
-1, bottom
-top
-width
-1);
620 if (X11DRV_SetupGCForPen( dc
))
621 TSXDrawRectangle( display
, physDev
->drawable
, physDev
->gc
,
622 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
623 right
-left
-1, bottom
-top
-1 );
625 physDev
->pen
.width
= oldwidth
;
626 physDev
->pen
.linejoin
= oldjoinstyle
;
630 /***********************************************************************
634 X11DRV_RoundRect( DC
*dc
, INT left
, INT top
, INT right
,
635 INT bottom
, INT ell_width
, INT ell_height
)
637 INT width
, oldwidth
, oldendcap
;
638 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
640 TRACE("(%d %d %d %d %d %d\n",
641 left
, top
, right
, bottom
, ell_width
, ell_height
);
643 left
= XLPTODP( dc
, left
);
644 top
= YLPTODP( dc
, top
);
645 right
= XLPTODP( dc
, right
);
646 bottom
= YLPTODP( dc
, bottom
);
648 if ((left
== right
) || (top
== bottom
))
651 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
652 called with width/height < 0 */
653 ell_width
= MAX(abs( ell_width
* dc
->vportExtX
/ dc
->wndExtX
), 1);
654 ell_height
= MAX(abs( ell_height
* dc
->vportExtY
/ dc
->wndExtY
), 1);
656 /* Fix the coordinates */
658 if (right
< left
) { INT tmp
= right
; right
= left
; left
= tmp
; }
659 if (bottom
< top
) { INT tmp
= bottom
; bottom
= top
; top
= tmp
; }
661 oldwidth
= width
= physDev
->pen
.width
;
662 oldendcap
= physDev
->pen
.endcap
;
663 if (!width
) width
= 1;
664 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
666 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
668 if (2*width
> (right
-left
)) width
=(right
-left
+ 1)/2;
669 if (2*width
> (bottom
-top
)) width
=(bottom
-top
+ 1)/2;
671 right
-= (width
- 1) / 2;
673 bottom
-= (width
- 1) / 2;
675 if(width
== 0) width
= 1;
676 physDev
->pen
.width
= width
;
677 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
679 if (X11DRV_SetupGCForBrush( dc
))
681 if (ell_width
> (right
-left
) )
682 if (ell_height
> (bottom
-top
) )
683 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
684 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
685 right
- left
- 1, bottom
- top
- 1,
688 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
689 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
690 right
- left
- 1, ell_height
, 0, 180 * 64 );
691 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
693 dc
->w
.DCOrgY
+ bottom
- ell_height
- 1,
694 right
- left
- 1, ell_height
, 180 * 64,
697 else if (ell_height
> (bottom
-top
) ){
698 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
699 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
700 ell_width
, bottom
- top
- 1, 90 * 64, 180 * 64 );
701 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
702 dc
->w
.DCOrgX
+ right
- ell_width
-1, dc
->w
.DCOrgY
+ top
,
703 ell_width
, bottom
- top
- 1, 270 * 64, 180 * 64 );
705 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
706 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
707 ell_width
, ell_height
, 90 * 64, 90 * 64 );
708 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
710 dc
->w
.DCOrgY
+ bottom
- ell_height
- 1,
711 ell_width
, ell_height
, 180 * 64, 90 * 64 );
712 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
713 dc
->w
.DCOrgX
+ right
- ell_width
- 1,
714 dc
->w
.DCOrgY
+ bottom
- ell_height
- 1,
715 ell_width
, ell_height
, 270 * 64, 90 * 64 );
716 TSXFillArc( display
, physDev
->drawable
, physDev
->gc
,
717 dc
->w
.DCOrgX
+ right
- ell_width
- 1,
719 ell_width
, ell_height
, 0, 90 * 64 );
721 if (ell_width
< right
- left
)
723 TSXFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
724 dc
->w
.DCOrgX
+ left
+ (ell_width
+ 1) / 2,
725 dc
->w
.DCOrgY
+ top
+ 1,
726 right
- left
- ell_width
- 1,
727 (ell_height
+ 1) / 2 - 1);
728 TSXFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
729 dc
->w
.DCOrgX
+ left
+ (ell_width
+ 1) / 2,
730 dc
->w
.DCOrgY
+ bottom
- (ell_height
) / 2 - 1,
731 right
- left
- ell_width
- 1,
734 if (ell_height
< bottom
- top
)
736 TSXFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
737 dc
->w
.DCOrgX
+ left
+ 1,
738 dc
->w
.DCOrgY
+ top
+ (ell_height
+ 1) / 2,
740 bottom
- top
- ell_height
- 1);
743 /* FIXME: this could be done with on X call
744 * more efficient and probably more correct
745 * on any X server: XDrawArcs will draw
746 * straight horizontal and vertical lines
747 * if width or height are zero.
749 * BTW this stuff is optimized for an Xfree86 server
750 * read the comments inside the X11DRV_DrawArc function
752 if (X11DRV_SetupGCForPen(dc
)) {
753 if (ell_width
> (right
-left
) )
754 if (ell_height
> (bottom
-top
) )
755 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
756 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
757 right
- left
- 1, bottom
-top
- 1, 0 , 360 * 64 );
759 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
760 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
761 right
- left
- 1, ell_height
- 1, 0 , 180 * 64 );
762 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
764 dc
->w
.DCOrgY
+ bottom
- ell_height
,
765 right
- left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
767 else if (ell_height
> (bottom
-top
) ){
768 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
769 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
770 ell_width
- 1 , bottom
- top
- 1, 90 * 64 , 180 * 64 );
771 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
772 dc
->w
.DCOrgX
+ right
- ell_width
,
774 ell_width
- 1 , bottom
- top
- 1, 270 * 64 , 180 * 64 );
776 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
777 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ top
,
778 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
779 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
780 dc
->w
.DCOrgX
+ left
, dc
->w
.DCOrgY
+ bottom
- ell_height
,
781 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
782 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
783 dc
->w
.DCOrgX
+ right
- ell_width
,
784 dc
->w
.DCOrgY
+ bottom
- ell_height
,
785 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
786 TSXDrawArc( display
, physDev
->drawable
, physDev
->gc
,
787 dc
->w
.DCOrgX
+ right
- ell_width
, dc
->w
.DCOrgY
+ top
,
788 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
790 if (ell_width
< right
- left
)
792 TSXDrawLine( display
, physDev
->drawable
, physDev
->gc
,
793 dc
->w
.DCOrgX
+ left
+ ell_width
/ 2,
795 dc
->w
.DCOrgX
+ right
- (ell_width
+1) / 2,
797 TSXDrawLine( display
, physDev
->drawable
, physDev
->gc
,
798 dc
->w
.DCOrgX
+ left
+ ell_width
/ 2 ,
799 dc
->w
.DCOrgY
+ bottom
- 1,
800 dc
->w
.DCOrgX
+ right
- (ell_width
+1)/ 2,
801 dc
->w
.DCOrgY
+ bottom
- 1);
803 if (ell_height
< bottom
- top
)
805 TSXDrawLine( display
, physDev
->drawable
, physDev
->gc
,
806 dc
->w
.DCOrgX
+ right
- 1,
807 dc
->w
.DCOrgY
+ top
+ ell_height
/ 2,
808 dc
->w
.DCOrgX
+ right
- 1,
809 dc
->w
.DCOrgY
+ bottom
- (ell_height
+1) / 2);
810 TSXDrawLine( display
, physDev
->drawable
, physDev
->gc
,
812 dc
->w
.DCOrgY
+ top
+ ell_height
/ 2,
814 dc
->w
.DCOrgY
+ bottom
- (ell_height
+1) / 2);
817 physDev
->pen
.width
= oldwidth
;
818 physDev
->pen
.endcap
= oldendcap
;
823 /***********************************************************************
827 X11DRV_SetPixel( DC
*dc
, INT x
, INT y
, COLORREF color
)
830 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
832 x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, x
);
833 y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, y
);
834 pixel
= X11DRV_PALETTE_ToPhysical( dc
, color
);
836 TSXSetForeground( display
, physDev
->gc
, pixel
);
837 TSXSetFunction( display
, physDev
->gc
, GXcopy
);
838 TSXDrawPoint( display
, physDev
->drawable
, physDev
->gc
, x
, y
);
840 /* inefficient but simple... */
842 return X11DRV_PALETTE_ToLogical(pixel
);
846 /***********************************************************************
850 X11DRV_GetPixel( DC
*dc
, INT x
, INT y
)
852 static Pixmap pixmap
= 0;
855 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
857 x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, x
);
858 y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, y
);
859 EnterCriticalSection( &X11DRV_CritSection
);
860 if (dc
->w
.flags
& DC_MEMORY
)
862 image
= XGetImage( display
, physDev
->drawable
, x
, y
, 1, 1,
863 AllPlanes
, ZPixmap
);
867 /* If we are reading from the screen, use a temporary copy */
868 /* to avoid a BadMatch error */
869 if (!pixmap
) pixmap
= XCreatePixmap( display
, X11DRV_GetXRootWindow(),
870 1, 1, dc
->w
.bitsPerPixel
);
871 XCopyArea( display
, physDev
->drawable
, pixmap
, BITMAP_colorGC
,
873 image
= XGetImage( display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
875 pixel
= XGetPixel( image
, 0, 0 );
876 XDestroyImage( image
);
877 LeaveCriticalSection( &X11DRV_CritSection
);
879 return X11DRV_PALETTE_ToLogical(pixel
);
883 /***********************************************************************
887 X11DRV_PaintRgn( DC
*dc
, HRGN hrgn
)
890 HRGN tmpVisRgn
, prevVisRgn
;
891 HDC hdc
= dc
->hSelf
; /* FIXME: should not mix dc/hdc this way */
892 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
894 if (!(tmpVisRgn
= CreateRectRgn( 0, 0, 0, 0 ))) return FALSE
;
896 /* Transform region into device co-ords */
897 if ( !REGION_LPTODP( hdc
, tmpVisRgn
, hrgn
)
898 || OffsetRgn( tmpVisRgn
, dc
->w
.DCOrgX
, dc
->w
.DCOrgY
) == ERROR
) {
899 DeleteObject( tmpVisRgn
);
903 /* Modify visible region */
904 if (!(prevVisRgn
= SaveVisRgn16( hdc
))) {
905 DeleteObject( tmpVisRgn
);
908 CombineRgn( tmpVisRgn
, prevVisRgn
, tmpVisRgn
, RGN_AND
);
909 SelectVisRgn16( hdc
, tmpVisRgn
);
910 DeleteObject( tmpVisRgn
);
912 /* Fill the region */
914 GetRgnBox( dc
->w
.hGCClipRgn
, &box
);
915 if (X11DRV_SetupGCForBrush( dc
))
916 TSXFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
918 box
.right
-box
.left
, box
.bottom
-box
.top
);
920 /* Restore the visible region */
922 RestoreVisRgn16( hdc
);
926 /**********************************************************************
930 X11DRV_Polyline( DC
*dc
, const POINT
* pt
, INT count
)
935 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
937 if((oldwidth
= physDev
->pen
.width
) == 0) physDev
->pen
.width
= 1;
939 points
= (XPoint
*) xmalloc (sizeof (XPoint
) * (count
));
940 for (i
= 0; i
< count
; i
++)
942 points
[i
].x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, pt
[i
].x
);
943 points
[i
].y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, pt
[i
].y
);
946 if (X11DRV_SetupGCForPen ( dc
))
947 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
948 points
, count
, CoordModeOrigin
);
951 physDev
->pen
.width
= oldwidth
;
956 /**********************************************************************
960 X11DRV_Polygon( DC
*dc
, const POINT
* pt
, INT count
)
964 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
966 points
= (XPoint
*) xmalloc (sizeof (XPoint
) * (count
+1));
967 for (i
= 0; i
< count
; i
++)
969 points
[i
].x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, pt
[i
].x
);
970 points
[i
].y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, pt
[i
].y
);
972 points
[count
] = points
[0];
974 if (X11DRV_SetupGCForBrush( dc
))
975 TSXFillPolygon( display
, physDev
->drawable
, physDev
->gc
,
976 points
, count
+1, Complex
, CoordModeOrigin
);
978 if (X11DRV_SetupGCForPen ( dc
))
979 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
980 points
, count
+1, CoordModeOrigin
);
987 /**********************************************************************
991 X11DRV_PolyPolygon( DC
*dc
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
994 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
996 /* FIXME: The points should be converted to device coords before */
997 /* creating the region. */
999 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, dc
->w
.polyFillMode
);
1000 X11DRV_PaintRgn( dc
, hrgn
);
1001 DeleteObject( hrgn
);
1003 /* Draw the outline of the polygons */
1005 if (X11DRV_SetupGCForPen ( dc
))
1010 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1011 points
= (XPoint
*) xmalloc( sizeof(XPoint
) * (max
+1) );
1013 for (i
= 0; i
< polygons
; i
++)
1015 for (j
= 0; j
< counts
[i
]; j
++)
1017 points
[j
].x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, pt
->x
);
1018 points
[j
].y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, pt
->y
);
1021 points
[j
] = points
[0];
1022 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
1023 points
, j
+ 1, CoordModeOrigin
);
1031 /**********************************************************************
1032 * X11DRV_PolyPolyline
1035 X11DRV_PolyPolyline( DC
*dc
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1037 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1038 if (X11DRV_SetupGCForPen ( dc
))
1043 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1044 points
= (XPoint
*) xmalloc( sizeof(XPoint
) * (max
+1) );
1046 for (i
= 0; i
< polylines
; i
++)
1048 for (j
= 0; j
< counts
[i
]; j
++)
1050 points
[j
].x
= dc
->w
.DCOrgX
+ XLPTODP( dc
, pt
->x
);
1051 points
[j
].y
= dc
->w
.DCOrgY
+ YLPTODP( dc
, pt
->y
);
1054 points
[j
] = points
[0];
1055 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
1056 points
, j
+ 1, CoordModeOrigin
);
1064 /**********************************************************************
1065 * X11DRV_InternalFloodFill
1067 * Internal helper function for flood fill.
1068 * (xorg,yorg) is the origin of the X image relative to the drawable.
1069 * (x,y) is relative to the origin of the X image.
1071 static void X11DRV_InternalFloodFill(XImage
*image
, DC
*dc
,
1074 Pixel pixel
, WORD fillType
)
1076 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1079 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1080 (XGetPixel(image,x,y) != pixel) : \
1081 (XGetPixel(image,x,y) == pixel))
1083 if (!TO_FLOOD(x
,y
)) return;
1085 /* Find left and right boundaries */
1088 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1089 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1090 XFillRectangle( display
, physDev
->drawable
, physDev
->gc
,
1091 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1093 /* Set the pixels of this line so we don't fill it again */
1095 for (x
= left
; x
< right
; x
++)
1097 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1098 else XPutPixel( image
, x
, y
, ~pixel
);
1101 /* Fill the line above */
1108 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1109 if (x
>= right
) break;
1110 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1111 X11DRV_InternalFloodFill(image
, dc
, x
-1, y
,
1112 xOrg
, yOrg
, pixel
, fillType
);
1116 /* Fill the line below */
1118 if ((y
+= 2) < image
->height
)
1123 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1124 if (x
>= right
) break;
1125 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1126 X11DRV_InternalFloodFill(image
, dc
, x
-1, y
,
1127 xOrg
, yOrg
, pixel
, fillType
);
1134 /**********************************************************************
1135 * X11DRV_DoFloodFill
1137 * Main flood-fill routine.
1139 * The Xlib critical section must be entered before calling this function.
1142 struct FloodFill_params
1151 static BOOL
X11DRV_DoFloodFill( const struct FloodFill_params
*params
)
1155 DC
*dc
= params
->dc
;
1156 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1158 if (GetRgnBox( dc
->w
.hGCClipRgn
, &rect
) == ERROR
) return FALSE
;
1160 if (!(image
= XGetImage( display
, physDev
->drawable
,
1163 rect
.right
- rect
.left
,
1164 rect
.bottom
- rect
.top
,
1165 AllPlanes
, ZPixmap
))) return FALSE
;
1167 if (X11DRV_SetupGCForBrush( dc
))
1169 /* ROP mode is always GXcopy for flood-fill */
1170 XSetFunction( display
, physDev
->gc
, GXcopy
);
1171 X11DRV_InternalFloodFill(image
, dc
,
1172 XLPTODP(dc
,params
->x
) + dc
->w
.DCOrgX
- rect
.left
,
1173 YLPTODP(dc
,params
->y
) + dc
->w
.DCOrgY
- rect
.top
,
1176 X11DRV_PALETTE_ToPhysical( dc
, params
->color
),
1180 XDestroyImage( image
);
1185 /**********************************************************************
1186 * X11DRV_ExtFloodFill
1189 X11DRV_ExtFloodFill( DC
*dc
, INT x
, INT y
, COLORREF color
,
1193 struct FloodFill_params params
;
1195 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n",
1196 x
, y
, color
, fillType
);
1201 params
.color
= color
;
1202 params
.fillType
= fillType
;
1204 if (!PtVisible( dc
->hSelf
, x
, y
)) return FALSE
;
1205 EnterCriticalSection( &X11DRV_CritSection
);
1206 result
= CALL_LARGE_STACK( X11DRV_DoFloodFill
, ¶ms
);
1207 LeaveCriticalSection( &X11DRV_CritSection
);
1211 /******************************************************************
1213 * *Very* simple bezier drawing code,
1215 * It uses a recursive algorithm to divide the curve in a series
1216 * of straight line segements. Not ideal but for me sufficient.
1217 * If you are in need for something better look for some incremental
1220 * 7 July 1998 Rein Klazes
1224 * some macro definitions for bezier drawing
1226 * to avoid trucation errors the coordinates are
1227 * shifted upwards. When used in drawing they are
1228 * shifted down again, including correct rounding
1229 * and avoiding floating point arithmatic
1230 * 4 bits should allow 27 bits coordinates which I saw
1231 * somewere in the win32 doc's
1235 #define BEZIERSHIFTBITS 4
1236 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
1237 #define BEZIERPIXEL BEZIERSHIFTUP(1)
1238 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
1239 /* maximum depth of recursion */
1240 #define BEZIERMAXDEPTH 8
1242 /* size of array to store points on */
1243 /* enough for one curve */
1244 #define BEZMAXPOINTS (150)
1246 /* calculate Bezier average, in this case the middle
1247 * correctly rounded...
1250 #define BEZIERMIDDLE(Mid, P1, P2) \
1251 (Mid).x=((P1).x+(P2).x + 1)/2;\
1252 (Mid).y=((P1).y+(P2).y + 1)/2;
1254 /**********************************************************
1255 * BezierCheck helper function to check
1256 * that recursion can be terminated
1257 * Points[0] and Points[3] are begin and endpoint
1258 * Points[1] and Points[2] are control points
1259 * level is the recursion depth
1260 * returns true if the recusion can be terminated
1262 static BOOL
BezierCheck( int level
, POINT
*Points
)
1265 dx
=Points
[3].x
-Points
[0].x
;
1266 dy
=Points
[3].y
-Points
[0].y
;
1267 if(ABS(dy
)<=ABS(dx
)){/* shallow line */
1268 /* check that control points are between begin and end */
1269 if(Points
[1].x
< Points
[0].x
){
1270 if(Points
[1].x
< Points
[3].x
)
1273 if(Points
[1].x
> Points
[3].x
)
1275 if(Points
[2].x
< Points
[0].x
){
1276 if(Points
[2].x
< Points
[3].x
)
1279 if(Points
[2].x
> Points
[3].x
)
1281 dx
=BEZIERSHIFTDOWN(dx
);
1282 if(!dx
) return TRUE
;
1283 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
1284 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
1285 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
1286 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
1290 }else{ /* steep line */
1291 /* check that control points are between begin and end */
1292 if(Points
[1].y
< Points
[0].y
){
1293 if(Points
[1].y
< Points
[3].y
)
1296 if(Points
[1].y
> Points
[3].y
)
1298 if(Points
[2].y
< Points
[0].y
){
1299 if(Points
[2].y
< Points
[3].y
)
1302 if(Points
[2].y
> Points
[3].y
)
1304 dy
=BEZIERSHIFTDOWN(dy
);
1305 if(!dy
) return TRUE
;
1306 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
1307 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
1308 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
1309 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1316 /***********************************************************************
1318 * Draw a -what microsoft calls- bezier curve
1319 * The routine recursively devides the curve
1320 * in two parts until a straight line can be drawn
1322 * level recusion depth counted backwards
1324 * Points array of begin(0), end(3) and control points(1 and 2)
1325 * XPoints array with points calculated sofar
1326 * *pIx nr points calculated sofar
1329 static void X11DRV_Bezier(int level
, DC
* dc
, POINT
*Points
,
1330 XPoint
* xpoints
, unsigned int* pIx
)
1332 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1334 if(*pIx
== BEZMAXPOINTS
){
1335 if (X11DRV_SetupGCForPen( dc
))
1336 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
1337 xpoints
, *pIx
, CoordModeOrigin
);
1340 if(!level
|| BezierCheck(level
, Points
)) {
1342 xpoints
[*pIx
].x
= dc
->w
.DCOrgX
+ BEZIERSHIFTDOWN(Points
[0].x
);
1343 xpoints
[*pIx
].y
= dc
->w
.DCOrgY
+ BEZIERSHIFTDOWN(Points
[0].y
);
1346 xpoints
[*pIx
].x
= dc
->w
.DCOrgX
+ BEZIERSHIFTDOWN(Points
[3].x
);
1347 xpoints
[*pIx
].y
= dc
->w
.DCOrgY
+ BEZIERSHIFTDOWN(Points
[3].y
);
1350 POINT Points2
[4]; /* for the second recursive call */
1351 Points2
[3]=Points
[3];
1352 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1353 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1354 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1356 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1357 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1358 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1360 Points2
[0]=Points
[3];
1362 /* do the two halves */
1363 X11DRV_Bezier(level
-1, dc
, Points
, xpoints
, pIx
);
1364 X11DRV_Bezier(level
-1, dc
, Points2
, xpoints
, pIx
);
1368 /***********************************************************************
1370 * Implement functionality for PolyBezier and PolyBezierTo
1372 * [i] dc pointer to device context
1373 * [i] start, first point in curve
1374 * [i] BezierPoints , array of point filled with rest of the points
1375 * [i] count, number of points in BezierPoints, must be a
1379 X11DRV_PolyBezier(DC
*dc
, POINT start
, const POINT
* BezierPoints
, DWORD count
)
1385 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1387 TRACE("dc=%p count=%ld %ld,%ld - %ld,%ld - %ld,%ld - %ld,%ld\n",
1390 (BezierPoints
+0)->x
, (BezierPoints
+0)->y
,
1391 (BezierPoints
+1)->x
, (BezierPoints
+1)->y
,
1392 (BezierPoints
+2)->x
, (BezierPoints
+2)->y
);
1393 if(!count
|| count
% 3){/* paranoid */
1394 WARN(" bad value for count : %ld\n", count
);
1397 xpoints
=(XPoint
*) xmalloc( sizeof(XPoint
)*BEZMAXPOINTS
);
1398 start
.x
=BEZIERSHIFTUP(XLPTODP(dc
,start
.x
));
1399 start
.y
=BEZIERSHIFTUP(YLPTODP(dc
,start
.y
));
1403 Points
[i
].x
= BEZIERSHIFTUP(XLPTODP(dc
,BezierPoints
->x
));
1404 Points
[i
].y
= BEZIERSHIFTUP(YLPTODP(dc
,BezierPoints
->y
));
1408 X11DRV_Bezier(BEZIERMAXDEPTH
, dc
, Points
, xpoints
, &ix
);
1411 if (ix
&& X11DRV_SetupGCForPen( dc
))
1412 TSXDrawLines( display
, physDev
->drawable
, physDev
->gc
,
1413 xpoints
, ix
, CoordModeOrigin
);
1418 /**********************************************************************
1422 X11DRV_SetBkColor( DC
*dc
, COLORREF color
)
1424 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1427 oldColor
= dc
->w
.backgroundColor
;
1428 dc
->w
.backgroundColor
= color
;
1430 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( dc
, color
);
1435 /**********************************************************************
1436 * X11DRV_SetTextColor
1439 X11DRV_SetTextColor( DC
*dc
, COLORREF color
)
1441 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
1444 oldColor
= dc
->w
.textColor
;
1445 dc
->w
.textColor
= color
;
1447 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( dc
, color
);
1452 #endif /* !defined(X_DISPLAY_MISSING) */