Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Drawing curves for a line and bezier curve (Read 1979 times)
kwinovich
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 2
Joined: Mar 24th, 2008
Drawing curves for a line and bezier curve
Mar 24th, 2008 at 3:54pm
Print Post  
I am using FlowChart.net. I want to draw a line with curves on it. I also need to draw a bezier curve with curves instead of a line. Here is a sample of what I need:

http://img96.imageshack.us/img96/238/arcdraw5sv.jpg

The user should be able to move the arrow/curve end point and have the curves draw themselves as shown in the graphic. Also, the user should be able to size a bezier curve and have the curves that makeup the bezier draw themselves too.

How can I go about this using the FlowChart.net component? I need this to expand as the user draws the line by dragging the mouse. I understand I can override draw methods but I havent been able to get that working. How can I go about getting the points on the line to actually draw the arcs?

Thanks for any help!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drawing curves for a line and bezier curve
Reply #1 - Mar 24th, 2008 at 6:20pm
Print Post  
This works for straight-line links:

Code
Select All
private void diagram_DrawArrow(object sender, DrawLinkEventArgs e)
{
	if (e.Shadow)
		return;

	for (int i = 0; i < e.Link.SegmentCount; ++i)
	{
		PointF a = e.Points[i];
		PointF b = e.Points[i + 1];

		float angle = 0, r = 0;
		Convert.DekartToPolar(a, b, ref angle, ref r);

		int c = (int)(r/3) + 1;
		if (c < 2)
			continue;
		PointF[] points = new PointF[c];
		for (int j = 0; j < c; ++j)
			points[j] = new PointF(j * 3, (j % 2) == 0 ? -1 : 1);

		GraphicsState gs = e.Graphics.Save();
		e.Graphics.TranslateTransform(a.X, a.Y);
		e.Graphics.RotateTransform(-angle);

		e.Graphics.DrawCurve(Pens.Black, points);

		e.Graphics.Restore(gs);
	}
}
 



Copy the Convert class from the CustomDraw sample. You might use the same code for Beziers too by approximating them with straight lines, but there'll be some more complex calculations involved in order to have smooth joins between the segments.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Drawing curves for a line and bezier curve
Reply #2 - Mar 24th, 2008 at 6:23pm
Print Post  
That was a handler for the DrawLink event - you can paste it over the same-named method in the CustomDraw sample to check how it works.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint