home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / LOC.C < prev    next >
Text File  |  1993-05-28  |  1KB  |  68 lines

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