home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / windows / x / 19344 < prev    next >
Encoding:
Text File  |  1992-11-19  |  4.0 KB  |  170 lines

  1. Path: sparky!uunet!stanford.edu!ames!elroy.jpl.nasa.gov!news.aero.org!gurlitz
  2. From: gurlitz@aero.org (Thomas R. Gurlitz)
  3. Newsgroups: comp.windows.x
  4. Subject: Help with GXxor option ?
  5. Date: 19 Nov 1992 17:44:23 GMT
  6. Organization: The Aerospace Corporation, El Segundo, CA
  7. Lines: 158
  8. Distribution: world
  9. Message-ID: <1egjpnINN9c0@news.aero.org>
  10. NNTP-Posting-Host: aerospace.aero.org
  11.  
  12. Hi,
  13.  
  14. I'm trying to use GXxor to draw and erase lines. The following program
  15. is not doing what I had hoped to do, so I obviously don't understand
  16. this option to XSetFunction. I would greatly appreciate any help I
  17. can get on this.
  18.  
  19. The program (modelled on "helloworld.c") is intended to draw a line,
  20. wait a few seconds, then erase the line. At each mouse button press,
  21. a slightly different line segment should be drawn, displayed a few
  22. seconds, then erased. The print statements tell me when each line is drawn
  23. or undrawn.
  24.  
  25. That's what I would like to happen. However what actually happens is
  26. that the first line segment is drawn, never erased, and successive
  27. mouse button presses don't appear to make any changes to the windows.
  28.  
  29. Typing "q" does exit the program.
  30.  
  31. Please mail any repsonses to:
  32.  
  33. gurlitz@aerospace.aero.org
  34.  
  35.                 Thanks,
  36.                 Tom Gurlitz
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. /* X include files                            */
  47. #include <X11/Xlib.h>
  48. #include <X11/X.h>
  49. #include <X11/Xutil.h>
  50.  
  51.  
  52. main(int argc, char **argv)
  53. {
  54.     Display        *mydisplay;
  55.     Window        mywindow;
  56.     GC            mygc;
  57.     XEvent        myevent;
  58.     KeySym        mykey;
  59.     XSizeHints        myhint;
  60.     int            myscreen;
  61.     unsigned long    myforeground, mybackground;
  62.     int            i;
  63.     char        text[10];
  64.     int            done;
  65.     char        hello[]    = {"Hello World."};
  66.     XPoint        points[2];
  67.  
  68.     /*    Initialization                            */
  69.     mydisplay        = XOpenDisplay("");
  70.     myscreen        = DefaultScreen(mydisplay);
  71.  
  72.     /*    Default pixel values                        */
  73.     mybackground    = WhitePixel(mydisplay, myscreen);
  74.     myforeground    = BlackPixel(mydisplay, myscreen);
  75.  
  76.     /*    Window size                            */
  77.     myhint.x        = 200.;
  78.     myhint.y        = 300.;
  79.     myhint.width    = 600;
  80.     myhint.height    = 600;
  81.     myhint.flags    = PPosition | PSize;
  82.  
  83.     /*    Window Creation                            */ 
  84.     mywindow        = XCreateSimpleWindow(mydisplay, 
  85.                 DefaultRootWindow(mydisplay),
  86.                 myhint.x, myhint.y, myhint.width,
  87.                 myhint.height, 5, myforeground, mybackground);
  88.     XSetStandardProperties(mydisplay, mywindow, hello, hello,
  89.                 None, argv, argc, &myhint);
  90.  
  91.     /*    GC creation and initialization                    */
  92.     mygc = XCreateGC(mydisplay, mywindow, 0, 0);
  93.     XSetBackground(mydisplay, mygc, mybackground);
  94.     XSetForeground(mydisplay, mygc, myforeground);
  95.  
  96.     /* input event                            */
  97.     XSelectInput(mydisplay, mywindow,
  98.             ButtonPressMask | KeyPressMask | ExposureMask);
  99.  
  100.     /* window mapping                            */
  101.     XMapRaised(mydisplay, mywindow);
  102.  
  103.     points[0].x         = 20;
  104.     points[0].y         = 20;
  105.     points[1].x         = 400;
  106.     points[1].y         = 400;
  107.  
  108.     /*    looping                                */
  109.     done    = 0;
  110.     while (done == 0)
  111.     {
  112.     /*  next event                            */
  113.     XNextEvent(mydisplay, &myevent);
  114.     switch (myevent.type)
  115.     {
  116.         case Expose:
  117.         if (myevent.xexpose.count = 0)
  118.         XDrawImageString(myevent.xexpose.display, 
  119.                     myevent.xexpose.window, mygc,
  120.                     50, 50, hello, strlen(hello) );
  121.         break;
  122.  
  123.         /*    process keyboard                    */
  124.         case MappingNotify:
  125.         XRefreshKeyboardMapping(&myevent);
  126.         break;
  127.  
  128.         /*    process mouse                        */
  129.         case ButtonPress:
  130.  
  131.         /*  Draw Line                        */
  132.  
  133.         XDrawLines(mydisplay, mywindow, mygc, points, 2,
  134.                 CoordModeOrigin);
  135.         XFlush(mydisplay);
  136.         printf("Line drawn\n");
  137.  
  138.         sleep(2);
  139.  
  140.         /*  Undraw Line                        */
  141.  
  142.         XSetFunction(mydisplay, mygc, GXxor);
  143.         XDrawLines(mydisplay, mywindow, mygc, points, 2,
  144.                     CoordModeOrigin);
  145.         printf("Line undrawn\n");
  146.  
  147.  
  148.         points[0].x    += 10;
  149.         points[0].y    += 10;
  150.         points[1].x    += 20;
  151.         points[1].y    += 20;
  152.  
  153.         break;
  154.  
  155.         /*    process keyboard input                    */
  156.         case KeyPress:
  157.         i = XLookupString(&myevent, text, 10, &mykey, 0);
  158.         if (i == 1 && text[0] == 'q')
  159.         done = 1;
  160.         break;
  161.     }
  162.     }
  163.  
  164.     /* termination                            */
  165.     XFreeGC(mydisplay, mygc);
  166.     XDestroyWindow(mydisplay, mywindow);
  167.     XCloseDisplay(mydisplay);
  168.     exit(0);
  169. }
  170.