hegyi@27: #include hegyi@27: #include hegyi@27: #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@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@27: } hegyi@27: hegyi@27: void GraphDisplayerCanvas::zoomFit() hegyi@27: { 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: // add some space hegyi@27: aw -= 5; if (aw < 0) aw = 0; hegyi@27: ah -= 5; if (ah < 0) ah = 0; hegyi@27: hegyi@27: // get the bounding box of the graph hegyi@27: double wx1, wy1, wx2, wy2; hegyi@27: Gnome::Canvas::Item* pCanvasItem = root(); hegyi@27: pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); hegyi@27: hegyi@27: // fit the graph to the window hegyi@27: double ppu1 = (double) aw / fabs(wx2 - wx1); hegyi@27: double ppu2 = (double) ah / fabs(wy2 - wy1); hegyi@27: set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); hegyi@27: } hegyi@27: hegyi@27: void GraphDisplayerCanvas::zoom100() hegyi@27: { hegyi@27: set_pixels_per_unit(1.0); hegyi@27: } hegyi@27: hegyi@27: void GraphDisplayerCanvas::updateScrollRegion() hegyi@27: { hegyi@27: double wx1, wy1, wx2, wy2; hegyi@27: Gnome::Canvas::Item* pCanvasItem = root(); hegyi@27: pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); hegyi@27: set_scroll_region(wx1, wy1, wx2, wy2); hegyi@27: }