Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Moving lines around (arrows) (Read 2684 times)
Aaron
YaBB Newbies
*
Offline


Looking for support

Posts: 44
Joined: Nov 9th, 2007
Moving lines around (arrows)
Feb 5th, 2008 at 11:35am
Print Post  
Hello

(I'm using .NET 2.0, FCNET 4.0.3... still)

Is there a quick way for the user to select an arrow and then drag it around? Right now, all I can do is select each controlpoint and move it.

So what I would love to see is that when the user is hoovering the mouse above a selected arrow (a loose line in this case) the "move" cursor shows up. Clicking + Dragging should result in the arrow being dragged around. Just like what happens if you select a box AND an arrow at the same time (this drags everything around).

Any ideas on implementation?

Thanks again

Aaron

Edit: I'm really using 4.3.1 (don't know where I keep getting the 4.0.3 from)
« Last Edit: Feb 5th, 2008 at 2:06pm by Aaron »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving lines around (arrows)
Reply #1 - Feb 5th, 2008 at 1:56pm
Print Post  
Hi,

From what I saw, unconnected links are not moved even when in multiple selection. The following code implements that:

Code
Select All
private void diagram_SelectionMoving(object sender, ValidationEventArgs e)
{
	MoveLineBehavior b = view.CustomBehavior as MoveLineBehavior;
	if (b == null)
		return;

	PointF current = view.ClientToDoc(view.PointToClient(MousePosition));

	foreach (DiagramLink link in diagram.Selection.Links)
	{
		if (link.Origin is DummyNode && link.Destination is DummyNode)
		{
			for (int i = 0; i < link.ControlPoints.Count; ++i)
			{
				PointF p = link.ControlPoints[i];
				p.X += current.X - startDrag.X;
				p.Y += current.Y - startDrag.Y;
				link.ControlPoints[i] = p;
			}

			link.UpdateFromPoints();
		}
	}

	startDrag = current;
}

private void view_MouseDown(object sender, MouseEventArgs e)
{
	startDrag = view.ClientToDoc(view.PointToClient(MousePosition));
}

internal PointF startDrag;
 



Next, using a custom behavior object, you can trick the control to process moving a single selected link as if it's in a multiple selection:

Code
Select All
class MoveLineBehavior : LinkShapesBehavior
{
	public MoveLineBehavior(DiagramView view) : base(view)
	{
	}

	public override InteractionState StartDraw(PointF point)
	{
		DiagramLink link = Diagram.GetLinkAt(point, 1);
		if (link != null && link.Origin is DummyNode && link.Destination is DummyNode)
			return new InteractionState(Diagram.Selection, 8, Action.Modify);

		return base.StartDraw(point);
	}
}
 



That code uses the V5 API. I can't remember if version 4.0.3 had support for custom behaviors. If it doesn't, you might have to add some hidden node to the selection, e.g. in the MouseDown event, to implement that. Otherwise you should be able to port the code to V4 by replacing DiagramLink with Arrow, Diagram.Links with FlowChart.Arrows, etc..

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Aaron
YaBB Newbies
*
Offline


Looking for support

Posts: 44
Joined: Nov 9th, 2007
Re: Moving lines around (arrows)
Reply #2 - Feb 6th, 2008 at 6:29am
Print Post  
Thanks Stoyo.

After some work I got it pretty much as I like it. When the user holds down the Alt key, the lines can be moved by dragging them, otherwise new segments are created when dragging over the line.

Just one minor detail I haven't figured out yet. You say we trick the control into believing it's a multiple selection. But when I select one (moveable) line, hoovering the mouse above it doesn't result in the "move" cursor image. This does happen when you really multiselect some components. Can I make it happen?

Other than that, great solution. I had no problems getting it to work in 4.3.1 by the way.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving lines around (arrows)
Reply #3 - Feb 6th, 2008 at 7:40am
Print Post  
Yes, override the Behavior.SetMouseCursor method and implement it just like StartDraw. Return the move Cursor object from the "if" statement, otherwise return base.SetMouseCursor().

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Aaron
YaBB Newbies
*
Offline


Looking for support

Posts: 44
Joined: Nov 9th, 2007
Re: Moving lines around (arrows)
Reply #4 - Feb 6th, 2008 at 10:34am
Print Post  
O yeah, missed that one. It works perfectly now! Thanks a lot Stoyo.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint