Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Anchor expansion (Read 2373 times)
j poz
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Nov 21st, 2012
Anchor expansion
Jan 21st, 2015 at 6:24pm
Print Post  
We want to implement a feature so that when a user hovers their mouse over an anchor, the anchor is grows in size to indicate we are over it. Do you have any suggestions for how to implement this functionality?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor expansion
Reply #1 - Jan 22nd, 2015 at 12:00pm
Print Post  
You could implement it by setting MarkStyle.Custom and handling DrawAnchorPoint event:

Code
Select All
new AnchorPattern(new[]
	{ new AnchorPoint(50, 100, true, true, MarkStyle.Custom)},
	"test");
diagram.DrawAnchorPoint += OnDrawAnchorPoint;

private void OnDrawAnchorPoint(object sender, DrawAnchorPointEventArgs e)
{
	var mouseViewPosition = diagramView.PointToClient(MousePosition);
	var mousePosition = diagramView.ClientToDoc(mouseViewPosition);

	var rect = new RectangleF(e.Location, new SizeF(0, 0));
	if (Utilities.Distance(mousePosition, e.Location) < 3)
		rect.Inflate(3, 3);
	else
		rect.Inflate(1.5f, 1.5f);
	e.Graphics.DrawRectangle(Pens.Red, rect);
}

private void diagramView_MouseMove(object sender, MouseEventArgs e)
{
	var mousePosition = diagramView.ClientToDoc(e.Location);
	var node = diagram.GetNodeAt(mousePosition, 5);
	if (node != null && node.AnchorPattern != null)
	{
		var r = node.GetRepaintRect(false);
		r.Inflate(3, 3);
		diagram.Invalidate(r);
	}
} 



Alternatively you could draw a filled shape from DrawForeground handler to cover the standard anchor point.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
j poz
Junior Member
**
Offline


I Love MindFusion!

Posts: 78
Joined: Nov 21st, 2012
Re: Anchor expansion
Reply #2 - Feb 2nd, 2015 at 6:19pm
Print Post  
Thank you. We were able to make this work. However, we want to make the expanded anchor appear over the diagramlink, but the diagram link seems to be drawn after DrawAnchorPoint so it gets drawn over our expanded anchor.

Is there a way to make this work the way we want it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Anchor expansion
Reply #3 - Feb 3rd, 2015 at 11:38am
Print Post  
You could draw it from DrawLink handler instead:

Code
Select All
private void OnDrawAnchorPoint(object sender, DrawAnchorPointEventArgs e)
{
	var mouseViewPosition = diagramView.PointToClient(MousePosition);
	var mousePosition = diagramView.ClientToDoc(mouseViewPosition);

	var rect = new RectangleF(e.Location, new SizeF(0, 0));
	if (Utilities.Distance(mousePosition, e.Location) < 3)
	{
		rect.Inflate(3, 3);
		highlightAnchorPoint = rect;
	}
	else
	{
		rect.Inflate(1.5f, 1.5f);
		e.Graphics.DrawRectangle(Pens.Red, rect);
	}
}

RectangleF? highlightAnchorPoint;

private void diagram_InitializeLink(object sender, LinkEventArgs e)
{
	e.Link.CustomDraw = CustomDraw.Additional;
}

private void diagram_DrawLink(object sender, DrawLinkEventArgs e)
{
	if (highlightAnchorPoint != null && !e.Shadow)
		e.Graphics.DrawRectangle(Pens.Red, highlightAnchorPoint.Value);
}


private void diagramView_MouseMove(object sender, MouseEventArgs e)
{
	var mousePosition = diagramView.ClientToDoc(e.Location);
	var node = diagram.GetNodeAt(mousePosition, 5);
	if (node != null && node.AnchorPattern != null)
	{
		var r = node.GetRepaintRect(false);
		r.Inflate(3, 3);
		diagram.Invalidate(r);
	}
	else if (highlightAnchorPoint != null)
	{
		diagram.Invalidate();
		highlightAnchorPoint = null;
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint