diff -r 6bf9a0be1802 -r 164783ceb9be broken_edge.cc --- a/broken_edge.cc Wed Jun 15 13:05:32 2005 +0000 +++ b/broken_edge.cc Thu Jun 16 18:08:04 2005 +0000 @@ -1,14 +1,131 @@ #include +#include +#include -BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g) +BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g), isbutton(false) { + my_points=new Gnome::Art::Point[3]; + + arrow=new Gnome::Canvas::Polygon(g); + *arrow << Gnome::Canvas::Properties::fill_color("red"); + arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edge_former_event_handler)); + set_points(p); +} + +BrokenEdge::~BrokenEdge() +{ + if(arrow)delete(arrow); +} + +void BrokenEdge::set_points(Gnome::Canvas::Points p) +{ + bool set_arrow=false; if(p.size()==2) { + set_arrow=true; Gnome::Canvas::Points points_with_center; - points_with_center.push_back(p[0]); - points_with_center.push_back(Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+30 , (p[0].get_y()+p[1].get_y())/2 )+30 ); - points_with_center.push_back(p[1]); - + points_with_center.push_back(my_points[0]=p[0]); + points_with_center.push_back(my_points[1]=Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+0 , (p[0].get_y()+p[1].get_y())/2 )+0 ); + points_with_center.push_back(my_points[2]=p[1]); property_points().set_value(points_with_center); + } + if(p.size()==3) + { + set_arrow=true; + property_points().set_value(p); + for(int i=0;i<3;i++) + { + my_points[i]=p[i]; + } + } + + if(set_arrow) + { + //calculating coordinates of the direction indicator arrow + + xy target( my_points[2].get_x(), my_points[2].get_y() ); + xy center( my_points[1].get_x(), my_points[1].get_y() ); + + xy unit_vector_in_dir(target-center); + // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); } } + +bool BrokenEdge::edge_former_event_handler(GdkEvent* e) +{ + switch(e->type) + { + case GDK_BUTTON_PRESS: + //we mark the location of the event to be able to calculate parameters of dragging + clicked_x=e->button.x; + clicked_y=e->button.y; + isbutton=true; + break; + case GDK_BUTTON_RELEASE: + 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; + + points_new.push_back(my_points[0]); + points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy)); + points_new.push_back(my_points[2]); + + set_points(points_new); + + clicked_x=e->motion.x; + clicked_y=e->motion.y; + + } + default: break; + } + + return true; +}