alpar@174: /* -*- C++ -*- alpar@174: * alpar@174: * This file is a part of LEMON, a generic C++ optimization library alpar@174: * alpar@174: * Copyright (C) 2003-2006 alpar@174: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@174: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@174: * alpar@174: * Permission to use, modify and distribute this software is granted alpar@174: * provided that this copyright notice appears in all copies. For alpar@174: * precise terms see the accompanying LICENSE file. alpar@174: * alpar@174: * This software is provided "AS IS" with no warranty of any kind, alpar@174: * express or implied, and with no claim as to its suitability for any alpar@174: * purpose. alpar@174: * alpar@174: */ alpar@174: hegyi@194: #include 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: }