2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 Alexandre Julliard
8 * FIXME: none of these functions obey the GM_ADVANCED
14 #include <X11/Intrinsic.h>
39 #include "debugtools.h"
41 DEFAULT_DEBUG_CHANNEL(graphics);
43 #define ABS(x) ((x)<0?(-(x)):(x))
45 /* ROP code to GC function conversion */
46 const int X11DRV_XROPfunction[16] =
48 GXclear, /* R2_BLACK */
49 GXnor, /* R2_NOTMERGEPEN */
50 GXandInverted, /* R2_MASKNOTPEN */
51 GXcopyInverted, /* R2_NOTCOPYPEN */
52 GXandReverse, /* R2_MASKPENNOT */
53 GXinvert, /* R2_NOT */
54 GXxor, /* R2_XORPEN */
55 GXnand, /* R2_NOTMASKPEN */
56 GXand, /* R2_MASKPEN */
57 GXequiv, /* R2_NOTXORPEN */
59 GXorInverted, /* R2_MERGENOTPEN */
60 GXcopy, /* R2_COPYPEN */
61 GXorReverse, /* R2_MERGEPENNOT */
62 GXor, /* R2_MERGEPEN */
67 /***********************************************************************
68 * X11DRV_SetupGCForPatBlt
70 * Setup the GC for a PatBlt operation using current brush.
71 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
72 * Return FALSE if brush is BS_NULL, TRUE otherwise.
74 BOOL X11DRV_SetupGCForPatBlt( DC * dc, GC gc, BOOL fMapColors )
79 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
81 if (physDev->brush.style == BS_NULL) return FALSE;
82 if (physDev->brush.pixel == -1)
84 /* Special case used for monochrome pattern brushes.
85 * We need to swap foreground and background because
86 * Windows does it the wrong way...
88 val.foreground = physDev->backgroundPixel;
89 val.background = physDev->textPixel;
93 val.foreground = physDev->brush.pixel;
94 val.background = physDev->backgroundPixel;
96 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
98 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
99 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
102 val.function = X11DRV_XROPfunction[dc->w.ROPmode-1];
104 ** Let's replace GXinvert by GXxor with (black xor white)
105 ** This solves the selection color and leak problems in excel
106 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
108 if (val.function == GXinvert)
110 val.foreground = BlackPixelOfScreen(X11DRV_GetXScreen()) ^ WhitePixelOfScreen(X11DRV_GetXScreen());
111 val.function = GXxor;
113 val.fill_style = physDev->brush.fillStyle;
114 switch(val.fill_style)
117 case FillOpaqueStippled:
118 if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
119 val.stipple = physDev->brush.pixmap;
124 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
128 EnterCriticalSection( &X11DRV_CritSection );
129 pixmap = XCreatePixmap( display, X11DRV_GetXRootWindow(),
130 8, 8, X11DRV_GetDepth() );
131 image = XGetImage( display, physDev->brush.pixmap, 0, 0, 8, 8,
132 AllPlanes, ZPixmap );
133 for (y = 0; y < 8; y++)
134 for (x = 0; x < 8; x++)
135 XPutPixel( image, x, y,
136 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
137 XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
138 XDestroyImage( image );
139 LeaveCriticalSection( &X11DRV_CritSection );
142 else val.tile = physDev->brush.pixmap;
150 val.ts_x_origin = dc->w.DCOrgX + dc->w.brushOrgX;
151 val.ts_y_origin = dc->w.DCOrgY + dc->w.brushOrgY;
152 val.fill_rule = (dc->w.polyFillMode==WINDING) ? WindingRule : EvenOddRule;
153 TSXChangeGC( display, gc,
154 GCFunction | GCForeground | GCBackground | GCFillStyle |
155 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
157 if (pixmap) TSXFreePixmap( display, pixmap );
162 /***********************************************************************
163 * X11DRV_SetupGCForBrush
165 * Setup physDev->gc for drawing operations using current brush.
166 * Return FALSE if brush is BS_NULL, TRUE otherwise.
168 BOOL X11DRV_SetupGCForBrush( DC * dc )
170 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
171 return X11DRV_SetupGCForPatBlt( dc, physDev->gc, FALSE );
175 /***********************************************************************
176 * X11DRV_SetupGCForPen
178 * Setup physDev->gc for drawing operations using current pen.
179 * Return FALSE if pen is PS_NULL, TRUE otherwise.
181 BOOL X11DRV_SetupGCForPen( DC * dc )
184 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
186 if (physDev->pen.style == PS_NULL) return FALSE;
188 switch (dc->w.ROPmode)
191 val.foreground = BlackPixelOfScreen( X11DRV_GetXScreen() );
192 val.function = GXcopy;
195 val.foreground = WhitePixelOfScreen( X11DRV_GetXScreen() );
196 val.function = GXcopy;
199 val.foreground = physDev->pen.pixel;
200 /* It is very unlikely someone wants to XOR with 0 */
201 /* This fixes the rubber-drawings in paintbrush */
202 if (val.foreground == 0)
203 val.foreground = BlackPixelOfScreen( X11DRV_GetXScreen() )
204 ^ WhitePixelOfScreen( X11DRV_GetXScreen() );
205 val.function = GXxor;
208 val.foreground = physDev->pen.pixel;
209 val.function = X11DRV_XROPfunction[dc->w.ROPmode-1];
211 val.background = physDev->backgroundPixel;
212 val.fill_style = FillSolid;
213 if ((physDev->pen.width <= 1) &&
214 (physDev->pen.style != PS_SOLID) &&
215 (physDev->pen.style != PS_INSIDEFRAME))
217 TSXSetDashes( display, physDev->gc, 0, physDev->pen.dashes,
218 physDev->pen.dash_len );
219 val.line_style = (dc->w.backgroundMode == OPAQUE) ?
220 LineDoubleDash : LineOnOffDash;
222 else val.line_style = LineSolid;
223 val.line_width = physDev->pen.width;
224 if (val.line_width <= 1) {
225 val.cap_style = CapNotLast;
227 switch (physDev->pen.endcap)
229 case PS_ENDCAP_SQUARE:
230 val.cap_style = CapProjecting;
233 val.cap_style = CapButt;
235 case PS_ENDCAP_ROUND:
237 val.cap_style = CapRound;
240 switch (physDev->pen.linejoin)
243 val.join_style = JoinBevel;
246 val.join_style = JoinMiter;
250 val.join_style = JoinRound;
252 TSXChangeGC( display, physDev->gc,
253 GCFunction | GCForeground | GCBackground | GCLineWidth |
254 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
259 /***********************************************************************
260 * X11DRV_SetupGCForText
262 * Setup physDev->gc for text drawing operations.
263 * Return FALSE if the font is null, TRUE otherwise.
265 BOOL X11DRV_SetupGCForText( DC * dc )
267 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
268 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
274 val.function = GXcopy; /* Text is always GXcopy */
275 val.foreground = physDev->textPixel;
276 val.background = physDev->backgroundPixel;
277 val.fill_style = FillSolid;
280 TSXChangeGC( display, physDev->gc,
281 GCFunction | GCForeground | GCBackground | GCFillStyle |
285 WARN("Physical font failure\n" );
289 /***********************************************************************
293 X11DRV_LineTo( DC *dc, INT x, INT y )
295 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
297 if (X11DRV_SetupGCForPen( dc )) {
298 /* Update the pixmap from the DIB section */
299 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
300 TSXDrawLine(display, physDev->drawable, physDev->gc,
301 dc->w.DCOrgX + XLPTODP( dc, dc->w.CursPosX ),
302 dc->w.DCOrgY + YLPTODP( dc, dc->w.CursPosY ),
303 dc->w.DCOrgX + XLPTODP( dc, x ),
304 dc->w.DCOrgY + YLPTODP( dc, y ) );
305 /* Update the DIBSection from the pixmap */
306 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
313 /***********************************************************************
316 * Helper functions for Arc(), Chord() and Pie().
317 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
321 X11DRV_DrawArc( DC *dc, INT left, INT top, INT right,
322 INT bottom, INT xstart, INT ystart,
323 INT xend, INT yend, INT lines )
325 INT xcenter, ycenter, istart_angle, idiff_angle;
326 INT width, oldwidth, oldendcap;
327 double start_angle, end_angle;
329 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
332 left = XLPTODP( dc, left );
333 top = YLPTODP( dc, top );
334 right = XLPTODP( dc, right );
335 bottom = YLPTODP( dc, bottom );
336 xstart = XLPTODP( dc, xstart );
337 ystart = YLPTODP( dc, ystart );
338 xend = XLPTODP( dc, xend );
339 yend = YLPTODP( dc, yend );
341 if (right < left) { INT tmp = right; right = left; left = tmp; }
342 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
343 if ((left == right) || (top == bottom)
344 ||(lines && ((right-left==1)||(bottom-top==1)))) return TRUE;
346 if( dc->w.ArcDirection == AD_CLOCKWISE )
347 { INT tmp = xstart; xstart = xend; xend = tmp;
348 tmp = ystart; ystart = yend; yend = tmp; }
350 oldwidth = width = physDev->pen.width;
351 oldendcap = physDev->pen.endcap;
352 if (!width) width = 1;
353 if(physDev->pen.style == PS_NULL) width = 0;
355 if ((physDev->pen.style == PS_INSIDEFRAME))
357 if (2*width > (right-left)) width=(right-left + 1)/2;
358 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
360 right -= (width - 1) / 2;
362 bottom -= (width - 1) / 2;
364 if(width == 0) width = 1; /* more accurate */
365 physDev->pen.width = width;
366 physDev->pen.endcap = PS_ENDCAP_SQUARE;
368 xcenter = (right + left) / 2;
369 ycenter = (bottom + top) / 2;
370 start_angle = atan2( (double)(ycenter-ystart)*(right-left),
371 (double)(xstart-xcenter)*(bottom-top) );
372 end_angle = atan2( (double)(ycenter-yend)*(right-left),
373 (double)(xend-xcenter)*(bottom-top) );
374 if ((xstart==xend)&&(ystart==yend))
375 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
379 else /* notorious cases */
380 if ((start_angle == PI)&&( end_angle <0))
383 if ((end_angle == PI)&&( start_angle <0))
385 istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
386 idiff_angle = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
387 if (idiff_angle <= 0) idiff_angle += 360 * 64;
389 /* Update the pixmap from the DIB section */
390 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
392 /* Fill arc with brush if Chord() or Pie() */
394 if ((lines > 0) && X11DRV_SetupGCForBrush( dc )) {
395 TSXSetArcMode( display, physDev->gc,
396 (lines==1) ? ArcChord : ArcPieSlice);
397 TSXFillArc( display, physDev->drawable, physDev->gc,
398 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
399 right-left-1, bottom-top-1, istart_angle, idiff_angle );
403 /* Draw arc and lines */
405 if (X11DRV_SetupGCForPen( dc )){
406 TSXDrawArc( display, physDev->drawable, physDev->gc,
407 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
408 right-left-1, bottom-top-1, istart_angle, idiff_angle );
410 /* use the truncated values */
411 start_angle=(double)istart_angle*PI/64./180.;
412 end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
413 /* calculate the endpoints and round correctly */
414 points[0].x = (int) floor(dc->w.DCOrgX + (right+left)/2.0 +
415 cos(start_angle) * (right-left-width*2+2) / 2. + 0.5);
416 points[0].y = (int) floor(dc->w.DCOrgY + (top+bottom)/2.0 -
417 sin(start_angle) * (bottom-top-width*2+2) / 2. + 0.5);
418 points[1].x = (int) floor(dc->w.DCOrgX + (right+left)/2.0 +
419 cos(end_angle) * (right-left-width*2+2) / 2. + 0.5);
420 points[1].y = (int) floor(dc->w.DCOrgY + (top+bottom)/2.0 -
421 sin(end_angle) * (bottom-top-width*2+2) / 2. + 0.5);
423 /* OK this stuff is optimized for Xfree86
424 * which is probably the most used server by
425 * wine users. Other X servers will not
426 * display correctly. (eXceed for instance)
427 * so if you feel you must change make sure that
428 * you either use Xfree86 or seperate your changes
429 * from these (compile switch or whatever)
433 points[3] = points[1];
434 points[1].x = dc->w.DCOrgX + xcenter;
435 points[1].y = dc->w.DCOrgY + ycenter;
436 points[2] = points[1];
437 dx1=points[1].x-points[0].x;
438 dy1=points[1].y-points[0].y;
439 if(((top-bottom) | -2) == -2)
440 if(dy1>0) points[1].y--;
442 if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
443 if(((-dx1*9))<(dy1*16)) points[0].y--;
444 if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
446 if(dy1 < 0) points[0].y--;
447 if(((right-left) | -2) == -2) points[1].x--;
449 dx1=points[3].x-points[2].x;
450 dy1=points[3].y-points[2].y;
451 if(((top-bottom) | -2 ) == -2)
452 if(dy1 < 0) points[2].y--;
454 if( dy1>0) points[3].y--;
455 if(((right-left) | -2) == -2 ) points[2].x--;
458 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
462 TSXDrawLines( display, physDev->drawable, physDev->gc,
463 points, lines+1, CoordModeOrigin );
468 /* Update the DIBSection of the pixmap */
469 if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE);
471 physDev->pen.width = oldwidth;
472 physDev->pen.endcap = oldendcap;
477 /***********************************************************************
481 X11DRV_Arc( DC *dc, INT left, INT top, INT right, INT bottom,
482 INT xstart, INT ystart, INT xend, INT yend )
484 return X11DRV_DrawArc( dc, left, top, right, bottom,
485 xstart, ystart, xend, yend, 0 );
489 /***********************************************************************
493 X11DRV_Pie( 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, 2 );
500 /***********************************************************************
504 X11DRV_Chord( DC *dc, INT left, INT top, INT right, INT bottom,
505 INT xstart, INT ystart, INT xend, INT yend )
507 return X11DRV_DrawArc( dc, left, top, right, bottom,
508 xstart, ystart, xend, yend, 1 );
512 /***********************************************************************
516 X11DRV_Ellipse( DC *dc, INT left, INT top, INT right, INT bottom )
519 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
522 left = XLPTODP( dc, left );
523 top = YLPTODP( dc, top );
524 right = XLPTODP( dc, right );
525 bottom = YLPTODP( dc, bottom );
526 if ((left == right) || (top == bottom)) return TRUE;
528 if (right < left) { INT tmp = right; right = left; left = tmp; }
529 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
531 oldwidth = width = physDev->pen.width;
532 if (!width) width = 1;
533 if(physDev->pen.style == PS_NULL) width = 0;
535 if ((physDev->pen.style == PS_INSIDEFRAME))
537 if (2*width > (right-left)) width=(right-left + 1)/2;
538 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
540 right -= (width - 1) / 2;
542 bottom -= (width - 1) / 2;
544 if(width == 0) width = 1; /* more accurate */
545 physDev->pen.width = width;
547 /* Update the pixmap from the DIB section */
548 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
550 if (X11DRV_SetupGCForBrush( dc ))
552 TSXFillArc( display, physDev->drawable, physDev->gc,
553 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
554 right-left-1, bottom-top-1, 0, 360*64 );
557 if (X11DRV_SetupGCForPen( dc ))
559 TSXDrawArc( display, physDev->drawable, physDev->gc,
560 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
561 right-left-1, bottom-top-1, 0, 360*64 );
565 /* Update the DIBSection from the pixmap */
566 if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE);
568 physDev->pen.width = oldwidth;
573 /***********************************************************************
577 X11DRV_Rectangle(DC *dc, INT left, INT top, INT right, INT bottom)
579 INT width, oldwidth, oldjoinstyle;
580 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
583 TRACE("(%d %d %d %d)\n",
584 left, top, right, bottom);
586 left = XLPTODP( dc, left );
587 top = YLPTODP( dc, top );
588 right = XLPTODP( dc, right );
589 bottom = YLPTODP( dc, bottom );
591 if ((left == right) || (top == bottom)) return TRUE;
593 if (right < left) { INT tmp = right; right = left; left = tmp; }
594 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
596 oldwidth = width = physDev->pen.width;
597 if (!width) width = 1;
598 if(physDev->pen.style == PS_NULL) width = 0;
600 if ((physDev->pen.style == PS_INSIDEFRAME))
602 if (2*width > (right-left)) width=(right-left + 1)/2;
603 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
605 right -= (width - 1) / 2;
607 bottom -= (width - 1) / 2;
609 if(width == 1) width = 0;
610 physDev->pen.width = width;
611 oldjoinstyle = physDev->pen.linejoin;
612 if(physDev->pen.type != PS_GEOMETRIC)
613 physDev->pen.linejoin = PS_JOIN_MITER;
615 /* Update the pixmap from the DIB section */
616 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
618 if ((right > left + width) && (bottom > top + width))
619 if (X11DRV_SetupGCForBrush( dc ))
621 TSXFillRectangle( display, physDev->drawable, physDev->gc,
622 dc->w.DCOrgX + left + (width + 1) / 2,
623 dc->w.DCOrgY + top + (width + 1) / 2,
624 right-left-width-1, bottom-top-width-1);
627 if (X11DRV_SetupGCForPen( dc ))
629 TSXDrawRectangle( display, physDev->drawable, physDev->gc,
630 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
631 right-left-1, bottom-top-1 );
635 /* Update the DIBSection from the pixmap */
636 if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE);
638 physDev->pen.width = oldwidth;
639 physDev->pen.linejoin = oldjoinstyle;
643 /***********************************************************************
647 X11DRV_RoundRect( DC *dc, INT left, INT top, INT right,
648 INT bottom, INT ell_width, INT ell_height )
650 INT width, oldwidth, oldendcap;
651 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
654 TRACE("(%d %d %d %d %d %d\n",
655 left, top, right, bottom, ell_width, ell_height);
657 left = XLPTODP( dc, left );
658 top = YLPTODP( dc, top );
659 right = XLPTODP( dc, right );
660 bottom = YLPTODP( dc, bottom );
662 if ((left == right) || (top == bottom))
665 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
666 called with width/height < 0 */
667 ell_width = max(abs( ell_width * dc->vportExtX / dc->wndExtX ), 1);
668 ell_height = max(abs( ell_height * dc->vportExtY / dc->wndExtY ), 1);
670 /* Fix the coordinates */
672 if (right < left) { INT tmp = right; right = left; left = tmp; }
673 if (bottom < top) { INT tmp = bottom; bottom = top; top = tmp; }
675 oldwidth = width = physDev->pen.width;
676 oldendcap = physDev->pen.endcap;
677 if (!width) width = 1;
678 if(physDev->pen.style == PS_NULL) width = 0;
680 if ((physDev->pen.style == PS_INSIDEFRAME))
682 if (2*width > (right-left)) width=(right-left + 1)/2;
683 if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
685 right -= (width - 1) / 2;
687 bottom -= (width - 1) / 2;
689 if(width == 0) width = 1;
690 physDev->pen.width = width;
691 physDev->pen.endcap = PS_ENDCAP_SQUARE;
693 /* Update the pixmap from the DIB section */
694 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
696 if (X11DRV_SetupGCForBrush( dc ))
698 if (ell_width > (right-left) )
699 if (ell_height > (bottom-top) )
700 TSXFillArc( display, physDev->drawable, physDev->gc,
701 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
702 right - left - 1, bottom - top - 1,
705 TSXFillArc( display, physDev->drawable, physDev->gc,
706 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
707 right - left - 1, ell_height, 0, 180 * 64 );
708 TSXFillArc( display, physDev->drawable, physDev->gc,
710 dc->w.DCOrgY + bottom - ell_height - 1,
711 right - left - 1, ell_height, 180 * 64,
714 else if (ell_height > (bottom-top) ){
715 TSXFillArc( display, physDev->drawable, physDev->gc,
716 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
717 ell_width, bottom - top - 1, 90 * 64, 180 * 64 );
718 TSXFillArc( display, physDev->drawable, physDev->gc,
719 dc->w.DCOrgX + right - ell_width -1, dc->w.DCOrgY + top,
720 ell_width, bottom - top - 1, 270 * 64, 180 * 64 );
722 TSXFillArc( display, physDev->drawable, physDev->gc,
723 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
724 ell_width, ell_height, 90 * 64, 90 * 64 );
725 TSXFillArc( display, physDev->drawable, physDev->gc,
727 dc->w.DCOrgY + bottom - ell_height - 1,
728 ell_width, ell_height, 180 * 64, 90 * 64 );
729 TSXFillArc( display, physDev->drawable, physDev->gc,
730 dc->w.DCOrgX + right - ell_width - 1,
731 dc->w.DCOrgY + bottom - ell_height - 1,
732 ell_width, ell_height, 270 * 64, 90 * 64 );
733 TSXFillArc( display, physDev->drawable, physDev->gc,
734 dc->w.DCOrgX + right - ell_width - 1,
736 ell_width, ell_height, 0, 90 * 64 );
738 if (ell_width < right - left)
740 TSXFillRectangle( display, physDev->drawable, physDev->gc,
741 dc->w.DCOrgX + left + (ell_width + 1) / 2,
742 dc->w.DCOrgY + top + 1,
743 right - left - ell_width - 1,
744 (ell_height + 1) / 2 - 1);
745 TSXFillRectangle( display, physDev->drawable, physDev->gc,
746 dc->w.DCOrgX + left + (ell_width + 1) / 2,
747 dc->w.DCOrgY + bottom - (ell_height) / 2 - 1,
748 right - left - ell_width - 1,
751 if (ell_height < bottom - top)
753 TSXFillRectangle( display, physDev->drawable, physDev->gc,
754 dc->w.DCOrgX + left + 1,
755 dc->w.DCOrgY + top + (ell_height + 1) / 2,
757 bottom - top - ell_height - 1);
761 /* FIXME: this could be done with on X call
762 * more efficient and probably more correct
763 * on any X server: XDrawArcs will draw
764 * straight horizontal and vertical lines
765 * if width or height are zero.
767 * BTW this stuff is optimized for an Xfree86 server
768 * read the comments inside the X11DRV_DrawArc function
770 if (X11DRV_SetupGCForPen(dc)) {
771 if (ell_width > (right-left) )
772 if (ell_height > (bottom-top) )
773 TSXDrawArc( display, physDev->drawable, physDev->gc,
774 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
775 right - left - 1, bottom -top - 1, 0 , 360 * 64 );
777 TSXDrawArc( display, physDev->drawable, physDev->gc,
778 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
779 right - left - 1, ell_height - 1, 0 , 180 * 64 );
780 TSXDrawArc( display, physDev->drawable, physDev->gc,
782 dc->w.DCOrgY + bottom - ell_height,
783 right - left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
785 else if (ell_height > (bottom-top) ){
786 TSXDrawArc( display, physDev->drawable, physDev->gc,
787 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
788 ell_width - 1 , bottom - top - 1, 90 * 64 , 180 * 64 );
789 TSXDrawArc( display, physDev->drawable, physDev->gc,
790 dc->w.DCOrgX + right - ell_width,
792 ell_width - 1 , bottom - top - 1, 270 * 64 , 180 * 64 );
794 TSXDrawArc( display, physDev->drawable, physDev->gc,
795 dc->w.DCOrgX + left, dc->w.DCOrgY + top,
796 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
797 TSXDrawArc( display, physDev->drawable, physDev->gc,
798 dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
799 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
800 TSXDrawArc( display, physDev->drawable, physDev->gc,
801 dc->w.DCOrgX + right - ell_width,
802 dc->w.DCOrgY + bottom - ell_height,
803 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
804 TSXDrawArc( display, physDev->drawable, physDev->gc,
805 dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
806 ell_width - 1, ell_height - 1, 0, 90 * 64 );
808 if (ell_width < right - left)
810 TSXDrawLine( display, physDev->drawable, physDev->gc,
811 dc->w.DCOrgX + left + ell_width / 2,
813 dc->w.DCOrgX + right - (ell_width+1) / 2,
815 TSXDrawLine( display, physDev->drawable, physDev->gc,
816 dc->w.DCOrgX + left + ell_width / 2 ,
817 dc->w.DCOrgY + bottom - 1,
818 dc->w.DCOrgX + right - (ell_width+1)/ 2,
819 dc->w.DCOrgY + bottom - 1);
821 if (ell_height < bottom - top)
823 TSXDrawLine( display, physDev->drawable, physDev->gc,
824 dc->w.DCOrgX + right - 1,
825 dc->w.DCOrgY + top + ell_height / 2,
826 dc->w.DCOrgX + right - 1,
827 dc->w.DCOrgY + bottom - (ell_height+1) / 2);
828 TSXDrawLine( display, physDev->drawable, physDev->gc,
830 dc->w.DCOrgY + top + ell_height / 2,
832 dc->w.DCOrgY + bottom - (ell_height+1) / 2);
837 /* Update the DIBSection from the pixmap */
838 if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE);
840 physDev->pen.width = oldwidth;
841 physDev->pen.endcap = oldendcap;
846 /***********************************************************************
850 X11DRV_SetPixel( DC *dc, INT x, INT y, COLORREF color )
853 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
855 x = dc->w.DCOrgX + XLPTODP( dc, x );
856 y = dc->w.DCOrgY + YLPTODP( dc, y );
857 pixel = X11DRV_PALETTE_ToPhysical( dc, color );
859 TSXSetForeground( display, physDev->gc, pixel );
860 TSXSetFunction( display, physDev->gc, GXcopy );
861 TSXDrawPoint( display, physDev->drawable, physDev->gc, x, y );
863 /* inefficient but simple... */
865 /* FIXME: the DIBSection pixel should be updated too */
867 return X11DRV_PALETTE_ToLogical(pixel);
871 /***********************************************************************
875 X11DRV_GetPixel( DC *dc, INT x, INT y )
877 static Pixmap pixmap = 0;
880 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
882 x = dc->w.DCOrgX + XLPTODP( dc, x );
883 y = dc->w.DCOrgY + YLPTODP( dc, y );
884 EnterCriticalSection( &X11DRV_CritSection );
885 if (dc->w.flags & DC_MEMORY)
887 image = XGetImage( display, physDev->drawable, x, y, 1, 1,
888 AllPlanes, ZPixmap );
892 /* If we are reading from the screen, use a temporary copy */
893 /* to avoid a BadMatch error */
894 if (!pixmap) pixmap = XCreatePixmap( display, X11DRV_GetXRootWindow(),
895 1, 1, dc->w.bitsPerPixel );
896 XCopyArea( display, physDev->drawable, pixmap, BITMAP_colorGC,
898 image = XGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
900 pixel = XGetPixel( image, 0, 0 );
901 XDestroyImage( image );
902 LeaveCriticalSection( &X11DRV_CritSection );
904 return X11DRV_PALETTE_ToLogical(pixel);
908 /***********************************************************************
912 X11DRV_PaintRgn( DC *dc, HRGN hrgn )
915 HRGN tmpVisRgn, prevVisRgn;
916 HDC hdc = dc->hSelf; /* FIXME: should not mix dc/hdc this way */
917 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
919 if (!(tmpVisRgn = CreateRectRgn( 0, 0, 0, 0 ))) return FALSE;
921 /* Transform region into device co-ords */
922 if ( !REGION_LPTODP( hdc, tmpVisRgn, hrgn )
923 || OffsetRgn( tmpVisRgn, dc->w.DCOrgX, dc->w.DCOrgY ) == ERROR) {
924 DeleteObject( tmpVisRgn );
928 /* Modify visible region */
929 if (!(prevVisRgn = SaveVisRgn16( hdc ))) {
930 DeleteObject( tmpVisRgn );
933 CombineRgn( tmpVisRgn, prevVisRgn, tmpVisRgn, RGN_AND );
934 SelectVisRgn16( hdc, tmpVisRgn );
935 DeleteObject( tmpVisRgn );
937 /* Fill the region */
939 GetRgnBox( dc->w.hGCClipRgn, &box );
940 if (X11DRV_SetupGCForBrush( dc ))
942 /* Update the pixmap from the DIB section */
943 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
945 TSXFillRectangle( display, physDev->drawable, physDev->gc,
947 box.right-box.left, box.bottom-box.top );
949 /* Update the DIBSection from the pixmap */
950 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
953 /* Restore the visible region */
955 RestoreVisRgn16( hdc );
959 /**********************************************************************
963 X11DRV_Polyline( DC *dc, const POINT* pt, INT count )
968 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
970 if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1;
972 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
974 WARN("No memory to convert POINTs to XPoints!\n");
977 for (i = 0; i < count; i++)
979 points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x );
980 points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y );
983 if (X11DRV_SetupGCForPen ( dc ))
985 /* Update the pixmap from the DIB section */
986 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
988 TSXDrawLines( display, physDev->drawable, physDev->gc,
989 points, count, CoordModeOrigin );
991 /* Update the DIBSection from the pixmap */
992 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
995 HeapFree( GetProcessHeap(), 0, points );
996 physDev->pen.width = oldwidth;
1001 /**********************************************************************
1005 X11DRV_Polygon( DC *dc, const POINT* pt, INT count )
1009 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1010 BOOL update = FALSE;
1012 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1014 WARN("No memory to convert POINTs to XPoints!\n");
1017 for (i = 0; i < count; i++)
1019 points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x );
1020 points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y );
1022 points[count] = points[0];
1024 /* Update the pixmap from the DIB section */
1025 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
1027 if (X11DRV_SetupGCForBrush( dc ))
1029 TSXFillPolygon( display, physDev->drawable, physDev->gc,
1030 points, count+1, Complex, CoordModeOrigin);
1033 if (X11DRV_SetupGCForPen ( dc ))
1035 TSXDrawLines( display, physDev->drawable, physDev->gc,
1036 points, count+1, CoordModeOrigin );
1040 /* Update the DIBSection from the pixmap */
1041 if (update) X11DRV_DIB_UpdateDIBSection(dc, TRUE);
1043 HeapFree( GetProcessHeap(), 0, points );
1048 /**********************************************************************
1049 * X11DRV_PolyPolygon
1052 X11DRV_PolyPolygon( DC *dc, const POINT* pt, const INT* counts, UINT polygons)
1055 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1057 /* FIXME: The points should be converted to device coords before */
1058 /* creating the region. */
1060 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, dc->w.polyFillMode );
1061 X11DRV_PaintRgn( dc, hrgn );
1062 DeleteObject( hrgn );
1064 /* Draw the outline of the polygons */
1066 if (X11DRV_SetupGCForPen ( dc ))
1071 /* Update the pixmap from the DIB section */
1072 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
1074 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1075 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1077 WARN("No memory to convert POINTs to XPoints!\n");
1080 for (i = 0; i < polygons; i++)
1082 for (j = 0; j < counts[i]; j++)
1084 points[j].x = dc->w.DCOrgX + XLPTODP( dc, pt->x );
1085 points[j].y = dc->w.DCOrgY + YLPTODP( dc, pt->y );
1088 points[j] = points[0];
1089 TSXDrawLines( display, physDev->drawable, physDev->gc,
1090 points, j + 1, CoordModeOrigin );
1093 /* Update the DIBSection of the dc's bitmap */
1094 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
1096 HeapFree( GetProcessHeap(), 0, points );
1102 /**********************************************************************
1103 * X11DRV_PolyPolyline
1106 X11DRV_PolyPolyline( DC *dc, const POINT* pt, const DWORD* counts, DWORD polylines )
1108 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1110 if (X11DRV_SetupGCForPen ( dc ))
1115 /* Update the pixmap from the DIB section */
1116 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
1118 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1119 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1121 WARN("No memory to convert POINTs to XPoints!\n");
1124 for (i = 0; i < polylines; i++)
1126 for (j = 0; j < counts[i]; j++)
1128 points[j].x = dc->w.DCOrgX + XLPTODP( dc, pt->x );
1129 points[j].y = dc->w.DCOrgY + YLPTODP( dc, pt->y );
1132 TSXDrawLines( display, physDev->drawable, physDev->gc,
1133 points, j, CoordModeOrigin );
1136 /* Update the DIBSection of the dc's bitmap */
1137 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
1139 HeapFree( GetProcessHeap(), 0, points );
1145 /**********************************************************************
1146 * X11DRV_InternalFloodFill
1148 * Internal helper function for flood fill.
1149 * (xorg,yorg) is the origin of the X image relative to the drawable.
1150 * (x,y) is relative to the origin of the X image.
1152 static void X11DRV_InternalFloodFill(XImage *image, DC *dc,
1155 Pixel pixel, WORD fillType )
1157 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1160 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1161 (XGetPixel(image,x,y) != pixel) : \
1162 (XGetPixel(image,x,y) == pixel))
1164 if (!TO_FLOOD(x,y)) return;
1166 /* Find left and right boundaries */
1169 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1170 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1171 XFillRectangle( display, physDev->drawable, physDev->gc,
1172 xOrg + left, yOrg + y, right-left, 1 );
1174 /* Set the pixels of this line so we don't fill it again */
1176 for (x = left; x < right; x++)
1178 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1179 else XPutPixel( image, x, y, ~pixel );
1182 /* Fill the line above */
1189 while ((x < right) && !TO_FLOOD(x,y)) x++;
1190 if (x >= right) break;
1191 while ((x < right) && TO_FLOOD(x,y)) x++;
1192 X11DRV_InternalFloodFill(image, dc, x-1, y,
1193 xOrg, yOrg, pixel, fillType );
1197 /* Fill the line below */
1199 if ((y += 2) < image->height)
1204 while ((x < right) && !TO_FLOOD(x,y)) x++;
1205 if (x >= right) break;
1206 while ((x < right) && TO_FLOOD(x,y)) x++;
1207 X11DRV_InternalFloodFill(image, dc, x-1, y,
1208 xOrg, yOrg, pixel, fillType );
1215 /**********************************************************************
1216 * X11DRV_DoFloodFill
1218 * Main flood-fill routine.
1220 * The Xlib critical section must be entered before calling this function.
1223 struct FloodFill_params
1232 static BOOL X11DRV_DoFloodFill( const struct FloodFill_params *params )
1236 DC *dc = params->dc;
1237 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1239 if (GetRgnBox( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
1241 if (!(image = XGetImage( display, physDev->drawable,
1244 rect.right - rect.left,
1245 rect.bottom - rect.top,
1246 AllPlanes, ZPixmap ))) return FALSE;
1248 if (X11DRV_SetupGCForBrush( dc ))
1250 /* Update the pixmap from the DIB section */
1251 X11DRV_DIB_UpdateDIBSection(dc, FALSE);
1253 /* ROP mode is always GXcopy for flood-fill */
1254 XSetFunction( display, physDev->gc, GXcopy );
1255 X11DRV_InternalFloodFill(image, dc,
1256 XLPTODP(dc,params->x) + dc->w.DCOrgX - rect.left,
1257 YLPTODP(dc,params->y) + dc->w.DCOrgY - rect.top,
1260 X11DRV_PALETTE_ToPhysical( dc, params->color ),
1263 /* Update the DIBSection of the dc's bitmap */
1264 X11DRV_DIB_UpdateDIBSection(dc, TRUE);
1267 XDestroyImage( image );
1272 /**********************************************************************
1273 * X11DRV_ExtFloodFill
1276 X11DRV_ExtFloodFill( DC *dc, INT x, INT y, COLORREF color,
1280 struct FloodFill_params params;
1282 TRACE("X11DRV_ExtFloodFill %d,%d %06lx %d\n",
1283 x, y, color, fillType );
1288 params.color = color;
1289 params.fillType = fillType;
1291 if (!PtVisible( dc->hSelf, x, y )) return FALSE;
1292 EnterCriticalSection( &X11DRV_CritSection );
1293 result = CALL_LARGE_STACK( X11DRV_DoFloodFill, ¶ms );
1294 LeaveCriticalSection( &X11DRV_CritSection );
1298 /**********************************************************************
1302 X11DRV_SetBkColor( DC *dc, COLORREF color )
1304 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1307 oldColor = dc->w.backgroundColor;
1308 dc->w.backgroundColor = color;
1310 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( dc, color );
1315 /**********************************************************************
1316 * X11DRV_SetTextColor
1319 X11DRV_SetTextColor( DC *dc, COLORREF color )
1321 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1324 oldColor = dc->w.textColor;
1325 dc->w.textColor = color;
1327 physDev->textPixel = X11DRV_PALETTE_ToPhysical( dc, color );
1332 /***********************************************************************
1335 BOOL X11DRV_GetDCOrgEx( DC *dc, LPPOINT lpp )
1337 if (!(dc->w.flags & DC_MEMORY))
1339 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *) dc->physDev;
1341 int w, h, border, depth;
1343 /* FIXME: this is not correct for managed windows */
1344 TSXGetGeometry( display, physDev->drawable, &root,
1345 (int*)&lpp->x, (int*)&lpp->y, &w, &h, &border, &depth );
1347 else lpp->x = lpp->y = 0;