gui/graph_displayer_canvas-zoom.cc
author deba
Mon, 14 Nov 2005 18:55:19 +0000
changeset 1794 79397d64f742
parent 1632 93ac8c521fe5
child 1819 fd82adfbe905
permissions -rwxr-xr-x
String->Double
ladanyi@1606
     1
#include "graph_displayer_canvas.h"
ladanyi@1606
     2
#include "broken_edge.h"
alpar@1632
     3
#include <cmath>
hegyi@1510
     4
hegyi@1510
     5
void GraphDisplayerCanvas::zoomIn()
hegyi@1510
     6
{
hegyi@1510
     7
  set_pixels_per_unit(
hegyi@1510
     8
      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@1510
     9
}
hegyi@1510
    10
hegyi@1510
    11
void GraphDisplayerCanvas::zoomOut()
hegyi@1510
    12
{
hegyi@1510
    13
  set_pixels_per_unit(
hegyi@1510
    14
      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@1510
    15
}
hegyi@1510
    16
hegyi@1510
    17
void GraphDisplayerCanvas::zoomFit()
hegyi@1510
    18
{
ladanyi@1777
    19
  updateScrollRegion();
ladanyi@1777
    20
hegyi@1510
    21
  // get the height and width of the canvas
hegyi@1510
    22
  Gtk::Allocation a = get_allocation();
hegyi@1510
    23
  int aw = a.get_width();
hegyi@1510
    24
  int ah = a.get_height();
hegyi@1510
    25
hegyi@1510
    26
  // get the bounding box of the graph
ladanyi@1777
    27
  update_now();
ladanyi@1777
    28
  double x1, y1, x2, y2;
ladanyi@1777
    29
  root()->get_bounds(x1, y1, x2, y2);
hegyi@1510
    30
hegyi@1510
    31
  // fit the graph to the window
ladanyi@1777
    32
  double ppu1 = (double) aw / fabs(x2 - x1);
ladanyi@1777
    33
  double ppu2 = (double) ah / fabs(y2 - y1);
hegyi@1510
    34
  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
hegyi@1510
    35
}
hegyi@1510
    36
hegyi@1510
    37
void GraphDisplayerCanvas::zoom100()
hegyi@1510
    38
{
ladanyi@1777
    39
  updateScrollRegion();
hegyi@1510
    40
  set_pixels_per_unit(1.0);
hegyi@1510
    41
}
hegyi@1510
    42
hegyi@1510
    43
void GraphDisplayerCanvas::updateScrollRegion()
hegyi@1510
    44
{
ladanyi@1777
    45
  // get_bounds() yields something sane only when no updates are pending
ladanyi@1777
    46
  // and it returns a sufficient, not an exact bounding box
ladanyi@1777
    47
  update_now();
ladanyi@1777
    48
  double x1, y1, x2, y2;
ladanyi@1777
    49
  root()->get_bounds(x1, y1, x2, y2);
ladanyi@1777
    50
  set_scroll_region(x1, y1, x2, y2);
hegyi@1510
    51
}