[Lemon-commits] [lemon_svn] hegyi: r2949 - glemon/trunk

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 21:51:25 CET 2006


Author: hegyi
Date: Mon Sep 18 18:02:20 2006
New Revision: 2949

Modified:
   glemon/trunk/graph_displayer_canvas-event.cc
   glemon/trunk/graph_displayer_canvas.h

Log:
When moving nodes with midbutton little red arrows keep their position.

Modified: glemon/trunk/graph_displayer_canvas-event.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas-event.cc	(original)
+++ glemon/trunk/graph_displayer_canvas-event.cc	Mon Sep 18 18:02:20 2006
@@ -101,15 +101,7 @@
 	      active_node=i;
 	    }
 	}
-      switch(e->button.button)
-	{
-	case 3:      
-	  isbutton=3;
-	  break;
-	default:
-	  isbutton=1;
-	  break;
-	}
+      isbutton=e->button.button;
       break;
     case GDK_BUTTON_RELEASE:
       if (coord_text)
@@ -191,10 +183,7 @@
             XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
 
             XY arrow_pos;
-	    if(isbutton==3)
-              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
-	    else
-              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
+	    arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
 
             mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
             edgesmap[ei]->draw();
@@ -216,10 +205,7 @@
             XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
 
             XY arrow_pos;
-	    if(isbutton==3)
-              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
-	    else
-              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
+	    arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
 
             mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
             edgesmap[ei]->draw();
@@ -237,58 +223,67 @@
   return false;
 }
 
-XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move)
+XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
 {
-  if(!move)
-  {
-    return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
-  }
-  else
-  {
-    //////////////////////////////////////////////////////////////////////////////////////////////////////
-    /////////// keeps shape-with scalar multiplication - version 2.
-    //////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    //old vector from one to the other node - a
-    xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
-    //new vector from one to the other node - b
-    xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
-
-    double absa=sqrt(a_v.normSquare());
-    double absb=sqrt(b_v.normSquare());
-
-    if ((absa == 0.0) || (absb == 0.0))
+  switch(move_code)
     {
+    case 1:
+      return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
+      break;
+    case 2:
       return old_arrow_pos;
+      break;
+    case 3:
+      {
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+	/////////// keeps shape-with scalar multiplication - version 2.
+	//////////////////////////////////////////////////////////////////////////////////////////////////////
+
+	//old vector from one to the other node - a
+	xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
+	//new vector from one to the other node - b
+	xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
+
+	double absa=sqrt(a_v.normSquare());
+	double absb=sqrt(b_v.normSquare());
+
+	if ((absa == 0.0) || (absb == 0.0))
+	  {
+	    return old_arrow_pos;
+	  }
+	else
+	  {
+	    //old vector from one node to the breakpoint - c
+	    xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
+
+	    //unit vector with the same direction to a_v
+	    xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
+
+	    //normal vector of unit vector with the same direction to a_v
+	    xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
+
+	    //unit vector with the same direction to b_v
+	    xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
+
+	    //normal vector of unit vector with the same direction to b_v
+	    xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
+
+	    //vector c in a_v_u and a_v_u_n co-ordinate system
+	    xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
+
+	    //new vector from one node to the breakpoint - d - we have to calculate this one
+	    xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
+
+	    return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
+	  }
+	break;
+      }
+    default:
+      break;
     }
-    else
-    {
-      //old vector from one node to the breakpoint - c
-      xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
-
-      //unit vector with the same direction to a_v
-      xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
-
-      //normal vector of unit vector with the same direction to a_v
-      xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
-
-      //unit vector with the same direction to b_v
-      xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
-
-      //normal vector of unit vector with the same direction to b_v
-      xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
-
-      //vector c in a_v_u and a_v_u_n co-ordinate system
-      xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
-
-      //new vector from one node to the breakpoint - d - we have to calculate this one
-      xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
-
-      return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
-    }
-  }
 }
 
+
 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
 {
   switch(e->type)

Modified: glemon/trunk/graph_displayer_canvas.h
==============================================================================
--- glemon/trunk/graph_displayer_canvas.h	(original)
+++ glemon/trunk/graph_displayer_canvas.h	Mon Sep 18 18:02:20 2006
@@ -378,7 +378,7 @@
   ///reference to the container, in which the canvas is
   NoteBookTab & mytab;
 
-  XY calcArrowPos(XY, XY, XY, XY, bool);
+  XY calcArrowPos(XY, XY, XY, XY, int);
 };
 
 #endif //GRAPH_DISPLAYER_CANVAS_H



More information about the Lemon-commits mailing list