Release 970120
[wine] / graphics / x11drv / graphics.c
1 /*
2  * X11 graphics driver graphics functions
3  *
4  * Copyright 1993,1994 Alexandre Julliard
5  */
6
7 #include <math.h>
8 #if defined(__EMX__)
9 #include <float.h>
10 #endif
11 #include <stdlib.h>
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/Intrinsic.h>
15 #ifndef PI
16 #define PI M_PI
17 #endif
18 #include <string.h>
19
20 #include "x11drv.h"
21 #include "bitmap.h"
22 #include "gdi.h"
23 #include "graphics.h"
24 #include "dc.h"
25 #include "bitmap.h"
26 #include "callback.h"
27 #include "metafile.h"
28 #include "syscolor.h"
29 #include "stddebug.h"
30 #include "palette.h"
31 #include "color.h"
32 #include "region.h"
33 #include "struct32.h"
34 #include "debug.h"
35 #include "xmalloc.h"
36
37
38 /**********************************************************************
39  *           X11DRV_MoveToEx
40  */
41 BOOL32
42 X11DRV_MoveToEx(DC *dc,INT32 x,INT32 y,LPPOINT32 pt) {
43     if (pt)
44     {
45         pt->x = dc->w.CursPosX;
46         pt->y = dc->w.CursPosY;
47     }
48     dc->w.CursPosX = x;
49     dc->w.CursPosY = y;
50     return TRUE;
51 }
52
53 /***********************************************************************
54  *           X11DRV_LineTo
55  */
56 BOOL32
57 X11DRV_LineTo( DC *dc, INT32 x, INT32 y )
58 {
59     if (DC_SetupGCForPen( dc ))
60         XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, 
61                   dc->w.DCOrgX + XLPTODP( dc, dc->w.CursPosX ),
62                   dc->w.DCOrgY + YLPTODP( dc, dc->w.CursPosY ),
63                   dc->w.DCOrgX + XLPTODP( dc, x ),
64                   dc->w.DCOrgY + YLPTODP( dc, y ) );
65     dc->w.CursPosX = x;
66     dc->w.CursPosY = y;
67     return TRUE;
68 }
69
70
71
72 /***********************************************************************
73  *           GRAPH_DrawArc
74  *
75  * Helper functions for Arc(), Chord() and Pie().
76  * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
77  */
78 static BOOL32
79 X11DRV_DrawArc( DC *dc, INT32 left, INT32 top, INT32 right,
80                 INT32 bottom, INT32 xstart, INT32 ystart,
81                 INT32 xend, INT32 yend, INT32 lines )
82 {
83     INT32 xcenter, ycenter, istart_angle, idiff_angle, tmp;
84     double start_angle, end_angle;
85     XPoint points[3];
86
87     left   = XLPTODP( dc, left );
88     top    = YLPTODP( dc, top );
89     right  = XLPTODP( dc, right );
90     bottom = YLPTODP( dc, bottom );
91     xstart = XLPTODP( dc, xstart );
92     ystart = YLPTODP( dc, ystart );
93     xend   = XLPTODP( dc, xend );
94     yend   = YLPTODP( dc, yend );
95     if ((left == right) || (top == bottom)) return FALSE;
96
97     xcenter = (right + left) / 2;
98     ycenter = (bottom + top) / 2;
99     start_angle = atan2( (double)(ycenter-ystart)*(right-left),
100                          (double)(xstart-xcenter)*(bottom-top) );
101     end_angle   = atan2( (double)(ycenter-yend)*(right-left),
102                          (double)(xend-xcenter)*(bottom-top) );
103     istart_angle = (INT32)(start_angle * 180 * 64 / PI);
104     idiff_angle  = (INT32)((end_angle - start_angle) * 180 * 64 / PI );
105     if (idiff_angle <= 0) idiff_angle += 360 * 64;
106     if (left > right) { tmp=left; left=right; right=tmp; }
107     if (top > bottom) { tmp=top; top=bottom; bottom=tmp; }
108
109       /* Fill arc with brush if Chord() or Pie() */
110
111     if ((lines > 0) && DC_SetupGCForBrush( dc ))
112     {
113         XSetArcMode( display, dc->u.x.gc, (lines==1) ? ArcChord : ArcPieSlice);
114         XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
115                  dc->w.DCOrgX + left, dc->w.DCOrgY + top,
116                  right-left-1, bottom-top-1, istart_angle, idiff_angle );
117     }
118
119       /* Draw arc and lines */
120
121     if (!DC_SetupGCForPen( dc )) return TRUE;
122     XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
123               dc->w.DCOrgX + left, dc->w.DCOrgY + top,
124               right-left-1, bottom-top-1, istart_angle, idiff_angle );
125     if (!lines) return TRUE;
126
127     points[0].x = dc->w.DCOrgX + xcenter + (int)(cos(start_angle) * (right-left) / 2);
128     points[0].y = dc->w.DCOrgY + ycenter - (int)(sin(start_angle) * (bottom-top) / 2);
129     points[1].x = dc->w.DCOrgX + xcenter + (int)(cos(end_angle) * (right-left) / 2);
130     points[1].y = dc->w.DCOrgY + ycenter - (int)(sin(end_angle) * (bottom-top) / 2);
131     if (lines == 2)
132     {
133         points[2] = points[1];
134         points[1].x = dc->w.DCOrgX + xcenter;
135         points[1].y = dc->w.DCOrgY + ycenter;
136     }
137     XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
138                 points, lines+1, CoordModeOrigin );
139     return TRUE;
140 }
141
142
143 /***********************************************************************
144  *           X11DRV_Arc
145  */
146 BOOL32
147 X11DRV_Arc( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
148             INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
149 {
150     return X11DRV_DrawArc( dc, left, top, right, bottom,
151                            xstart, ystart, xend, yend, 0 );
152 }
153
154
155 /***********************************************************************
156  *           X11DRV_Pie
157  */
158 BOOL32
159 X11DRV_Pie( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
160             INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
161 {
162     return X11DRV_DrawArc( dc, left, top, right, bottom,
163                            xstart, ystart, xend, yend, 2 );
164 }
165
166 /***********************************************************************
167  *           X11DRV_Chord
168  */
169 BOOL32
170 X11DRV_Chord( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom,
171               INT32 xstart, INT32 ystart, INT32 xend, INT32 yend )
172 {
173     return X11DRV_DrawArc( dc, left, top, right, bottom,
174                            xstart, ystart, xend, yend, 1 );
175 }
176
177
178 /***********************************************************************
179  *           X11DRV_Ellipse
180  */
181 BOOL32
182 X11DRV_Ellipse( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom )
183 {
184     left   = XLPTODP( dc, left );
185     top    = YLPTODP( dc, top );
186     right  = XLPTODP( dc, right );
187     bottom = YLPTODP( dc, bottom );
188     if ((left == right) || (top == bottom)) return FALSE;
189
190     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
191     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
192     
193     if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
194         (dc->u.x.pen.width < right-left-1) &&
195         (dc->u.x.pen.width < bottom-top-1))
196     {
197         left   += dc->u.x.pen.width / 2;
198         right  -= (dc->u.x.pen.width + 1) / 2;
199         top    += dc->u.x.pen.width / 2;
200         bottom -= (dc->u.x.pen.width + 1) / 2;
201     }
202
203     if (DC_SetupGCForBrush( dc ))
204         XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
205                   dc->w.DCOrgX + left, dc->w.DCOrgY + top,
206                   right-left-1, bottom-top-1, 0, 360*64 );
207     if (DC_SetupGCForPen( dc ))
208         XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
209                   dc->w.DCOrgX + left, dc->w.DCOrgY + top,
210                   right-left-1, bottom-top-1, 0, 360*64 );
211     return TRUE;
212 }
213
214
215 /***********************************************************************
216  *           X11DRV_Rectangle
217  */
218 BOOL32
219 X11DRV_Rectangle(DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
220 {
221     INT32 width;
222     left   = XLPTODP( dc, left );
223     top    = YLPTODP( dc, top );
224     right  = XLPTODP( dc, right );
225     bottom = YLPTODP( dc, bottom );
226
227     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
228     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
229
230     if ((left == right) || (top == bottom))
231     {
232         if (DC_SetupGCForPen( dc ))
233             XDrawLine(display, dc->u.x.drawable, dc->u.x.gc, 
234                   dc->w.DCOrgX + left,
235                   dc->w.DCOrgY + top,
236                   dc->w.DCOrgX + right,
237                   dc->w.DCOrgY + bottom);
238         return TRUE;
239     }
240     width = dc->u.x.pen.width;
241     if (!width) width = 1;
242     if(dc->u.x.pen.style == PS_NULL) width = 0;
243
244     if ((dc->u.x.pen.style == PS_INSIDEFRAME) &&
245         (width < right-left) && (width < bottom-top))
246     {
247         left   += width / 2;
248         right  -= (width + 1) / 2;
249         top    += width / 2;
250         bottom -= (width + 1) / 2;
251     }
252
253     if (DC_SetupGCForBrush( dc ))
254         XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
255                         dc->w.DCOrgX + left + (width + 1) / 2,
256                         dc->w.DCOrgY + top + (width + 1) / 2,
257                         right-left-width-1, bottom-top-width-1);
258     if (DC_SetupGCForPen( dc ))
259         XDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
260                         dc->w.DCOrgX + left, dc->w.DCOrgY + top,
261                         right-left-1, bottom-top-1 );
262     return TRUE;
263 }
264
265 /***********************************************************************
266  *           X11DRV_RoundRect
267  */
268 BOOL32
269 X11DRV_RoundRect( DC *dc, INT32 left, INT32 top, INT32 right,
270                   INT32 bottom, INT32 ell_width, INT32 ell_height )
271 {
272     dprintf_graphics(stddeb, "X11DRV_RoundRect(%d %d %d %d  %d %d\n", 
273         left, top, right, bottom, ell_width, ell_height);
274
275     left   = XLPTODP( dc, left );
276     top    = YLPTODP( dc, top );
277     right  = XLPTODP( dc, right );
278     bottom = YLPTODP( dc, bottom );
279     ell_width  = abs( ell_width * dc->vportExtX / dc->wndExtX );
280     ell_height = abs( ell_height * dc->vportExtY / dc->wndExtY );
281
282     /* Fix the coordinates */
283
284     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
285     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
286     if (ell_width > right - left) ell_width = right - left;
287     if (ell_height > bottom - top) ell_height = bottom - top;
288
289     if (DC_SetupGCForBrush( dc ))
290     {
291         if (ell_width && ell_height)
292         {
293             XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
294                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
295                       ell_width, ell_height, 90 * 64, 90 * 64 );
296             XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
297                       dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
298                       ell_width, ell_height, 180 * 64, 90 * 64 );
299             XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
300                       dc->w.DCOrgX + right - ell_width,
301                       dc->w.DCOrgY + bottom - ell_height,
302                       ell_width, ell_height, 270 * 64, 90 * 64 );
303             XFillArc( display, dc->u.x.drawable, dc->u.x.gc,
304                       dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
305                       ell_width, ell_height, 0, 90 * 64 );
306         }
307         if (ell_width < right - left)
308         {
309             XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
310                             dc->w.DCOrgX + left + ell_width / 2,
311                             dc->w.DCOrgY + top,
312                             right - left - ell_width, ell_height / 2 );
313             XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
314                             dc->w.DCOrgX + left + ell_width / 2,
315                             dc->w.DCOrgY + bottom - (ell_height+1) / 2,
316                             right - left - ell_width, (ell_height+1) / 2 );
317         }
318         if  (ell_height < bottom - top)
319         {
320             XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
321                             dc->w.DCOrgX + left,
322                             dc->w.DCOrgY + top + ell_height / 2,
323                             right - left, bottom - top - ell_height );
324         }
325     }
326     if (DC_SetupGCForPen(dc))
327     {
328         if (ell_width && ell_height)
329         {
330             XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
331                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
332                       ell_width, ell_height, 90 * 64, 90 * 64 );
333             XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
334                       dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
335                       ell_width, ell_height, 180 * 64, 90 * 64 );
336             XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
337                       dc->w.DCOrgX + right - ell_width,
338                       dc->w.DCOrgY + bottom - ell_height,
339                       ell_width, ell_height, 270 * 64, 90 * 64 );
340             XDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
341                       dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
342                       ell_width, ell_height, 0, 90 * 64 );
343         }
344         if (ell_width < right - left)
345         {
346             XDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
347                        dc->w.DCOrgX + left + ell_width / 2,
348                        dc->w.DCOrgY + top,
349                        dc->w.DCOrgX + right - ell_width / 2,
350                        dc->w.DCOrgY + top );
351             XDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
352                        dc->w.DCOrgX + left + ell_width / 2,
353                        dc->w.DCOrgY + bottom,
354                        dc->w.DCOrgX + right - ell_width / 2,
355                        dc->w.DCOrgY + bottom );
356         }
357         if (ell_height < bottom - top)
358         {
359             XDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
360                        dc->w.DCOrgX + right,
361                        dc->w.DCOrgY + top + ell_height / 2,
362                        dc->w.DCOrgX + right,
363                        dc->w.DCOrgY + bottom - ell_height / 2 );
364             XDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
365                        dc->w.DCOrgX + left,
366                        dc->w.DCOrgY + top + ell_height / 2,
367                        dc->w.DCOrgX + left,
368                        dc->w.DCOrgY + bottom - ell_height / 2 );
369         }
370     }
371     return TRUE;
372 }
373
374
375 /***********************************************************************
376  *           X11DRV_SetPixel
377  */
378 COLORREF
379 X11DRV_SetPixel( DC *dc, INT32 x, INT32 y, COLORREF color )
380 {
381     Pixel pixel;
382     
383     x = dc->w.DCOrgX + XLPTODP( dc, x );
384     y = dc->w.DCOrgY + YLPTODP( dc, y );
385     pixel = COLOR_ToPhysical( dc, color );
386     
387     XSetForeground( display, dc->u.x.gc, pixel );
388     XSetFunction( display, dc->u.x.gc, GXcopy );
389     XDrawPoint( display, dc->u.x.drawable, dc->u.x.gc, x, y );
390
391     /* inefficient but simple... */
392
393     return COLOR_ToLogical(pixel);
394 }
395
396
397 /***********************************************************************
398  *           X11DRV_GetPixel
399  */
400 COLORREF
401 X11DRV_GetPixel( DC *dc, INT32 x, INT32 y )
402 {
403     static Pixmap pixmap = 0;
404     XImage * image;
405     int pixel;
406
407     x = dc->w.DCOrgX + XLPTODP( dc, x );
408     y = dc->w.DCOrgY + YLPTODP( dc, y );
409     if (dc->w.flags & DC_MEMORY)
410     {
411         image = XGetImage( display, dc->u.x.drawable, x, y, 1, 1,
412                            AllPlanes, ZPixmap );
413     }
414     else
415     {
416         /* If we are reading from the screen, use a temporary copy */
417         /* to avoid a BadMatch error */
418         if (!pixmap) pixmap = XCreatePixmap( display, rootWindow,
419                                              1, 1, dc->w.bitsPerPixel );
420         XCopyArea( display, dc->u.x.drawable, pixmap, BITMAP_colorGC,
421                    x, y, 1, 1, 0, 0 );
422         image = XGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
423     }
424     pixel = XGetPixel( image, 0, 0 );
425     XDestroyImage( image );
426     
427     return COLOR_ToLogical(pixel);
428 }
429
430
431 /***********************************************************************
432  *           X11DRV_PaintRgn
433  */
434 BOOL32
435 X11DRV_PaintRgn( DC *dc, HRGN32 hrgn )
436 {
437     RECT32 box;
438     HRGN32 tmpVisRgn, prevVisRgn;
439     HDC32  hdc = dc->hSelf; /* FIXME: should not mix dc/hdc this way */
440
441       /* Modify visible region */
442
443     if (!(prevVisRgn = SaveVisRgn( hdc ))) return FALSE;
444     if (!(tmpVisRgn = CreateRectRgn32( 0, 0, 0, 0 )))
445     {
446         RestoreVisRgn( hdc );
447         return FALSE;
448     }
449     CombineRgn32( tmpVisRgn, prevVisRgn, hrgn, RGN_AND );
450     SelectVisRgn( hdc, tmpVisRgn );
451     DeleteObject32( tmpVisRgn );
452
453       /* Fill the region */
454
455     GetRgnBox32( dc->w.hGCClipRgn, &box );
456     if (DC_SetupGCForBrush( dc ))
457         XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
458                         dc->w.DCOrgX + box.left, dc->w.DCOrgY + box.top,
459                         box.right-box.left, box.bottom-box.top );
460
461       /* Restore the visible region */
462
463     RestoreVisRgn( hdc );
464     return TRUE;
465 }
466
467 /**********************************************************************
468  *          X11DRV_Polyline
469  */
470 BOOL32
471 X11DRV_Polyline( DC *dc, const LPPOINT32 pt, INT32 count )
472 {
473     register int i;
474
475     if (DC_SetupGCForPen( dc ))
476         for (i = 0; i < count-1; i ++)
477             XDrawLine (display, dc->u.x.drawable, dc->u.x.gc,  
478                        dc->w.DCOrgX + XLPTODP(dc, pt [i].x),
479                        dc->w.DCOrgY + YLPTODP(dc, pt [i].y),
480                        dc->w.DCOrgX + XLPTODP(dc, pt [i+1].x),
481                        dc->w.DCOrgY + YLPTODP(dc, pt [i+1].y));
482     return TRUE;
483 }
484
485
486 /**********************************************************************
487  *          X11DRV_Polygon
488  */
489 BOOL32
490 X11DRV_Polygon( DC *dc, LPPOINT32 pt, INT32 count )
491 {
492     register int i;
493     XPoint *points;
494
495     points = (XPoint *) xmalloc (sizeof (XPoint) * (count+1));
496     for (i = 0; i < count; i++)
497     {
498         points[i].x = dc->w.DCOrgX + XLPTODP( dc, pt[i].x );
499         points[i].y = dc->w.DCOrgY + YLPTODP( dc, pt[i].y );
500     }
501     points[count] = points[0];
502
503     if (DC_SetupGCForBrush( dc ))
504         XFillPolygon( display, dc->u.x.drawable, dc->u.x.gc,
505                      points, count+1, Complex, CoordModeOrigin);
506
507     if (DC_SetupGCForPen ( dc ))
508         XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
509                    points, count+1, CoordModeOrigin );
510
511     free( points );
512     return TRUE;
513 }
514
515
516 /**********************************************************************
517  *          X11DRV_PolyPolygon
518  */
519 BOOL32 
520 X11DRV_PolyPolygon( DC *dc, LPPOINT32 pt, LPINT32 counts, UINT32 polygons)
521 {
522     HRGN32 hrgn;
523
524       /* FIXME: The points should be converted to device coords before */
525       /* creating the region. But as CreatePolyPolygonRgn is not */
526       /* really correct either, it doesn't matter much... */
527       /* At least the outline will be correct :-) */
528     hrgn = CreatePolyPolygonRgn32( pt, counts, polygons, dc->w.polyFillMode );
529     X11DRV_PaintRgn( dc, hrgn );
530     DeleteObject32( hrgn );
531
532       /* Draw the outline of the polygons */
533
534     if (DC_SetupGCForPen ( dc ))
535     {
536         int i, j, max = 0;
537         XPoint *points;
538
539         for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
540         points = (XPoint *) xmalloc( sizeof(XPoint) * (max+1) );
541
542         for (i = 0; i < polygons; i++)
543         {
544             for (j = 0; j < counts[i]; j++)
545             {
546                 points[j].x = dc->w.DCOrgX + XLPTODP( dc, pt->x );
547                 points[j].y = dc->w.DCOrgY + YLPTODP( dc, pt->y );
548                 pt++;
549             }
550             points[j] = points[0];
551             XDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
552                         points, j + 1, CoordModeOrigin );
553         }
554         free( points );
555     }
556     return TRUE;
557 }
558
559
560 /**********************************************************************
561  *          X11DRV_InternalFloodFill
562  *
563  * Internal helper function for flood fill.
564  * (xorg,yorg) is the origin of the X image relative to the drawable.
565  * (x,y) is relative to the origin of the X image.
566  */
567 static void X11DRV_InternalFloodFill(XImage *image, DC *dc,
568                                      int x, int y,
569                                      int xOrg, int yOrg,
570                                      Pixel pixel, WORD fillType )
571 {
572     int left, right;
573
574 #define TO_FLOOD(x,y)  ((fillType == FLOODFILLBORDER) ? \
575                         (XGetPixel(image,x,y) != pixel) : \
576                         (XGetPixel(image,x,y) == pixel))
577
578     if (!TO_FLOOD(x,y)) return;
579
580       /* Find left and right boundaries */
581
582     left = right = x;
583     while ((left > 0) && TO_FLOOD( left-1, y )) left--;
584     while ((right < image->width) && TO_FLOOD( right, y )) right++;
585     XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
586                     xOrg + left, yOrg + y, right-left, 1 );
587
588       /* Set the pixels of this line so we don't fill it again */
589
590     for (x = left; x < right; x++)
591     {
592         if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
593         else XPutPixel( image, x, y, ~pixel );
594     }
595
596       /* Fill the line above */
597
598     if (--y >= 0)
599     {
600         x = left;
601         while (x < right)
602         {
603             while ((x < right) && !TO_FLOOD(x,y)) x++;
604             if (x >= right) break;
605             while ((x < right) && TO_FLOOD(x,y)) x++;
606             X11DRV_InternalFloodFill(image, dc, x-1, y,
607                                      xOrg, yOrg, pixel, fillType );
608         }
609     }
610
611       /* Fill the line below */
612
613     if ((y += 2) < image->height)
614     {
615         x = left;
616         while (x < right)
617         {
618             while ((x < right) && !TO_FLOOD(x,y)) x++;
619             if (x >= right) break;
620             while ((x < right) && TO_FLOOD(x,y)) x++;
621             X11DRV_InternalFloodFill(image, dc, x-1, y,
622                                      xOrg, yOrg, pixel, fillType );
623         }
624     }
625 #undef TO_FLOOD    
626 }
627
628
629 /**********************************************************************
630  *          X11DRV_DoFloodFill
631  *
632  * Main flood-fill routine.
633  */
634 static BOOL32 X11DRV_DoFloodFill( DC *dc, RECT32 *rect, INT32 x, INT32 y,
635                                  COLORREF color, UINT32 fillType )
636 {
637     XImage *image;
638
639     if (!(image = XGetImage( display, dc->u.x.drawable,
640                              dc->w.DCOrgX + rect->left,
641                              dc->w.DCOrgY + rect->top,
642                              rect->right - rect->left,
643                              rect->bottom - rect->top,
644                              AllPlanes, ZPixmap ))) return FALSE;
645
646     if (DC_SetupGCForBrush( dc ))
647     {
648           /* ROP mode is always GXcopy for flood-fill */
649         XSetFunction( display, dc->u.x.gc, GXcopy );
650         X11DRV_InternalFloodFill(image, dc,
651                                  XLPTODP(dc,x) - rect->left,
652                                  YLPTODP(dc,y) - rect->top,
653                                  dc->w.DCOrgX + rect->left,
654                                  dc->w.DCOrgY + rect->top,
655                                  COLOR_ToPhysical( dc, color ), fillType );
656     }
657
658     XDestroyImage( image );
659     return TRUE;
660 }
661
662
663 /**********************************************************************
664  *          X11DRV_ExtFloodFill
665  */
666 BOOL32
667 X11DRV_ExtFloodFill( DC *dc, INT32 x, INT32 y, COLORREF color,
668                      UINT32 fillType )
669 {
670     RECT32 rect;
671     HDC32       hdc = dc->hSelf; /* FIXME */
672
673     dprintf_graphics( stddeb, "X11DRV_ExtFloodFill %d,%d %06lx %d\n",
674                       x, y, color, fillType );
675
676     if (!PtVisible32( hdc, x, y )) return FALSE;
677     if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
678
679     return CallTo32_LargeStack( (int(*)())X11DRV_DoFloodFill, 6,
680                                 dc, &rect, x, y, color, fillType );
681 }