1 #include <graph_displayer_canvas.h> |
1 #include <graph_displayer_canvas.h> |
2 #include <broken_edge.h> |
2 #include <broken_edge.h> |
3 #include <math.h> |
3 #include <math.h> |
4 |
4 |
5 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),target_item(NULL) |
5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL) |
6 { |
6 { |
7 |
7 |
8 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); |
8 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); |
9 |
9 |
10 active_node=INVALID; |
10 active_node=INVALID; |
179 case GDK_BUTTON_PRESS: |
179 case GDK_BUTTON_PRESS: |
180 //we mark the location of the event to be able to calculate parameters of dragging |
180 //we mark the location of the event to be able to calculate parameters of dragging |
181 clicked_x=e->button.x; |
181 clicked_x=e->button.x; |
182 clicked_y=e->button.y; |
182 clicked_y=e->button.y; |
183 active_item=(get_item_at(e->button.x, e->button.y)); |
183 active_item=(get_item_at(e->button.x, e->button.y)); |
184 isbutton=true; |
184 isbutton=1; |
185 break; |
185 break; |
186 case GDK_BUTTON_RELEASE: |
186 case GDK_BUTTON_RELEASE: |
187 isbutton=false; |
187 isbutton=0; |
188 active_item=NULL; |
188 active_item=NULL; |
189 updateScrollRegion(); |
189 updateScrollRegion(); |
190 break; |
190 break; |
191 case GDK_MOTION_NOTIFY: |
191 case GDK_MOTION_NOTIFY: |
192 //we only have to do sg. if the mouse button is pressed |
192 //we only have to do sg. if the mouse button is pressed |
374 |
382 |
375 clicked_x=e->motion.x; |
383 clicked_x=e->motion.x; |
376 clicked_y=e->motion.y; |
384 clicked_y=e->motion.y; |
377 |
385 |
378 //all the edges connected to the moved point has to be redrawn |
386 //all the edges connected to the moved point has to be redrawn |
379 EdgeIt e; |
387 EdgeIt ei; |
380 |
388 |
381 g.firstOut(e,active_node); |
389 g.firstOut(ei,active_node); |
382 |
390 |
383 for(;e!=INVALID;g.nextOut(e)) |
391 for(;ei!=INVALID;g.nextOut(ei)) |
384 { |
392 { |
385 Gnome::Canvas::Points coos; |
393 Gnome::Canvas::Points coos; |
386 double x1, x2, y1, y2; |
394 double x1, x2, y1, y2; |
387 |
395 |
388 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); |
396 nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2); |
389 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
397 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
390 |
398 |
391 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); |
399 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
392 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
400 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
393 |
401 |
394 edgesmap[e]->set_points(coos); |
402 if(isbutton==3) |
395 |
403 { |
396 edgesmap[e]->get_bounds(x1, y1, x2, y2); |
404 edgesmap[ei]->set_points(coos); |
397 |
405 } |
398 edgetextmap[e]->property_x().set_value((x1+x2)/2); |
406 else |
399 edgetextmap[e]->property_y().set_value((y1+y2)/2); |
407 { |
|
408 edgesmap[ei]->set_points(coos,true); |
|
409 } |
|
410 |
|
411 edgesmap[ei]->get_bounds(x1, y1, x2, y2); |
|
412 |
|
413 edgetextmap[ei]->property_x().set_value((x1+x2)/2); |
|
414 edgetextmap[ei]->property_y().set_value((y1+y2)/2); |
400 } |
415 } |
401 |
416 |
402 g.firstIn(e,active_node); |
417 g.firstIn(ei,active_node); |
403 for(;e!=INVALID;g.nextIn(e)) |
418 for(;ei!=INVALID;g.nextIn(ei)) |
404 { |
419 { |
405 Gnome::Canvas::Points coos; |
420 Gnome::Canvas::Points coos; |
406 double x1, x2, y1, y2; |
421 double x1, x2, y1, y2; |
407 |
422 |
408 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); |
423 nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2); |
409 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
424 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
410 |
425 |
411 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); |
426 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
412 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
427 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
413 |
428 |
414 edgesmap[e]->set_points(coos); |
429 if(isbutton==3) |
415 |
430 { |
416 edgesmap[e]->get_bounds(x1, y1, x2, y2); |
431 edgesmap[ei]->set_points(coos); |
417 |
432 } |
418 edgetextmap[e]->property_x().set_value((x1+x2)/2); |
433 else |
419 edgetextmap[e]->property_y().set_value((y1+y2)/2); |
434 { |
|
435 edgesmap[ei]->set_points(coos,true); |
|
436 } |
|
437 |
|
438 edgesmap[ei]->get_bounds(x1, y1, x2, y2); |
|
439 |
|
440 edgetextmap[ei]->property_x().set_value((x1+x2)/2); |
|
441 edgetextmap[ei]->property_y().set_value((y1+y2)/2); |
420 } |
442 } |
421 } |
443 } |
422 default: break; |
444 default: break; |
423 } |
445 } |
424 |
446 |