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