1.1 --- a/gui/graph_displayer_canvas-event.cc Wed Jun 29 15:41:33 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas-event.cc Wed Jun 29 19:44:30 2005 +0000
1.3 @@ -28,20 +28,19 @@
1.4 switch(newtool)
1.5 {
1.6 case MOVE:
1.7 - actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
1.8 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
1.9 break;
1.10
1.11 - //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group
1.12 case CREATE_NODE:
1.13 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
1.14 break;
1.15
1.16 case CREATE_EDGE:
1.17 - actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
1.18 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
1.19 break;
1.20
1.21 case ERASER:
1.22 - actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
1.23 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
1.24 break;
1.25
1.26 default:
1.27 @@ -60,9 +59,9 @@
1.28 {
1.29 case GDK_BUTTON_PRESS:
1.30 //we mark the location of the event to be able to calculate parameters of dragging
1.31 - clicked_x=e->button.x;
1.32 - clicked_y=e->button.y;
1.33 - active_item=(get_item_at(e->button.x, e->button.y));
1.34 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.35 +
1.36 + active_item=(get_item_at(clicked_x, clicked_y));
1.37 active_node=INVALID;
1.38 for (NodeIt i(g); i!=INVALID; ++i)
1.39 {
1.40 @@ -85,7 +84,6 @@
1.41 isbutton=0;
1.42 active_item=NULL;
1.43 active_node=INVALID;
1.44 - updateScrollRegion();
1.45 break;
1.46 case GDK_MOTION_NOTIFY:
1.47 //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
1.48 @@ -96,15 +94,19 @@
1.49 //new coordinate therefore the new movement
1.50 //has to be calculated from here
1.51
1.52 - double dx=e->motion.x-clicked_x;
1.53 - double dy=e->motion.y-clicked_y;
1.54 + double new_x, new_y;
1.55 +
1.56 + window_to_world (e->motion.x, e->motion.y, new_x, new_y);
1.57 +
1.58 + double dx=new_x-clicked_x;
1.59 + double dy=new_y-clicked_y;
1.60
1.61 //repositioning node and its text
1.62 active_item->move(dx, dy);
1.63 nodetextmap[active_node]->move(dx, dy);
1.64
1.65 - clicked_x=e->motion.x;
1.66 - clicked_y=e->motion.y;
1.67 + clicked_x=new_x;
1.68 + clicked_y=new_y;
1.69
1.70 //all the edges connected to the moved point has to be redrawn
1.71 EdgeIt ei;
1.72 @@ -168,7 +170,7 @@
1.73 default: break;
1.74 }
1.75
1.76 - return true;
1.77 + return false;
1.78 }
1.79
1.80 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
1.81 @@ -177,16 +179,21 @@
1.82 {
1.83
1.84 //draw the new node in red at the clicked place
1.85 + case GDK_2BUTTON_PRESS:
1.86 + std::cout << "double click" << std::endl;
1.87 + break;
1.88 case GDK_BUTTON_PRESS:
1.89 isbutton=1;
1.90
1.91 active_node=NodeIt(g,g.addNode());
1.92
1.93 //initiating values corresponding to new node in maps
1.94 -
1.95
1.96 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.97
1.98 + target_item=NULL;
1.99 + target_item=get_item_at(clicked_x, clicked_y);
1.100 +
1.101 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.102 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
1.103 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.104 @@ -205,9 +212,8 @@
1.105 {
1.106 double world_motion_x, world_motion_y;
1.107 GdkEvent * generated=new GdkEvent();
1.108 - window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
1.109 - generated->motion.x=world_motion_x;
1.110 - generated->motion.y=world_motion_y;
1.111 + generated->motion.x=e->motion.x;
1.112 + generated->motion.y=e->motion.y;
1.113 generated->type=GDK_MOTION_NOTIFY;
1.114 moveEventHandler(generated);
1.115 break;
1.116 @@ -216,10 +222,19 @@
1.117 //finalize the new node
1.118 case GDK_BUTTON_RELEASE:
1.119 isbutton=0;
1.120 - *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.121 + if(!target_item)
1.122 + {
1.123 + //Its appropriate color is given by update.
1.124 + //*active_item << Gnome::Canvas::Properties::fill_color("blue");
1.125 + }
1.126 + else
1.127 + {
1.128 + //In this case the given color has to be overwritten, because the noe covers an other item.
1.129 + *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
1.130 + }
1.131 + target_item=NULL;
1.132 active_item=NULL;
1.133 active_node=INVALID;
1.134 - updateScrollRegion();
1.135 break;
1.136 default:
1.137 break;
1.138 @@ -239,9 +254,10 @@
1.139 if(active_node==INVALID)
1.140 {
1.141 //we mark the location of the event to be able to calculate parameters of dragging
1.142 - clicked_x=e->button.x;
1.143 - clicked_y=e->button.y;
1.144 - active_item=(get_item_at(e->button.x, e->button.y));
1.145 +
1.146 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.147 +
1.148 + active_item=(get_item_at(clicked_x, clicked_y));
1.149 active_node=INVALID;
1.150 for (NodeIt i(g); i!=INVALID; ++i)
1.151 {
1.152 @@ -269,7 +285,8 @@
1.153 //node
1.154 else
1.155 {
1.156 - target_item=(get_item_at(e->button.x, e->button.y));
1.157 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.158 + target_item=(get_item_at(clicked_x, clicked_y));
1.159 Graph::NodeIt target_node=INVALID;
1.160 for (NodeIt i(g); i!=INVALID; ++i)
1.161 {
1.162 @@ -366,7 +383,8 @@
1.163 switch(e->type)
1.164 {
1.165 case GDK_BUTTON_PRESS:
1.166 - active_item=(get_item_at(e->button.x, e->button.y));
1.167 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.168 + active_item=(get_item_at(clicked_x, clicked_y));
1.169 active_node=INVALID;
1.170 active_edge=INVALID;
1.171 for (NodeIt i(g); i!=INVALID; ++i)
1.172 @@ -386,56 +404,61 @@
1.173 }
1.174 }
1.175 }
1.176 - *active_item << Gnome::Canvas::Properties::fill_color("red");
1.177 + if(active_item)
1.178 + {
1.179 + *active_item << Gnome::Canvas::Properties::fill_color("red");
1.180 + }
1.181 break;
1.182
1.183 case GDK_BUTTON_RELEASE:
1.184 - if(active_item==(get_item_at(e->button.x, e->button.y)))
1.185 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.186 + if(active_item)
1.187 {
1.188 - if(active_node!=INVALID)
1.189 + if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
1.190 {
1.191 + if(active_node!=INVALID)
1.192 + {
1.193
1.194 - //collecting edges to delete
1.195 - EdgeIt e;
1.196 - std::set<Graph::Edge> edges_to_delete;
1.197 + //collecting edges to delete
1.198 + EdgeIt e;
1.199 + std::set<Graph::Edge> edges_to_delete;
1.200
1.201 - g.firstOut(e,active_node);
1.202 - for(;e!=INVALID;g.nextOut(e))
1.203 + g.firstOut(e,active_node);
1.204 + for(;e!=INVALID;g.nextOut(e))
1.205 + {
1.206 + edges_to_delete.insert(e);
1.207 + }
1.208 +
1.209 + g.firstIn(e,active_node);
1.210 + for(;e!=INVALID;g.nextIn(e))
1.211 + {
1.212 + edges_to_delete.insert(e);
1.213 + }
1.214 +
1.215 + //deleting collected edges
1.216 + for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
1.217 + {
1.218 + deleteItem(*edge_set_it);
1.219 + }
1.220 + deleteItem(active_node);
1.221 + }
1.222 + //a simple edge was chosen
1.223 + else
1.224 {
1.225 - edges_to_delete.insert(e);
1.226 + deleteItem(active_edge);
1.227 }
1.228 -
1.229 - g.firstIn(e,active_node);
1.230 - for(;e!=INVALID;g.nextIn(e))
1.231 - {
1.232 - edges_to_delete.insert(e);
1.233 - }
1.234 -
1.235 - //deleting collected edges
1.236 - for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
1.237 - {
1.238 - deleteItem(*edge_set_it);
1.239 - }
1.240 - deleteItem(active_node);
1.241 }
1.242 - //a simple edge was chosen
1.243 + //pointer was moved, deletion is cancelled
1.244 else
1.245 {
1.246 - deleteItem(active_edge);
1.247 - }
1.248 -
1.249 -
1.250 - }
1.251 - //pointer was moved, deletion is cancelled
1.252 - else
1.253 - {
1.254 - if(active_node!=INVALID)
1.255 - {
1.256 - *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.257 - }
1.258 - else
1.259 - {
1.260 - *active_item << Gnome::Canvas::Properties::fill_color("green");
1.261 + if(active_node!=INVALID)
1.262 + {
1.263 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.264 + }
1.265 + else
1.266 + {
1.267 + *active_item << Gnome::Canvas::Properties::fill_color("green");
1.268 + }
1.269 }
1.270 }
1.271 //reseting datas
1.272 @@ -450,7 +473,7 @@
1.273 default:
1.274 break;
1.275 }
1.276 - return true;
1.277 + return false;
1.278 }
1.279
1.280 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)