home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / touchup / part05 / fat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-14  |  5.5 KB  |  226 lines

  1.  
  2. /**************************************************************************
  3.    Touchup a bitmap graphics editor for the Sun Workstation running SunView
  4.    Copyright (c) 1988 by Raymond Kreisel
  5.    1/22/88 @ Suny Stony Brook
  6.  
  7.    This program may be redistributed without fee as long as this copyright
  8.    notice is intact.
  9.  
  10. ==> PLEASE send comments and bug reports to one of the following addresses:
  11.  
  12.        Ray Kreisel
  13.        CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
  14.  
  15.        UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk   
  16.        ARPA-Internet: rayk@sbcs.sunysb.edu            
  17.        CSnet: rayk@suny-sb
  18.        (If nobody is home at any of the above addresses try:
  19.         S72QKRE@TOWSONVX.BITNET                    )
  20.  
  21.  "If I get home before daylight, I just might get some sleep tonight...."
  22.  
  23. **************************************************************************/
  24. /**************************************************************************
  25.     file: fat.c
  26.     purpose: This file contains the functions that handle the
  27.         magnifing class command.
  28.  
  29.     modifications:
  30.         date:    Tue Mar 22 22:04:58 EST 1988
  31.         author:    rayk
  32.         changes:add comments
  33. **************************************************************************/
  34.  
  35. #include "header.h"
  36.  
  37. int old_cur_color=0-1;
  38.  
  39. /*
  40.  * Let's go into magnify mode !!
  41.  */
  42. fat_mode(item, event)
  43. Panel_item      item;
  44. Event           *event;
  45. {
  46.     if (image_depth==1)
  47.     old_cur_color = cur_color;
  48.     if (select_pt_x == -1)
  49.        {
  50.     ERROR("Select point first then select Magnify");
  51.     set_select_mode();
  52.     return(0);
  53.        }
  54.     
  55.     if (fat_source_x != -1)
  56.        select_fat_region();
  57.     fat_source_x = select_pt_x- (int)window_get(fat_canvas, CANVAS_WIDTH)/magnify_fac/2;
  58.     fat_source_y = select_pt_y- (int)window_get(fat_canvas, CANVAS_HEIGHT)/magnify_fac/2;
  59.     clean_point();
  60.     (void)window_set(fat_frame, WIN_SHOW, TRUE, 0);
  61.     select_fat_region();
  62.     fat_update(0,0);
  63. }
  64.  
  65.  
  66. /*
  67.  * kill off the magnify window
  68.  */
  69. fat_done(item, event)
  70. Panel_item      item;
  71. Event           *event;
  72. {
  73.     if ((image_depth==1) && (old_cur_color != -1))
  74.     {
  75.     cur_color = old_cur_color;
  76.         old_cur_color = 0-1;
  77.     }
  78.     if (fat_source_x != -1)
  79.        select_fat_region();
  80.     (void)window_set(fat_frame, WIN_SHOW, FALSE, 0);
  81.     fat_source_x = 0-1;
  82.     fat_source_y = 0-1;
  83. }
  84.  
  85.  
  86.  
  87. /*
  88.  * The event handler for the canvas of the magnifying class window
  89.  * You can do 3 things.
  90.  *  left: inverse the bit the mouse is on top of and continue
  91.  *        to draw in that color
  92.  *  middle: use this to draw the magnified view
  93.  *  right: use to set the current color to the color of the pixel
  94.  *         under the cursor
  95.  */
  96. fat_handle_event(canvas_local, event)
  97. Canvas  canvas_local;
  98. Event   *event;
  99. {
  100.     if (event_is_up(event))
  101.        return;
  102.     switch (event_id(event)) {
  103.      case MS_LEFT:
  104.         if (image_depth ==1)
  105.                    {
  106.               cur_color = 1^pw_get(pw,fat_source_x + (int)event_x(event)/magnify_fac,fat_source_y + (int)event_y(event)/magnify_fac);
  107.            }
  108.         fat_draw(fat_pw,pw, event_x(event), event_y(event));
  109.         break;
  110.      case MS_MIDDLE:
  111.         fat_x = event_x(event);
  112.         fat_y = event_y(event);
  113.         break;
  114.      case MS_RIGHT:
  115.          fat_match_color(event_x(event), event_y(event));
  116.                 break;
  117.          case LOC_DRAG:
  118.             if (window_get(canvas_local, WIN_EVENT_STATE, MS_LEFT))
  119.         fat_draw(fat_pw,pw, event_x(event), event_y(event));
  120.         else if (window_get(canvas_local, WIN_EVENT_STATE, MS_MIDDLE))
  121.         {
  122.         fat_update(fat_x-event_x(event),fat_y-event_y(event));
  123.         fat_x = event_x(event);
  124.         fat_y = event_y(event);
  125.         }
  126.         break;
  127.  
  128.     }
  129. }
  130.  
  131.  
  132. /*
  133.  * Find out the color of the pixel under the cursor
  134.  */
  135. fat_match_color(x,y)
  136. int x,y;
  137. {
  138.   x = fat_source_x + x/magnify_fac;
  139.   y = fat_source_y + y/magnify_fac;
  140.   update_cur_color(0,0,pw_get(pw,x,y));
  141. }
  142.  
  143.  
  144. /*
  145.  * This is the function that updates the display of the magnifyied view
  146.  * This function is called when the middle but is used to draw this window
  147.  */
  148. fat_update(offset_x,offset_y)
  149. int offset_x,offset_y;
  150. {
  151. int w,h;
  152.  
  153.   w = (int) window_get(fat_canvas, CANVAS_WIDTH);
  154.   h = (int) window_get(fat_canvas, CANVAS_HEIGHT);
  155.   select_fat_region();
  156.   fat_source_x += offset_x/magnify_fac;
  157.   fat_source_y += offset_y/magnify_fac;
  158.   if (w >= SCREEN_MAX_X)
  159.      w=SCREEN_MAX_X-1;
  160.   if (h >= SCREEN_MAX_Y)
  161.      h=SCREEN_MAX_Y-1;
  162.  
  163. /*
  164.  * check if you are within the pixrect
  165.  */
  166. #ifdef NO_FASTAN
  167.   if (fat_source_x < 0)
  168.     fat_source_x = 0;
  169.   if (fat_source_y < 0)
  170.     fat_source_y = 0;
  171.   if (fat_source_x+w/magnify_fac > image_wid)
  172.     fat_source_x = image_wid - w/magnify_fac;
  173.   if (fat_source_y+h/magnify_fac > image_hgt)
  174.     fat_source_y = image_hgt - h/magnify_fac;
  175. #endif
  176.  
  177.   pw_mag(fat_pw, 0, 0, w, h, magnify_fac, pw->pw_prretained,
  178.      fat_source_x, fat_source_y);
  179.   select_fat_region();
  180. }
  181.  
  182.  
  183. /*
  184.  * get the current magnification level
  185.  */
  186. fat_parms(item, event)
  187. Panel_item      item;
  188. Event           *event;
  189. {
  190.   select_fat_region();
  191.   magnify_fac = (int)panel_get_value(magnify_cycle) + 1;
  192.   select_fat_region();
  193.   fat_update(0,0);
  194. }
  195.  
  196.  
  197. /*
  198.  * show which region of the drawing area bitmap is being magnified
  199.  */
  200. select_fat_region()
  201. {
  202. int w,h;
  203.   w = (int) window_get(fat_canvas, CANVAS_WIDTH);
  204.   h = (int) window_get(fat_canvas, CANVAS_HEIGHT);
  205.   select_region(pw,fat_source_x-1,fat_source_y-1,
  206.           fat_source_x+w/magnify_fac+1,fat_source_y+h/magnify_fac+1);
  207. }
  208.  
  209.  
  210.  
  211. /*
  212.  * handle the drawing inside of the magnified view window
  213.  */
  214. fat_draw(fat_pw,pw,x,y)
  215. struct pixwin *fat_pw,*pw;
  216. int x,y;
  217. {
  218.   x = x/magnify_fac*magnify_fac;
  219.   y = y/magnify_fac*magnify_fac;
  220.   pw_write(fat_pw,x,y,magnify_fac,magnify_fac,PIX_COLOR(cur_color) | PIX_SRC,NILPR,0,0);
  221.   x = fat_source_x + x/magnify_fac;
  222.   y = fat_source_y + y/magnify_fac;
  223.   pw_put(pw,x,y,cur_color);
  224. }
  225.  
  226.