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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    grphtext.c (Color Graph Text)
  6.  * Purpose:    Initialize or reset color bar and graph
  7.  * Subroutine:    init_colorbar_label()        returns: void
  8.  * Subroutine:    init_color_graph_label()    returns: void
  9.  * Subroutine:    create_cgraph_box()        returns: Window
  10.  * Xlib calls:    XMoveWindow(), XResizeWindow(), XMapWindow(), XCreateWindow()
  11.  * Xlib calls:    XTextWidth()
  12.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  13.  *        You may do anything you like with this file except remove
  14.  *        this copyright.  The Smithsonian Astrophysical Observatory
  15.  *        makes no representations about the suitability of this
  16.  *        software for any purpose.  It is provided "as is" without
  17.  *        express or implied warranty.
  18.  * Modified:    {0} Michael VanHilst    initial version         22 June 1989
  19.  *        {n} <who> -- <does what> -- <when>
  20.  */
  21.  
  22. #include <stdio.h>        /* stderr, NULL, etc. */
  23. #include <X11/Xlib.h>        /* X window stuff */
  24. #include <X11/Xutil.h>        /* X window manager stuff */
  25. #include "hfiles/struct.h"    /* declare structure types */
  26. #include "hfiles/extern.h"    /* extern main parameter structures */
  27. #include "hfiles/cgraph.h"
  28.  
  29. extern struct cgraphRec cgraph;
  30.  
  31. /*
  32.  * Subroutine:    init_color_graph_label
  33.  * Purpose:    Set labeling pieces according to the graph window size
  34.  * Xlib calls:    XMoveWindow(), XResizeWindow(), XMapWindow()
  35.  */
  36. void init_color_graph_label ( )
  37. {
  38.   int new = 0;
  39.   int move = 0;
  40.   int resize = 0;
  41.   Window create_cgraph_box();
  42.   void init_color_graph_label();
  43.   static void init_colorbar_label();
  44.  
  45.   if( cgraph.graphlabel.active == 0 )
  46.     return;
  47.   if( cgraph.vertical ) {
  48.     if( (cgraph.graphlabel.gamma_ID != NULL) &&
  49.         (cgraph.graphlabel.width != graphbox.width) )
  50.       resize = 1;
  51.     cgraph.graphlabel.width = graphbox.width - cgraph.barlabel.width;
  52.     /* place boxes together (side-by-side) and centered */
  53.     if( graphbox.width >= cgraph.graphlabel.four_limit ) {
  54.       cgraph.graphlabel.geq_x =
  55.     2 + ((graphbox.width - cgraph.graphlabel.four_limit) / 2);
  56.       cgraph.graphlabel.red_x =
  57.     cgraph.graphlabel.geq_x + cgraph.graphlabel.geq_width + 3;
  58.       if( (cgraph.graphlabel.gamma_ID != NULL) &&
  59.       (cgraph.graphlabel.geq_active == 0) ) {
  60.     /* prior state existed without use of geq window */
  61.     move = 1;
  62.     if( cgraph.graphlabel.geq_ID == NULL ) {
  63.       cgraph.graphlabel.geq_ID =
  64.         create_cgraph_box(cgraph.graphlabel.geq_x,
  65.                   cgraph.graphlabel.geq_y,
  66.                   cgraph.graphlabel.geq_width,
  67.                   cgraph.graphlabel.geq_height, graphbox.display,
  68.                   cgraph.graphlabel.gamma_ID, -1, CenterGravity);
  69.     } else {
  70.       /* geq window exists but isn't mapped */
  71.       XMoveWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID,
  72.               cgraph.graphlabel.geq_x, cgraph.graphlabel.geq_y);
  73.       XMapWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID);
  74.     }
  75.       }
  76.       cgraph.graphlabel.geq_active = 1;
  77.     } else {
  78.       cgraph.graphlabel.red_x = 
  79.     ((graphbox.width - cgraph.graphlabel.three_limit) / 2);
  80.       if( cgraph.graphlabel.geq_ID && cgraph.graphlabel.active ) {
  81.     XUnmapWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID);
  82.     move = 1;
  83.       }
  84.       cgraph.graphlabel.geq_active = 0;
  85.     }
  86.     cgraph.graphlabel.green_x =
  87.       cgraph.graphlabel.red_x + cgraph.graphlabel.box_width + 3;
  88.     cgraph.graphlabel.blue_x =
  89.       cgraph.graphlabel.green_x + cgraph.graphlabel.box_width + 3;
  90.     /* offset "min" and "max" from bottom, offset "max" from right */
  91.     cgraph.graphlabel.min_y = graphbox.height - cgraph.graphlabel.minmax_yoff;
  92.     cgraph.graphlabel.max_y = cgraph.graphlabel.min_y;
  93.     cgraph.graphlabel.max_x = graphbox.width - cgraph.graphlabel.minmax_xoff;
  94.     if( cgraph.graphlabel.gamma_ID == NULL ) {
  95.       cgraph.graphlabel.gamma_ID =
  96.     create_cgraph_box(cgraph.barlabel.width, 0,
  97.               cgraph.graphlabel.width, cgraph.graphlabel.height,
  98.               graphbox.display, graphbox.ID, -1, NorthGravity);
  99.       cgraph.graphlabel.minmax_ID = graphbox.ID;
  100.       new = 1;
  101.     }
  102.   } else {
  103.     if( (cgraph.graphlabel.gamma_ID != NULL) &&
  104.         (cgraph.graphlabel.height != graphbox.height) )
  105.       resize = 1;
  106.     cgraph.graphlabel.height = graphbox.height;
  107.     /* place boxes together (one_above-the-other) and centered */
  108.     if( cgraph.graphlabel.height >= cgraph.graphlabel.four_limit ) {
  109.       cgraph.graphlabel.geq_y =
  110.     (1 + cgraph.graphlabel.height - cgraph.graphlabel.four_limit) / 2;
  111.       cgraph.graphlabel.red_y =
  112.     cgraph.graphlabel.geq_y + cgraph.graphlabel.box_height + 3;
  113.       if( (cgraph.graphlabel.gamma_ID != NULL) &&
  114.       (cgraph.graphlabel.geq_active == 0) ) {
  115.     /* prior state existed without use of geq window */
  116.     move = 1;
  117.     if( cgraph.graphlabel.geq_ID == NULL )
  118.       cgraph.graphlabel.geq_ID =
  119.         create_cgraph_box(cgraph.graphlabel.geq_x,
  120.                   cgraph.graphlabel.geq_y,
  121.                   cgraph.graphlabel.geq_width,
  122.                   cgraph.graphlabel.geq_height, graphbox.display,
  123.                   cgraph.graphlabel.gamma_ID, -1, CenterGravity);
  124.     else
  125.       /* geq window exists but isn't mapped */
  126.       XMoveWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID,
  127.               cgraph.graphlabel.geq_x, cgraph.graphlabel.geq_y);
  128.     XMapWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID);
  129.       }
  130.       cgraph.graphlabel.geq_active = 1;
  131.     } else {
  132.       cgraph.graphlabel.red_y =
  133.     1 + ((cgraph.graphlabel.height - cgraph.graphlabel.three_limit) / 2);
  134.       if( cgraph.graphlabel.geq_ID && cgraph.graphlabel.active ) {
  135.     XUnmapWindow(cgraph.graph.display, cgraph.graphlabel.geq_ID);
  136.     move = 1;
  137.       }
  138.       cgraph.graphlabel.geq_active = 0;
  139.     }      
  140.     cgraph.graphlabel.green_y =
  141.       cgraph.graphlabel.red_y + cgraph.graphlabel.box_height + 3;
  142.     cgraph.graphlabel.blue_y =
  143.       cgraph.graphlabel.green_y + cgraph.graphlabel.box_height + 3;
  144.     /* offset "min" from bottom */
  145.     cgraph.graphlabel.min_y = graphbox.height - cgraph.graphlabel.minmax_yoff;
  146.     if( cgraph.graphlabel.gamma_ID == NULL ) {
  147.       cgraph.graphlabel.gamma_ID =
  148.     create_cgraph_box((int)graphbox.width - cgraph.graphlabel.width, 0,
  149.               cgraph.graphlabel.width, cgraph.graphlabel.height,
  150.               graphbox.display, graphbox.ID, -1, EastGravity);
  151.       cgraph.graphlabel.minmax_ID = graphbox.ID;
  152.       new = 1;
  153.     }
  154.   }
  155.   if( new ) {
  156.     if( cgraph.graphlabel.geq_active )
  157.       cgraph.graphlabel.geq_ID =
  158.     create_cgraph_box(cgraph.graphlabel.geq_x, cgraph.graphlabel.geq_y,
  159.               cgraph.graphlabel.geq_width,
  160.               cgraph.graphlabel.geq_height, graphbox.display,
  161.               cgraph.graphlabel.gamma_ID, -1, CenterGravity);
  162.     cgraph.graphlabel.red_ID =
  163.       create_cgraph_box(cgraph.graphlabel.red_x, cgraph.graphlabel.red_y,
  164.             cgraph.graphlabel.box_width,
  165.             cgraph.graphlabel.box_height,
  166.             graphbox.display, cgraph.graphlabel.gamma_ID,
  167.             color.hard.red, CenterGravity);
  168.     cgraph.graphlabel.green_ID =
  169.       create_cgraph_box(cgraph.graphlabel.green_x, cgraph.graphlabel.green_y,
  170.             cgraph.graphlabel.box_width,
  171.             cgraph.graphlabel.box_height,
  172.             graphbox.display, cgraph.graphlabel.gamma_ID,
  173.             color.hard.green, CenterGravity);
  174.     cgraph.graphlabel.blue_ID =
  175.       create_cgraph_box(cgraph.graphlabel.blue_x, cgraph.graphlabel.blue_y,
  176.             cgraph.graphlabel.box_width,
  177.             cgraph.graphlabel.box_height,
  178.             graphbox.display, cgraph.graphlabel.gamma_ID,
  179.             color.hard.blue, CenterGravity);
  180.     init_colorbar_label();
  181.     XMapSubwindows(graphbox.display, cgraph.graphlabel.gamma_ID);
  182.   } else {
  183.     if( resize ) {
  184.       XResizeWindow(graphbox.display, cgraph.graphlabel.gamma_ID,
  185.             cgraph.graphlabel.width, cgraph.graphlabel.height);
  186.     }
  187.     if( move ) {
  188.       XMoveWindow(graphbox.display, cgraph.graphlabel.red_ID,
  189.           cgraph.graphlabel.red_x, cgraph.graphlabel.red_y);
  190.       XMoveWindow(graphbox.display, cgraph.graphlabel.green_ID,
  191.           cgraph.graphlabel.green_x, cgraph.graphlabel.green_y);
  192.       XMoveWindow(graphbox.display, cgraph.graphlabel.blue_ID,
  193.           cgraph.graphlabel.blue_x, cgraph.graphlabel.blue_y);
  194.     }
  195.   }
  196. }
  197.  
  198. /*
  199.  * Subroutine:    init_colorbar_label
  200.  * Xlib calls:    XResizeWindow()
  201.  */
  202. static void init_colorbar_label ( )
  203. {
  204.   Window create_cgraph_box();
  205.   if( (cgraph.graphlabel.active == 0) || (cgraph.barlabel.max_ID != NULL) )
  206.     return;
  207.   if( cgraph.vertical ) {
  208.     cgraph.barlabel.max_ID =
  209.       create_cgraph_box(0, 0, cgraph.barlabel.width, cgraph.barlabel.height,
  210.             graphbox.display, graphbox.ID, -1, NorthWestGravity);
  211.     cgraph.barlabel.min_ID =
  212.       create_cgraph_box(0, (int)graphbox.height - cgraph.barlabel.height,
  213.             cgraph.barlabel.width, cgraph.barlabel.height,
  214.             graphbox.display, graphbox.ID, -1, SouthWestGravity);
  215.     /* 3 digits are centered, "0" uses same right justification */
  216.     cgraph.barlabel.max_x = cgraph.graphlabel.box_x +
  217.       ((3 + cgraph.barlabel.width - cgraph.barlabel.base_width) / 2);
  218.     cgraph.barlabel.min_x = cgraph.barlabel.max_x +
  219.       XTextWidth(cgraph.fontstruct, "20", 2);
  220.   } else {
  221.     cgraph.barlabel.min_ID =
  222.       create_cgraph_box(0, (int)graphbox.height - cgraph.barlabel.height,
  223.             cgraph.barlabel.width, cgraph.barlabel.height,
  224.             graphbox.display, graphbox.ID, -1, SouthWestGravity);
  225.     cgraph.barlabel.max_ID =
  226.       create_cgraph_box((int)graphbox.width - cgraph.graphlabel.width,
  227.             (int)graphbox.height - cgraph.barlabel.height,
  228.             cgraph.barlabel.width, cgraph.barlabel.height,
  229.             graphbox.display, graphbox.ID, -1, SouthEastGravity);
  230.     cgraph.barlabel.max_y = cgraph.graphlabel.box_y +
  231.       ((cgraph.barlabel.height - cgraph.graphlabel.box_height) / 2);
  232.     cgraph.barlabel.min_y = cgraph.barlabel.max_y;
  233.   }
  234. }
  235.  
  236. /*
  237.  * Subroutine:    create_cgraph_box
  238.  * Purpose:    Create window with window gravity and optional colored border
  239.  * Xlib call:    XCreateWindow()
  240.  */
  241. Window create_cgraph_box ( x, y, width, height, display, parent,
  242.                border_color, window_gravity )
  243.      int x, y, width, height;
  244.      Display *display;
  245.      Window parent;
  246.      int border_color;
  247.      int window_gravity;
  248. {
  249.   XSetWindowAttributes attributes;
  250.   Window wndw;
  251.  
  252.   attributes.win_gravity = window_gravity;
  253.   attributes.background_pixel = color.hard.std_white;
  254.   attributes.event_mask = ExposureMask; 
  255.   if( border_color < 0 ) {
  256.     wndw = XCreateWindow(display, parent, x, y, (unsigned int)width,
  257.              (unsigned int)height, (unsigned int)0,
  258.              CopyFromParent, CopyFromParent, CopyFromParent,
  259.              CWBackPixel | CWWinGravity | CWEventMask,
  260.              &attributes);
  261.   } else {
  262.     unsigned long valuemask;
  263.     attributes.border_pixel = (unsigned long)border_color;
  264.     valuemask = CWBackPixel | CWWinGravity | CWEventMask | CWBorderPixel;
  265.     wndw = XCreateWindow(display, parent, x, y, (unsigned int)width,
  266.              (unsigned int)height, (unsigned int)1,
  267.              CopyFromParent, CopyFromParent, CopyFromParent,
  268.              valuemask, &attributes);
  269.   }
  270.   return( wndw );
  271. }
  272.