home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / VOGLE.ZIP / VOGLE / EXAMPLES / LOC.C < prev    next >
C/C++ Source or Header  |  2000-02-11  |  1KB  |  73 lines

  1. #include <stdio.h>
  2. #include "vogle.h"
  3.  
  4. /*
  5.  * a routine to demonstrate using locator.
  6.  */
  7. main()
  8. {
  9.     char    dev[50], name[50];
  10.     int    i, bt, curpnt, act, nchars;
  11.     float    x, y, sx, sy;
  12.  
  13.     fprintf(stderr,"Enter device name: ");
  14.     gets(dev);
  15.  
  16.     prefsize(512, 512);
  17.     vinit(dev);
  18.  
  19.     color(BLACK);
  20.     clear();
  21.  
  22.     color(BLUE);
  23.  
  24.     /*
  25.      * draw some axes
  26.      */
  27.     move2(0.0, 1.0);
  28.     draw2(0.0, -1.0);
  29.  
  30.     move2(1.0, 0.0);
  31.     draw2(-1.0, 0.0);
  32.  
  33.     color(GREEN);
  34.  
  35.     act = 0;
  36.     curpnt = 0;
  37.     /*
  38.      * locator returns whether a mouse button has been
  39.      * pressed or not. In a device such as the tektronix
  40.      * where you have to wait for a keypress to get the
  41.      * position of the crosshairs locator returns 0
  42.      * automatically on every second call. A return value
  43.      * of 2 indicates the second mouse button has been pressed.
  44.      * A return value of 1 indicates the first mouse button has
  45.      * been pressed. We wait for the locator to return zero so
  46.      * that we know the mouse button has been released.
  47.      */
  48.     while((bt = locator(&x, &y)) != 2) {
  49.         if (bt == -1) {
  50.             vexit();
  51.             printf("No locator device found\n");
  52.             exit(0);
  53.         } else if (bt == 0) {
  54.             act = 1;
  55.         } else if (act) {
  56.             act = 0;
  57.             if (bt == 1) {
  58.                 if (curpnt) {
  59.                     move2(sx, sy);
  60.                     draw2(x, y);
  61.                     curpnt = 0;
  62.                 } else
  63.                     curpnt = 1;
  64.                 sx = x;
  65.                 sy = y;
  66.             }
  67.         }
  68.     }
  69.  
  70.     vexit();
  71.  
  72. }
  73.