ladanyi@1606
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@1606
|
2 |
#include "broken_edge.h"
|
hegyi@1510
|
3 |
#include <math.h>
|
hegyi@1510
|
4 |
|
hegyi@1510
|
5 |
void GraphDisplayerCanvas::zoomIn()
|
hegyi@1510
|
6 |
{
|
hegyi@1510
|
7 |
set_pixels_per_unit(
|
hegyi@1510
|
8 |
(1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
|
hegyi@1510
|
9 |
}
|
hegyi@1510
|
10 |
|
hegyi@1510
|
11 |
void GraphDisplayerCanvas::zoomOut()
|
hegyi@1510
|
12 |
{
|
hegyi@1510
|
13 |
set_pixels_per_unit(
|
hegyi@1510
|
14 |
(1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
|
hegyi@1510
|
15 |
}
|
hegyi@1510
|
16 |
|
hegyi@1510
|
17 |
void GraphDisplayerCanvas::zoomFit()
|
hegyi@1510
|
18 |
{
|
hegyi@1510
|
19 |
// get the height and width of the canvas
|
hegyi@1510
|
20 |
Gtk::Allocation a = get_allocation();
|
hegyi@1510
|
21 |
int aw = a.get_width();
|
hegyi@1510
|
22 |
int ah = a.get_height();
|
hegyi@1510
|
23 |
// add some space
|
hegyi@1510
|
24 |
aw -= 5; if (aw < 0) aw = 0;
|
hegyi@1510
|
25 |
ah -= 5; if (ah < 0) ah = 0;
|
hegyi@1510
|
26 |
|
hegyi@1510
|
27 |
// get the bounding box of the graph
|
hegyi@1510
|
28 |
double wx1, wy1, wx2, wy2;
|
hegyi@1510
|
29 |
Gnome::Canvas::Item* pCanvasItem = root();
|
hegyi@1510
|
30 |
pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
|
hegyi@1510
|
31 |
|
hegyi@1510
|
32 |
// fit the graph to the window
|
hegyi@1510
|
33 |
double ppu1 = (double) aw / fabs(wx2 - wx1);
|
hegyi@1510
|
34 |
double ppu2 = (double) ah / fabs(wy2 - wy1);
|
hegyi@1510
|
35 |
set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
|
hegyi@1510
|
36 |
}
|
hegyi@1510
|
37 |
|
hegyi@1510
|
38 |
void GraphDisplayerCanvas::zoom100()
|
hegyi@1510
|
39 |
{
|
hegyi@1510
|
40 |
set_pixels_per_unit(1.0);
|
hegyi@1510
|
41 |
}
|
hegyi@1510
|
42 |
|
hegyi@1510
|
43 |
void GraphDisplayerCanvas::updateScrollRegion()
|
hegyi@1510
|
44 |
{
|
hegyi@1510
|
45 |
double wx1, wy1, wx2, wy2;
|
hegyi@1510
|
46 |
Gnome::Canvas::Item* pCanvasItem = root();
|
hegyi@1510
|
47 |
pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
|
hegyi@1510
|
48 |
set_scroll_region(wx1, wy1, wx2, wy2);
|
hegyi@1510
|
49 |
}
|