1.1 --- a/gui/graph_displayer_canvas-zoom.cc Fri Nov 04 17:44:13 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas-zoom.cc Fri Nov 04 19:07:15 2005 +0000
1.3 @@ -16,34 +16,36 @@
1.4
1.5 void GraphDisplayerCanvas::zoomFit()
1.6 {
1.7 + updateScrollRegion();
1.8 +
1.9 // get the height and width of the canvas
1.10 Gtk::Allocation a = get_allocation();
1.11 int aw = a.get_width();
1.12 int ah = a.get_height();
1.13 - // add some space
1.14 - aw -= 5; if (aw < 0) aw = 0;
1.15 - ah -= 5; if (ah < 0) ah = 0;
1.16
1.17 // get the bounding box of the graph
1.18 - double wx1, wy1, wx2, wy2;
1.19 - Gnome::Canvas::Item* pCanvasItem = root();
1.20 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.21 + update_now();
1.22 + double x1, y1, x2, y2;
1.23 + root()->get_bounds(x1, y1, x2, y2);
1.24
1.25 // fit the graph to the window
1.26 - double ppu1 = (double) aw / fabs(wx2 - wx1);
1.27 - double ppu2 = (double) ah / fabs(wy2 - wy1);
1.28 + double ppu1 = (double) aw / fabs(x2 - x1);
1.29 + double ppu2 = (double) ah / fabs(y2 - y1);
1.30 set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
1.31 }
1.32
1.33 void GraphDisplayerCanvas::zoom100()
1.34 {
1.35 + updateScrollRegion();
1.36 set_pixels_per_unit(1.0);
1.37 }
1.38
1.39 void GraphDisplayerCanvas::updateScrollRegion()
1.40 {
1.41 - double wx1, wy1, wx2, wy2;
1.42 - Gnome::Canvas::Item* pCanvasItem = root();
1.43 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.44 - set_scroll_region(wx1, wy1, wx2, wy2);
1.45 + // get_bounds() yields something sane only when no updates are pending
1.46 + // and it returns a sufficient, not an exact bounding box
1.47 + update_now();
1.48 + double x1, y1, x2, y2;
1.49 + root()->get_bounds(x1, y1, x2, y2);
1.50 + set_scroll_region(x1, y1, x2, y2);
1.51 }