[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

1350.0. "Simple image movment" by GASDRS::PACK (Vertical learning curves) Thu Aug 31 1989 07:17

As a beginner at this game (X) can someone please explain why I can not
draw and then undraw a simple image.

Conceptually it seems to me that you need to xor the pixmap/image on to the
window and then xor the same image in the same place to remove it.  Is it
really not this simple.

The next note is a program to demonstate what we think should work, (but 
doesnt).

What is wrong with my conceptual understanding, or what is wrong with the code?

:J

T.RTitleUserPersonal
Name
DateLines
1350.1An example of the codeGASDRS::PACKVertical learning curvesThu Aug 31 1989 07:20117
/*
   Jeremy Pack digital 24-Aug-1989
*/ 

#include <stdio.h>
#include <decw$include/Xlib.h>
#include <decw$include/Xutil.h>
#include <decw$include/Xatom.h>

#define jetr_width 16
#define jetr_height 16
#define jetr_x_hot 0
#define jetr_y_hot 0
static char jetr_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x7d, 0x00, 0xfb, 0x01,
   0xf3, 0x1f, 0xff, 0x7f, 0xfe, 0xff, 0xf0, 0x07, 0xf8, 0x03, 0x7c, 0x00,
   0x1e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00};

#define screenNumber    DefaultScreen(display)
#define rootWindow      RootWindow(display,screenNumber)
#define displayWidth    DisplayWidth(display,screenNumber)
#define displayHeight   DisplayHeight(display,screenNumber)
#define windowX         (displayWidth/4)
#define windowY         (displayHeight/8)
#define blackPixel      BlackPixel(display,screenNumber)
#define whitePixel      WhitePixel(display,screenNumber)
#define defaultGC       DefaultGC(disprog_dir:jetr.bm>play,screenNumber)
#define depth           DefaultDepth(display,screenNumber)
#define borderWidth     1
#define minWidth        (displayWidth/2)
#define minHeight       (displayWidth/4)

main(argc,argv)
   unsigned int argc;
   char *argv[];
{
Display *display;			/* display id		*/
Window window;				/* main window id	*/
GC  gcor;	    /* graphic context to or values onto window	*/   
XImage	*jetrimage;
unsigned long attribute_mask;
XSetWindowAttributes window_attributes;
XEvent event;
int x,y;
unsigned long	gcmask;
XGCValues   gcvalues;
Pixmap pixmap;

      /* request creation of main display			    */
      if (!(display = XOpenDisplay(NULL)))
	    {
	    fprintf(stderr,"WINDOW-F-BADDISP	Can't open display\n");
	    exit(0);
	    }

   /* Define window attributes and create the window */
   window_attributes.border_pixel = blackPixel;
   window_attributes.background_pixel = whitePixel;
   window_attributes.event_mask = ButtonPressMask|ButtonReleaseMask|ExposureMask;
   attribute_mask = CWBorderPixel|CWEventMask|CWBackPixel;


   /* create the window	*/
   window = XCreateWindow(display,rootWindow,
                          windowX,windowY,minWidth,minHeight,
                          borderWidth,depth,
                          CopyFromParent,      /* window class */
                          CopyFromParent,      /* Visual */
                          attribute_mask,
                          &window_attributes);

   /* Tell the window manager about our window */
   XMapWindow(display,window);

   /* copy gc for xor function	    */
   gcmask = GCFunction;
   gcvalues.function = GXxor; /*ensures exclusive of of pixel values  */
   gcor = XCreateGC(display, window, GCFunction, &gcvalues);

   /* create pix map and then image for jet */
   pixmap = XCreatePixmapFromBitmapData(display,window,
					jetr_bits,jetr_width,
					jetr_height,blackPixel,whitePixel,
				        depth);
   jetrimage = XGetImage(display, pixmap,0,0,jetr_width,jetr_width,AllPlanes
			    ,XYPixmap); 

   y  = minHeight/2;
   for(x = minWidth/4; x<= minWidth* 0.75; x++)
	{
	/* paint the jet on */
	XPutImage(display, window, gcor,jetrimage,0,0,x,y,
		  jetr_width,jetr_height);
	XSync(display,0);

	/* xor the jet off - this is the bit that 'doesnt' work */
	XPutImage(display, window, gcor,jetrimage,0,0,x,y,
		  jetr_width,jetr_height);
	XSync(display,0);

	}
   do
   {
       
   XNextEvent(display,&event);

   } while (event.type != ButtonPress);

   XFreePixmap(display,pixmap);
   XDestroyImage(jetrimage);
   XDestroyWindow(display,window);

   exit(1);
}
    


1350.2Give WM a chanceDECWIN::KLEINThu Aug 31 1989 10:355
You're not giving the window manager a chance to map your window.  You must
wait until the MapNotify (or Expose) event before you do your drawing.

-steve-

1350.3It works but not the way we wantGASDRS::PACKVertical learning curvesThu Aug 31 1989 11:529
Steve:
	Yes I suppose you have a point, thats what comes with putting simple
cutdown programs in as an example.  The enclosed program actually runs, what
happens is the object (a jet) leaves a (vapour) trail as it moves, which says
to us the 2nd XPutImage does not xor the object back off the window, that is
my real problem, any clues ?

:J

1350.4ZPixmap is ZAnswerDECWIN::KLEINThu Aug 31 1989 12:3213
On a "whim" I changed XYPixmap to ZPixmap, and your program now works.
Don't ask...

>>   jetrimage = XGetImage(display, pixmap,0,0,jetr_width,jetr_width,AllPlanes
>>			    ,XYPixmap); 

becomes:

   jetrimage = XGetImage(display, pixmap,0,0,jetr_width,jetr_width,AllPlanes
			    ,ZPixmap); 

-steve-

1350.5I wont ask, it works, thanks alot . I suppose this is *just* a feature of X ;-)GASDRS::PACKVertical learning curvesFri Sep 01 1989 11:481
1350.6Maybe a bug, but there are better ways in any caseDECWIN::FISHERBurns Fisher 381-1466, ZKO3-4/W23Thu Sep 07 1989 14:0731
I can't think offhand why Z vs XY pixmap mode would make a difference here
unless there is a bug.  That is quite possible; XY pixmap mode is not
all the commonly used.

On the other hand, there are better ways to do the same thing.  My first
suggestion would be to write only a 1-deep pixmap rather than a full depth
pixmap.  Then use CopyPlane with a GC having the following attributes:

	Plane Mask:  BlackPixel ^ WhitePixel
	Foreground:  0xffffffff
	Background:  0

This will guarnatee to flip the bits under the plane from BlackPixel to
WhitePixel or from WhitePixel to BlackPixel and will leave bits not under
the plane image unchanged.  If you have more than just fg and bg on the
screen you have a harder task; you will have to allocate a plane for the
plane.

The way you have it, I think it will flip BlackPixel bits not under the plane
to 0, WhitePixel bits not under the plane to (BlackPixel ^ WhitePixel),
BlackPixel bits that are under the plane to (BlackPixel ^ WhitePixel) and
WhitePixel bits that are under the plane to 0.  This will work by
coincidence some of the time (if BlackPixel = 0 and WhitePixel = 1, for
example) but will give you random results sometimes.  My way will also
save you quite a lot of offscreen memory which can translate into
performance.

Burns



1350.7LEMA::PACKVertical learning curvesThu Sep 21 1989 06:422
Thanks Burns will give it a go.  :J