Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to reach the style like MS-Visio with diagram? (Read 2186 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to reach the style like MS-Visio with diagram?
Dec 22nd, 2014 at 8:04am
Print Post  
hi,
I want to use shapenod in diagram to reach the MS-Visio's Style.I attach the goal (and my project) I want to get? could you please give me some hepl?
  

Question01.jpg (Attachment deleted)
question02.jpg (Attachment deleted)
Project.rar (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to reach the style like MS-Visio with diagram?
Reply #1 - Dec 22nd, 2014 at 10:19am
Print Post  
Hi,

For selection appearance and moving from any point inside node, set HandlesStyle = Custom and handle the Draw/HitTest events like this:

Code
Select All
void diagram_DrawAdjustmentHandles(object sender, DrawItemEventArgs e)
{
	var node = (DiagramNode)e.Item;
	var bounds = node.Bounds;
	bounds.Location = new Point();
	var handlesStyles = new[] { HandlesStyle.DashFrame, HandlesStyle.SquareHandles };

	foreach (var style in handlesStyles)
	{
		InternalUtils.DrawAdjustmentHandles(
			e.Graphics,
			diagram.ActiveItemHandlesStyle,
			diagram.DisabledHandlesStyle,
			bounds,
			node.RotationAngle,
			node.EnabledHandles & ~AdjustmentHandles.Move,
			false,
			style,
			diagram.AdjustmentHandlesSize,
			node);
	}
}

private void diagram_HitTestAdjustmentHandles(object sender, HitTestEventArgs e)
{
	var node = e.Item as DiagramNode;
	var size = new Size(
		diagram.AdjustmentHandlesSize,
		diagram.AdjustmentHandlesSize);

	Rect r = e.Item.GetBounds();
	if (node != null)
	{
		var location = node.Bounds.Location;
		var diagOffset = new Vector(location.X, location.Y);
		double rotationAngle = node.RotationAngle;

		Point localPoint = RotatePointAt(e.MousePosition, node.GetCenter(), -rotationAngle);
		if (r.Contains(localPoint))
			e.HitResult = 8;

		localPoint = localPoint - diagOffset;

		var TopLeft = new Point(0, 0);
		var TopLeftRect = new Rect(TopLeft, size);
		if (TopLeftRect.Contains(localPoint))
			e.HitResult = 0;

		var TopMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, 0);
		var TopMiddleRect = new Rect(TopMiddle, size);
		if (TopMiddleRect.Contains(localPoint))
			e.HitResult = 4;

		var TopRight = new Point(node.Bounds.Width - size.Width, 0);
		var TopRightRect = new Rect(TopRight, size);
		if (TopRightRect.Contains(localPoint))
			e.HitResult = 1;

		var MiddleLeft = new Point(0, node.Bounds.Height / 2 - size.Height / 2);
		var MiddleLeftRect = new Rect(MiddleLeft, size);
		if (MiddleLeftRect.Contains(localPoint))
			e.HitResult = 7;

		var MiddleRight = new Point(node.Bounds.Width - size.Width, node.Bounds.Height / 2 - size.Height / 2);
		var MiddleRightRect = new Rect(MiddleRight, size);
		if (MiddleRightRect.Contains(localPoint))
			e.HitResult = 5;

		var bottomLeft = new Point(0, node.Bounds.Height - size.Height);
		var bottomLeftRect = new Rect(bottomLeft, size);
		if (bottomLeftRect.Contains(localPoint))
			e.HitResult = 3;

		var bottomMiddle = new Point(node.Bounds.Width / 2 - size.Width / 2, node.Bounds.Height - size.Height);
		var bottomMiddleRect = new Rect(bottomMiddle, size);
		if (bottomMiddleRect.Contains(localPoint))
			e.HitResult = 6;

		var bottomRight = new Point(node.Bounds.Width - size.Width, node.Bounds.Height - size.Height);
		var bottomRightRect = new Rect(bottomRight, size);
		if (bottomRightRect.Contains(localPoint))
			e.HitResult = 2;
	}
} 



You could draw the red rectangles from either DrawAnchorPoint, DrawNode or DrawForeground event handlers. For first two options you will have to either set MarkStyle.Custom for anchor points or set node.CustomDraw = Additional.

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


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to reach the style like MS-Visio with diagram?
Reply #2 - Dec 23rd, 2014 at 1:21am
Print Post  
hi Stoyan,
Thanks For your help,but I can't find any code of the method named 'RotatePointAt',
and I have tried the DrawAnchorPoint, DrawNode and DrawForeground event,
but those can't be raised when the mouse move on or in the node?
Could you please set it to me ?
« Last Edit: Dec 23rd, 2014 at 8:32am by heyx »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to reach the style like MS-Visio with diagram?
Reply #3 - Dec 23rd, 2014 at 1:32pm
Print Post  
Hi,

Code
Select All
Point RotatePointAt(Point point, Point pivot, double angle)
{
	Matrix rotation = new Matrix();
	rotation.RotateAt(angle, pivot.X, pivot.Y);
	Point res = rotation.Transform(point);
	return res;
} 



Call node.Repaint or diagram.InvalidateForeground when you need to draw new highlight state.

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