When moving nodes with midbutton little red arrows keep their position.
authorhegyi
Mon, 18 Sep 2006 16:02:20 +0000
changeset 1485adf29662354
parent 147 10ef59f6633c
child 149 930e838ad5b6
When moving nodes with midbutton little red arrows keep their position.
graph_displayer_canvas-event.cc
graph_displayer_canvas.h
     1.1 --- a/graph_displayer_canvas-event.cc	Wed Sep 13 09:16:29 2006 +0000
     1.2 +++ b/graph_displayer_canvas-event.cc	Mon Sep 18 16:02:20 2006 +0000
     1.3 @@ -101,15 +101,7 @@
     1.4  	      active_node=i;
     1.5  	    }
     1.6  	}
     1.7 -      switch(e->button.button)
     1.8 -	{
     1.9 -	case 3:      
    1.10 -	  isbutton=3;
    1.11 -	  break;
    1.12 -	default:
    1.13 -	  isbutton=1;
    1.14 -	  break;
    1.15 -	}
    1.16 +      isbutton=e->button.button;
    1.17        break;
    1.18      case GDK_BUTTON_RELEASE:
    1.19        if (coord_text)
    1.20 @@ -191,10 +183,7 @@
    1.21              XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
    1.22  
    1.23              XY arrow_pos;
    1.24 -	    if(isbutton==3)
    1.25 -              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    1.26 -	    else
    1.27 -              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
    1.28 +	    arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    1.29  
    1.30              mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
    1.31              edgesmap[ei]->draw();
    1.32 @@ -216,10 +205,7 @@
    1.33              XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
    1.34  
    1.35              XY arrow_pos;
    1.36 -	    if(isbutton==3)
    1.37 -              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
    1.38 -	    else
    1.39 -              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
    1.40 +	    arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    1.41  
    1.42              mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
    1.43              edgesmap[ei]->draw();
    1.44 @@ -237,57 +223,66 @@
    1.45    return false;
    1.46  }
    1.47  
    1.48 -XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move)
    1.49 +XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
    1.50  {
    1.51 -  if(!move)
    1.52 -  {
    1.53 -    return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
    1.54 -  }
    1.55 -  else
    1.56 -  {
    1.57 -    //////////////////////////////////////////////////////////////////////////////////////////////////////
    1.58 -    /////////// keeps shape-with scalar multiplication - version 2.
    1.59 -    //////////////////////////////////////////////////////////////////////////////////////////////////////
    1.60 +  switch(move_code)
    1.61 +    {
    1.62 +    case 1:
    1.63 +      return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
    1.64 +      break;
    1.65 +    case 2:
    1.66 +      return old_arrow_pos;
    1.67 +      break;
    1.68 +    case 3:
    1.69 +      {
    1.70 +	//////////////////////////////////////////////////////////////////////////////////////////////////////
    1.71 +	/////////// keeps shape-with scalar multiplication - version 2.
    1.72 +	//////////////////////////////////////////////////////////////////////////////////////////////////////
    1.73  
    1.74 -    //old vector from one to the other node - a
    1.75 -    xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
    1.76 -    //new vector from one to the other node - b
    1.77 -    xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
    1.78 +	//old vector from one to the other node - a
    1.79 +	xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
    1.80 +	//new vector from one to the other node - b
    1.81 +	xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
    1.82  
    1.83 -    double absa=sqrt(a_v.normSquare());
    1.84 -    double absb=sqrt(b_v.normSquare());
    1.85 +	double absa=sqrt(a_v.normSquare());
    1.86 +	double absb=sqrt(b_v.normSquare());
    1.87  
    1.88 -    if ((absa == 0.0) || (absb == 0.0))
    1.89 -    {
    1.90 -      return old_arrow_pos;
    1.91 +	if ((absa == 0.0) || (absb == 0.0))
    1.92 +	  {
    1.93 +	    return old_arrow_pos;
    1.94 +	  }
    1.95 +	else
    1.96 +	  {
    1.97 +	    //old vector from one node to the breakpoint - c
    1.98 +	    xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
    1.99 +
   1.100 +	    //unit vector with the same direction to a_v
   1.101 +	    xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
   1.102 +
   1.103 +	    //normal vector of unit vector with the same direction to a_v
   1.104 +	    xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
   1.105 +
   1.106 +	    //unit vector with the same direction to b_v
   1.107 +	    xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
   1.108 +
   1.109 +	    //normal vector of unit vector with the same direction to b_v
   1.110 +	    xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
   1.111 +
   1.112 +	    //vector c in a_v_u and a_v_u_n co-ordinate system
   1.113 +	    xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
   1.114 +
   1.115 +	    //new vector from one node to the breakpoint - d - we have to calculate this one
   1.116 +	    xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
   1.117 +
   1.118 +	    return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
   1.119 +	  }
   1.120 +	break;
   1.121 +      }
   1.122 +    default:
   1.123 +      break;
   1.124      }
   1.125 -    else
   1.126 -    {
   1.127 -      //old vector from one node to the breakpoint - c
   1.128 -      xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
   1.129 +}
   1.130  
   1.131 -      //unit vector with the same direction to a_v
   1.132 -      xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
   1.133 -
   1.134 -      //normal vector of unit vector with the same direction to a_v
   1.135 -      xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
   1.136 -
   1.137 -      //unit vector with the same direction to b_v
   1.138 -      xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
   1.139 -
   1.140 -      //normal vector of unit vector with the same direction to b_v
   1.141 -      xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
   1.142 -
   1.143 -      //vector c in a_v_u and a_v_u_n co-ordinate system
   1.144 -      xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
   1.145 -
   1.146 -      //new vector from one node to the breakpoint - d - we have to calculate this one
   1.147 -      xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
   1.148 -
   1.149 -      return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
   1.150 -    }
   1.151 -  }
   1.152 -}
   1.153  
   1.154  bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
   1.155  {
     2.1 --- a/graph_displayer_canvas.h	Wed Sep 13 09:16:29 2006 +0000
     2.2 +++ b/graph_displayer_canvas.h	Mon Sep 18 16:02:20 2006 +0000
     2.3 @@ -378,7 +378,7 @@
     2.4    ///reference to the container, in which the canvas is
     2.5    NoteBookTab & mytab;
     2.6  
     2.7 -  XY calcArrowPos(XY, XY, XY, XY, bool);
     2.8 +  XY calcArrowPos(XY, XY, XY, XY, int);
     2.9  };
    2.10  
    2.11  #endif //GRAPH_DISPLAYER_CANVAS_H