Changeset 1441:fd4b6f6d592a in lemon-0.x
- Timestamp:
- 06/02/05 01:30:13 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1917
- Location:
- gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/graph_displayer_canvas.cc
r1440 r1441 4 4 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) 5 5 { 6 //set_center_scroll_region(true); 6 7 7 8 //first edges are drawn, to hide joining with nodes later … … 51 52 } 52 53 54 /* 53 55 //setting zoom to be able to see the whole graph on the canvas 54 56 … … 60 62 std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl; 61 63 std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl; 62 64 */ 65 updateScrollRegion(); 63 66 } 64 67 … … 174 177 }; 175 178 176 177 int GraphDisplayerCanvas::rezoom ()178 {179 180 //searches for the minimum and the maximum181 //value of the coordinates of the nodes to182 //set the pixel rpo unit to a value to be183 //able to see the whole graph in the canvas184 //\todo does not work properly185 186 double x1, x2, y1, y2;187 int x,y;188 189 NodeIt i(g);190 nodesmap[i]->get_bounds(x1, y1, x2, y2);191 192 x=(int)((x1+x2)/2);193 y=(int)((y1+y2)/2);194 195 int maxx=0, maxy=0, minx=(int)x, miny=(int)y;196 197 for (; i!=INVALID; ++i)198 {199 nodesmap[i]->get_bounds(x1, y1, x2, y2);200 201 x=(int)((x1+x2)/2);202 y=(int)((y1+y2)/2);203 204 if(x>maxx)maxx=x;205 if(y>maxy)maxy=y;206 if(x<minx)minx=x;207 if(y<miny)miny=y;208 }209 210 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);211 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);212 213 set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));214 return 0;215 };216 217 218 179 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) 219 180 { … … 301 262 return true; 302 263 } 264 265 void GraphDisplayerCanvas::zoomIn() 266 { 267 set_pixels_per_unit( 268 (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit()); 269 } 270 271 void GraphDisplayerCanvas::zoomOut() 272 { 273 set_pixels_per_unit( 274 (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit()); 275 } 276 277 void GraphDisplayerCanvas::zoomFit() 278 { 279 // get the height and width of the canvas 280 Gtk::Allocation a = get_allocation(); 281 int aw = a.get_width(); 282 int ah = a.get_height(); 283 // add some space 284 aw -= 5; if (aw < 0) aw = 0; 285 ah -= 5; if (ah < 0) ah = 0; 286 //std::cout << "aw=" << aw << " ah=" << ah << std::endl; 287 288 // get the bounding box of the graph 289 set_pixels_per_unit(1.0); // I don't really understand why this is necessary 290 double wx1, wy1, wx2, wy2; 291 double cx1, cy1, cx2, cy2; 292 Gnome::Canvas::Item* pCanvasItem = root(); 293 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); 294 //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl; 295 w2c(wx1, wy1, cx1, cy1); 296 w2c(wx2, wy2, cx2, cy2); 297 //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl; 298 //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl; 299 300 // fit the graph to the window 301 double ppu1 = (double) aw / fabs(cx2 - cx1); 302 double ppu2 = (double) ah / fabs(cy2 - cy1); 303 //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl; 304 (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2); 305 } 306 307 void GraphDisplayerCanvas::zoom100() 308 { 309 set_pixels_per_unit(1.0); 310 } 311 312 void GraphDisplayerCanvas::updateScrollRegion() 313 { 314 double wx1, wy1, wx2, wy2; 315 int cx1, cy1, cx2, cy2; 316 Gnome::Canvas::Item* pCanvasItem = root(); 317 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); 318 w2c(wx1, wy1, cx1, cy1); 319 w2c(wx2, wy2, cx2, cy2); 320 set_scroll_region(cx1, cy1, cx2, cy2); 321 } -
gui/graph_displayer_canvas.h
r1440 r1441 30 30 int changeText (std::string mapname); 31 31 32 ///Changes the dot-pro-pixel to be able to show the whole graph. 33 int rezoom(); 32 ///Callback for 'ViewZoomIn' action. 33 virtual void zoomIn(); 34 ///Callback for 'ViewZoomOut' action. 35 virtual void zoomOut(); 36 ///Callback for 'ViewZoomFit' action. 37 virtual void zoomFit(); 38 ///Callback for 'ViewZoom100' action. 39 virtual void zoom100(); 40 ///Sets the scroll region of the convas to the bounding box of the graph. 41 void updateScrollRegion(); 34 42 35 43 protected: … … 76 84 Gnome::Canvas::Item * active_item; 77 85 78 86 static const int zoom_step = 5; 79 87 }; 80 88 -
gui/main_win.cc
r1435 r1441 1 1 #include <main_win.h> 2 2 3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms) 3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, 4 MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms) 4 5 { 5 6 set_title (title); … … 8 9 9 10 ag=Gtk::ActionGroup::create(); 11 12 ag->add( Gtk::Action::create("FileMenu", "_File") ); 13 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW), 14 sigc::mem_fun(*this, &MainWin::newFile)); 15 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN), 16 sigc::mem_fun(*this, &MainWin::openFile)); 17 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE), 18 sigc::mem_fun(*this, &MainWin::saveFile)); 19 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS), 20 sigc::mem_fun(*this, &MainWin::saveFileAs)); 21 ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), 22 sigc::mem_fun(*this, &MainWin::quit)); 23 24 ag->add( Gtk::Action::create("ViewMenu", "_View") ); 25 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN), 26 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn)); 27 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT), 28 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut)); 29 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT), 30 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit)); 31 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100), 32 sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100)); 33 10 34 ag->add( Gtk::Action::create("ShowMenu", "_Show") ); 11 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps)); 12 ag->add( Gtk::Action::create("FileMenu", "_File") ); 13 ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit)); 14 ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") ); 15 ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!! 35 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), 36 sigc::mem_fun(*this, &MainWin::showMaps)); 16 37 17 38 uim=Gtk::UIManager::create(); … … 26 47 " <menubar name='MenuBar'>" 27 48 " <menu action='FileMenu'>" 49 " <menuitem action='FileNew'/>" 50 " <menuitem action='FileOpen'/>" 51 " <menuitem action='FileSave'/>" 52 " <menuitem action='FileSaveAs'/>" 28 53 " <menuitem action='FileQuit'/>" 54 " </menu>" 55 " <menu action='ViewMenu'>" 56 " <menuitem action='ViewZoomIn' />" 57 " <menuitem action='ViewZoomOut' />" 58 " <menuitem action='ViewZoomFit' />" 59 " <menuitem action='ViewZoom100' />" 29 60 " </menu>" 30 61 " <menu action='ShowMenu'>" 31 62 " <menuitem action='ShowMaps'/>" 32 63 " </menu>" 33 " <menu action='ZoomMenu'>"34 " <menuitem action='ZoomRezoom'/>"35 " </menu>"36 64 " </menubar>" 65 " <toolbar name='ToolBar'>" 66 " <toolitem action='FileNew' />" 67 " <toolitem action='FileOpen' />" 68 " <toolitem action='FileSave' />" 69 " <separator />" 70 " <toolitem action='ViewZoomIn' />" 71 " <toolitem action='ViewZoomOut' />" 72 " <toolitem action='ViewZoomFit' />" 73 " <toolitem action='ViewZoom100' />" 74 " </toolbar>" 37 75 "</ui>"; 38 76 … … 46 84 47 85 Gtk::Widget* menubar = uim->get_widget("/MenuBar"); 48 if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK); 86 if (menubar){ 87 vbox.pack_start(*menubar, Gtk::PACK_SHRINK); 88 } 49 89 50 vbox.pack_start(gd_canvas); 90 Gtk::Widget* toolbar = uim->get_widget("/ToolBar"); 91 if (toolbar) 92 { 93 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS); 94 vbox.pack_start(*toolbar, Gtk::PACK_SHRINK); 95 } 96 97 Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow()); 98 pScrolledWindow->add(gd_canvas); 99 vbox.pack_start(*pScrolledWindow); 100 //vbox.pack_start(gd_canvas); 51 101 52 102 show_all_children(); … … 63 113 } 64 114 65 void MainWin:: rezoom()115 void MainWin::newFile() 66 116 { 67 gd_canvas.rezoom();117 std::cerr << "MainWin::newFile(): not yet implemented" << std::endl; 68 118 } 69 119 120 void MainWin::openFile() 121 { 122 std::cerr << "MainWin::openFile(): not yet implemented" << std::endl; 123 } 124 125 void MainWin::saveFile() 126 { 127 std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl; 128 } 129 130 void MainWin::saveFileAs() 131 { 132 std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl; 133 } -
gui/main_win.h
r1440 r1441 40 40 ///This function makes map-setup window popped up. 41 41 virtual void showMaps(); 42 43 ///Exit 42 ///Callback for 'FileNew' action. 43 virtual void newFile(); 44 ///Callback for 'FileOpen' action. 45 virtual void openFile(); 46 ///Callback for 'FileSave' action. 47 virtual void saveFile(); 48 ///Callback for 'FileSaveAs' action. 49 virtual void saveFileAs(); 50 ///Callback for 'Quit' action. 44 51 virtual void quit(); 45 46 ///Refit screen to be able to show the whole graph.47 virtual void rezoom();48 49 52 }; 50 53
Note: See TracChangeset
for help on using the changeset viewer.