1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/graph_displayer_canvas-zoom.cc Fri Jun 24 07:58:18 2005 +0000
1.3 @@ -0,0 +1,49 @@
1.4 +#include <graph_displayer_canvas.h>
1.5 +#include <broken_edge.h>
1.6 +#include <math.h>
1.7 +
1.8 +void GraphDisplayerCanvas::zoomIn()
1.9 +{
1.10 + set_pixels_per_unit(
1.11 + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
1.12 +}
1.13 +
1.14 +void GraphDisplayerCanvas::zoomOut()
1.15 +{
1.16 + set_pixels_per_unit(
1.17 + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
1.18 +}
1.19 +
1.20 +void GraphDisplayerCanvas::zoomFit()
1.21 +{
1.22 + // get the height and width of the canvas
1.23 + Gtk::Allocation a = get_allocation();
1.24 + int aw = a.get_width();
1.25 + int ah = a.get_height();
1.26 + // add some space
1.27 + aw -= 5; if (aw < 0) aw = 0;
1.28 + ah -= 5; if (ah < 0) ah = 0;
1.29 +
1.30 + // get the bounding box of the graph
1.31 + double wx1, wy1, wx2, wy2;
1.32 + Gnome::Canvas::Item* pCanvasItem = root();
1.33 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.34 +
1.35 + // fit the graph to the window
1.36 + double ppu1 = (double) aw / fabs(wx2 - wx1);
1.37 + double ppu2 = (double) ah / fabs(wy2 - wy1);
1.38 + set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
1.39 +}
1.40 +
1.41 +void GraphDisplayerCanvas::zoom100()
1.42 +{
1.43 + set_pixels_per_unit(1.0);
1.44 +}
1.45 +
1.46 +void GraphDisplayerCanvas::updateScrollRegion()
1.47 +{
1.48 + double wx1, wy1, wx2, wy2;
1.49 + Gnome::Canvas::Item* pCanvasItem = root();
1.50 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.51 + set_scroll_region(wx1, wy1, wx2, wy2);
1.52 +}