hegyi@1
|
1 |
/* -*- C++ -*-
|
hegyi@1
|
2 |
*
|
hegyi@1
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
hegyi@1
|
4 |
*
|
hegyi@1
|
5 |
* Copyright (C) 2003-2006
|
hegyi@1
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
hegyi@1
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
hegyi@1
|
8 |
*
|
hegyi@1
|
9 |
* Permission to use, modify and distribute this software is granted
|
hegyi@1
|
10 |
* provided that this copyright notice appears in all copies. For
|
hegyi@1
|
11 |
* precise terms see the accompanying LICENSE file.
|
hegyi@1
|
12 |
*
|
hegyi@1
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
hegyi@1
|
14 |
* express or implied, and with no claim as to its suitability for any
|
hegyi@1
|
15 |
* purpose.
|
hegyi@1
|
16 |
*
|
hegyi@1
|
17 |
*/
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#include <graph_displayer_canvas.h>
|
hegyi@1
|
20 |
#include <cmath>
|
hegyi@1
|
21 |
|
hegyi@1
|
22 |
void DigraphDisplayerCanvas::zoomIn()
|
hegyi@1
|
23 |
{
|
hegyi@1
|
24 |
set_pixels_per_unit(
|
hegyi@1
|
25 |
(1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
|
hegyi@1
|
26 |
if(zoomtrack)
|
hegyi@1
|
27 |
{
|
hegyi@1
|
28 |
propertyChange(false, N_RADIUS);
|
hegyi@1
|
29 |
propertyChange(true, E_WIDTH);
|
hegyi@1
|
30 |
}
|
hegyi@1
|
31 |
}
|
hegyi@1
|
32 |
|
hegyi@1
|
33 |
void DigraphDisplayerCanvas::zoomOut()
|
hegyi@1
|
34 |
{
|
hegyi@1
|
35 |
set_pixels_per_unit(
|
hegyi@1
|
36 |
(1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
|
hegyi@1
|
37 |
if(zoomtrack)
|
hegyi@1
|
38 |
{
|
hegyi@1
|
39 |
propertyChange(true, E_WIDTH);
|
hegyi@1
|
40 |
propertyChange(false, N_RADIUS);
|
hegyi@1
|
41 |
}
|
hegyi@1
|
42 |
}
|
hegyi@1
|
43 |
|
hegyi@1
|
44 |
void DigraphDisplayerCanvas::zoomFit()
|
hegyi@1
|
45 |
{
|
hegyi@1
|
46 |
updateScrollRegion();
|
hegyi@1
|
47 |
|
hegyi@1
|
48 |
// get the height and width of the canvas
|
hegyi@1
|
49 |
Gtk::Allocation a = get_allocation();
|
hegyi@1
|
50 |
int aw = a.get_width();
|
hegyi@1
|
51 |
int ah = a.get_height();
|
hegyi@1
|
52 |
|
hegyi@1
|
53 |
// get the bounding box of the digraph
|
hegyi@1
|
54 |
update_now();
|
hegyi@1
|
55 |
double x1, y1, x2, y2;
|
hegyi@1
|
56 |
root()->get_bounds(x1, y1, x2, y2);
|
hegyi@1
|
57 |
|
hegyi@1
|
58 |
// fit the digraph to the window
|
hegyi@1
|
59 |
double ppu1 = (double) aw / fabs(x2 - x1);
|
hegyi@1
|
60 |
double ppu2 = (double) ah / fabs(y2 - y1);
|
hegyi@1
|
61 |
set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
|
hegyi@1
|
62 |
|
hegyi@1
|
63 |
if(zoomtrack)
|
hegyi@1
|
64 |
{
|
hegyi@1
|
65 |
propertyChange(true, E_WIDTH);
|
hegyi@1
|
66 |
propertyChange(false, N_RADIUS);
|
hegyi@1
|
67 |
}
|
hegyi@1
|
68 |
}
|
hegyi@1
|
69 |
|
hegyi@1
|
70 |
void DigraphDisplayerCanvas::zoom100()
|
hegyi@1
|
71 |
{
|
hegyi@1
|
72 |
updateScrollRegion();
|
hegyi@1
|
73 |
set_pixels_per_unit(1.0);
|
hegyi@1
|
74 |
|
hegyi@1
|
75 |
if(zoomtrack)
|
hegyi@1
|
76 |
{
|
hegyi@1
|
77 |
propertyChange(true, E_WIDTH);
|
hegyi@1
|
78 |
propertyChange(false, N_RADIUS);
|
hegyi@1
|
79 |
}
|
hegyi@1
|
80 |
}
|
hegyi@1
|
81 |
|
hegyi@1
|
82 |
void DigraphDisplayerCanvas::updateScrollRegion()
|
hegyi@1
|
83 |
{
|
hegyi@1
|
84 |
// get_bounds() yields something sane only when no updates are pending
|
hegyi@1
|
85 |
// and it returns a sufficient, not an exact bounding box
|
hegyi@1
|
86 |
update_now();
|
hegyi@1
|
87 |
double x1, y1, x2, y2;
|
hegyi@1
|
88 |
root()->get_bounds(x1, y1, x2, y2);
|
hegyi@1
|
89 |
set_scroll_region(x1, y1, x2, y2);
|
hegyi@1
|
90 |
}
|