#include "graph_displayer_canvas.h" #include "broken_edge.h" #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() { updateScrollRegion(); // get the height and width of the canvas Gtk::Allocation a = get_allocation(); int aw = a.get_width(); int ah = a.get_height(); // get the bounding box of the graph 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(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() { // 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); }