DrawLine.cs Questions .. aka I've hijacked the trendline.
Posted: Wed Aug 25, 2010 7:39 am
Greetings,
I've been enjoying myself butchering the DrawLine.cs class. Now I have some questions.
First some background. I need to add a few tools such as Fibonacci Arcs, Fans, Retracement, Speed Resistance etc etc ad nauseum.
Most of these can be based around a trend line. i.e. the user drags a trend line on the screen and voila I draw all the other relevant level and resistance lines.
The DrawLine class is perfect for this as it has all the wonderful dragging functionality. Below is my code in your sourcecode (its WIP so its a bit messy atm).
I think it would be better if instead of using DrawLine.cs to do my modifications I could somehow make a copy of this Drawline class (say DrawLine2.cs) in which I did all my mods (that way when the next version comes out I could easily just drop my Drawline2 class into the project and reap the benfits of the latest bug fixes)
Question 1: So how do I add another tool to Teechart?(which will be a clone of DrawLine.cs)
Now because there is no documentation for the source code I'm doing the hack thing and guessing at how the Charts work 'under the hood' ... please feel free to scream in dismay at my hacking
Question 2:
Drag Handles - I dont understand how these work and I'm stuffing something up. see the below image.
Item 1 is a standard Drawline .. when the mouse hovers over the centre of the line the mouse icon changes to a hand indicating the line can be Dragged.
In the case of item 2 the arrow points to where the drag handle is (somewhere out in space) .. can you explain to me how to set the area for these Drag handles ??? i.e. put the drag handle in the correct place.
(please note Screen capture doesnt capture the mouse ... so 'pretend' you can see a hand icon where the arrow points ) Question 3: Can I adjust the line properties of these independantly .. at the moment everything inherits from the same values .. do you think I should be approaching this differently ? Drawline does have a collection of lines I noticed but I'm not sure how to deal with them.(please refer to above Code (AStyle == DrawLineStyle.FibonacciArc) where you can see the code I ripped off the Fibonacci class) Edit: Upon reflection I think the way to deal with the 2 above problems is to overload the line styles, kind of how they are now, but ensure they only draw 1 line (as originally designed) and in the case of the fibonacci I can create a Drawline that has 4 DrawLineItems - 1 drawline and 3 Fibonacci Lines .. then I'll still be able to drag the straight drawline AND have some control over the styles of each fibonacci Arc ....
Edit 2: Well that great idea didnt work at all ... all the drawlineItems have a single x,y points .. they obviously need to have there start and end points set before they get to the drawing routines .. wheras I want to draw them based on the position of the first drawn line .. back to the drawing board on that idea.
I've been enjoying myself butchering the DrawLine.cs class. Now I have some questions.
First some background. I need to add a few tools such as Fibonacci Arcs, Fans, Retracement, Speed Resistance etc etc ad nauseum.
Most of these can be based around a trend line. i.e. the user drags a trend line on the screen and voila I draw all the other relevant level and resistance lines.
The DrawLine class is perfect for this as it has all the wonderful dragging functionality. Below is my code in your sourcecode (its WIP so its a bit messy atm).
Code: Select all
private void DoDrawLine(Graphics3D g, Point StartPos, Point EndPos, DrawLineStyle AStyle)
{
bool oldBrush;
if (!base.Chart.Aspect.View3D) // Not in 3D mode
{
if (AStyle != DrawLineStyle.Line)
{
if (AStyle == DrawLineStyle.HorizParallel)
{
g.HorizontalLine(StartPos.X, EndPos.X, StartPos.Y);
g.HorizontalLine(StartPos.X, EndPos.X, EndPos.Y);
}
else if (AStyle == DrawLineStyle.Rectangle)
{
oldBrush = g.Brush.Visible;
g.Brush.Visible = false;
g.Rectangle(Utils.FromLTRB(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y));
g.Brush.Visible = oldBrush;
}
else if (AStyle == DrawLineStyle.Ellipse)
{
oldBrush = g.Brush.Visible;
g.Brush.Visible = false;
g.Ellipse(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
g.Brush.Visible = oldBrush;
}
else if (AStyle == DrawLineStyle.Extreme)
{
g.Line(StartPos.X - 20, StartPos.Y, EndPos.X -20, EndPos.Y);
g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
g.Line(StartPos.X + 20, StartPos.Y, EndPos.X + 20, EndPos.Y);
}
else if (AStyle == DrawLineStyle.SpeedResistance)
{
g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
int xr = g.Chart.ChartBounds.Right; //Debug.Print("Xr:"+ xr.ToString());
//int yt = g.Chart.ChartBounds.Top; Debug.Print("Yt:" + yt.ToString());
int xl = g.Chart.ChartBounds.Left; Debug.Print("Xl:" + xl.ToString());
//int yb = g.Chart.ChartBounds.Bottom; Debug.Print("Yb:" + yb.ToString());
// Debug.Print("----------------------------");
double M = ((double)EndPos.Y - (double)StartPos.Y)/(3 * ((double)EndPos.X - (double)StartPos.X));
M = (double.IsNaN(M)||double.IsInfinity(M)) ? -1000 : M;
double C = (double)StartPos.Y - M * (double)StartPos.X;
double Yd; //= M * (double)xr + C;
int YD; // = Convert.ToInt32(Yd);
if (EndPos.X < StartPos.X)
{
Yd = M * (double)xl + C;
YD = Convert.ToInt32(Yd);
g.Line(StartPos.X, StartPos.Y, xl, YD);
}
else
{
Yd = M * (double)xr + C;
YD = Convert.ToInt32(Yd);
g.Line(StartPos.X, StartPos.Y, xr, YD);
}
double M2 = (2 * ((double)EndPos.Y - (double)StartPos.Y)) / (3 * ((double)EndPos.X - (double)StartPos.X));
M2 = (double.IsNaN(M2)||double.IsInfinity(M2)) ? -1000 : M2;
double C2 = (double)StartPos.Y - M2 * (double)StartPos.X;
if (EndPos.X < StartPos.X)
{
Yd = M2 * (double)xl + C2;
YD = Convert.ToInt32(Yd);
g.Line(StartPos.X, StartPos.Y, xl, YD);
}
else
{
Yd = M2 * (double)xr + C2;
YD = Convert.ToInt32(Yd);
g.Line(StartPos.X, StartPos.Y, xr, YD);
}
}
else if (AStyle == DrawLineStyle.Vertical)
{
g.VerticalLine(StartPos.X, StartPos.Y, EndPos.Y);
}
else if (AStyle == DrawLineStyle.Horizontal)
{
g.HorizontalLine(StartPos.X, EndPos.X, StartPos.Y);
}
else if (AStyle == DrawLineStyle.FibonacciArc)
{
g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
//Point center = new Point(Convert.ToInt32(Math.Abs((EndPos.X - StartPos.X)/2)), Convert.ToInt32(Math.Abs((EndPos.Y - StartPos.Y)/2)));
Point center = new Point(EndPos.X, EndPos.Y);
Arc(g, center, 100, EndPos.Y < StartPos.Y);
Arc(g, center, 150, EndPos.Y < StartPos.Y);
Arc(g, center, 200, EndPos.Y < StartPos.Y);
}
else if (AStyle == DrawLineStyle.FibonacciFan)
{
g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
if (EndPos.X - StartPos.X > 0)
{
foreach (double lvl in defaultfab)
{
int xr = g.Chart.ChartBounds.Right;
double xend = xr;
double k = ((double)EndPos.Y - (double)StartPos.Y) / ((double)EndPos.X - (double)StartPos.X) *(100.0 - lvl) / 100.0; Debug.Print("k " + k.ToString() + " lvl " + lvl.ToString());
double yend = (double)StartPos.Y + k * (xend - (double)StartPos.X);
Point endp = new Point(xr, Convert.ToInt32(yend)); Debug.Print("xend:" + xend.ToString() + " yend:" + yend.ToString());
Point sp = new Point(StartPos.X, StartPos.Y);
Fan(g, sp, endp);
}
}
}
else
{
g.VerticalLine(StartPos.X, StartPos.Y, EndPos.Y);
g.VerticalLine(EndPos.X, StartPos.Y, EndPos.Y);
}
}
else
{
g.Line(StartPos.X, StartPos.Y, EndPos.X, EndPos.Y);
}
Question 1: So how do I add another tool to Teechart?(which will be a clone of DrawLine.cs)
Now because there is no documentation for the source code I'm doing the hack thing and guessing at how the Charts work 'under the hood' ... please feel free to scream in dismay at my hacking
Question 2:
Drag Handles - I dont understand how these work and I'm stuffing something up. see the below image.
Item 1 is a standard Drawline .. when the mouse hovers over the centre of the line the mouse icon changes to a hand indicating the line can be Dragged.
In the case of item 2 the arrow points to where the drag handle is (somewhere out in space) .. can you explain to me how to set the area for these Drag handles ??? i.e. put the drag handle in the correct place.
(please note Screen capture doesnt capture the mouse ... so 'pretend' you can see a hand icon where the arrow points ) Question 3: Can I adjust the line properties of these independantly .. at the moment everything inherits from the same values .. do you think I should be approaching this differently ? Drawline does have a collection of lines I noticed but I'm not sure how to deal with them.(please refer to above Code (AStyle == DrawLineStyle.FibonacciArc) where you can see the code I ripped off the Fibonacci class) Edit: Upon reflection I think the way to deal with the 2 above problems is to overload the line styles, kind of how they are now, but ensure they only draw 1 line (as originally designed) and in the case of the fibonacci I can create a Drawline that has 4 DrawLineItems - 1 drawline and 3 Fibonacci Lines .. then I'll still be able to drag the straight drawline AND have some control over the styles of each fibonacci Arc ....
Edit 2: Well that great idea didnt work at all ... all the drawlineItems have a single x,y points .. they obviously need to have there start and end points set before they get to the drawing routines .. wheras I want to draw them based on the position of the first drawn line .. back to the drawing board on that idea.