Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Styled links (Read 2875 times)
PetrOs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Styled links
Sep 26th, 2012 at 1:08pm
Print Post  
Hey,

Is there a way to make an arrow to look like in the attached image?
The link is anchored on both ends (red crosses symbolize the anchors), but its graphical representation on the "head end" should terminate earlier then the anchor, with a gap between.

I know that I would be able to do it using the templated nodes, but it would mean that I would probably need to rebuild the anchoring functionality...
  

nonthrough_arrow.png (Attachment deleted)
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Styled links
Reply #1 - Sep 26th, 2012 at 5:12pm
Print Post  
Hi,

Set CustomDraw = Full and handle DrawLink like this:

Code
Select All
private void OnDrawLink(object sender, DrawLinkEventArgs e)
{
	var l = e.Link;
	var len = l.Length;
	var gap = 30;
	var tip = 20;
	var wth = 10;
	var path = new PathGeometry();
	var figure = new PathFigure(
		new Point(0, 0),
		new[]
		{
			new LineSegment(new Point(0, -wth), true),
			new LineSegment(new Point(len - gap - tip, -wth), true),
			new LineSegment(new Point(len - gap, 0), true),
			new LineSegment(new Point(len - gap - tip, +wth), true),
			new LineSegment(new Point(0, +wth), true)
		},
		true);
	path.Figures.Add(figure);

	double a = 0, r = 0;
	MindFusion.Geometry2D.Convert.CartesianToPolar(
		l.StartPoint, l.EndPoint, ref a, ref r);
	e.Graphics.PushTransform(
		new TranslateTransform(l.StartPoint.X, l.StartPoint.Y));
	e.Graphics.PushTransform(
		new RotateTransform(-a));
	e.Graphics.DrawGeometry(l.Brush, l.Pen, path);
	e.Graphics.Pop();
	e.Graphics.Pop();
} 



or if you have a custom link class, do that in the Draw() override. e.Link.Length will have a nice value for your purpose if the link is set to one-segment polyline.

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


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Re: Styled links
Reply #2 - Sep 28th, 2012 at 11:18am
Print Post  
Thanks! Problem solved, even if a bit of adaptation was needed, especially a yet another transform operation to the upper right corner. The origin was always in the top-left corner of the link-occupied space, so
e.Graphics.PushTransform(
           new TranslateTransform(l.StartPoint.X, l.StartPoint.Y));
was not correctly working, I had to add a transform to the top-left of the viewport first.

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Styled links
Reply #3 - Sep 28th, 2012 at 11:32am
Print Post  
Do you mean when doing that from a DiagramLink.Draw override? The code worked as is from the DrawLink event for me.
  
Back to top
 
IP Logged
 
PetrOs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 36
Joined: May 26th, 2011
Re: Styled links
Reply #4 - Sep 28th, 2012 at 3:15pm
Print Post  
Yes, when doing it from the Draw override. Another two small bits were:
CarthesianToPolar was not existing, was called DekartToPolar in my case. Also, no StartPoint and EndPoint properties on the link here.

Anyways, the final code looks like this:
Code (C++)
Select All
public override void Draw(DrawingContext graphics, MindFusion.Diagramming.Wpf.RenderOptions options)
        {

	        var l = this;
	        var len = l.Length;
	        var gap = 10;
	        var tip = 3;
	        var wth = 3;
	        var path = new PathGeometry();
	        var figure = new PathFigure(
		        new Point(0, 0),
		        new[]
		        {
			        new LineSegment(new Point(0, -wth), true),
			        new LineSegment(new Point(len - gap - tip, -wth), true),
			        new LineSegment(new Point(len - gap, 0), true),
			        new LineSegment(new Point(len - gap - tip, +wth), true),
			        new LineSegment(new Point(0, +wth), true)
		        },
		        true);
	        path.Figures.Add(figure);

	        double a = 0, r = 0;
            var start = OriginConnection.GetEndPoint();
            var end = DestinationConnection.GetEndPoint();
            // first, return to global!
            graphics.PushTransform(
                new TranslateTransform(-Math.Min(start.X, end.X), -Math.Min(start.Y, end.Y)));

	        MindFusion.Geometry2D.Convert.DekartToPolar(
                start, end, ref a, ref r);
	        // now, go to the start point
            graphics.PushTransform(
                new TranslateTransform(start.X, start.Y));
            // then rotate to correct position
            graphics.PushTransform(
		        new RotateTransform(-a));
            graphics.DrawGeometry(l.Brush, l.Pen, path);
            graphics.Pop();
            graphics.Pop();
            graphics.Pop();

        }
 

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint