hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: void DigraphDisplayerCanvas::zoomIn() hegyi@1: { hegyi@1: set_pixels_per_unit( hegyi@1: (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); hegyi@1: if(zoomtrack) hegyi@1: { hegyi@1: propertyChange(false, N_RADIUS); hegyi@1: propertyChange(true, E_WIDTH); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void DigraphDisplayerCanvas::zoomOut() hegyi@1: { hegyi@1: set_pixels_per_unit( hegyi@1: (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); hegyi@1: if(zoomtrack) hegyi@1: { hegyi@1: propertyChange(true, E_WIDTH); hegyi@1: propertyChange(false, N_RADIUS); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void DigraphDisplayerCanvas::zoomFit() hegyi@1: { hegyi@1: updateScrollRegion(); hegyi@1: hegyi@1: // get the height and width of the canvas hegyi@1: Gtk::Allocation a = get_allocation(); hegyi@1: int aw = a.get_width(); hegyi@1: int ah = a.get_height(); hegyi@1: hegyi@1: // get the bounding box of the digraph hegyi@1: update_now(); hegyi@1: double x1, y1, x2, y2; hegyi@1: root()->get_bounds(x1, y1, x2, y2); hegyi@1: hegyi@1: // fit the digraph to the window hegyi@1: double ppu1 = (double) aw / fabs(x2 - x1); hegyi@1: double ppu2 = (double) ah / fabs(y2 - y1); hegyi@1: set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); hegyi@1: hegyi@1: if(zoomtrack) hegyi@1: { hegyi@1: propertyChange(true, E_WIDTH); hegyi@1: propertyChange(false, N_RADIUS); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void DigraphDisplayerCanvas::zoom100() hegyi@1: { hegyi@1: updateScrollRegion(); hegyi@1: set_pixels_per_unit(1.0); hegyi@1: hegyi@1: if(zoomtrack) hegyi@1: { hegyi@1: propertyChange(true, E_WIDTH); hegyi@1: propertyChange(false, N_RADIUS); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void DigraphDisplayerCanvas::updateScrollRegion() hegyi@1: { hegyi@1: // get_bounds() yields something sane only when no updates are pending hegyi@1: // and it returns a sufficient, not an exact bounding box hegyi@1: update_now(); hegyi@1: double x1, y1, x2, y2; hegyi@1: root()->get_bounds(x1, y1, x2, y2); hegyi@1: set_scroll_region(x1, y1, x2, y2); hegyi@1: }