#include #include #include void GraphDisplayerCanvas::zoomIn() { set_pixels_per_unit( (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); } void GraphDisplayerCanvas::zoomOut() { set_pixels_per_unit( (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); } void GraphDisplayerCanvas::zoomFit() { // 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); // fit the graph to the window double ppu1 = (double) aw / fabs(wx2 - wx1); double ppu2 = (double) ah / fabs(wy2 - wy1); set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); } void GraphDisplayerCanvas::zoom100() { 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); }