[comp.windows.x] Xlib/GC question

misha@huji.ac.il (Michael Pak) (08/06/90)

Hi there.


    Suppose I "XCreateSimpleWindow" (on a monochrome display) with
    foreground color set to WhitePixel(display,screen) and background
    color set to BlackPixel(display,screen).
    I then create the following GC:
    (exerpt from real code:)
 --------------
    XGCValues gcval;
  unsigned long valmask;
  valmask=(GCForeground GCBackground GCTileStipXOrigin GCTileStipYOrigin
     GCFillStyle GCTile);
  gcval.foreground = BlackPixel(display,screen);
  gcval.background = WhitePixel(display,screen);
  gcval.tile=bit_bitmap;
  gcval.ts_x_origin=0;
  gcval.ts_y_origin=0;
  gcval.fill_style=FillTiled;
  *fill_gc=XCreateGC(display,window,valmask,&gcval);
-----------------
  The question is:
     If I perform XFillRectangle(display,window,fill_gc,x,y,width,height),  what
 should I get? I mean, can it be that on different servers I'll get
  different results?

I ask it, because when I run it on our IBM RT, (ACIS 4.3, X11R4), I get
the foreground in white and the background in black, and on any other
server (all release 4), I get the opposite.

I stumbled across this strange behaviour, because there are some programs
which behave in one way on IBM RT, and another on any other server.

Thanks a lot.

******************************************
* Michael Pak                            *
* Department of Computer Science,        *
* Hebrew University of Jerusalem, Israel *
* E-Mail: misha@boojum.huji.ac.il        *
******************************************

mouse@SHAMASH.MCRCIM.MCGILL.EDU (der Mouse) (08/09/90)

> Suppose I "XCreateSimpleWindow" (on a monochrome display) with
> foreground color set to WhitePixel(display,screen) and background
> color set to BlackPixel(display,screen).
> I then create the following GC:
> (exerpt from real code:)
> --------------
> XGCValues gcval;
> unsigned long valmask;
> valmask=(GCForeground GCBackground GCTileStipXOrigin GCTileStipYOrigin
> 	GCFillStyle GCTile);

Uhhh...is this "real code" in C, as it appears to be?  If so, could you
possibly explain why this doesn't produce syntax errors galore?

> gcval.foreground = BlackPixel(display,screen);
> gcval.background = WhitePixel(display,screen);
> gcval.tile=bit_bitmap;
> gcval.ts_x_origin=0;
> gcval.ts_y_origin=0;
> gcval.fill_style=FillTiled;
> *fill_gc=XCreateGC(display,window,valmask,&gcval);

> If I perform XFillRectangle(display,window,fill_gc,x,y,width,height),
> what should I get? I mean, can it be that on different servers I'll
> get different results?

Yes and no.  The results will be consistent from one point of view but
not from another.

> I ask it, because when I run it on our IBM RT, (ACIS 4.3, X11R4), I
> get the foreground in white and the background in black, and on any
> other server (all release 4), I get the opposite.

Ah, but everywhere, you get the foreground in 1 and the background in
0.  This is the sense in which you will get consistent behavior.

If you try the above code on a non-1-bit display, you will (or
certainly should) get a BadMatch error; this is a clue.

I think you're confusing tiling with stippling.  What you appear to
want to do is what X calls opaque stippling (a fill-style of
FillOpaqueStippled).  Asking the server to tile means asking it to take
a given Pixmap and simply replicate it to generate the fill pattern.
(This operation ignores the foreground and background colors in the
GC.)  On the other hand, stippling, or at least opaque stippling,
amounts to generating a tile by taking the stipple and replacing each 1
pixel with a pixel containing the GC's foreground color and each 0
pixel with a pixel containing the GC's background color.  (Non-opaque
stippling is similar; the difference is that destination pixels
corresponding to 0 pixels in the stipple are not modified by a
non-opaque stipple - non-opaque stippling uses the foreground color but
not the background color from the GC.)

Try just changing "tile" to "stipple" and FillTiled to
FillOpaqueStippled and see if it doesn't do what you want.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu