- added toolbar
authorladanyi
Wed, 01 Jun 2005 23:30:13 +0000
changeset 1441fd4b6f6d592a
parent 1440 3d2e3cfb2a6c
child 1442 1e3c69aa035b
- added toolbar
- added ScrolledWindow for the canvas
- zooming
gui/graph_displayer_canvas.cc
gui/graph_displayer_canvas.h
gui/main_win.cc
gui/main_win.h
     1.1 --- a/gui/graph_displayer_canvas.cc	Fri May 27 10:34:20 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas.cc	Wed Jun 01 23:30:13 2005 +0000
     1.3 @@ -3,6 +3,7 @@
     1.4  
     1.5  GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
     1.6  {
     1.7 +  //set_center_scroll_region(true);
     1.8  
     1.9    //first edges are drawn, to hide joining with nodes later
    1.10  
    1.11 @@ -50,6 +51,7 @@
    1.12      (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
    1.13    }
    1.14  
    1.15 +/*
    1.16    //setting zoom to be able to see the whole graph on the canvas
    1.17  
    1.18    double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    1.19 @@ -59,7 +61,8 @@
    1.20    std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
    1.21    std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
    1.22    std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
    1.23 -
    1.24 +*/
    1.25 +  updateScrollRegion();
    1.26  }
    1.27  
    1.28  GraphDisplayerCanvas::~GraphDisplayerCanvas()
    1.29 @@ -173,48 +176,6 @@
    1.30    return 0;
    1.31  };
    1.32  
    1.33 -
    1.34 -int GraphDisplayerCanvas::rezoom ()
    1.35 -{
    1.36 -
    1.37 -  //searches for the minimum and the maximum
    1.38 -  //value of the coordinates of the nodes to
    1.39 -  //set the pixel rpo unit to a value to be 
    1.40 -  //able to see the whole graph in the canvas
    1.41 -  //\todo does not work properly
    1.42 -
    1.43 -  double x1, x2, y1, y2;
    1.44 -  int x,y;
    1.45 -
    1.46 -  NodeIt i(g);
    1.47 -  nodesmap[i]->get_bounds(x1, y1, x2, y2);
    1.48 -
    1.49 -  x=(int)((x1+x2)/2);
    1.50 -  y=(int)((y1+y2)/2);
    1.51 -  
    1.52 -  int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
    1.53 -
    1.54 -  for (; i!=INVALID; ++i)
    1.55 -  {
    1.56 -    nodesmap[i]->get_bounds(x1, y1, x2, y2);
    1.57 -
    1.58 -    x=(int)((x1+x2)/2);
    1.59 -    y=(int)((y1+y2)/2);
    1.60 -
    1.61 -    if(x>maxx)maxx=x;
    1.62 -    if(y>maxy)maxy=y;
    1.63 -    if(x<minx)minx=x;
    1.64 -    if(y<miny)miny=y;
    1.65 -  }
    1.66 -
    1.67 -  double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    1.68 -  double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
    1.69 -
    1.70 -  set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
    1.71 -  return 0;
    1.72 -};
    1.73 -
    1.74 -
    1.75  bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
    1.76  {
    1.77    switch(e->type)
    1.78 @@ -300,3 +261,61 @@
    1.79    //rezoom();
    1.80    return true;
    1.81  }
    1.82 +
    1.83 +void GraphDisplayerCanvas::zoomIn()
    1.84 +{
    1.85 +  set_pixels_per_unit(
    1.86 +      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
    1.87 +}
    1.88 +
    1.89 +void GraphDisplayerCanvas::zoomOut()
    1.90 +{
    1.91 +  set_pixels_per_unit(
    1.92 +      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
    1.93 +}
    1.94 +
    1.95 +void GraphDisplayerCanvas::zoomFit()
    1.96 +{
    1.97 +  // get the height and width of the canvas
    1.98 +  Gtk::Allocation a = get_allocation();
    1.99 +  int aw = a.get_width();
   1.100 +  int ah = a.get_height();
   1.101 +  // add some space
   1.102 +  aw -= 5; if (aw < 0) aw = 0;
   1.103 +  ah -= 5; if (ah < 0) ah = 0;
   1.104 +  //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
   1.105 +
   1.106 +  // get the bounding box of the graph
   1.107 +  set_pixels_per_unit(1.0); // I don't really understand why this is necessary
   1.108 +  double wx1, wy1, wx2, wy2;
   1.109 +  double cx1, cy1, cx2, cy2;
   1.110 +  Gnome::Canvas::Item* pCanvasItem = root();
   1.111 +  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   1.112 +  //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
   1.113 +  w2c(wx1, wy1, cx1, cy1);
   1.114 +  w2c(wx2, wy2, cx2, cy2);
   1.115 +  //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
   1.116 +  //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
   1.117 +
   1.118 +  // fit the graph to the window
   1.119 +  double ppu1 = (double) aw / fabs(cx2 - cx1);
   1.120 +  double ppu2 = (double) ah / fabs(cy2 - cy1);
   1.121 +  //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
   1.122 +  (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
   1.123 +}
   1.124 +
   1.125 +void GraphDisplayerCanvas::zoom100()
   1.126 +{
   1.127 +  set_pixels_per_unit(1.0);
   1.128 +}
   1.129 +
   1.130 +void GraphDisplayerCanvas::updateScrollRegion()
   1.131 +{
   1.132 +  double wx1, wy1, wx2, wy2;
   1.133 +  int cx1, cy1, cx2, cy2;
   1.134 +  Gnome::Canvas::Item* pCanvasItem = root();
   1.135 +  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   1.136 +  w2c(wx1, wy1, cx1, cy1);
   1.137 +  w2c(wx2, wy2, cx2, cy2);
   1.138 +  set_scroll_region(cx1, cy1, cx2, cy2);
   1.139 +}
     2.1 --- a/gui/graph_displayer_canvas.h	Fri May 27 10:34:20 2005 +0000
     2.2 +++ b/gui/graph_displayer_canvas.h	Wed Jun 01 23:30:13 2005 +0000
     2.3 @@ -29,8 +29,16 @@
     2.4    ///\param mapname is the name of the map which contains the new values
     2.5    int changeText (std::string mapname);
     2.6  
     2.7 -  ///Changes the dot-pro-pixel to be able to show the whole graph.
     2.8 -  int rezoom();
     2.9 +  ///Callback for 'ViewZoomIn' action.
    2.10 +  virtual void zoomIn();
    2.11 +  ///Callback for 'ViewZoomOut' action.
    2.12 +  virtual void zoomOut();
    2.13 +  ///Callback for 'ViewZoomFit' action.
    2.14 +  virtual void zoomFit();
    2.15 +  ///Callback for 'ViewZoom100' action.
    2.16 +  virtual void zoom100();
    2.17 +  ///Sets the scroll region of the convas to the bounding box of the graph.
    2.18 +  void updateScrollRegion();
    2.19  
    2.20  protected:
    2.21  
    2.22 @@ -75,7 +83,7 @@
    2.23    ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
    2.24    Gnome::Canvas::Item * active_item;
    2.25  
    2.26 -
    2.27 +  static const int zoom_step = 5;
    2.28  };
    2.29  
    2.30  #endif //GRAPH_DISPLAYER_CANVAS_H
     3.1 --- a/gui/main_win.cc	Fri May 27 10:34:20 2005 +0000
     3.2 +++ b/gui/main_win.cc	Wed Jun 01 23:30:13 2005 +0000
     3.3 @@ -1,18 +1,39 @@
     3.4  #include <main_win.h>
     3.5  
     3.6 -MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
     3.7 +MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
     3.8 +    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
     3.9  {
    3.10    set_title (title);
    3.11    set_default_size(WIN_WIDTH,WIN_HEIGHT);
    3.12    add(vbox);
    3.13  
    3.14    ag=Gtk::ActionGroup::create();
    3.15 +
    3.16 +  ag->add( Gtk::Action::create("FileMenu", "_File") );
    3.17 +  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
    3.18 +      sigc::mem_fun(*this, &MainWin::newFile));
    3.19 +  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
    3.20 +      sigc::mem_fun(*this, &MainWin::openFile));
    3.21 +  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
    3.22 +      sigc::mem_fun(*this, &MainWin::saveFile));
    3.23 +  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
    3.24 +      sigc::mem_fun(*this, &MainWin::saveFileAs));
    3.25 +  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
    3.26 +      sigc::mem_fun(*this, &MainWin::quit));
    3.27 +
    3.28 +  ag->add( Gtk::Action::create("ViewMenu", "_View") );
    3.29 +  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
    3.30 +      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
    3.31 +  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
    3.32 +      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
    3.33 +  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
    3.34 +      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
    3.35 +  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
    3.36 +      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
    3.37 +  
    3.38    ag->add( Gtk::Action::create("ShowMenu", "_Show") );
    3.39 -  ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps));
    3.40 -  ag->add( Gtk::Action::create("FileMenu", "_File") );
    3.41 -  ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit));
    3.42 -  ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") );
    3.43 -  ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!!
    3.44 +  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
    3.45 +      sigc::mem_fun(*this, &MainWin::showMaps));
    3.46  
    3.47    uim=Gtk::UIManager::create();
    3.48    uim->insert_action_group(ag);
    3.49 @@ -25,15 +46,32 @@
    3.50        "<ui>"
    3.51        "  <menubar name='MenuBar'>"
    3.52        "    <menu action='FileMenu'>"
    3.53 +      "      <menuitem action='FileNew'/>"
    3.54 +      "      <menuitem action='FileOpen'/>"
    3.55 +      "      <menuitem action='FileSave'/>"
    3.56 +      "      <menuitem action='FileSaveAs'/>"
    3.57        "      <menuitem action='FileQuit'/>"
    3.58        "    </menu>"
    3.59 +      "    <menu action='ViewMenu'>"
    3.60 +      "      <menuitem action='ViewZoomIn' />"
    3.61 +      "      <menuitem action='ViewZoomOut' />"
    3.62 +      "      <menuitem action='ViewZoomFit' />"
    3.63 +      "      <menuitem action='ViewZoom100' />"
    3.64 +      "    </menu>"
    3.65        "    <menu action='ShowMenu'>"
    3.66        "      <menuitem action='ShowMaps'/>"
    3.67        "    </menu>"
    3.68 -      "    <menu action='ZoomMenu'>"
    3.69 -      "      <menuitem action='ZoomRezoom'/>"
    3.70 -      "    </menu>"
    3.71        "  </menubar>"
    3.72 +      "  <toolbar name='ToolBar'>"
    3.73 +      "    <toolitem action='FileNew' />"
    3.74 +      "    <toolitem action='FileOpen' />"
    3.75 +      "    <toolitem action='FileSave' />"
    3.76 +      "    <separator />"
    3.77 +      "    <toolitem action='ViewZoomIn' />"
    3.78 +      "    <toolitem action='ViewZoomOut' />"
    3.79 +      "    <toolitem action='ViewZoomFit' />"
    3.80 +      "    <toolitem action='ViewZoom100' />"
    3.81 +      "  </toolbar>"
    3.82        "</ui>";
    3.83  
    3.84      uim->add_ui_from_string(ui_info);
    3.85 @@ -45,9 +83,21 @@
    3.86    }
    3.87  
    3.88    Gtk::Widget* menubar = uim->get_widget("/MenuBar");
    3.89 -  if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
    3.90 +  if (menubar){
    3.91 +    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
    3.92 +  }
    3.93  
    3.94 -  vbox.pack_start(gd_canvas);
    3.95 +  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
    3.96 +  if (toolbar)
    3.97 +  {
    3.98 +    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
    3.99 +    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
   3.100 +  }
   3.101 +
   3.102 +  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
   3.103 +  pScrolledWindow->add(gd_canvas);
   3.104 +  vbox.pack_start(*pScrolledWindow);
   3.105 +  //vbox.pack_start(gd_canvas);
   3.106  
   3.107    show_all_children();
   3.108  }
   3.109 @@ -62,8 +112,22 @@
   3.110    hide();
   3.111  }
   3.112  
   3.113 -void MainWin::rezoom()
   3.114 +void MainWin::newFile()
   3.115  {
   3.116 -  gd_canvas.rezoom();
   3.117 +  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
   3.118  }
   3.119  
   3.120 +void MainWin::openFile()
   3.121 +{
   3.122 +  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
   3.123 +}
   3.124 +
   3.125 +void MainWin::saveFile()
   3.126 +{
   3.127 +  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
   3.128 +}
   3.129 +
   3.130 +void MainWin::saveFileAs()
   3.131 +{
   3.132 +  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
   3.133 +}
     4.1 --- a/gui/main_win.h	Fri May 27 10:34:20 2005 +0000
     4.2 +++ b/gui/main_win.h	Wed Jun 01 23:30:13 2005 +0000
     4.3 @@ -39,13 +39,16 @@
     4.4  
     4.5    ///This function makes map-setup window popped up.
     4.6    virtual void showMaps();
     4.7 -
     4.8 -  ///Exit
     4.9 +  ///Callback for 'FileNew' action.
    4.10 +  virtual void newFile();
    4.11 +  ///Callback for 'FileOpen' action.
    4.12 +  virtual void openFile();
    4.13 +  ///Callback for 'FileSave' action.
    4.14 +  virtual void saveFile();
    4.15 +  ///Callback for 'FileSaveAs' action.
    4.16 +  virtual void saveFileAs();
    4.17 +  ///Callback for 'Quit' action.
    4.18    virtual void quit();
    4.19 -
    4.20 -  ///Refit screen to be able to show the whole graph.
    4.21 -  virtual void rezoom();
    4.22 -
    4.23  };
    4.24  
    4.25  #endif //MAIN_WIN_H