gui/graph_displayer_canvas-zoom.cc
author deba
Wed, 01 Mar 2006 10:17:25 +0000
changeset 1990 15fb7a4ea6be
parent 1777 a70cee06ae9c
permissions -rwxr-xr-x
Some classes assumed that the GraphMaps should be inherited
from an ObserverBase. These classes parents replaced with
DefaultMap which cause that the graph maps should not be
inherited from the ObserverBase.
ladanyi@1606
     1
#include "graph_displayer_canvas.h"
alpar@1632
     2
#include <cmath>
hegyi@1510
     3
hegyi@1510
     4
void GraphDisplayerCanvas::zoomIn()
hegyi@1510
     5
{
hegyi@1510
     6
  set_pixels_per_unit(
hegyi@1510
     7
      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@1510
     8
}
hegyi@1510
     9
hegyi@1510
    10
void GraphDisplayerCanvas::zoomOut()
hegyi@1510
    11
{
hegyi@1510
    12
  set_pixels_per_unit(
hegyi@1510
    13
      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@1510
    14
}
hegyi@1510
    15
hegyi@1510
    16
void GraphDisplayerCanvas::zoomFit()
hegyi@1510
    17
{
ladanyi@1777
    18
  updateScrollRegion();
ladanyi@1777
    19
hegyi@1510
    20
  // get the height and width of the canvas
hegyi@1510
    21
  Gtk::Allocation a = get_allocation();
hegyi@1510
    22
  int aw = a.get_width();
hegyi@1510
    23
  int ah = a.get_height();
hegyi@1510
    24
hegyi@1510
    25
  // get the bounding box of the graph
ladanyi@1777
    26
  update_now();
ladanyi@1777
    27
  double x1, y1, x2, y2;
ladanyi@1777
    28
  root()->get_bounds(x1, y1, x2, y2);
hegyi@1510
    29
hegyi@1510
    30
  // fit the graph to the window
ladanyi@1777
    31
  double ppu1 = (double) aw / fabs(x2 - x1);
ladanyi@1777
    32
  double ppu2 = (double) ah / fabs(y2 - y1);
hegyi@1510
    33
  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
hegyi@1510
    34
}
hegyi@1510
    35
hegyi@1510
    36
void GraphDisplayerCanvas::zoom100()
hegyi@1510
    37
{
ladanyi@1777
    38
  updateScrollRegion();
hegyi@1510
    39
  set_pixels_per_unit(1.0);
hegyi@1510
    40
}
hegyi@1510
    41
hegyi@1510
    42
void GraphDisplayerCanvas::updateScrollRegion()
hegyi@1510
    43
{
ladanyi@1777
    44
  // get_bounds() yields something sane only when no updates are pending
ladanyi@1777
    45
  // and it returns a sufficient, not an exact bounding box
ladanyi@1777
    46
  update_now();
ladanyi@1777
    47
  double x1, y1, x2, y2;
ladanyi@1777
    48
  root()->get_bounds(x1, y1, x2, y2);
ladanyi@1777
    49
  set_scroll_region(x1, y1, x2, y2);
hegyi@1510
    50
}