Changeset 1499:9316dcc0a355 in lemon-0.x for gui
- Timestamp:
- 06/16/05 20:08:04 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1980
- Location:
- gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/broken_edge.cc
r1497 r1499 1 1 #include <broken_edge.h> 2 #include <lemon/xy.h> 3 #include <math.h> 2 4 3 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g) 5 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p) : Line(g), isbutton(false) 4 6 { 7 my_points=new Gnome::Art::Point[3]; 8 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)); 12 set_points(p); 13 } 14 15 BrokenEdge::~BrokenEdge() 16 { 17 if(arrow)delete(arrow); 18 } 19 20 void BrokenEdge::set_points(Gnome::Canvas::Points p) 21 { 22 bool set_arrow=false; 5 23 if(p.size()==2) 6 24 { 25 set_arrow=true; 7 26 Gnome::Canvas::Points points_with_center; 8 points_with_center.push_back(p[0]); 9 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 ); 10 points_with_center.push_back(p[1]); 11 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]); 12 30 property_points().set_value(points_with_center); 31 } 32 if(p.size()==3) 33 { 34 set_arrow=true; 35 property_points().set_value(p); 36 for(int i=0;i<3;i++) 37 { 38 my_points[i]=p[i]; 39 } 40 } 41 42 if(set_arrow) 43 { 44 //calculating coordinates of the direction indicator arrow 45 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() ); 48 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; 53 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; 56 57 { 58 // /\ top 59 // / \ 60 // - - c(enter)l(eft), ccl, ccr, cr 61 // || 62 // || b(ottom)l, br 63 } 64 65 double size=3; 66 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); 74 75 // std::cout << bl << " " << br << " " << ccl << " " << ccr << " " << cl << " " << cr << " " << top << std::endl; 76 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 ) ); 85 86 arrow->property_points().set_value(arrow_points); 13 87 } 14 88 } 89 90 bool BrokenEdge::edge_former_event_handler(GdkEvent* e) 91 { 92 switch(e->type) 93 { 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; 98 isbutton=true; 99 break; 100 case GDK_BUTTON_RELEASE: 101 isbutton=false; 102 break; 103 case GDK_MOTION_NOTIFY: 104 //we only have to do sg. if the mouse button is pressed 105 if(isbutton) 106 { 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 111 112 double dx=e->motion.x-clicked_x; 113 double dy=e->motion.y-clicked_y; 114 115 Gnome::Canvas::Points points_new; 116 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]); 120 121 set_points(points_new); 122 123 clicked_x=e->motion.x; 124 clicked_y=e->motion.y; 125 126 } 127 default: break; 128 } 129 130 return true; 131 } -
gui/broken_edge.h
r1497 r1499 10 10 class BrokenEdge : public Gnome::Canvas::Line 11 11 { 12 Gnome::Canvas::Polygon * arrow; 13 Gnome::Art::Point * my_points; 14 15 ///Indicates whether the button of mouse is pressed or not 16 bool isbutton; 17 18 ///At this location was the mousebutton pressed. 19 ///It helps to calculate the distance of dragging. 20 double clicked_x, clicked_y; 21 22 ///event handler for forming edges 23 bool edge_former_event_handler(GdkEvent*); 12 24 public: 13 25 BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points); 26 ~BrokenEdge(); 27 void set_points(Gnome::Canvas::Points); 14 28 }; 15 29 -
gui/graph_displayer_canvas.cc
r1497 r1499 24 24 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); 25 25 26 //edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);27 26 edgesmap[i]=new BrokenEdge(displayed_graph, coos); 28 27 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); … … 393 392 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 394 393 395 edgesmap[e]-> property_points().set_value(coos);394 edgesmap[e]->set_points(coos); 396 395 397 396 edgesmap[e]->get_bounds(x1, y1, x2, y2); … … 413 412 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 414 413 415 edgesmap[e]-> property_points().set_value(coos);414 edgesmap[e]->set_points(coos); 416 415 417 416 edgesmap[e]->get_bounds(x1, y1, x2, y2); … … 544 543 545 544 //drawing new edge 546 edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);545 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos); 547 546 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); 548 547 edgesmap[active_edge]->property_width_pixels().set_value(10); -
gui/graph_displayer_canvas.h
r1496 r1499 6 6 #include <all_include.h> 7 7 #include <mapstorage.h> 8 #include <broken_edge.h> 8 9 #include <libgnomecanvasmm.h> 9 10 #include <libgnomecanvasmm/polygon.h> … … 84 85 85 86 ///Map of edges of graph 86 Graph::EdgeMap< Gnome::Canvas::Line *> edgesmap;87 Graph::EdgeMap<BrokenEdge *> edgesmap; 87 88 88 89 ///Map of texts to write on edges … … 111 112 112 113 static const int zoom_step = 5; 114 113 115 }; 114 116
Note: See TracChangeset
for help on using the changeset viewer.