Changeset 1478:bc7ae573d77d in lemon-0.x
- Timestamp:
- 06/13/05 21:49:33 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1958
- Location:
- gui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/edit_win.cc
r1469 r1478 15 15 set_title(title); 16 16 set_default_size(200, 50); 17 17 set_keep_above(true); 18 18 signal_key_press_event().connect(sigc::mem_fun(*this, &EditWin::close_if_escape_is_pressed)); 19 19 20 //buttons array 21 buttons=new (Gtk::RadioButton *) [TOOL_NUM]; 22 for(int i=0;i<TOOL_NUM;i++) 23 { 24 buttons[i]=NULL; 25 } 26 27 Gtk::RadioButton::Group group;//=buttons[MOVE]->get_group(); 28 20 29 //New node button 21 button=new Gtk::Button("New Node"); 22 button->signal_clicked().connect 30 buttons[CREATE_NODE]=new Gtk::RadioButton("New Node"); 31 buttons[CREATE_NODE]->set_mode(false); 32 buttons[CREATE_NODE]->set_group(group); 33 buttons[CREATE_NODE]->signal_clicked().connect 23 34 ( 24 35 sigc::bind … … 28 39 ) 29 40 ); 30 table.attach(*button ,0,1,0,1);41 table.attach(*buttons[CREATE_NODE],0,1,0,1); 31 42 32 43 //New edge button 33 button=new Gtk::Button("New Edge"); 34 button->signal_clicked().connect 44 buttons[CREATE_EDGE]=new Gtk::RadioButton("New Edge"); 45 buttons[CREATE_EDGE]->set_mode(false); 46 buttons[CREATE_EDGE]->set_group(group); 47 buttons[CREATE_EDGE]->signal_clicked().connect 35 48 ( 36 49 sigc::bind … … 40 53 ) 41 54 ); 42 table.attach(*button ,1,2,0,1);55 table.attach(*buttons[CREATE_EDGE],1,2,0,1); 43 56 44 57 //Move button 45 button=new Gtk::Button("Move"); 46 button->signal_clicked().connect 58 buttons[MOVE]=new Gtk::RadioButton("Move"); 59 buttons[MOVE]->set_mode(false); 60 buttons[MOVE]->set_group(group); 61 buttons[MOVE]->signal_clicked().connect 47 62 ( 48 63 sigc::bind … … 52 67 ) 53 68 ); 54 table.attach(*button ,0,1,1,2);55 69 table.attach(*buttons[MOVE],0,1,1,2); 70 56 71 add(table); 57 72 -
gui/edit_win.h
r1469 r1478 16 16 protected: 17 17 ///The \ref GraphDisplayerCanvas on which the graph will be drawn. 18 ///It has to be known for this class, because 19 ///when a map assigned to a certain attribute 20 ///a function of the \ref GraphDisplayerCanvas will be called. 18 ///It has to be known for this class, because the appropriate 19 //callback function for each tool is implemented in that class 21 20 GraphDisplayerCanvas & gdc; 22 21 22 ///Table that holds the tools. 23 23 Gtk::Table table; 24 24 25 Gtk::Label * label;26 Gtk:: Button * button;25 ///these buttons are RadioButtons with classic look 26 Gtk::RadioButton ** buttons; 27 27 28 28 public: -
gui/graph_displayer_canvas.cc
r1474 r1478 6 6 7 7 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); 8 9 active_node=INVALID; 10 active_edge=INVALID; 8 11 9 12 //set_center_scroll_region(true); … … 311 314 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false); 312 315 break; 316 317 //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group 313 318 case CREATE_NODE: 314 319 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); 315 320 break; 321 316 322 case CREATE_EDGE: 317 323 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); … … 344 350 isbutton=false; 345 351 active_item=NULL; 352 active_node=INVALID; 346 353 updateScrollRegion(); 347 354 break; 348 355 case GDK_MOTION_NOTIFY: 349 //we only have to do sg. if the mouse button is pressed 350 if( isbutton)356 //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes 357 if(active_node!=INVALID) 351 358 { 352 359 //new coordinates will be the old values, … … 417 424 switch(e->type) 418 425 { 426 427 //draw the new node in red at the clicked place 419 428 case GDK_BUTTON_PRESS: 420 429 isbutton=true; … … 430 439 (nodesmap[active_node])->show(); 431 440 break; 441 442 //move the new node 432 443 case GDK_MOTION_NOTIFY: 433 444 { … … 441 452 break; 442 453 } 454 455 //finalize the new node 443 456 case GDK_BUTTON_RELEASE: 444 457 isbutton=false; 445 458 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 446 459 active_item=NULL; 460 active_node=INVALID; 447 461 updateScrollRegion(); 448 462 break; … … 458 472 { 459 473 case GDK_BUTTON_PRESS: 460 if(!active_item) 474 //in edge creatino right button has special meaning 475 if(e->button.button!=3) 461 476 { 462 //we mark the location of the event to be able to calculate parameters of dragging 463 clicked_x=e->button.x; 464 clicked_y=e->button.y; 465 active_item=(get_item_at(e->button.x, e->button.y)); 466 active_node=INVALID; 467 for (NodeIt i(g); i!=INVALID; ++i) 477 //there is not yet selected node 478 if(active_node==INVALID) 468 479 { 469 if(nodesmap[i]==active_item) 480 //we mark the location of the event to be able to calculate parameters of dragging 481 clicked_x=e->button.x; 482 clicked_y=e->button.y; 483 active_item=(get_item_at(e->button.x, e->button.y)); 484 active_node=INVALID; 485 for (NodeIt i(g); i!=INVALID; ++i) 470 486 { 471 active_node=i; 487 if(nodesmap[i]==active_item) 488 { 489 active_node=i; 490 } 491 } 492 //the clicked item is really a node 493 if(active_node!=INVALID) 494 { 495 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 496 isbutton=true; 497 } 498 //clicked item was not a node. It could be e.g. edge. 499 else 500 { 501 active_item=NULL; 472 502 } 473 503 } 474 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 475 isbutton=true; 476 } 477 else 478 { 479 target_item=(get_item_at(e->button.x, e->button.y)); 480 Graph::NodeIt target_node=INVALID; 481 for (NodeIt i(g); i!=INVALID; ++i) 504 //we only have to do sg. if the mouse button 505 // is pressed already once AND the click was 506 // on a node that was found in the set of 507 //nodes, and now we only search for the second 508 //node 509 else 482 510 { 483 if(nodesmap[i]==target_item) 511 target_item=(get_item_at(e->button.x, e->button.y)); 512 Graph::NodeIt target_node=INVALID; 513 for (NodeIt i(g); i!=INVALID; ++i) 484 514 { 485 target_node=i; 515 if(nodesmap[i]==target_item) 516 { 517 target_node=i; 518 } 519 } 520 //the clicked item is a node, the edge can be drawn 521 if(target_node!=INVALID) 522 { 523 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red"); 524 525 //creating new edge 526 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); 527 528 //calculating coordinates of new edge 529 Gnome::Canvas::Points coos; 530 double x1, x2, y1, y2; 531 532 active_item->get_bounds(x1, y1, x2, y2); 533 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 534 535 target_item->get_bounds(x1, y1, x2, y2); 536 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 537 538 //drawing new edge 539 edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos); 540 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); 541 edgesmap[active_edge]->property_width_pixels().set_value(10); 542 543 //redraw nodes to blank terminations of the new edge 544 target_item->raise_to_top(); 545 active_item->raise_to_top(); 546 547 //initializing edge-text as well, to empty string 548 edgesmap[active_edge]->get_bounds(x1, y1, x2, y2); 549 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, ""); 550 edgetextmap[active_edge]->property_fill_color().set_value("black"); 551 } 552 //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. 553 else 554 { 555 target_item=NULL; 486 556 } 487 557 } 488 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");489 490 //creating new edge491 // Graph::Edge new_edge=g.addEdge(active_node, target_node);492 active_edge=EdgeIt(g,g.addEdge(active_node, target_node));493 494 //calculating coordinates of new edge495 Gnome::Canvas::Points coos;496 double x1, x2, y1, y2;497 498 active_item->get_bounds(x1, y1, x2, y2);499 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));500 501 target_item->get_bounds(x1, y1, x2, y2);502 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));503 504 //drawing new edge505 edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);506 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");507 edgesmap[active_edge]->property_width_pixels().set_value(10);508 509 //redraw nodes to blank terminations of the new edge510 target_item->raise_to_top();511 active_item->raise_to_top();512 513 //initializing edge-text as well, to empty string514 edgesmap[active_edge]->get_bounds(x1, y1, x2, y2);515 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");516 edgetextmap[active_edge]->property_fill_color().set_value("black");517 558 } 518 559 break; 519 560 case GDK_BUTTON_RELEASE: 520 561 isbutton=false; 521 if(target_item) 562 //we clear settings in two cases 563 //1: the edge is ready (target_item has valid value) 564 //2: the edge creation is cancelled with right button 565 if((target_item)||(e->button.button==3)) 522 566 { 523 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 524 *target_item << Gnome::Canvas::Properties::fill_color("blue"); 525 active_item=NULL; 526 target_item=NULL; 567 if(active_item) 568 { 569 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 570 active_item=NULL; 571 } 572 if(target_item) 573 { 574 *target_item << Gnome::Canvas::Properties::fill_color("blue"); 575 target_item=NULL; 576 } 577 active_node=INVALID; 578 active_edge=INVALID; 527 579 } 528 580 break;
Note: See TracChangeset
for help on using the changeset viewer.