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

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


Author: hegyi
Date: Mon Jun 13 12:30:08 2005
New Revision: 1954

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

Log:
Edge creation is available.

Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc	Mon Jun 13 12:30:08 2005
@@ -1,13 +1,10 @@
 #include <graph_displayer_canvas.h>
 #include <math.h>
 
-GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
+GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL),target_item(NULL)
 {
-  Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
-  *origo << Gnome::Canvas::Properties::fill_color("black");
-  *origo << Gnome::Canvas::Properties::outline_color("black");
   
-  actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
+  actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
 
   //set_center_scroll_region(true);
 
@@ -366,7 +363,6 @@
         clicked_y=e->motion.y;
 
 	//all the edges connected to the moved point has to be redrawn
-
         EdgeIt e;
 
         g.firstOut(e,active_node);
@@ -458,7 +454,81 @@
 
 bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
 {
-  e=e;
+  switch(e->type)
+    {
+    case GDK_BUTTON_PRESS:
+      if(!active_item)
+	{
+	  //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;
+	  active_item=(get_item_at(e->button.x, e->button.y));
+	  active_node=INVALID;
+	  for (NodeIt i(g); i!=INVALID; ++i)
+	    {
+	      if(nodesmap[i]==active_item)
+		{
+		  active_node=i;
+		}
+	    }
+	  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
+	  isbutton=true;
+	}
+      else
+	{
+	  target_item=(get_item_at(e->button.x, e->button.y));
+	  Graph::NodeIt target_node=INVALID;
+	  for (NodeIt i(g); i!=INVALID; ++i)
+	    {
+	      if(nodesmap[i]==target_item)
+		{
+		  target_node=i;
+		}
+	    }
+	  *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
+
+	  //creating new edge
+	  //	  Graph::Edge new_edge=g.addEdge(active_node, target_node);
+	  active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
+	  
+	  //calculating coordinates of new edge
+	  Gnome::Canvas::Points coos;
+	  double x1, x2, y1, y2;
+	  
+	  active_item->get_bounds(x1, y1, x2, y2);
+	  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+	  target_item->get_bounds(x1, y1, x2, y2);
+	  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]) << Gnome::Canvas::Properties::fill_color("green");
+	  edgesmap[active_edge]->property_width_pixels().set_value(10);
+
+	  //redraw nodes to blank terminations of the new edge
+	  target_item->raise_to_top();
+	  active_item->raise_to_top();
+
+	  //initializing edge-text as well, to empty string
+	  edgesmap[active_edge]->get_bounds(x1, y1, x2, y2);
+	  edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
+	  edgetextmap[active_edge]->property_fill_color().set_value("black");
+	}
+      break;
+    case GDK_BUTTON_RELEASE:
+      isbutton=false;
+      if(target_item)
+	{
+	  *active_item << Gnome::Canvas::Properties::fill_color("blue");
+	  *target_item << Gnome::Canvas::Properties::fill_color("blue");
+	  active_item=NULL;
+	  target_item=NULL;
+	}
+      break;
+    default:
+      break;
+    }
   return false;
 }
 

Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.h	Mon Jun 13 12:30:08 2005
@@ -96,8 +96,9 @@
   ///this variable is needed, because
   ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
   ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
-  Gnome::Canvas::Item * active_item;
+  Gnome::Canvas::Item * active_item, * target_item;
   Graph::NodeIt active_node;
+  Graph::EdgeIt active_edge;
 
   static const int zoom_step = 5;
 };



More information about the Lemon-commits mailing list