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