Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom drawing on links (Read 3694 times)
_FKS_
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 26th, 2010
Custom drawing on links
Oct 26th, 2010 at 8:32pm
Print Post  
Hi,

I'm trying to display links with a "highlight" underneath.

I've tried to achieve that by making the links custom drawable, and drawing a bezier with a PathGradientBrush attached to a Pen. However that doesn't seem to do anything. If I set the Pen's brush to anything else, such as LinearGradientBrush it works fine, but that's not what I want.

I essentially want a Linear gradient, but it should follow the bezier curve. Is there any way to achieve that?

Thanks!
Alex.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom drawing on links
Reply #1 - Oct 26th, 2010 at 9:04pm
Print Post  
Hi,

Should the gradient change along the link's length, or orthogonally along the width? I don't think GDI+ supports any of these for a Bezier curve, but it's possible to implement a custom gradient.

Stoyan
  
Back to top
 
IP Logged
 
_FKS_
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 26th, 2010
Re: Custom drawing on links
Reply #2 - Oct 26th, 2010 at 9:23pm
Print Post  
That would be along the width. When you say it's possible to implement a custom gradient, you mean on the client side? I was thinking of simulating the gradient by drawing the bezier several times with different widths, but that wouldn't be exactly fast. Would you possibly have other solutions?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom drawing on links
Reply #3 - Oct 26th, 2010 at 9:43pm
Print Post  
With the 'on the client side' do you mean you are not using the Windows Forms control? WinForms / GDI+ does not support such gradients, but indeed you can implement them by drawing several times with a different width:

Code
Select All
private void diagram_DrawLink(object sender, DrawLinkEventArgs e)
{
	for (float width = 2; width > 0; width -= 0.5f)
	{
		Color color = Color.FromArgb(40, Color.Red);
		System.Drawing.Pen pen = new System.Drawing.Pen(color, width);
		e.Graphics.DrawBeziers(pen, e.Link.ControlPoints.GetArray());
		pen.Dispose();
	}
} 



E.g. that code creates kind of glow effect where the color is more solid at the center, since it is merged with the background from the previous DrawBeziers.

I don't think a built-in gradient would be much faster, and there shouldn't be that big delay unless you draw hundreds of links.

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


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 26th, 2010
Re: Custom drawing on links
Reply #4 - Oct 27th, 2010 at 9:37pm
Print Post  
Thanks, that does the job!
  
Back to top
 
IP Logged
 
_FKS_
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 4
Joined: Oct 26th, 2010
Re: Custom drawing on links
Reply #5 - Oct 28th, 2010 at 10:23pm
Print Post  
Stoyo, one more thing if you would. Why is it that IntermediateShapes aren't drawn on Bezier links? The code clearly states that "draw arrowheads, intermediate are skipped for Bezier links".

If you ever decide to add it, you might also consider the following. Some of our links are sometimes very long, and sometimes cross the screen. The result is that you don't have any clue about their direction. I was planning on adding "Intermediate Shapes" every N units on the links, so you can always see the direction of the link, no matter how long it is. That could possibly be a nice addition to Flowchart. In the meanwhile, I'll add that on our side through custom drawing.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Custom drawing on links
Reply #6 - Oct 29th, 2010 at 7:54am
Print Post  
Hi Alex,

Actually intermediate shapes are supported for Bezier links too, since the 5.3.4 release. If you are with an older version, try the latest 5.4. If you are not in a hurry for your own release, you might also use the v5.5. beta, no one wants to try our betas otherwise.

We can also add arrowheads at every few units, but only for straight-line links for the time being. Beziers have only a few points on them whose position can be easily found - the end segment points and the tangent one between the middle two control points. For other locations we could use the Bezier formula, but GDI+ draws Beziers using some approximation algorithm and we are not sure which one.

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