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