Function names are corrected according to naming conventions.
1 #include <broken_edge.h>
4 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false)
6 my_points=new Gnome::Art::Point[3];
8 arrow=new Gnome::Canvas::Polygon(g);
9 *arrow << Gnome::Canvas::Properties::fill_color("red");
10 arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler));
14 BrokenEdge::~BrokenEdge()
16 if(arrow)delete(arrow);
19 void BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
27 Gnome::Canvas::Points points_with_center;
28 points_with_center.push_back(my_points[0]=p[0]);
29 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 );
30 points_with_center.push_back(my_points[2]=p[1]);
31 property_points().set_value(points_with_center);
36 property_points().set_value(p);
47 Gnome::Canvas::Points points;
52 points.push_back(my_points[i]);
54 property_points().set_value(points);
60 //calculating coordinates of the direction indicator arrow
62 xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
63 xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
65 xy<gdouble> unit_vector_in_dir(target-center);
66 // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <<unit_vector_in_dir.normSquare() ;
67 unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
68 // std::cout << " = " << unit_vector_in_dir << std::endl;
70 xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
71 // std::cout << unit_norm_vector << std::endl;
76 // - - // c(enter)l(eft), ccl, ccr, cr
78 // || // b(ottom)l, br
83 xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
84 xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
85 xy<gdouble> ccl(center + unit_vector_in_dir * size + unit_norm_vector * size );
86 xy<gdouble> ccr(center + unit_vector_in_dir * size - unit_norm_vector * size );
87 xy<gdouble> cl (center + unit_vector_in_dir * size + unit_norm_vector * 2 * size );
88 xy<gdouble> cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
89 xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
91 // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl;
93 Gnome::Canvas::Points arrow_points;
94 arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );
95 arrow_points.push_back(Gnome::Art::Point( br.x , br.y ) );
96 arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
97 arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y ) );
98 arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
99 arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y ) );
100 arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
102 arrow->property_points().set_value(arrow_points);
106 bool BrokenEdge::edgeFormerEventHandler(GdkEvent* e)
110 case GDK_BUTTON_PRESS:
111 //we mark the location of the event to be able to calculate parameters of dragging
112 if(gdc.getActualTool()!=CREATE_NODE)
114 gdc.toggleEdgeActivity(this, true);
115 clicked_x=e->button.x;
116 clicked_y=e->button.y;
120 case GDK_BUTTON_RELEASE:
121 if(gdc.getActualTool()!=CREATE_NODE)
123 gdc.toggleEdgeActivity(this, false);
127 case GDK_MOTION_NOTIFY:
128 //we only have to do sg. if the mouse button is pressed
131 //new coordinates will be the old values,
132 //because the item will be moved to the
133 //new coordinate therefore the new movement
134 //has to be calculated from here
136 double dx=e->motion.x-clicked_x;
137 double dy=e->motion.y-clicked_y;
139 Gnome::Canvas::Points points_new;
141 points_new.push_back(my_points[0]);
142 points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
143 points_new.push_back(my_points[2]);
145 setPoints(points_new);
146 gdc.textReposition(xy<double>(my_points[1].get_x(),my_points[1].get_y()));
148 clicked_x=e->motion.x;
149 clicked_y=e->motion.y;
158 xy<double> BrokenEdge::getArrowPos()
160 xy<double> ret_val(my_points[1].get_x(),my_points[1].get_y());