COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-zoom.cc @ 156:c5cdf6690cdf

Last change on this file since 156:c5cdf6690cdf was 156:c5cdf6690cdf, checked in by Hegyi Péter, 18 years ago

Zoom tracking of nodes is implemented and is switchable.

  • Property exe set to *
File size: 1.4 KB
Line 
1#include "graph_displayer_canvas.h"
2#include <cmath>
3
4void GraphDisplayerCanvas::zoomIn()
5{
6  set_pixels_per_unit(
7      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
8  if(zoomtrack)
9    {
10      propertyChange(false, N_RADIUS);
11    }
12}
13
14void GraphDisplayerCanvas::zoomOut()
15{
16  set_pixels_per_unit(
17      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
18  if(zoomtrack)
19    {
20      propertyChange(false, N_RADIUS);
21    }
22}
23
24void GraphDisplayerCanvas::zoomFit()
25{
26  updateScrollRegion();
27
28  // get the height and width of the canvas
29  Gtk::Allocation a = get_allocation();
30  int aw = a.get_width();
31  int ah = a.get_height();
32
33  // get the bounding box of the graph
34  update_now();
35  double x1, y1, x2, y2;
36  root()->get_bounds(x1, y1, x2, y2);
37
38  // fit the graph to the window
39  double ppu1 = (double) aw / fabs(x2 - x1);
40  double ppu2 = (double) ah / fabs(y2 - y1);
41  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
42
43  if(zoomtrack)
44    {
45      propertyChange(false, N_RADIUS);
46    }
47}
48
49void GraphDisplayerCanvas::zoom100()
50{
51  updateScrollRegion();
52  set_pixels_per_unit(1.0);
53
54  if(zoomtrack)
55    {
56      propertyChange(false, N_RADIUS);
57    }
58}
59
60void GraphDisplayerCanvas::updateScrollRegion()
61{
62  // get_bounds() yields something sane only when no updates are pending
63  // and it returns a sufficient, not an exact bounding box
64  update_now();
65  double x1, y1, x2, y2;
66  root()->get_bounds(x1, y1, x2, y2);
67  set_scroll_region(x1, y1, x2, y2);
68}
Note: See TracBrowser for help on using the repository browser.