home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / csrslct.c < prev    next >
C/C++ Source or Header  |  1991-01-05  |  7KB  |  200 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    csrslct.c (Cursor Select)
  6.  * Purpose:    Initialize and change states of the software cursor
  7.  * Subroutine:    select_cursor()            returns: void
  8.  * Subroutine:    init_software_cursors()        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         4 June 1989
  16.  *        {1} MVH added arrow and text cursors              1 Jan 1991
  17.  *        {n} <who> -- <does what> -- <when>
  18.  */
  19.  
  20. #include <stdio.h>        /*  stderr, NULL, etc.  */
  21. #include <X11/Xlib.h>        /*  X window stuff  */
  22. #include <X11/Xutil.h>        /*  X window manager stuff  */
  23. #include "hfiles/constant.h"    /*  Define codes  */
  24. #include "hfiles/struct.h"    /*  Declare structure types  */
  25. #include "hfiles/extern.h"    /*  Extern main parameter structures  */
  26.  
  27. #ifdef ANSIC
  28. /*  Exported declarations must be centralized before ANSI C can be used  */
  29.  
  30. void        select_cursor();
  31. void        init_software_cursors();
  32.  
  33. #else
  34.  
  35.   int init_vertices();
  36.   void make_cursor(), disp_dispbox(), erase_cursor(), enable_ortho_button();
  37.   void set_submenu_toggle(), delete_annuli(), enable_annuli_button();
  38.   void collapse_polygon(), start_polygon(), make_new_annulus(), disp_cursor();
  39.   void clear_textcursor(), new_textcursor();
  40.   char *calloc_errchk();
  41.   void note_current_disp_transform(), d_transform();
  42.  
  43. #endif
  44.  
  45.  
  46. /*  Subroutine:    select_cursor
  47.  *  Purpose:    Respond to command input from user interface
  48.  */
  49. void select_cursor ()
  50. {
  51.   /*  If main menu selection, set mode(s) and return  */
  52.   if( control.response[1] == 0 ) {
  53.     control.mode = COP;
  54.     if( cursor.type == COP_Text )
  55.       grab_keys_for_textcursor(1);
  56.     return;
  57.   }
  58.   if( (control.response[1] & COP_Shape) != 0 ) {
  59.     /*  Erase the current cursor and set the new one  */
  60.     if( cursor.annuli ) {
  61.       /*  Annuli cannot be an initial condition (erases if in overlay)  */
  62.       delete_annuli(&cursor, 1);
  63.       cursor.annuli = 0;
  64.       set_submenu_toggle(COP, COP_Annuli, 0);
  65.     }
  66.     if( cursor.overwrites_image_data ) {
  67.       int point_cnt = cursor.point_cnt;
  68.       cursor.point_cnt = 0;
  69.       /*  Polygon is either collapsed or eliminated, so no need to save cnt  */
  70.       cursor.rectangle_cnt = 0;
  71.       /*  Redraw image and any saved cursors  */
  72.       disp_dispbox();
  73.       cursor.point_cnt = point_cnt;
  74.     } else {
  75.       /*  Just erase the cursor  */
  76.       erase_cursor(&cursor);
  77.     }
  78.     /*  If changing cursor type  */
  79.     if( cursor.type != control.response[1] ) {
  80.       if( cursor.type == COP_Polygon ) {
  81.     /*  Suppress hash-marks and vertex list  */
  82.     cursor.rectangle_cnt = 0;
  83.     cursor.poly_cnt = 0;
  84.       } else if( cursor.type == COP_Text ) {
  85.     clear_textcursor();
  86.       }
  87.       cursor.type = control.response[1];
  88.       /*  Set vertex coordinates and any other environment stuff  */
  89.       if( (cursor.type == COP_Box) ||
  90.       (cursor.type == COP_Ellipse) ) {
  91.     enable_annuli_button(1);
  92.     enable_ortho_button(1);
  93.     make_cursor(&cursor);
  94.       } else if( cursor.type == COP_Circle ) {
  95.     enable_annuli_button(1);
  96.     enable_ortho_button(0);
  97.     make_cursor(&cursor);
  98.       } else {
  99.     enable_annuli_button(0);
  100.     enable_ortho_button(0);
  101.     if( cursor.type == COP_Polygon ) {
  102.       /*  Prepare special polygon facilities  */
  103.       start_polygon(&cursor, &coord);
  104.     } else if( cursor.type == COP_Text ) {
  105.       new_textcursor();
  106.     } else {
  107.       /*  This leaves Point and Arrow  */
  108.       make_cursor(&cursor);
  109.     }
  110.       }
  111.     } else if( cursor.type == COP_Polygon ) {
  112.       /*  Reclicking on polygon resets all its points  */
  113.       collapse_polygon(&cursor);
  114.     }
  115.   } else if( control.response[1] == COP_Annuli ) {
  116.     if( cursor.annuli ) {
  117.       /*  If turning off annuli  */
  118.       cursor.annuli = 0;
  119.       if( cursor.next_annulus != 0 ) {
  120.     delete_annuli(&cursor, 1);
  121.     if( cursor.overwrites_image_data )
  122.       /*  Redraw image and cursor  */
  123.       disp_dispbox();
  124.       }
  125.       if( cursor.type != COP_Circle )
  126.     enable_ortho_button(1);
  127.     } else {
  128.       /*  If turning on annuli  */
  129.       if( (cursor.type == COP_Point) || (cursor.type == COP_Polygon) ) {
  130.     /*  This should never happen  */
  131.     set_submenu_toggle(COP, COP_Annuli, 0);
  132.       } else {
  133.     cursor.annuli = 1;
  134.     /*  Current cursor becomes first annulus  */
  135.     make_new_annulus(&cursor);
  136.       }
  137.       enable_ortho_button(0);
  138.     }
  139.   } else if( control.response[1] == COP_Orthogonal ) {
  140.     if( cursor.annuli )
  141.       return;
  142.     if( cursor.overwrites_image_data ) {
  143.       int point_cnt = cursor.point_cnt;
  144.       cursor.point_cnt = 0;
  145.       /*  Polygon is either collapsed or eliminated, so no need to save cnt  */
  146.       cursor.rectangle_cnt = 0;
  147.       /*  Redraw image and any saved cursors  */
  148.       disp_dispbox();
  149.       cursor.point_cnt = point_cnt;
  150.     } else {
  151.       /*  Just erase the cursor  */
  152.       erase_cursor(&cursor);
  153.     }
  154.     cursor.rot.angle = 0.0;
  155.     cursor.rot.cos = -1.0;
  156.     cursor.rot.sin = 0.0;
  157.     if( (cursor.type == COP_Ellipse) || (cursor.type == COP_Box) )
  158.       make_cursor(&cursor);
  159.     else
  160.       return;
  161.   }
  162.   /*  Draw the cursor  */
  163.   disp_cursor(&cursor);
  164.   /*  If cursor isn't the mode, make it the mode  */
  165.   control.mode = COP;
  166. }
  167.  
  168.  
  169. /*  Subroutine:    init_software_cursors
  170.  *  Purpose:    Initialize the cursor parameters
  171.  *  Prestate:    Color must be determined and dispbox must be created and sized
  172.  */
  173. void init_software_cursors ()
  174. {
  175.   cursor.points =
  176.     (XPoint *)calloc_errchk(CURSOR_MAX + 1, sizeof(XPoint), "Cursor");
  177.   /*  Record the current display parameters, to later recognize a change  */
  178.   note_current_disp_transform(&coord.filetodisp);
  179.   /*  If cursor position not set, center it on image  */
  180.   if( (cursor.file.X < 0.0) || (cursor.file.Y < 0.0) )
  181.     d_transform(&coord.imgtofile, (double)coord.img.cenX,
  182.         (double)coord.img.cenY, &cursor.file.X, &cursor.file.Y);
  183.   if( (cursor.type == COP_Polygon) || (cursor.type == COP_Point) ) {
  184.     cursor.annuli = 0;
  185.     if( cursor.type == COP_Polygon )
  186.       /*  Prepare special polygon facilities  */
  187.       start_polygon(&cursor, &coord);
  188.   } else {
  189.     make_cursor (&cursor);
  190.     if( cursor.annuli )
  191.       /*  Current cursor becomes first annulus  */
  192.       make_new_annulus(&cursor);
  193.   }
  194.   /*  Set cursor drawing color params  */
  195.   cursor.win.display = dispbox.display;
  196.   cursor.win.ID = dispbox.ID;
  197.   cursor.overwrites_image_data = !color.cursor_overlay;
  198.   cursor.draw = &color.gcset.draw;
  199. }
  200.