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