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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    panwndw.c (Pan Window)
  6.  * Purpose:    Size the pan window to fit the image area and set it up
  7.  * Subroutine:    init_panbox_dimensions()    returns: void
  8.  * Subroutine:    init_panbox_coords()        returns: void
  9.  * Subroutine:    new_panbox()            returns: void
  10.  * Extern:    screen_width, screen_height in WndwInit.c
  11.  * Extern:    button_left, button_middle, button_hmin in WndwConfig.c
  12.  * Xlib calls:    none
  13.  * Copyright:    1988 Smithsonian Astrophysical Observatory
  14.  *        You may do anything you like with this file except remove
  15.  *        this copyright.  The Smithsonian Astrophysical Observatory
  16.  *        makes no representations about the suitability of this
  17.  *        software for any purpose.  It is provided "as is" without
  18.  *        express or implied warranty.
  19.  * Modified:    {0} Michael VanHilst    initial version        21 December 1988
  20.  *        {n} <who> -- <does what> -- <when>
  21.  */
  22.  
  23. #include <X11/Xlib.h>            /* X window stuff */
  24. #include <X11/Xutil.h>            /* window manager stuff */
  25. #include "hfiles/define.h"        /* define MIN, MAX, etc */
  26. #include "hfiles/struct.h"        /* all struct record types */
  27. #include "hfiles/extern.h"        /* major declared structs */
  28.  
  29. /* root window dimensions in wndwinit.c */
  30. extern int screen_width, screen_height;
  31.  
  32. static double ip_zoom;
  33. static int pan_xwidth, pan_yheight;
  34. /*
  35.  * Subroutine:    init_panbox_dimensions
  36.  * Purpose:    Set size of the panbox to fit exact area of image img specs.
  37.  * Called by:    new_panbox() below
  38.  * Called by:    configure_windowgroup() in WndwConfig.c to init or regroup.
  39.  */
  40. void init_panbox_dimensions ( )
  41. {
  42.   int xzoom, yzoom;
  43.  
  44.   /* calculate the drawing area for the given window size */
  45.   pan_xwidth = panbox.hints.max_width - (2 * panbox.xzero);
  46.   pan_yheight = panbox.hints.max_height - (2 * panbox.yzero);
  47.   /* select a zoom factor which fits image within pan window */
  48.   xzoom = (coord.img.width - 1) / pan_xwidth + 1;
  49.   yzoom = (coord.img.height - 1) / pan_yheight + 1;
  50.   if( (xzoom > 1) || (yzoom > 1) ) {
  51.     /* big image rule: zoom for which one dimension is window size or less */
  52.     ip_zoom = 1.0 / (double)MAX(xzoom,yzoom);
  53.   } else {
  54.     /* small image rule: zoom for which one side is greater than 1/2 window */
  55.     xzoom = pan_xwidth / coord.img.width;
  56.     yzoom = pan_yheight / coord.img.height;
  57.     ip_zoom = (double)MIN(xzoom,yzoom);
  58.   }
  59.   /* specify pan window size for perfect fit to zoomed img */
  60.   pan_xwidth = (int)((double)coord.img.width * ip_zoom);
  61.   pan_yheight = (int)((double)coord.img.height * ip_zoom);
  62.   panbox.hints.width = pan_xwidth + (2 * panbox.xzero);
  63.   panbox.hints.height = pan_yheight + (2 * panbox.yzero);
  64.   /* aspect ratio may put one side below minimum */
  65.   if( panbox.hints.min_width > panbox.hints.width )
  66.     panbox.hints.min_width = panbox.hints.width;
  67.   if( panbox.hints.min_height > panbox.hints.height )
  68.     panbox.hints.min_height = panbox.hints.height;
  69.   /* set sizing guidlines to maintain image aspect ratio */
  70.   panbox.hints.min_aspect.x = coord.img.width;
  71.   panbox.hints.max_aspect.x = coord.img.width;
  72.   panbox.hints.min_aspect.y = coord.img.height;
  73.   panbox.hints.max_aspect.y = coord.img.height;
  74. }
  75.  
  76. /*
  77.  * Subroutine:    init_panbox_coords
  78.  * Purpose:    Set the panbox coordinate system for the actual window.
  79.  * Note:    Drawing area must be as decided above in init_panbox1.
  80.  */
  81. void init_panbox_coords ( )
  82. {
  83.   void get_window_dimensions();
  84.   void set_coordsys(), set_transform(), combine_transform(), set_edges();
  85.  
  86.   panbox.xzero = MAX(0, ((int)panbox.width - pan_xwidth)/2);
  87.   panbox.yzero = MAX(0, ((int)panbox.height - pan_yheight)/2);
  88.   panbox.xwidth = pan_xwidth;
  89.   panbox.yheight = pan_yheight;
  90.   /* fill out pan window coordinate system parameters */
  91.   set_coordsys(&coord.pan, 0.5, (int)panbox.width, (int)panbox.height,
  92.            panbox.xzero, panbox.yzero, panbox.xzero + panbox.xwidth - 1,
  93.            panbox.yzero + panbox.yheight - 1);
  94.   /* compute coordinate conversions between pan and img systems */
  95.   set_transform(coord.img.cenX, coord.img.cenY, ip_zoom,
  96.         &coord.pan, &coord.img, &coord.pantoimg, &coord.imgtopan);
  97.   combine_transform(&coord.pantofile, &coord.pantoimg, &coord.imgtofile);
  98.   set_edges(&coord.pantofile, &coord.file, &coord.pan, &coord.fp);
  99. }
  100.  
  101. /*
  102.  * Subroutine:    new_panbox
  103.  * Purpose:    Create or readjust panbox (coord.img must be set).
  104.  * Called by:    imtool_response()
  105.  */
  106. void new_panbox ( newdata )
  107.      int newdata;        /* boolean to force loading new image */
  108. {
  109.   int diff;
  110.   int changed = 0;
  111.   void init_panbox_dimensions(), init_panbox_coords(), init_panbuf();
  112.   void new_panimage(), new_pancursor();
  113.  
  114.   /* choose size to fit image aspect ratio for blocked pan image */
  115.   init_panbox_dimensions();
  116.   /* if window was changed */
  117.   if( (panbox.hints.width != panbox.width) ||
  118.       (panbox.hints.height != panbox.height) ) {
  119.     /* resize the window (this causes an expose event) */
  120.     diff = panbox.width - panbox.hints.width;
  121.     panbox.width = panbox.hints.width;
  122.     panbox.height = panbox.hints.height;
  123.     if( diff ) {
  124.       panbox.x += diff;
  125.       XMoveResizeWindow(panbox.display, panbox.ID, panbox.x, panbox.y,
  126.             panbox.width, panbox.height);
  127.     } else
  128.       XResizeWindow(panbox.display, panbox.ID, panbox.width, panbox.height);
  129.     changed = 1;
  130.   }
  131.   init_panbox_coords();
  132.   /* get bigger buffer if needed */
  133.   init_panbuf();
  134.   if( newdata || changed ) {
  135.     /* create a new image to fit the panbox */
  136.     new_panimage();
  137.     /* set up the new panbox display area cursor */
  138.     new_pancursor(0);
  139.   }
  140. }
  141.