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