# HG changeset patch # User ladanyi # Date 1117668613 0 # Node ID fd4b6f6d592ad20484e74938ba1f387c62844725 # Parent 3d2e3cfb2a6cebe7b11b6bee300ffafaf132a9d4 - added toolbar - added ScrolledWindow for the canvas - zooming diff -r 3d2e3cfb2a6c -r fd4b6f6d592a gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Fri May 27 10:34:20 2005 +0000 +++ b/gui/graph_displayer_canvas.cc Wed Jun 01 23:30:13 2005 +0000 @@ -3,6 +3,7 @@ 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) { + //set_center_scroll_region(true); //first edges are drawn, to hide joining with nodes later @@ -50,6 +51,7 @@ (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); } +/* //setting zoom to be able to see the whole graph on the canvas double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); @@ -59,7 +61,8 @@ std::cout<get_bounds(x1, y1, x2, y2); - - x=(int)((x1+x2)/2); - y=(int)((y1+y2)/2); - - int maxx=0, maxy=0, minx=(int)x, miny=(int)y; - - for (; i!=INVALID; ++i) - { - nodesmap[i]->get_bounds(x1, y1, x2, y2); - - x=(int)((x1+x2)/2); - y=(int)((y1+y2)/2); - - if(x>maxx)maxx=x; - if(y>maxy)maxy=y; - if(xabs(minx))?(abs(maxx)+80):(abs(minx)+80); - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); - - set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); - return 0; -}; - - bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) { switch(e->type) @@ -300,3 +261,61 @@ //rezoom(); return true; } + +void GraphDisplayerCanvas::zoomIn() +{ + set_pixels_per_unit( + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); +} + +void GraphDisplayerCanvas::zoomOut() +{ + set_pixels_per_unit( + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); +} + +void GraphDisplayerCanvas::zoomFit() +{ + // get the height and width of the canvas + Gtk::Allocation a = get_allocation(); + int aw = a.get_width(); + int ah = a.get_height(); + // add some space + aw -= 5; if (aw < 0) aw = 0; + ah -= 5; if (ah < 0) ah = 0; + //std::cout << "aw=" << aw << " ah=" << ah << std::endl; + + // get the bounding box of the graph + set_pixels_per_unit(1.0); // I don't really understand why this is necessary + double wx1, wy1, wx2, wy2; + double cx1, cy1, cx2, cy2; + Gnome::Canvas::Item* pCanvasItem = root(); + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); + //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl; + w2c(wx1, wy1, cx1, cy1); + w2c(wx2, wy2, cx2, cy2); + //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl; + //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl; + + // fit the graph to the window + double ppu1 = (double) aw / fabs(cx2 - cx1); + double ppu2 = (double) ah / fabs(cy2 - cy1); + //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl; + (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2); +} + +void GraphDisplayerCanvas::zoom100() +{ + set_pixels_per_unit(1.0); +} + +void GraphDisplayerCanvas::updateScrollRegion() +{ + double wx1, wy1, wx2, wy2; + int cx1, cy1, cx2, cy2; + Gnome::Canvas::Item* pCanvasItem = root(); + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); + w2c(wx1, wy1, cx1, cy1); + w2c(wx2, wy2, cx2, cy2); + set_scroll_region(cx1, cy1, cx2, cy2); +} diff -r 3d2e3cfb2a6c -r fd4b6f6d592a gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Fri May 27 10:34:20 2005 +0000 +++ b/gui/graph_displayer_canvas.h Wed Jun 01 23:30:13 2005 +0000 @@ -29,8 +29,16 @@ ///\param mapname is the name of the map which contains the new values int changeText (std::string mapname); - ///Changes the dot-pro-pixel to be able to show the whole graph. - int rezoom(); + ///Callback for 'ViewZoomIn' action. + virtual void zoomIn(); + ///Callback for 'ViewZoomOut' action. + virtual void zoomOut(); + ///Callback for 'ViewZoomFit' action. + virtual void zoomFit(); + ///Callback for 'ViewZoom100' action. + virtual void zoom100(); + ///Sets the scroll region of the convas to the bounding box of the graph. + void updateScrollRegion(); protected: @@ -75,7 +83,7 @@ ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution Gnome::Canvas::Item * active_item; - + static const int zoom_step = 5; }; #endif //GRAPH_DISPLAYER_CANVAS_H diff -r 3d2e3cfb2a6c -r fd4b6f6d592a gui/main_win.cc --- a/gui/main_win.cc Fri May 27 10:34:20 2005 +0000 +++ b/gui/main_win.cc Wed Jun 01 23:30:13 2005 +0000 @@ -1,18 +1,39 @@ #include -MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms) +MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, + MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms) { set_title (title); set_default_size(WIN_WIDTH,WIN_HEIGHT); add(vbox); ag=Gtk::ActionGroup::create(); + + ag->add( Gtk::Action::create("FileMenu", "_File") ); + ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), + sigc::mem_fun(*this, &MainWin::newFile)); + ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), + sigc::mem_fun(*this, &MainWin::openFile)); + ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), + sigc::mem_fun(*this, &MainWin::saveFile)); + ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), + sigc::mem_fun(*this, &MainWin::saveFileAs)); + ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), + sigc::mem_fun(*this, &MainWin::quit)); + + ag->add( Gtk::Action::create("ViewMenu", "_View") ); + ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); + ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut)); + ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit)); + ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100)); + ag->add( Gtk::Action::create("ShowMenu", "_Show") ); - ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps)); - ag->add( Gtk::Action::create("FileMenu", "_File") ); - ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit)); - ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") ); - ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!! + ag->add( Gtk::Action::create("ShowMaps", "_Maps"), + sigc::mem_fun(*this, &MainWin::showMaps)); uim=Gtk::UIManager::create(); uim->insert_action_group(ag); @@ -25,15 +46,32 @@ "" " " " " + " " + " " + " " + " " " " " " + " " + " " + " " + " " + " " + " " " " " " " " - " " - " " - " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " ""; uim->add_ui_from_string(ui_info); @@ -45,9 +83,21 @@ } Gtk::Widget* menubar = uim->get_widget("/MenuBar"); - if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK); + if (menubar){ + vbox.pack_start(*menubar, Gtk::PACK_SHRINK); + } - vbox.pack_start(gd_canvas); + Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); + if (toolbar) + { + static_cast(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); + vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); + } + + Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow()); + pScrolledWindow->add(gd_canvas); + vbox.pack_start(*pScrolledWindow); + //vbox.pack_start(gd_canvas); show_all_children(); } @@ -62,8 +112,22 @@ hide(); } -void MainWin::rezoom() +void MainWin::newFile() { - gd_canvas.rezoom(); + std::cerr << "MainWin::newFile(): not yet implemented" << std::endl; } +void MainWin::openFile() +{ + std::cerr << "MainWin::openFile(): not yet implemented" << std::endl; +} + +void MainWin::saveFile() +{ + std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl; +} + +void MainWin::saveFileAs() +{ + std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl; +} diff -r 3d2e3cfb2a6c -r fd4b6f6d592a gui/main_win.h --- a/gui/main_win.h Fri May 27 10:34:20 2005 +0000 +++ b/gui/main_win.h Wed Jun 01 23:30:13 2005 +0000 @@ -39,13 +39,16 @@ ///This function makes map-setup window popped up. virtual void showMaps(); - - ///Exit + ///Callback for 'FileNew' action. + virtual void newFile(); + ///Callback for 'FileOpen' action. + virtual void openFile(); + ///Callback for 'FileSave' action. + virtual void saveFile(); + ///Callback for 'FileSaveAs' action. + virtual void saveFileAs(); + ///Callback for 'Quit' action. virtual void quit(); - - ///Refit screen to be able to show the whole graph. - virtual void rezoom(); - }; #endif //MAIN_WIN_H