/// <summary> /// Render this object to the specified <see c_ref="Graphics"/> device. /// </summary> /// <remarks> /// This method is normally only called by the Draw method /// of the parent <see c_ref="GraphObjList"/> collection object. /// </remarks> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see c_ref="PaneBase"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see c_ref="GraphPane"/> object using the /// <see c_ref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> override public void Draw(Graphics g, PaneBase pane, float scaleFactor) { // Convert the arrow coordinates from the user coordinate system // to the screen coordinate system PointF pix1 = Location.TransformTopLeft(pane); PointF pix2 = Location.TransformBottomRight(pane); if (pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 && pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000) { // calculate the length and the angle of the arrow "vector" double dy = pix2.Y - pix1.Y; double dx = pix2.X - pix1.X; float angle = (float)Math.Atan2(dy, dx) * 180.0F / (float)Math.PI; float length = (float)Math.Sqrt(dx * dx + dy * dy); // Save the old transform matrix Matrix transform = g.Transform; // Move the coordinate system so it is located at the starting point // of this arrow g.TranslateTransform(pix1.X, pix1.Y); // Rotate the coordinate system according to the angle of this arrow // about the starting point g.RotateTransform(angle); // get a pen according to this arrow properties using (Pen pen = _line.GetPen(pane, scaleFactor)) //new Pen( _line._color, pane.ScaledPenWidth( _line._width, scaleFactor ) ) ) { //pen.DashStyle = _style; g.DrawLine(pen, 0, 0, length, 0); } // Restore the transform matrix back to its original state g.Transform = transform; } }
/// <summary> /// Render this object to the specified <see c_ref="Graphics"/> device. /// </summary> /// <remarks> /// This method is normally only called by the Draw method /// of the parent <see c_ref="GraphObjList"/> collection object. /// </remarks> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see c_ref="PaneBase"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see c_ref="GraphPane"/> object using the /// <see c_ref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public override void Draw( Graphics g, PaneBase pane, float scaleFactor ) { // Convert the arrow coordinates from the user coordinate system // to the screen coordinate system PointF pix1 = Location.TransformTopLeft( pane ); PointF pix2 = Location.TransformBottomRight( pane ); if ( pix1.X > -10000 && pix1.X < 100000 && pix1.Y > -100000 && pix1.Y < 100000 && pix2.X > -10000 && pix2.X < 100000 && pix2.Y > -100000 && pix2.Y < 100000 ) { // get a scaled size for the arrowhead float scaledSize = _size * scaleFactor; // calculate the length and the angle of the arrow "vector" double dy = pix2.Y - pix1.Y; double dx = pix2.X - pix1.X; float angle = (float)Math.Atan2( dy, dx ) * 180.0F / (float)Math.PI; float length = (float)Math.Sqrt( dx * dx + dy * dy ); // Save the old transform matrix Matrix transform = g.Transform; // Move the coordinate system so it is located at the starting point // of this arrow g.TranslateTransform( pix1.X, pix1.Y ); // Rotate the coordinate system according to the angle of this arrow // about the starting point g.RotateTransform( angle ); // get a pen according to this arrow properties using ( Pen pen = _line.GetPen( pane, scaleFactor ) ) //new Pen( _color, pane.ScaledPenWidth( _penWidth, scaleFactor ) ) ) { //pen.DashStyle = _style; // Only show the arrowhead if required if ( _isArrowHead ) { // Draw the line segment for this arrow g.DrawLine( pen, 0, 0, length - scaledSize + 1, 0 ); // Create a polygon representing the arrowhead based on the scaled // size PointF[] polyPt = new PointF[4]; float hsize = scaledSize / 3.0F; polyPt[0].X = length; polyPt[0].Y = 0; polyPt[1].X = length - scaledSize; polyPt[1].Y = hsize; polyPt[2].X = length - scaledSize; polyPt[2].Y = -hsize; polyPt[3] = polyPt[0]; using ( SolidBrush brush = new SolidBrush( _line._color ) ) // render the arrowhead g.FillPolygon( brush, polyPt ); } else g.DrawLine( pen, 0, 0, length, 0 ); } // Restore the transform matrix back to its original state g.Transform = transform; } }