[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); |
---|
[157] | 11 | propertyChange(true, E_WIDTH); |
---|
[156] | 12 | } |
---|
[27] | 13 | } |
---|
| 14 | |
---|
| 15 | void GraphDisplayerCanvas::zoomOut() |
---|
| 16 | { |
---|
| 17 | set_pixels_per_unit( |
---|
| 18 | (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); |
---|
[156] | 19 | if(zoomtrack) |
---|
| 20 | { |
---|
[157] | 21 | propertyChange(true, E_WIDTH); |
---|
[156] | 22 | propertyChange(false, N_RADIUS); |
---|
| 23 | } |
---|
[27] | 24 | } |
---|
| 25 | |
---|
| 26 | void GraphDisplayerCanvas::zoomFit() |
---|
| 27 | { |
---|
[87] | 28 | updateScrollRegion(); |
---|
| 29 | |
---|
[27] | 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 |
---|
[87] | 36 | update_now(); |
---|
| 37 | double x1, y1, x2, y2; |
---|
| 38 | root()->get_bounds(x1, y1, x2, y2); |
---|
[27] | 39 | |
---|
| 40 | // fit the graph to the window |
---|
[87] | 41 | double ppu1 = (double) aw / fabs(x2 - x1); |
---|
| 42 | double ppu2 = (double) ah / fabs(y2 - y1); |
---|
[27] | 43 | set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
---|
[156] | 44 | |
---|
| 45 | if(zoomtrack) |
---|
| 46 | { |
---|
[157] | 47 | propertyChange(true, E_WIDTH); |
---|
[156] | 48 | propertyChange(false, N_RADIUS); |
---|
| 49 | } |
---|
[27] | 50 | } |
---|
| 51 | |
---|
| 52 | void GraphDisplayerCanvas::zoom100() |
---|
| 53 | { |
---|
[87] | 54 | updateScrollRegion(); |
---|
[27] | 55 | set_pixels_per_unit(1.0); |
---|
[156] | 56 | |
---|
| 57 | if(zoomtrack) |
---|
| 58 | { |
---|
[157] | 59 | propertyChange(true, E_WIDTH); |
---|
[156] | 60 | propertyChange(false, N_RADIUS); |
---|
| 61 | } |
---|
[27] | 62 | } |
---|
| 63 | |
---|
| 64 | void GraphDisplayerCanvas::updateScrollRegion() |
---|
| 65 | { |
---|
[87] | 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); |
---|
[27] | 72 | } |
---|