home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / pancrsr.c < prev    next >
C/C++ Source or Header  |  1990-05-02  |  3KB  |  114 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    pancrsr.c (Pan Cursor)
  6.  * Purpose:    Handle the pan window cursor
  7.  * Subroutine:    draw_pancursor()        returns: void
  8.  * Subroutine:    new_pancursor()            returns: void
  9.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  10.  *        You may do anything you like with this file except remove
  11.  *        this copyright.  The Smithsonian Astrophysical Observatory
  12.  *        makes no representations about the suitability of this
  13.  *        software for any purpose.  It is provided "as is" without
  14.  *        express or implied warranty.
  15.  * Modified:    {0} Michael VanHilst    initial version         29 May 1989
  16.  *        {n} <who> -- <does what> -- <when>
  17.  */
  18.  
  19. #include <X11/Xlib.h>        /* X window stuff */
  20. #include <X11/Xutil.h>        /* X window manager stuff */
  21. #include "hfiles/struct.h"    /* declare structure types */
  22. #include "hfiles/extern.h"    /* extern main parameter structures */
  23. #include "hfiles/define.h"    /* define MIN */
  24.  
  25. static int pancur_x, pancur_y;
  26. static unsigned int pancur_width, pancur_height;
  27. static int pancur_present = 0;
  28.  
  29. /*
  30.  * Subroutine:    draw_pancursor
  31.  * Purpose:    Draw the pan window cursor
  32.  */
  33. void draw_pancursor ( )
  34. {
  35.   GC gc, set_gc();
  36.  
  37.   if( pancur_present ) {
  38.     gc = set_gc(&color.gcset.draw);
  39.     XDrawRectangle(panbox.display, panbox.ID, gc,
  40.            pancur_x, pancur_y, pancur_width, pancur_height);
  41.   }
  42. }
  43.  
  44. /*
  45.  * Subroutine:    new_pancursor
  46.  * Purpose:    Create and draw panbox cursor given image coordinates
  47.  */
  48. void new_pancursor ( track )
  49.      int track;
  50. {
  51.   float panX1, panX2, panY1, panY2;
  52.   GC gc, set_gc();
  53.   void disp_window(), i_transform();
  54.   static void set_pancursor();
  55.  
  56.   if( pancur_present ) {
  57.     /* erase the old box if it was visible */
  58.     if( (color.cursor_overlay) || track ) {
  59.       gc = set_gc(&color.gcset.undraw);
  60.       XDrawRectangle(panbox.display, panbox.ID, gc,
  61.              pancur_x, pancur_y, pancur_width, pancur_height);
  62.     } else {
  63.       /* draw a new image to erase old cursor */
  64.       disp_window(&panbox);
  65.     }
  66.   }
  67.   /* calculate display corners in pan coords */
  68.   i_transform(&coord.imgtopan,
  69.           coord.tid.srcX1, coord.tid.srcY1, &panX1, &panY1);
  70.   i_transform(&coord.imgtopan,
  71.           coord.tid.srcX2, coord.tid.srcY2, &panX2, &panY2);
  72.   set_pancursor(&coord.pan, (int)panX1, (int)panX2, (int)panY1, (int)panY2);
  73.   /* draw the new box if it is visible */
  74.   if( pancur_present ) {
  75.     if( track )
  76.       gc = set_gc(&color.gcset.track);
  77.     else
  78.       gc = set_gc(&color.gcset.draw);
  79.     XDrawRectangle(panbox.display, panbox.ID, gc,
  80.            pancur_x, pancur_y, pancur_width, pancur_height);
  81.   }
  82. }
  83.  
  84. /*
  85.  * Subroutine:    set_pancursor
  86.  * Purpose:    Set points in a panbox cursor
  87.  */
  88. static void set_pancursor ( pan, left_x, right_x, top_y, low_y )
  89.      Coordsys *pan;
  90.      int left_x, right_x, top_y, low_y;
  91. {
  92.   /* limit pan cursor to the panbox dimensions */
  93.   if( left_x < pan->X1i )
  94.     pancur_x = pan->X1i;
  95.   else
  96.     pancur_x = left_x;
  97.   if( right_x > pan->X2i )
  98.     pancur_width = pan->X2i - pancur_x;
  99.   else
  100.     pancur_width = right_x - pancur_x;
  101.   if( top_y < pan->Y1i )
  102.     pancur_y = pan->Y1i;
  103.   else
  104.     pancur_y = top_y;
  105.   if( low_y > pan->Y2i )
  106.     pancur_height = pan->Y2i - pancur_y;
  107.   else
  108.     pancur_height = low_y - pancur_y;
  109.   if( (pancur_width > 0) && (pancur_height > 0) )
  110.     pancur_present = 1;
  111.   else
  112.     pancur_present = 0;
  113. }
  114.