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@27
|
8 |
}
|
hegyi@27
|
9 |
|
hegyi@27
|
10 |
void GraphDisplayerCanvas::zoomOut()
|
hegyi@27
|
11 |
{
|
hegyi@27
|
12 |
set_pixels_per_unit(
|
hegyi@27
|
13 |
(1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
|
hegyi@27
|
14 |
}
|
hegyi@27
|
15 |
|
hegyi@27
|
16 |
void GraphDisplayerCanvas::zoomFit()
|
hegyi@27
|
17 |
{
|
ladanyi@87
|
18 |
updateScrollRegion();
|
ladanyi@87
|
19 |
|
hegyi@27
|
20 |
// get the height and width of the canvas
|
hegyi@27
|
21 |
Gtk::Allocation a = get_allocation();
|
hegyi@27
|
22 |
int aw = a.get_width();
|
hegyi@27
|
23 |
int ah = a.get_height();
|
hegyi@27
|
24 |
|
hegyi@27
|
25 |
// get the bounding box of the graph
|
ladanyi@87
|
26 |
update_now();
|
ladanyi@87
|
27 |
double x1, y1, x2, y2;
|
ladanyi@87
|
28 |
root()->get_bounds(x1, y1, x2, y2);
|
hegyi@27
|
29 |
|
hegyi@27
|
30 |
// fit the graph to the window
|
ladanyi@87
|
31 |
double ppu1 = (double) aw / fabs(x2 - x1);
|
ladanyi@87
|
32 |
double ppu2 = (double) ah / fabs(y2 - y1);
|
hegyi@27
|
33 |
set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
|
hegyi@27
|
34 |
}
|
hegyi@27
|
35 |
|
hegyi@27
|
36 |
void GraphDisplayerCanvas::zoom100()
|
hegyi@27
|
37 |
{
|
ladanyi@87
|
38 |
updateScrollRegion();
|
hegyi@27
|
39 |
set_pixels_per_unit(1.0);
|
hegyi@27
|
40 |
}
|
hegyi@27
|
41 |
|
hegyi@27
|
42 |
void GraphDisplayerCanvas::updateScrollRegion()
|
hegyi@27
|
43 |
{
|
ladanyi@87
|
44 |
// get_bounds() yields something sane only when no updates are pending
|
ladanyi@87
|
45 |
// and it returns a sufficient, not an exact bounding box
|
ladanyi@87
|
46 |
update_now();
|
ladanyi@87
|
47 |
double x1, y1, x2, y2;
|
ladanyi@87
|
48 |
root()->get_bounds(x1, y1, x2, y2);
|
ladanyi@87
|
49 |
set_scroll_region(x1, y1, x2, y2);
|
hegyi@27
|
50 |
}
|