improved zooming gui
authorladanyi
Fri, 04 Nov 2005 19:07:15 +0000
branchgui
changeset 87b44281e4cca7
parent 86 0c34609f83cd
child 88 c397e85ec555
improved zooming
graph_displayer_canvas-event.cc
graph_displayer_canvas-zoom.cc
main_win.cc
     1.1 --- a/graph_displayer_canvas-event.cc	Wed Nov 02 12:44:50 2005 +0000
     1.2 +++ b/graph_displayer_canvas-event.cc	Fri Nov 04 19:07:15 2005 +0000
     1.3 @@ -308,7 +308,6 @@
     1.4        target_item=NULL;
     1.5        active_item=NULL;
     1.6        active_node=INVALID;
     1.7 -
     1.8        break;
     1.9      default:
    1.10        break;
     2.1 --- a/graph_displayer_canvas-zoom.cc	Wed Nov 02 12:44:50 2005 +0000
     2.2 +++ b/graph_displayer_canvas-zoom.cc	Fri Nov 04 19:07:15 2005 +0000
     2.3 @@ -16,34 +16,36 @@
     2.4  
     2.5  void GraphDisplayerCanvas::zoomFit()
     2.6  {
     2.7 +  updateScrollRegion();
     2.8 +
     2.9    // get the height and width of the canvas
    2.10    Gtk::Allocation a = get_allocation();
    2.11    int aw = a.get_width();
    2.12    int ah = a.get_height();
    2.13 -  // add some space
    2.14 -  aw -= 5; if (aw < 0) aw = 0;
    2.15 -  ah -= 5; if (ah < 0) ah = 0;
    2.16  
    2.17    // get the bounding box of the graph
    2.18 -  double wx1, wy1, wx2, wy2;
    2.19 -  Gnome::Canvas::Item* pCanvasItem = root();
    2.20 -  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
    2.21 +  update_now();
    2.22 +  double x1, y1, x2, y2;
    2.23 +  root()->get_bounds(x1, y1, x2, y2);
    2.24  
    2.25    // fit the graph to the window
    2.26 -  double ppu1 = (double) aw / fabs(wx2 - wx1);
    2.27 -  double ppu2 = (double) ah / fabs(wy2 - wy1);
    2.28 +  double ppu1 = (double) aw / fabs(x2 - x1);
    2.29 +  double ppu2 = (double) ah / fabs(y2 - y1);
    2.30    set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
    2.31  }
    2.32  
    2.33  void GraphDisplayerCanvas::zoom100()
    2.34  {
    2.35 +  updateScrollRegion();
    2.36    set_pixels_per_unit(1.0);
    2.37  }
    2.38  
    2.39  void GraphDisplayerCanvas::updateScrollRegion()
    2.40  {
    2.41 -  double wx1, wy1, wx2, wy2;
    2.42 -  Gnome::Canvas::Item* pCanvasItem = root();
    2.43 -  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
    2.44 -  set_scroll_region(wx1, wy1, wx2, wy2);
    2.45 +  // get_bounds() yields something sane only when no updates are pending
    2.46 +  // and it returns a sufficient, not an exact bounding box
    2.47 +  update_now();
    2.48 +  double x1, y1, x2, y2;
    2.49 +  root()->get_bounds(x1, y1, x2, y2);
    2.50 +  set_scroll_region(x1, y1, x2, y2);
    2.51  }
     3.1 --- a/main_win.cc	Wed Nov 02 12:44:50 2005 +0000
     3.2 +++ b/main_win.cc	Fri Nov 04 19:07:15 2005 +0000
     3.3 @@ -127,11 +127,6 @@
     3.4    uim->insert_action_group(ag);
     3.5    add_accel_group(uim->get_accel_group());
     3.6  
     3.7 -  /*
     3.8 -      "      <menuitem action='ViewZoomFit' />"
     3.9 -      "    <toolitem action='ViewZoomFit' />"
    3.10 -   */
    3.11 -
    3.12    try
    3.13    {
    3.14  
    3.15 @@ -150,6 +145,7 @@
    3.16        "      <menuitem action='ViewZoomIn' />"
    3.17        "      <menuitem action='ViewZoomOut' />"
    3.18        "      <menuitem action='ViewZoom100' />"
    3.19 +      "      <menuitem action='ViewZoomFit' />"
    3.20        "    </menu>"
    3.21        "    <menu action='ShowMenu'>"
    3.22        "      <menuitem action='ShowMaps'/>"
    3.23 @@ -164,6 +160,7 @@
    3.24        "    <toolitem action='ViewZoomIn' />"
    3.25        "    <toolitem action='ViewZoomOut' />"
    3.26        "    <toolitem action='ViewZoom100' />"
    3.27 +      "    <toolitem action='ViewZoomFit' />"
    3.28        "    <separator />"
    3.29        "    <toolitem action='MoveItem' />"
    3.30        "    <toolitem action='CreateNode' />"
    3.31 @@ -197,6 +194,7 @@
    3.32    }
    3.33  
    3.34    Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
    3.35 +  pScrolledWindow->set_shadow_type(Gtk::SHADOW_IN);
    3.36    pScrolledWindow->add(gd_canvas);
    3.37    vbox.pack_start(*pScrolledWindow);
    3.38