#include "graph_displayer_canvas.h" #include GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc) : Line(g), edge(_edge), gdc(gc), isbutton(false) { arrow=new Gnome::Canvas::Polygon(g); *arrow << Gnome::Canvas::Properties::fill_color("red"); arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler)); arrow->lower_to_bottom(); draw(); } GraphDisplayerCanvas::BrokenEdge::~BrokenEdge() { if(arrow)delete(arrow); } void GraphDisplayerCanvas::BrokenEdge::draw() { MapStorage& ms = gdc.mytab.mapstorage; // update the edge { Gnome::Canvas::Points points; Node source = ms.graph.source(edge); Node target = ms.graph.target(edge); points.push_back(Gnome::Art::Point(ms.coords[source].x, ms.coords[source].y)); points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x, ms.arrow_pos[edge].y)); points.push_back(Gnome::Art::Point(ms.coords[target].x, ms.coords[target].y)); property_points().set_value(points); } // update the arrow { //calculating coordinates of the direction indicator arrow XY target(ms.coords[ms.graph.target(edge)]); XY center(ms.arrow_pos[edge]); XY unit_vector_in_dir(target-center); double length=sqrt( unit_vector_in_dir.normSquare() ); // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); } } bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e) { switch(e->type) { case GDK_BUTTON_PRESS: //we mark the location of the event to be able to calculate parameters of dragging if(gdc.getActualTool()!=CREATE_NODE) { gdc.toggleEdgeActivity(this, true); clicked_x=e->button.x; clicked_y=e->button.y; isbutton=true; } break; case GDK_BUTTON_RELEASE: if(gdc.getActualTool()!=CREATE_NODE) { gdc.toggleEdgeActivity(this, false); isbutton=false; } break; case GDK_MOTION_NOTIFY: //we only have to do sg. if the mouse button is pressed if(isbutton) { //new coordinates will be the old values, //because the item will be moved to the //new coordinate therefore the new movement //has to be calculated from here double dx=e->motion.x-clicked_x; double dy=e->motion.y-clicked_y; Gnome::Canvas::Points points_new; gdc.mytab.mapstorage.arrow_pos.set(edge, gdc.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy)); draw(); gdc.textReposition(gdc.mytab.mapstorage.arrow_pos[edge]); clicked_x=e->motion.x; clicked_y=e->motion.y; } default: break; } return true; }