diff -r 5214b33f954d -r a70cee06ae9c gui/graph_displayer_canvas-zoom.cc --- a/gui/graph_displayer_canvas-zoom.cc Fri Nov 04 17:44:13 2005 +0000 +++ b/gui/graph_displayer_canvas-zoom.cc Fri Nov 04 19:07:15 2005 +0000 @@ -16,34 +16,36 @@ void GraphDisplayerCanvas::zoomFit() { + updateScrollRegion(); + // get the height and width of the canvas Gtk::Allocation a = get_allocation(); int aw = a.get_width(); int ah = a.get_height(); - // add some space - aw -= 5; if (aw < 0) aw = 0; - ah -= 5; if (ah < 0) ah = 0; // get the bounding box of the graph - double wx1, wy1, wx2, wy2; - Gnome::Canvas::Item* pCanvasItem = root(); - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); + update_now(); + double x1, y1, x2, y2; + root()->get_bounds(x1, y1, x2, y2); // fit the graph to the window - double ppu1 = (double) aw / fabs(wx2 - wx1); - double ppu2 = (double) ah / fabs(wy2 - wy1); + double ppu1 = (double) aw / fabs(x2 - x1); + double ppu2 = (double) ah / fabs(y2 - y1); set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); } void GraphDisplayerCanvas::zoom100() { + updateScrollRegion(); set_pixels_per_unit(1.0); } void GraphDisplayerCanvas::updateScrollRegion() { - double wx1, wy1, wx2, wy2; - Gnome::Canvas::Item* pCanvasItem = root(); - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); - set_scroll_region(wx1, wy1, wx2, wy2); + // get_bounds() yields something sane only when no updates are pending + // and it returns a sufficient, not an exact bounding box + update_now(); + double x1, y1, x2, y2; + root()->get_bounds(x1, y1, x2, y2); + set_scroll_region(x1, y1, x2, y2); }