home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume19 / xfig / part03 / w_zoom.c < prev   
Encoding:
C/C++ Source or Header  |  1993-05-27  |  3.6 KB  |  147 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1991 by Henning Spruth
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include <X11/keysym.h>
  14. #include "fig.h"
  15. #include "mode.h"
  16. #include "resources.h"
  17. #include "object.h"
  18. #include "paintop.h"
  19. #include "u_create.h"
  20. #include "u_elastic.h"
  21. #include "w_canvas.h"
  22. #include "w_setup.h"
  23. #include "w_zoom.h"
  24. #include "w_indpanel.h"
  25.  
  26. extern        elastic_box();
  27. extern        show_zoom();
  28. extern        pan_origin();
  29.  
  30. /* extern int           gc_thickness[NUMOPS]; */
  31.  
  32. static        do_zoom();
  33. static        zoom_up();
  34. static        init_zoombox_drawing();
  35.  
  36. static int    (*save_kbd_proc) ();
  37. static int    (*save_locmove_proc) ();
  38. static int    (*save_leftbut_proc) ();
  39. static int    (*save_middlebut_proc) ();
  40. static int    (*save_rightbut_proc) ();
  41. static Cursor    save_cur_cursor;
  42. static int    save_action_on;
  43.  
  44. float        zoomscale = 1.0;
  45. int        zoomxoff = 0;
  46. int        zoomyoff = 0;
  47.  
  48. static Boolean    zoom_in_progress = False;
  49.  
  50. /* used for private box drawing functions */
  51. static int    my_fix_x, my_fix_y;
  52. static int    my_cur_x, my_cur_y;
  53.  
  54. zoom_selected(x, y, button)
  55.     int            x, y;
  56.     unsigned int    button;
  57. {
  58.     if (!zoom_in_progress) {
  59.     switch (button) {
  60.     case Button1:
  61.         init_zoombox_drawing(x, y);
  62.         break;
  63.     case Button2:
  64.         pan_origin();
  65.         break;
  66.     case Button3:
  67.         zoomscale = 1.0;
  68.         show_zoom(&ind_switches[ZOOM_SWITCH_INDEX]);
  69.         break;
  70.     }
  71.     } else if (button == Button1)
  72.     do_zoom(x, y);
  73. }
  74.  
  75.  
  76. static
  77. my_box(x, y)
  78.     int            x, y;
  79. {
  80.     elastic_box(my_fix_x, my_fix_y, my_cur_x, my_cur_y);
  81.     my_cur_x = x;
  82.     my_cur_y = y;
  83.     elastic_box(my_fix_x, my_fix_y, my_cur_x, my_cur_y);
  84. }
  85.  
  86.  
  87.  
  88. static
  89. init_zoombox_drawing(x, y)
  90.     int            x, y;
  91. {
  92.     save_kbd_proc = canvas_kbd_proc;
  93.     save_locmove_proc = canvas_locmove_proc;
  94.     save_leftbut_proc = canvas_leftbut_proc;
  95.     save_middlebut_proc = canvas_middlebut_proc;
  96.     save_rightbut_proc = canvas_rightbut_proc;
  97.     save_kbd_proc = canvas_kbd_proc;
  98.     save_cur_cursor = cur_cursor;
  99.  
  100.     my_cur_x = my_fix_x = x;
  101.     my_cur_y = my_fix_y = y;
  102.     canvas_locmove_proc = moving_box;
  103.  
  104.     canvas_locmove_proc = my_box;
  105.     canvas_leftbut_proc = do_zoom;
  106.     canvas_middlebut_proc = canvas_rightbut_proc = null_proc;
  107.     elastic_box(my_fix_x, my_fix_y, my_cur_x, my_cur_y);
  108.     set_temp_cursor(null_cursor);
  109.     set_action_on();
  110.     zoom_in_progress = True;
  111. }
  112.  
  113. static
  114. do_zoom(x, y)
  115.     int            x, y;
  116. {
  117.     int            dimx, dimy;
  118.     float        scalex, scaley;
  119.  
  120.     elastic_box(my_fix_x, my_fix_y, my_cur_x, my_cur_y);
  121.     zoomxoff = my_fix_x < x ? my_fix_x : x;
  122.     zoomyoff = my_fix_y < y ? my_fix_y : y;
  123.     dimx = abs(x - my_fix_x);
  124.     dimy = abs(y - my_fix_y);
  125.     if (zoomxoff < 0)
  126.     zoomxoff = 0;
  127.     if (zoomyoff < 0)
  128.     zoomyoff = 0;
  129.     if (dimx && dimy) {
  130.     scalex = CANVAS_WD / (float) dimx;
  131.     scaley = CANVAS_HT / (float) dimy;
  132.     zoomscale = (int)((scalex > scaley ? scaley : scalex)+.99);
  133.  
  134.     show_zoom(&ind_switches[ZOOM_SWITCH_INDEX]);
  135.     }
  136.     /* restore state */
  137.     canvas_kbd_proc = save_kbd_proc;
  138.     canvas_locmove_proc = save_locmove_proc;
  139.     canvas_leftbut_proc = save_leftbut_proc;
  140.     canvas_middlebut_proc = save_middlebut_proc;
  141.     canvas_rightbut_proc = save_rightbut_proc;
  142.     canvas_kbd_proc = save_kbd_proc;
  143.     set_cursor(save_cur_cursor);
  144.     action_on = save_action_on;
  145.     zoom_in_progress = False;
  146. }
  147.