1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/graph_displayer_canvas-zoom.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,90 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <graph_displayer_canvas.h>
1.23 +#include <cmath>
1.24 +
1.25 +void DigraphDisplayerCanvas::zoomIn()
1.26 +{
1.27 + set_pixels_per_unit(
1.28 + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
1.29 + if(zoomtrack)
1.30 + {
1.31 + propertyChange(false, N_RADIUS);
1.32 + propertyChange(true, E_WIDTH);
1.33 + }
1.34 +}
1.35 +
1.36 +void DigraphDisplayerCanvas::zoomOut()
1.37 +{
1.38 + set_pixels_per_unit(
1.39 + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
1.40 + if(zoomtrack)
1.41 + {
1.42 + propertyChange(true, E_WIDTH);
1.43 + propertyChange(false, N_RADIUS);
1.44 + }
1.45 +}
1.46 +
1.47 +void DigraphDisplayerCanvas::zoomFit()
1.48 +{
1.49 + updateScrollRegion();
1.50 +
1.51 + // get the height and width of the canvas
1.52 + Gtk::Allocation a = get_allocation();
1.53 + int aw = a.get_width();
1.54 + int ah = a.get_height();
1.55 +
1.56 + // get the bounding box of the digraph
1.57 + update_now();
1.58 + double x1, y1, x2, y2;
1.59 + root()->get_bounds(x1, y1, x2, y2);
1.60 +
1.61 + // fit the digraph to the window
1.62 + double ppu1 = (double) aw / fabs(x2 - x1);
1.63 + double ppu2 = (double) ah / fabs(y2 - y1);
1.64 + set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
1.65 +
1.66 + if(zoomtrack)
1.67 + {
1.68 + propertyChange(true, E_WIDTH);
1.69 + propertyChange(false, N_RADIUS);
1.70 + }
1.71 +}
1.72 +
1.73 +void DigraphDisplayerCanvas::zoom100()
1.74 +{
1.75 + updateScrollRegion();
1.76 + set_pixels_per_unit(1.0);
1.77 +
1.78 + if(zoomtrack)
1.79 + {
1.80 + propertyChange(true, E_WIDTH);
1.81 + propertyChange(false, N_RADIUS);
1.82 + }
1.83 +}
1.84 +
1.85 +void DigraphDisplayerCanvas::updateScrollRegion()
1.86 +{
1.87 + // get_bounds() yields something sane only when no updates are pending
1.88 + // and it returns a sufficient, not an exact bounding box
1.89 + update_now();
1.90 + double x1, y1, x2, y2;
1.91 + root()->get_bounds(x1, y1, x2, y2);
1.92 + set_scroll_region(x1, y1, x2, y2);
1.93 +}