[comp.windows.x] rubber banding in X

laymon@nepal.steinmetz (Marc A Laymon) (05/25/88)

Question #1:

I want to draw a rubber-banding line.  It would seem to me that I want
to repeatedly draw a line in exclusive-or mode.  I tried to use the
following code fragment (and several variations thereof) to try to set
the graphics context to exclusive-or, then call XDrawLine using the
graphics context.  My line does not show up.  Can someone tell me what
I am doing wrong or suggest another approach ?  

----------------------------------------------------------------------------
    Display 	*dpy ;
    int     g_black ;
    int     g_white ;
    unsigned long    mask ;
    GC	  xor_gc ;
    XGCValues    xgcv ;

    g_black = BlackPixel (dpy, screen);
    g_white = WhitePixel (dpy, screen);
    mask = g_black ^ g_white ;

    xgcv.foreground = mask ;
    xgcv.background = g_white ;
    xgcv.line_width = 1 ;
    xgcv.function = GXxor ;

    gc_mask = 0 ;
    gc_mask = GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth ;

    xor_gc = XCreateGC (dpy, Rootwindow, GCFunction, &xgcv) ;

    while (*whatever*)
    {
	[code to modify x[1] & y[1]]
	XDrawLine (dpy, Rootwindow, xor_gc, x[0], y[0], x[1], y[1]) ;
    }

--------------------------------------------------------------------------

Question #2

I created a graphic widget using the X Intrinsics.  This widget is just
a blank window into which I can use Xlib graphics functions.  This works
fine.  However, if my base window containing this graphic widget is
resized or moved via the window manager, I lose the contents of the window.  
Is there an easy way to preserve and restore the random contents of a window ?
Regions or buffers don't seem to be what I want.

Thanks in advance.


 Marc Laymon			ARPANET: laymon@ge-crd.arpa
 GE Corp. R&D			USENET:  steinmetz!nepal!laymon
 Schenectady, NY

price@WSL.DEC.COM (05/26/88)

Two things:

Instead of Xor, try GXinvert. It works for me, anyway.

Also, set subwindow_mode to IncludeInferiors.
This way, your rubberband line will draw on top of any child windows
of the root. Remember that a window manager may place a "pseudo" root
window between you and the real root window.

Oh, and finally, set line width to 0. This tells the server to use any available
line drawing acceleration. Does wonders for the VAXstation II/GPX lines.

-chuck

price@WSL.DEC.COM (05/26/88)

Oh, I missed part of what you did wrong when I wrote my last reply.

You need to make the following changes also:

xgcv.foreground = g_white;
xgcv.background = g_black;
xgcv.plane_mask = mask;

-chuck