graph_displayer_canvas-zoom.cc
branchgui
changeset 38 9cab23d9b124
child 53 e73d7540bd24
equal deleted inserted replaced
-1:000000000000 0:0792374e4234
       
     1 #include <graph_displayer_canvas.h>
       
     2 #include <broken_edge.h>
       
     3 #include <math.h>
       
     4 
       
     5 void GraphDisplayerCanvas::zoomIn()
       
     6 {
       
     7   set_pixels_per_unit(
       
     8       (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
       
     9 }
       
    10 
       
    11 void GraphDisplayerCanvas::zoomOut()
       
    12 {
       
    13   set_pixels_per_unit(
       
    14       (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
       
    15 }
       
    16 
       
    17 void GraphDisplayerCanvas::zoomFit()
       
    18 {
       
    19   // get the height and width of the canvas
       
    20   Gtk::Allocation a = get_allocation();
       
    21   int aw = a.get_width();
       
    22   int ah = a.get_height();
       
    23   // add some space
       
    24   aw -= 5; if (aw < 0) aw = 0;
       
    25   ah -= 5; if (ah < 0) ah = 0;
       
    26 
       
    27   // get the bounding box of the graph
       
    28   double wx1, wy1, wx2, wy2;
       
    29   Gnome::Canvas::Item* pCanvasItem = root();
       
    30   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
       
    31 
       
    32   // fit the graph to the window
       
    33   double ppu1 = (double) aw / fabs(wx2 - wx1);
       
    34   double ppu2 = (double) ah / fabs(wy2 - wy1);
       
    35   set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
       
    36 }
       
    37 
       
    38 void GraphDisplayerCanvas::zoom100()
       
    39 {
       
    40   set_pixels_per_unit(1.0);
       
    41 }
       
    42 
       
    43 void GraphDisplayerCanvas::updateScrollRegion()
       
    44 {
       
    45   double wx1, wy1, wx2, wy2;
       
    46   Gnome::Canvas::Item* pCanvasItem = root();
       
    47   pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
       
    48   set_scroll_region(wx1, wy1, wx2, wy2);
       
    49 }