14 (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); |
14 (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); |
15 } |
15 } |
16 |
16 |
17 void GraphDisplayerCanvas::zoomFit() |
17 void GraphDisplayerCanvas::zoomFit() |
18 { |
18 { |
|
19 updateScrollRegion(); |
|
20 |
19 // get the height and width of the canvas |
21 // get the height and width of the canvas |
20 Gtk::Allocation a = get_allocation(); |
22 Gtk::Allocation a = get_allocation(); |
21 int aw = a.get_width(); |
23 int aw = a.get_width(); |
22 int ah = a.get_height(); |
24 int ah = a.get_height(); |
23 // add some space |
|
24 aw -= 5; if (aw < 0) aw = 0; |
|
25 ah -= 5; if (ah < 0) ah = 0; |
|
26 |
25 |
27 // get the bounding box of the graph |
26 // get the bounding box of the graph |
28 double wx1, wy1, wx2, wy2; |
27 update_now(); |
29 Gnome::Canvas::Item* pCanvasItem = root(); |
28 double x1, y1, x2, y2; |
30 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
29 root()->get_bounds(x1, y1, x2, y2); |
31 |
30 |
32 // fit the graph to the window |
31 // fit the graph to the window |
33 double ppu1 = (double) aw / fabs(wx2 - wx1); |
32 double ppu1 = (double) aw / fabs(x2 - x1); |
34 double ppu2 = (double) ah / fabs(wy2 - wy1); |
33 double ppu2 = (double) ah / fabs(y2 - y1); |
35 set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
34 set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
36 } |
35 } |
37 |
36 |
38 void GraphDisplayerCanvas::zoom100() |
37 void GraphDisplayerCanvas::zoom100() |
39 { |
38 { |
|
39 updateScrollRegion(); |
40 set_pixels_per_unit(1.0); |
40 set_pixels_per_unit(1.0); |
41 } |
41 } |
42 |
42 |
43 void GraphDisplayerCanvas::updateScrollRegion() |
43 void GraphDisplayerCanvas::updateScrollRegion() |
44 { |
44 { |
45 double wx1, wy1, wx2, wy2; |
45 // get_bounds() yields something sane only when no updates are pending |
46 Gnome::Canvas::Item* pCanvasItem = root(); |
46 // and it returns a sufficient, not an exact bounding box |
47 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
47 update_now(); |
48 set_scroll_region(wx1, wy1, wx2, wy2); |
48 double x1, y1, x2, y2; |
|
49 root()->get_bounds(x1, y1, x2, y2); |
|
50 set_scroll_region(x1, y1, x2, y2); |
49 } |
51 } |