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