home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!stanford.edu!ames!elroy.jpl.nasa.gov!news.aero.org!gurlitz
- From: gurlitz@aero.org (Thomas R. Gurlitz)
- Newsgroups: comp.windows.x
- Subject: Help with GXxor option ?
- Date: 19 Nov 1992 17:44:23 GMT
- Organization: The Aerospace Corporation, El Segundo, CA
- Lines: 158
- Distribution: world
- Message-ID: <1egjpnINN9c0@news.aero.org>
- NNTP-Posting-Host: aerospace.aero.org
-
- Hi,
-
- I'm trying to use GXxor to draw and erase lines. The following program
- is not doing what I had hoped to do, so I obviously don't understand
- this option to XSetFunction. I would greatly appreciate any help I
- can get on this.
-
- The program (modelled on "helloworld.c") is intended to draw a line,
- wait a few seconds, then erase the line. At each mouse button press,
- a slightly different line segment should be drawn, displayed a few
- seconds, then erased. The print statements tell me when each line is drawn
- or undrawn.
-
- That's what I would like to happen. However what actually happens is
- that the first line segment is drawn, never erased, and successive
- mouse button presses don't appear to make any changes to the windows.
-
- Typing "q" does exit the program.
-
- Please mail any repsonses to:
-
- gurlitz@aerospace.aero.org
-
- Thanks,
- Tom Gurlitz
-
-
-
-
-
-
-
-
-
- /* X include files */
- #include <X11/Xlib.h>
- #include <X11/X.h>
- #include <X11/Xutil.h>
-
-
- main(int argc, char **argv)
- {
- Display *mydisplay;
- Window mywindow;
- GC mygc;
- XEvent myevent;
- KeySym mykey;
- XSizeHints myhint;
- int myscreen;
- unsigned long myforeground, mybackground;
- int i;
- char text[10];
- int done;
- char hello[] = {"Hello World."};
- XPoint points[2];
-
- /* Initialization */
- mydisplay = XOpenDisplay("");
- myscreen = DefaultScreen(mydisplay);
-
- /* Default pixel values */
- mybackground = WhitePixel(mydisplay, myscreen);
- myforeground = BlackPixel(mydisplay, myscreen);
-
- /* Window size */
- myhint.x = 200.;
- myhint.y = 300.;
- myhint.width = 600;
- myhint.height = 600;
- myhint.flags = PPosition | PSize;
-
- /* Window Creation */
- mywindow = XCreateSimpleWindow(mydisplay,
- DefaultRootWindow(mydisplay),
- myhint.x, myhint.y, myhint.width,
- myhint.height, 5, myforeground, mybackground);
- XSetStandardProperties(mydisplay, mywindow, hello, hello,
- None, argv, argc, &myhint);
-
- /* GC creation and initialization */
- mygc = XCreateGC(mydisplay, mywindow, 0, 0);
- XSetBackground(mydisplay, mygc, mybackground);
- XSetForeground(mydisplay, mygc, myforeground);
-
- /* input event */
- XSelectInput(mydisplay, mywindow,
- ButtonPressMask | KeyPressMask | ExposureMask);
-
- /* window mapping */
- XMapRaised(mydisplay, mywindow);
-
- points[0].x = 20;
- points[0].y = 20;
- points[1].x = 400;
- points[1].y = 400;
-
- /* looping */
- done = 0;
- while (done == 0)
- {
- /* next event */
- XNextEvent(mydisplay, &myevent);
- switch (myevent.type)
- {
- case Expose:
- if (myevent.xexpose.count = 0)
- XDrawImageString(myevent.xexpose.display,
- myevent.xexpose.window, mygc,
- 50, 50, hello, strlen(hello) );
- break;
-
- /* process keyboard */
- case MappingNotify:
- XRefreshKeyboardMapping(&myevent);
- break;
-
- /* process mouse */
- case ButtonPress:
-
- /* Draw Line */
-
- XDrawLines(mydisplay, mywindow, mygc, points, 2,
- CoordModeOrigin);
- XFlush(mydisplay);
- printf("Line drawn\n");
-
- sleep(2);
-
- /* Undraw Line */
-
- XSetFunction(mydisplay, mygc, GXxor);
- XDrawLines(mydisplay, mywindow, mygc, points, 2,
- CoordModeOrigin);
- printf("Line undrawn\n");
-
-
- points[0].x += 10;
- points[0].y += 10;
- points[1].x += 20;
- points[1].y += 20;
-
- break;
-
- /* process keyboard input */
- case KeyPress:
- i = XLookupString(&myevent, text, 10, &mykey, 0);
- if (i == 1 && text[0] == 'q')
- done = 1;
- break;
- }
- }
-
- /* termination */
- XFreeGC(mydisplay, mygc);
- XDestroyWindow(mydisplay, mywindow);
- XCloseDisplay(mydisplay);
- exit(0);
- }
-