graph_displayer_canvas-zoom.cc
author hegyi
Thu, 28 Sep 2006 14:32:40 +0000
changeset 156 c5cdf6690cdf
parent 89 4042761b21e3
child 157 7e6ad28aeb9e
permissions -rwxr-xr-x
Zoom tracking of nodes is implemented and is switchable.
ladanyi@53
     1
#include "graph_displayer_canvas.h"
alpar@59
     2
#include <cmath>
hegyi@27
     3
hegyi@27
     4
void GraphDisplayerCanvas::zoomIn()
hegyi@27
     5
{
hegyi@27
     6
  set_pixels_per_unit(
hegyi@27
     7
      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@156
     8
  if(zoomtrack)
hegyi@156
     9
    {
hegyi@156
    10
      propertyChange(false, N_RADIUS);
hegyi@156
    11
    }
hegyi@27
    12
}
hegyi@27
    13
hegyi@27
    14
void GraphDisplayerCanvas::zoomOut()
hegyi@27
    15
{
hegyi@27
    16
  set_pixels_per_unit(
hegyi@27
    17
      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@156
    18
  if(zoomtrack)
hegyi@156
    19
    {
hegyi@156
    20
      propertyChange(false, N_RADIUS);
hegyi@156
    21
    }
hegyi@27
    22
}
hegyi@27
    23
hegyi@27
    24
void GraphDisplayerCanvas::zoomFit()
hegyi@27
    25
{
ladanyi@87
    26
  updateScrollRegion();
ladanyi@87
    27
hegyi@27
    28
  // get the height and width of the canvas
hegyi@27
    29
  Gtk::Allocation a = get_allocation();
hegyi@27
    30
  int aw = a.get_width();
hegyi@27
    31
  int ah = a.get_height();
hegyi@27
    32
hegyi@27
    33
  // get the bounding box of the graph
ladanyi@87
    34
  update_now();
ladanyi@87
    35
  double x1, y1, x2, y2;
ladanyi@87
    36
  root()->get_bounds(x1, y1, x2, y2);
hegyi@27
    37
hegyi@27
    38
  // fit the graph to the window
ladanyi@87
    39
  double ppu1 = (double) aw / fabs(x2 - x1);
ladanyi@87
    40
  double ppu2 = (double) ah / fabs(y2 - y1);
hegyi@27
    41
  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
hegyi@156
    42
hegyi@156
    43
  if(zoomtrack)
hegyi@156
    44
    {
hegyi@156
    45
      propertyChange(false, N_RADIUS);
hegyi@156
    46
    }
hegyi@27
    47
}
hegyi@27
    48
hegyi@27
    49
void GraphDisplayerCanvas::zoom100()
hegyi@27
    50
{
ladanyi@87
    51
  updateScrollRegion();
hegyi@27
    52
  set_pixels_per_unit(1.0);
hegyi@156
    53
hegyi@156
    54
  if(zoomtrack)
hegyi@156
    55
    {
hegyi@156
    56
      propertyChange(false, N_RADIUS);
hegyi@156
    57
    }
hegyi@27
    58
}
hegyi@27
    59
hegyi@27
    60
void GraphDisplayerCanvas::updateScrollRegion()
hegyi@27
    61
{
ladanyi@87
    62
  // get_bounds() yields something sane only when no updates are pending
ladanyi@87
    63
  // and it returns a sufficient, not an exact bounding box
ladanyi@87
    64
  update_now();
ladanyi@87
    65
  double x1, y1, x2, y2;
ladanyi@87
    66
  root()->get_bounds(x1, y1, x2, y2);
ladanyi@87
    67
  set_scroll_region(x1, y1, x2, y2);
hegyi@27
    68
}