graph_displayer_canvas-zoom.cc
author hegyi
Mon, 02 Oct 2006 19:00:23 +0000
changeset 158 aa50a64b3a6e
parent 156 c5cdf6690cdf
child 174 95872af46fc4
permissions -rwxr-xr-x
Two redundant lines were removed.
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@157
    11
      propertyChange(true, E_WIDTH);
hegyi@156
    12
    }
hegyi@27
    13
}
hegyi@27
    14
hegyi@27
    15
void GraphDisplayerCanvas::zoomOut()
hegyi@27
    16
{
hegyi@27
    17
  set_pixels_per_unit(
hegyi@27
    18
      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
hegyi@156
    19
  if(zoomtrack)
hegyi@156
    20
    {
hegyi@157
    21
      propertyChange(true, E_WIDTH);
hegyi@156
    22
      propertyChange(false, N_RADIUS);
hegyi@156
    23
    }
hegyi@27
    24
}
hegyi@27
    25
hegyi@27
    26
void GraphDisplayerCanvas::zoomFit()
hegyi@27
    27
{
ladanyi@87
    28
  updateScrollRegion();
ladanyi@87
    29
hegyi@27
    30
  // get the height and width of the canvas
hegyi@27
    31
  Gtk::Allocation a = get_allocation();
hegyi@27
    32
  int aw = a.get_width();
hegyi@27
    33
  int ah = a.get_height();
hegyi@27
    34
hegyi@27
    35
  // get the bounding box of the graph
ladanyi@87
    36
  update_now();
ladanyi@87
    37
  double x1, y1, x2, y2;
ladanyi@87
    38
  root()->get_bounds(x1, y1, x2, y2);
hegyi@27
    39
hegyi@27
    40
  // fit the graph to the window
ladanyi@87
    41
  double ppu1 = (double) aw / fabs(x2 - x1);
ladanyi@87
    42
  double ppu2 = (double) ah / fabs(y2 - y1);
hegyi@27
    43
  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
hegyi@156
    44
hegyi@156
    45
  if(zoomtrack)
hegyi@156
    46
    {
hegyi@157
    47
      propertyChange(true, E_WIDTH);
hegyi@156
    48
      propertyChange(false, N_RADIUS);
hegyi@156
    49
    }
hegyi@27
    50
}
hegyi@27
    51
hegyi@27
    52
void GraphDisplayerCanvas::zoom100()
hegyi@27
    53
{
ladanyi@87
    54
  updateScrollRegion();
hegyi@27
    55
  set_pixels_per_unit(1.0);
hegyi@156
    56
hegyi@156
    57
  if(zoomtrack)
hegyi@156
    58
    {
hegyi@157
    59
      propertyChange(true, E_WIDTH);
hegyi@156
    60
      propertyChange(false, N_RADIUS);
hegyi@156
    61
    }
hegyi@27
    62
}
hegyi@27
    63
hegyi@27
    64
void GraphDisplayerCanvas::updateScrollRegion()
hegyi@27
    65
{
ladanyi@87
    66
  // get_bounds() yields something sane only when no updates are pending
ladanyi@87
    67
  // and it returns a sufficient, not an exact bounding box
ladanyi@87
    68
  update_now();
ladanyi@87
    69
  double x1, y1, x2, y2;
ladanyi@87
    70
  root()->get_bounds(x1, y1, x2, y2);
ladanyi@87
    71
  set_scroll_region(x1, y1, x2, y2);
hegyi@27
    72
}