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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /*
  6.  * Module:    draw.c (Draw Button)
  7.  * Project:    PROS -- ROSAT RSDC
  8.  * Purpose:    Draw buttons to server under various circumstances
  9.  * Subroutine:    btn_DrawButton()        returns: void
  10.  * Subroutine:    btn_PutImage()            returns: void
  11.  * Subroutine:    btn_DelightButtons()        returns: void
  12.  * Subroutine:    static btn_DimButtons()        returns: void
  13.  * Subroutine:    btn_RelightButtons()        returns: void
  14.  * Subroutine:    static btn_LightButtons()    returns: void
  15.  * Xlib calls:    XPutImage()
  16.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  17.  *        You may do anything you like with this file except remove
  18.  *        this copyright.  The Smithsonian Astrophysical Observatory
  19.  *        makes no representations about the suitability of this
  20.  *        software for any purpose.  It is provided "as is" without
  21.  *        express or implied warranty.
  22.  * Modified:    {0} Michael VanHilst    initial version        31 March 1989
  23.  *        {1} Rick Schumeyer (Naval Research Lab)            8 May 1991
  24.  * Fixed button problem on Alliant.  The buttons do not display correctly on
  25.  * the Alliant in the XYBitmap format.  If the -button option is given, I copy
  26.  * each button image from XYBitmap to ZPixmap, and display the ZPixmap.  The
  27.  * variable bad_buttons is set in ../cmdparse.c.
  28.  *        {n} <who> -- <does what> -- <when>
  29.  */
  30.  
  31. #include <stdio.h>
  32. #include <X11/Xlib.h>    /* needed for Buttons.h */
  33. #include "buttons.h"
  34.  
  35. #ifdef ALLIANT
  36. /* If bad_buttons=0, then draw XYBitmap (normal).  If bad_buttons=1, then draw
  37.  * ZPixmap.  bad_buttons will be set to 1 if -button is given on command line.
  38.  */
  39. int bad_buttons=0;
  40. XImage *zimage[250];
  41. int nbutton=0;
  42. int init_button=1;   /* =1 if buttons need to be initialized */
  43. int button_first=1;
  44. void put_z_image();
  45. #endif
  46.  
  47. /*
  48.  * Subroutine:    btn_DrawButton
  49.  * Purpose:    Draw button according to its status
  50.  * Returns:    void
  51.  * Called by:    
  52.  * Uses:    btn_PutImage() below
  53.  * Xlib calls:    none
  54.  */
  55. void btn_DrawButton ( button )
  56.      ButtonRecord *button;
  57. {
  58.   void btn_PutImage();
  59.  
  60.   if( button->highlight ) {
  61.     if( button->occupied )
  62.       btn_PutImage(button, ON_IN);
  63.     else
  64.       btn_PutImage(button, ON_OUT);
  65.   } else {
  66.     if( button->occupied )
  67.       btn_PutImage(button, OFF_IN);
  68.     else
  69.       btn_PutImage(button, OFF_OUT);
  70.   }
  71.   return;
  72. }
  73.  
  74. /*
  75.  * Subroutine:    btn_PutImage
  76.  * Purpose:    Draw button in given phase
  77.  * Returns:    void
  78.  * Called by:    btn_DrawButton() above
  79.  * Xlib calls:    XPutImage()
  80.  * Pre-state:    XImages for button and a GC must have been prepared before
  81.  */
  82. void btn_PutImage ( button, phase )
  83.      ButtonRecord *button;
  84.      int phase;
  85. {
  86. #ifdef ALLIANT
  87.     if (bad_buttons)
  88.       put_z_image(button, phase);
  89.     else
  90. #endif
  91.   XPutImage(button->display, button->wndwID, button->gc, button->image[phase],
  92.         0, 0, 0, 0, button->width, button->height);
  93. }
  94.  
  95. /*
  96.  * Subroutine:    btn_DelightButtons
  97.  * Purpose:    Make all highlighted buttons at this level of submenu
  98.  *        unhighlighted (used with While and Co-mode buttons to supress
  99.  *        some buttons while highlighting a specific one)
  100.  * Returns:    void
  101.  * Uses:    btn_DimButtons() below
  102.  * Called by:
  103.  * Xlib calls:    none
  104.  * Method:    Dim this box and all co-menu boxes
  105.  */
  106. void btn_DelightButtons ( buttonbox )
  107.      ButtonBox buttonbox;
  108. {
  109.   int i;
  110.   static void btn_DimButtons();
  111.  
  112.   btn_DimButtons(buttonbox);
  113.   for( i=0; i < buttonbox->co_menu_count; i++ ) {
  114.     btn_DimButtons(buttonbox->co_menu[i]);
  115.   }
  116. }
  117.  
  118.  
  119. /*
  120.  * Subroutine:    btn_DimButtons
  121.  * Purpose:    Make all highlighted buttons in this box unhighlighted except
  122.  *        the one presently being selected (used with While and Co-mode
  123.  *        buttons to supress all but selected button)
  124.  * Returns:    void
  125.  * Called by:    btn_DelightButtons() above
  126.  * Uses:    btn_PutImage() above
  127.  * Xlib calls:    none
  128.  * Method:    Unhighlight any buttons currently highlighted, except the one
  129.  *        presently being pressed
  130.  */
  131. static void btn_DimButtons ( buttonbox )
  132.      ButtonBox buttonbox;
  133. {
  134.   int i;
  135.   void btn_PutImage();
  136.  
  137.   for( i = 0; i < buttonbox->btn_cnt; i++ ) {
  138.     if( (buttonbox->buttons[i].highlight) &&
  139.     (buttonbox->down_btn != i) ) {
  140.       buttonbox->buttons[i].highlight = 0;
  141.       btn_PutImage(&buttonbox->buttons[i], OFF_OUT);
  142.     }
  143.   }
  144. }
  145.  
  146.  
  147. /*
  148.  * Subroutine:    btn_RelightButtons
  149.  * Purpose:    Make all selected buttons at this level of submenu highlighted
  150.  *        (used to restore default condition after btn_DelightButtons())
  151.  * Returns:    void
  152.  * Called by:    
  153.  * Uses:    btn_LightButtons() below
  154.  * Xlib calls:    none
  155.  */
  156. void btn_RelightButtons ( buttonbox )
  157.      ButtonBox buttonbox;
  158. {
  159.   int i;
  160.   static void btn_LightButtons();
  161.  
  162.   btn_LightButtons(buttonbox);
  163.   for( i=0; i < buttonbox->co_menu_count; i++ ) {
  164.     btn_LightButtons(buttonbox->co_menu[i] );
  165.   }
  166. }
  167.  
  168. /*
  169.  * Subroutine:    btn_LightButtons
  170.  * Purpose:    Make all select buttons in this box highlighted (used to
  171.  *        restore default condition after btn_DimButtons())
  172.  * Returns:    void
  173.  * Called by:    btn_RelightButtons() above
  174.  * Uses:    btn_PutImage() above
  175.  * Xlib calls:    none
  176.  */
  177. static void btn_LightButtons ( buttonbox )
  178.      ButtonBox buttonbox;
  179. {
  180.   int i;
  181.   void btn_PutImage();
  182.  
  183.   for( i = 0; i < buttonbox->btn_cnt; i++ ) {
  184.     if( buttonbox->buttons[i].selected ) {
  185.       buttonbox->buttons[i].highlight = 1;
  186.       if( buttonbox->buttons[i].occupied )
  187.     btn_PutImage(&buttonbox->buttons[i], ON_IN);
  188.       else
  189.     btn_PutImage(&buttonbox->buttons[i], ON_OUT);
  190.     }
  191.   }
  192. }
  193.  
  194.  
  195. #ifdef ALLIANT
  196. /*
  197.  * Subroutine: put_z_image
  198.  */
  199. void put_z_image(button, phase)
  200.      ButtonRecord *button;
  201.      int phase;
  202. {
  203.     char *d;
  204.     int i,j,l;
  205.     void init_z_image();
  206.  
  207.     if (init_button)
  208.       init_z_image();
  209.  
  210.     if (zimage[button->id[phase]]==NULL) {
  211.         d = (char *)malloc(button->width*button->height);
  212.         zimage[button->id[phase]] = XCreateImage
  213.           (button->display, DefaultVisual(button->display,0),
  214.            8, ZPixmap, 0, d, button->width, button->height, 8, 0);
  215.  
  216.         for (i=0;i<button->height;i++)
  217.           for (j=0;j<button->width;j++){
  218.               l = XGetPixel(button->image[phase],j,i);
  219.               XPutPixel(zimage[button->id[phase]],j,i,
  220.                         (l?BlackPixel(button->display,0):
  221.                          WhitePixel(button->display,0)));
  222.           }
  223.     }
  224.     XPutImage(button->display, button->wndwID, button->gc, 
  225.               zimage[button->id[phase]], 0, 0, 0, 0, button->width,
  226.               button->height);
  227. }
  228. /*
  229.  * Subroutine: init_z_image
  230.  */
  231. void init_z_image()
  232. {
  233.     int i;
  234.  
  235.     for (i=0; i<250; i++) {
  236.         if ((zimage[i] != NULL)&&(!button_first))
  237.           XDestroyImage(zimage[i]);
  238.         zimage[i]=NULL;
  239.     }
  240.  
  241.     nbutton=0;
  242.     init_button=0;
  243.     button_first=0;
  244. }
  245. #endif
  246.