[Lemon-commits] [lemon_svn] hegyi: r1980 - hugo/trunk/gui

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:49:14 CET 2006


Author: hegyi
Date: Thu Jun 16 20:08:04 2005
New Revision: 1980

Modified:
   hugo/trunk/gui/broken_edge.cc
   hugo/trunk/gui/broken_edge.h
   hugo/trunk/gui/graph_displayer_canvas.cc
   hugo/trunk/gui/graph_displayer_canvas.h

Log:
Little red arrows appear in breakpoints of edges.

Modified: hugo/trunk/gui/broken_edge.cc
==============================================================================
--- hugo/trunk/gui/broken_edge.cc	(original)
+++ hugo/trunk/gui/broken_edge.cc	Thu Jun 16 20:08:04 2005
@@ -1,14 +1,131 @@
 #include <broken_edge.h>
+#include <lemon/xy.h>
+#include <math.h>
 
-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<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
+      xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
+
+      xy<gdouble> unit_vector_in_dir(target-center);
+      //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
+      unit_vector_in_dir/=sqrt( unit_vector_in_dir.normSquare() );
+      //       std::cout << " = " << unit_vector_in_dir << std::endl;
+
+      xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
+      //       std::cout << unit_norm_vector << std::endl;
+
+      {      
+	//       /\             top
+	//      /  \
+	//      -  -      c(enter)l(eft), ccl, ccr, cr
+	//       ||
+	//       ||       b(ottom)l, br
+      }
+
+      double size=3;
+
+      xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
+      xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
+      xy<gdouble> ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
+      xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
+      xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
+      xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
+      xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
+	 
+      //       std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
+
+      Gnome::Canvas::Points arrow_points;
+      arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
+      arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
+      arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
+      arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
+      arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
+      arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
+      arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
+
+      arrow->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;
 }

Modified: hugo/trunk/gui/broken_edge.h
==============================================================================
--- hugo/trunk/gui/broken_edge.h	(original)
+++ hugo/trunk/gui/broken_edge.h	Thu Jun 16 20:08:04 2005
@@ -9,8 +9,22 @@
 
 class BrokenEdge : public Gnome::Canvas::Line
 {
+  Gnome::Canvas::Polygon * arrow;
+  Gnome::Art::Point * my_points;
+
+  ///Indicates whether the button of mouse is pressed or not
+  bool isbutton;
+
+  ///At this location was the mousebutton pressed.
+  ///It helps to calculate the distance of dragging.
+  double clicked_x, clicked_y;
+
+  ///event handler for forming edges
+  bool edge_former_event_handler(GdkEvent*);
  public:
   BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points);
+  ~BrokenEdge();
+  void set_points(Gnome::Canvas::Points);
 };
 
 

Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc	Thu Jun 16 20:08:04 2005
@@ -23,7 +23,6 @@
     coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
     coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
     
-    //edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
     edgesmap[i]=new BrokenEdge(displayed_graph, coos);
     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
     edgesmap[i]->property_width_pixels().set_value(10);    
@@ -392,7 +391,7 @@
             nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
 
-            edgesmap[e]->property_points().set_value(coos);
+            edgesmap[e]->set_points(coos);
 
 	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
 
@@ -412,7 +411,7 @@
             nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
             coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
 
-            edgesmap[e]->property_points().set_value(coos);
+            edgesmap[e]->set_points(coos);
 
 	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
 
@@ -543,7 +542,7 @@
 		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
 
 		  //drawing new edge
-		  edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);
+		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos);
 		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
 		  edgesmap[active_edge]->property_width_pixels().set_value(10);
 

Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.h	Thu Jun 16 20:08:04 2005
@@ -5,6 +5,7 @@
 
 #include <all_include.h>
 #include <mapstorage.h>
+#include <broken_edge.h>
 #include <libgnomecanvasmm.h>
 #include <libgnomecanvasmm/polygon.h>
 
@@ -83,7 +84,7 @@
   Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
 
   ///Map of edges of graph
-  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
+  Graph::EdgeMap<BrokenEdge *> edgesmap;
 
   ///Map of texts to write on edges
   Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
@@ -110,6 +111,7 @@
   Graph::EdgeIt active_edge;
 
   static const int zoom_step = 5;
+
 };
 
 #endif //GRAPH_DISPLAYER_CANVAS_H



More information about the Lemon-commits mailing list