Changeset 1468:d0ccb2fdeeff in lemon-0.x
- Timestamp:
- 06/10/05 13:58:03 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1948
- Location:
- gui
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/Makefile.am
r1435 r1468 14 14 mapstorage.h \ 15 15 map_win.cc \ 16 map_win.h 16 map_win.h \ 17 edit_win.cc \ 18 edit_win.h 17 19 18 20 gd_CXXFLAGS = $(GTK_CFLAGS) -
gui/all_include.h
r1442 r1468 17 17 #include <lemon/xy.h> 18 18 19 enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties; 19 enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties; 20 enum {MOVE, CREATE_NODE, CREATE_EDGE, TOOL_NUM}; // tools; 20 21 #define RANGE 3 21 22 #define WIN_WIDTH 900 -
gui/graph_displayer_canvas.cc
r1444 r1468 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 Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20); 7 *origo << Gnome::Canvas::Properties::fill_color("black"); 8 *origo << Gnome::Canvas::Properties::outline_color("black"); 9 10 actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); 11 6 12 //set_center_scroll_region(true); 7 13 … … 49 55 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 50 56 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); 51 (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); 52 } 53 54 /* 55 //setting zoom to be able to see the whole graph on the canvas 56 57 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); 58 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); 59 60 set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); 61 std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl; 62 std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl; 63 std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl; 64 */ 57 //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); 58 } 59 65 60 updateScrollRegion(); 66 61 } … … 309 304 set_scroll_region(wx1, wy1, wx2, wy2); 310 305 } 306 307 void GraphDisplayerCanvas::changeEditorialTool(int newtool) 308 { 309 actual_handler.disconnect(); 310 311 switch(newtool) 312 { 313 case MOVE: 314 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false); 315 break; 316 case CREATE_NODE: 317 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); 318 break; 319 case CREATE_EDGE: 320 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); 321 break; 322 default: 323 break; 324 } 325 } 326 327 bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e) 328 { 329 switch(e->type) 330 { 331 case GDK_BUTTON_PRESS: 332 //we mark the location of the event to be able to calculate parameters of dragging 333 clicked_x=e->button.x; 334 clicked_y=e->button.y; 335 active_item=(get_item_at(e->button.x, e->button.y)); 336 active_node=INVALID; 337 for (NodeIt i(g); i!=INVALID; ++i) 338 { 339 if(nodesmap[i]==active_item) 340 { 341 active_node=i; 342 } 343 } 344 isbutton=true; 345 break; 346 case GDK_BUTTON_RELEASE: 347 isbutton=false; 348 active_item=NULL; 349 updateScrollRegion(); 350 break; 351 case GDK_MOTION_NOTIFY: 352 //we only have to do sg. if the mouse button is pressed 353 if(isbutton) 354 { 355 //new coordinates will be the old values, 356 //because the item will be moved to the 357 //new coordinate therefore the new movement 358 //has to be calculated from here 359 360 double dx=e->motion.x-clicked_x; 361 double dy=e->motion.y-clicked_y; 362 363 active_item->move(dx, dy); 364 365 clicked_x=e->motion.x; 366 clicked_y=e->motion.y; 367 368 //all the edges connected to the moved point has to be redrawn 369 370 EdgeIt e; 371 372 g.firstOut(e,active_node); 373 374 for(;e!=INVALID;g.nextOut(e)) 375 { 376 Gnome::Canvas::Points coos; 377 double x1, x2, y1, y2; 378 379 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); 380 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 381 382 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); 383 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 384 385 edgesmap[e]->property_points().set_value(coos); 386 387 edgesmap[e]->get_bounds(x1, y1, x2, y2); 388 389 edgetextmap[e]->property_x().set_value((x1+x2)/2); 390 edgetextmap[e]->property_y().set_value((y1+y2)/2); 391 } 392 393 g.firstIn(e,active_node); 394 for(;e!=INVALID;g.nextIn(e)) 395 { 396 Gnome::Canvas::Points coos; 397 double x1, x2, y1, y2; 398 399 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); 400 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 401 402 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); 403 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 404 405 edgesmap[e]->property_points().set_value(coos); 406 407 edgesmap[e]->get_bounds(x1, y1, x2, y2); 408 409 edgetextmap[e]->property_x().set_value((x1+x2)/2); 410 edgetextmap[e]->property_y().set_value((y1+y2)/2); 411 } 412 } 413 default: break; 414 } 415 416 return true; 417 } 418 419 bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e) 420 { 421 switch(e->type) 422 { 423 case GDK_BUTTON_PRESS: 424 isbutton=true; 425 426 active_node=NodeIt(g,g.addNode()); 427 428 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 429 430 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); 431 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); 432 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 433 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); 434 (nodesmap[active_node])->show(); 435 break; 436 case GDK_MOTION_NOTIFY: 437 { 438 double world_motion_x, world_motion_y; 439 GdkEvent * generated=new GdkEvent(); 440 window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y); 441 generated->motion.x=world_motion_x; 442 generated->motion.y=world_motion_y; 443 generated->type=GDK_MOTION_NOTIFY; 444 move_event_handler(generated); 445 break; 446 } 447 case GDK_BUTTON_RELEASE: 448 isbutton=false; 449 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 450 active_item=NULL; 451 updateScrollRegion(); 452 break; 453 default: 454 break; 455 } 456 return false; 457 } 458 459 bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e) 460 { 461 e=e; 462 return false; 463 } 464 -
gui/graph_displayer_canvas.h
r1442 r1468 41 41 void updateScrollRegion(); 42 42 43 ///This function changes the tool in the graph-editor's hand 44 void changeEditorialTool(int); 45 43 46 protected: 44 47 … … 52 55 ///of the canvas 53 56 bool event_handler(GdkEvent* e, Node n); 57 58 ///actual event handler 59 /// 60 ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. 61 sigc::connection actual_handler; 62 63 ///event handler for the case when move-tool is active 64 bool move_event_handler(GdkEvent*); 65 ///event handler for the case when create_node-tool is active 66 bool create_node_event_handler(GdkEvent*); 67 ///event handler for the case when create_edge-tool is active 68 bool create_edge_event_handler(GdkEvent*); 54 69 55 70 ///The graph, on which we work … … 83 98 ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution 84 99 Gnome::Canvas::Item * active_item; 100 Graph::NodeIt active_node; 85 101 86 102 static const int zoom_step = 5; -
gui/main_win.cc
r1442 r1468 2 2 3 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 MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms) 5 5 { 6 6 set_title (title); … … 35 35 ag->add( Gtk::Action::create("ShowMaps", "_Maps"), 36 36 sigc::mem_fun(*this, &MainWin::showMaps)); 37 ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"), 38 sigc::mem_fun(*this, &MainWin::showEditorials)); 37 39 38 40 uim=Gtk::UIManager::create(); … … 61 63 " <menu action='ShowMenu'>" 62 64 " <menuitem action='ShowMaps'/>" 65 " <menuitem action='ShowEditorials'/>" 63 66 " </menu>" 64 67 " </menubar>" … … 108 111 } 109 112 113 void MainWin::showEditorials() 114 { 115 editwin.show(); 116 } 117 110 118 void MainWin::quit() 111 119 { -
gui/main_win.h
r1442 r1468 7 7 #include <mapstorage.h> 8 8 #include <map_win.h> 9 #include <edit_win.h> 9 10 #include <libgnomecanvasmm.h> 10 11 #include <libgnomecanvasmm/polygon.h> … … 26 27 MapWin mapwin; 27 28 29 ///Window of editorial tools. Its type is \ref EditWin 30 EditWin editwin; 31 28 32 ///The graph will be drawn on this \ref GraphDisplayerCanvas 29 33 GraphDisplayerCanvas gd_canvas; … … 40 44 ///This function makes map-setup window popped up. 41 45 virtual void showMaps(); 46 ///This function makes editorial window popped up. 47 virtual void showEditorials(); 42 48 ///Callback for 'FileNew' action. 43 49 virtual void newFile();
Note: See TracChangeset
for help on using the changeset viewer.