home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / csranli.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  5KB  |  176 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    csranli.c (Cursor Annuli)
  6.  * Purpose:    Deal with annuli of the software cursor
  7.  * Subroutine:    make_new_annulus()
  8.  * Subroutine:    move_annuli()
  9.  * Subroutine:    update_annuli_centers()            returns: void
  10.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  11.  *        You may do anything you like with this file except remove
  12.  *        this copyright.  The Smithsonian Astrophysical Observatory
  13.  *        makes no representations about the suitability of this
  14.  *        software for any purpose.  It is provided "as is" without
  15.  *        express or implied warranty.
  16.  * Modified:    {0} Michael VanHilst    initial version          4 June 1989
  17.  *        {n} <who> -- <does what> -- <when>
  18.  *
  19.  *  The interaction for annuli is as follows:
  20.  *  On menu button: set annuli flag (turn button off if point or polygon).
  21.  *  On middle button:
  22.  *   Push: free annuli if grabbed.  Make cursor at mouse or inc position.
  23.  *   Move: size with annuli restrictions
  24.  *   Release: install new annuli record, redraw all cursors.
  25.  *  Left button: move all centers
  26.  */
  27.  
  28. #include <stdio.h>        /* stderr, NULL, etc. */
  29. #include <X11/Xlib.h>        /* X window stuff */
  30. #include <X11/Xutil.h>        /* X window manager stuff */
  31. #include "hfiles/color.h"    /* cursor colors needed by Cursor.h */
  32. #include "hfiles/cursor.h"    /* define cursor parameter structures */
  33.  
  34. extern struct colorRec color;    /* need to know color.gcset */
  35.  
  36. /*
  37.  * Subroutine:    make_new_annulus
  38.  * Purpose:    Copy the cursor onto an annulus
  39.  */
  40. void make_new_annulus ( cursor )
  41.      struct cursorRec *cursor;
  42. {
  43.   struct cursorRec *annulus;
  44.   struct cursorRec *annuli;
  45.   struct cursorRec *copy_cursor();
  46.   int index;
  47.  
  48.   annulus = copy_cursor (cursor);
  49.   /* annuli are always include regions */
  50.   annulus->exclude_region = 0;
  51.   if( cursor->next_annulus == 0 ) {
  52.     annulus->next_annulus = 0;
  53.     annulus->index = 1;
  54.     cursor->next_annulus = annulus;
  55.   } else {
  56.     if( cursor->next_annulus->win.rayX > annulus->win.rayX ) {
  57.       annulus->next_annulus = cursor->next_annulus;
  58.       annulus->index = 1;
  59.       cursor->next_annulus = annulus;
  60.     } else {
  61.       annuli = cursor->next_annulus;
  62.       /* find sort position for new annulus */
  63.       while( (annuli->next_annulus != 0) &&
  64.          (annuli->next_annulus->win.rayX < annulus->win.rayX) ) {
  65.     annuli = annuli->next_annulus;
  66.       }
  67.       /* splice in the new annulus */
  68.       annulus->next_annulus = annuli->next_annulus;
  69.       annulus->index = annuli->index + 1;
  70.       annuli->next_annulus = annulus;
  71.     }
  72.     /* updates everybody's index */
  73.     index = annulus->index;
  74.     annuli = annulus->next_annulus;
  75.     while( annuli != NULL ) {
  76.       annuli->index = ++index;
  77.       annuli = annuli->next_annulus;
  78.     }
  79.   }
  80. }
  81.  
  82. /*
  83.  * Subroutine:    delete_annuli
  84.  * Purpose:    Remove all but the innermost annulus
  85.  * Called by:    select_cursor() in CursorCtrl.c
  86.  */
  87. void delete_annuli ( cursor, collapse )
  88.      struct cursorRec *cursor;
  89.      int collapse;        /* i: inner-ring-becomes-cursor */
  90. {
  91.   struct cursorRec *annulus, *temp;
  92.   void make_cursor(), draw_annuli(), free_cursor();
  93.  
  94.   if( (annulus = cursor->next_annulus) != NULL ) {
  95.     if( collapse ) {
  96.       /* make cursor like the innermost annulus */
  97.       cursor->win.rayX = annulus->win.rayX;
  98.       cursor->win.rayY = annulus->win.rayY;
  99.       make_cursor (cursor);
  100.     }
  101.     /* if image will not be redrawn, erase the annuli */
  102.     if( !cursor->overwrites_image_data )
  103.       draw_annuli(cursor, &color.gcset.undraw);
  104.     /* delete and free all annuli */
  105.     do {
  106.       temp = annulus->next_annulus;
  107.       free_cursor(annulus);
  108.       annulus = temp;
  109.     } while( annulus != 0 );
  110.     cursor->next_annulus = NULL;
  111.   }
  112. }
  113.  
  114. /*
  115.  * Subroutine:    move_annuli
  116.  * Purpose:    Change annuli location
  117.  */
  118. void move_annuli ( cursor, winx, winy )
  119.      struct cursorRec *cursor;
  120.      int winx, winy;
  121. {
  122.   int dxm, dym;
  123.   struct cursorRec *annulus;
  124.   void draw_annuli();
  125.  
  126.   /* HOW MUCH DID WE MOVE? */
  127.   dxm = winx - cursor->win.x;
  128.   dym = winy - cursor->win.y;
  129.   cursor->win.x = winx;
  130.   cursor->win.y = winy;
  131.   cursor->win.X = (double)cursor->win.x + 0.5;
  132.   cursor->win.Y = (double)cursor->win.y + 0.5;
  133.   /* erase the current annuli */
  134.   draw_annuli (cursor, &color.gcset.undraw);
  135.   /* move all the annuli */
  136.   annulus = cursor;
  137.   while( annulus != 0 ) {
  138.     register XPoint *points;
  139.     register int i;
  140.     int point_cnt;
  141.  
  142.     /* MOVE ALL POINTS */
  143.     point_cnt = annulus->point_cnt;
  144.     points = annulus->points;
  145.     for( i=0; i < point_cnt; i++ ) {
  146.       points[i].x += dxm;
  147.       points[i].y += dym;
  148.     }
  149.     /* UPDATE RECORD OF CENTER */
  150.     annulus->win.x = cursor->win.x;
  151.     annulus->win.y = cursor->win.y;
  152.     annulus->win.X = cursor->win.X;
  153.     annulus->win.Y = cursor->win.Y;
  154.     annulus = annulus->next_annulus;
  155.   }
  156.   /* draw the new annuli */
  157.   draw_annuli (cursor, &color.gcset.track);
  158. }
  159.  
  160. /*
  161.  * Subroutine:    recenter_annuli_centers
  162.  * Purpose:    Update cursor location params
  163.  */
  164. void update_annuli_centers ( cursor )
  165.      struct cursorRec *cursor;
  166. {
  167.   struct cursorRec *annulus;
  168.  
  169.   annulus = cursor->next_annulus;
  170.   while( annulus != 0 ) {
  171.     annulus->file.X = cursor->file.X;
  172.     annulus->file.Y = cursor->file.Y;
  173.     annulus = annulus->next_annulus;
  174.   }
  175. }
  176.