Little red arrows appear in breakpoints of edges.
1 #include <broken_edge.h>
5 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g), isbutton(false)
7 my_points=new Gnome::Art::Point[3];
9 arrow=new Gnome::Canvas::Polygon(g);
10 *arrow << Gnome::Canvas::Properties::fill_color("red");
11 arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edge_former_event_handler));
15 BrokenEdge::~BrokenEdge()
17 if(arrow)delete(arrow);
20 void BrokenEdge::set_points(Gnome::Canvas::Points p)
26 Gnome::Canvas::Points points_with_center;
27 points_with_center.push_back(my_points[0]=p[0]);
28 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 );
29 points_with_center.push_back(my_points[2]=p[1]);
30 property_points().set_value(points_with_center);
35 property_points().set_value(p);
44 //calculating coordinates of the direction indicator arrow
46 xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
47 xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
49 xy<gdouble> unit_vector_in_dir(target-center);
50 // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <<unit_vector_in_dir.normSquare() ;
51 unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
52 // std::cout << " = " << unit_vector_in_dir << std::endl;
54 xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
55 // std::cout << unit_norm_vector << std::endl;
60 // - - c(enter)l(eft), ccl, ccr, cr
67 xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
68 xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
69 xy<gdouble> ccl(center + unit_vector_in_dir * size + unit_norm_vector * size );
70 xy<gdouble> ccr(center + unit_vector_in_dir * size - unit_norm_vector * size );
71 xy<gdouble> cl (center + unit_vector_in_dir * size + unit_norm_vector * 2 * size );
72 xy<gdouble> cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
73 xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
75 // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
77 Gnome::Canvas::Points arrow_points;
78 arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );
79 arrow_points.push_back(Gnome::Art::Point( br.x , br.y ) );
80 arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
81 arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y ) );
82 arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
83 arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y ) );
84 arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
86 arrow->property_points().set_value(arrow_points);
90 bool BrokenEdge::edge_former_event_handler(GdkEvent* e)
94 case GDK_BUTTON_PRESS:
95 //we mark the location of the event to be able to calculate parameters of dragging
96 clicked_x=e->button.x;
97 clicked_y=e->button.y;
100 case GDK_BUTTON_RELEASE:
103 case GDK_MOTION_NOTIFY:
104 //we only have to do sg. if the mouse button is pressed
107 //new coordinates will be the old values,
108 //because the item will be moved to the
109 //new coordinate therefore the new movement
110 //has to be calculated from here
112 double dx=e->motion.x-clicked_x;
113 double dy=e->motion.y-clicked_y;
115 Gnome::Canvas::Points points_new;
117 points_new.push_back(my_points[0]);
118 points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
119 points_new.push_back(my_points[2]);
121 set_points(points_new);
123 clicked_x=e->motion.x;
124 clicked_y=e->motion.y;