graph_displayer_canvas-zoom.cc
author hegyi
Thu, 05 Jan 2006 12:30:09 +0000
branchgui
changeset 108 bf355fd6563e
parent 87 b44281e4cca7
child 156 c5cdf6690cdf
permissions -rwxr-xr-x
Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     3 
     4 void GraphDisplayerCanvas::zoomIn()
     5 {
     6   set_pixels_per_unit(
     7       (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
     8 }
     9 
    10 void GraphDisplayerCanvas::zoomOut()
    11 {
    12   set_pixels_per_unit(
    13       (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
    14 }
    15 
    16 void GraphDisplayerCanvas::zoomFit()
    17 {
    18   updateScrollRegion();
    19 
    20   // get the height and width of the canvas
    21   Gtk::Allocation a = get_allocation();
    22   int aw = a.get_width();
    23   int ah = a.get_height();
    24 
    25   // get the bounding box of the graph
    26   update_now();
    27   double x1, y1, x2, y2;
    28   root()->get_bounds(x1, y1, x2, y2);
    29 
    30   // fit the graph to the window
    31   double ppu1 = (double) aw / fabs(x2 - x1);
    32   double ppu2 = (double) ah / fabs(y2 - y1);
    33   set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
    34 }
    35 
    36 void GraphDisplayerCanvas::zoom100()
    37 {
    38   updateScrollRegion();
    39   set_pixels_per_unit(1.0);
    40 }
    41 
    42 void GraphDisplayerCanvas::updateScrollRegion()
    43 {
    44   // get_bounds() yields something sane only when no updates are pending
    45   // and it returns a sufficient, not an exact bounding box
    46   update_now();
    47   double x1, y1, x2, y2;
    48   root()->get_bounds(x1, y1, x2, y2);
    49   set_scroll_region(x1, y1, x2, y2);
    50 }