ladanyi@1606: #include "graph_displayer_canvas.h" alpar@1632: #include hegyi@1510: hegyi@1510: void GraphDisplayerCanvas::zoomIn() hegyi@1510: { hegyi@1510: set_pixels_per_unit( hegyi@1510: (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); hegyi@1510: } hegyi@1510: hegyi@1510: void GraphDisplayerCanvas::zoomOut() hegyi@1510: { hegyi@1510: set_pixels_per_unit( hegyi@1510: (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); hegyi@1510: } hegyi@1510: hegyi@1510: void GraphDisplayerCanvas::zoomFit() hegyi@1510: { ladanyi@1777: updateScrollRegion(); ladanyi@1777: hegyi@1510: // get the height and width of the canvas hegyi@1510: Gtk::Allocation a = get_allocation(); hegyi@1510: int aw = a.get_width(); hegyi@1510: int ah = a.get_height(); hegyi@1510: hegyi@1510: // get the bounding box of the graph ladanyi@1777: update_now(); ladanyi@1777: double x1, y1, x2, y2; ladanyi@1777: root()->get_bounds(x1, y1, x2, y2); hegyi@1510: hegyi@1510: // fit the graph to the window ladanyi@1777: double ppu1 = (double) aw / fabs(x2 - x1); ladanyi@1777: double ppu2 = (double) ah / fabs(y2 - y1); hegyi@1510: set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); hegyi@1510: } hegyi@1510: hegyi@1510: void GraphDisplayerCanvas::zoom100() hegyi@1510: { ladanyi@1777: updateScrollRegion(); hegyi@1510: set_pixels_per_unit(1.0); hegyi@1510: } hegyi@1510: hegyi@1510: void GraphDisplayerCanvas::updateScrollRegion() hegyi@1510: { ladanyi@1777: // get_bounds() yields something sane only when no updates are pending ladanyi@1777: // and it returns a sufficient, not an exact bounding box ladanyi@1777: update_now(); ladanyi@1777: double x1, y1, x2, y2; ladanyi@1777: root()->get_bounds(x1, y1, x2, y2); ladanyi@1777: set_scroll_region(x1, y1, x2, y2); hegyi@1510: }