private void DrawBackground(Graphics _canvas, double _fFadingFactor) { // The roundness of the rectangle is computed from the font size. int radius = (int)(m_fRescaledFontSize / 2); int diameter = radius * 2; GraphicsPath gp = new GraphicsPath(); gp.StartFigure(); int iOffsetX = 0; int iOffsetY = 0; if (m_bBackgroundIsRelative) { // If we are on relative coords (i.e: drawing the main label that follows the target) // then the background "top left" is actually relative to the current position. // (i.e: can be negative.) // Hence we need add to it the current track position. iOffsetX = m_RescaledLocation.X; iOffsetY = m_RescaledLocation.Y; } gp.AddArc(RescaledBackground.X + iOffsetX, RescaledBackground.Y + iOffsetY, diameter, diameter, 180, 90); gp.AddLine(RescaledBackground.X + iOffsetX + radius, RescaledBackground.Y + iOffsetY, RescaledBackground.X + iOffsetX + RescaledBackground.Width - diameter, RescaledBackground.Y + iOffsetY); gp.AddArc(RescaledBackground.X + iOffsetX + RescaledBackground.Width - diameter, RescaledBackground.Y + iOffsetY, diameter, diameter, 270, 90); gp.AddLine(RescaledBackground.X + iOffsetX + RescaledBackground.Width, RescaledBackground.Y + iOffsetY + radius, RescaledBackground.X + iOffsetX + RescaledBackground.Width, RescaledBackground.Y + iOffsetY + RescaledBackground.Height - diameter); gp.AddArc(RescaledBackground.X + iOffsetX + RescaledBackground.Width - diameter, RescaledBackground.Y + iOffsetY + RescaledBackground.Height - diameter, diameter, diameter, 0, 90); gp.AddLine(RescaledBackground.X + iOffsetX + RescaledBackground.Width - radius, RescaledBackground.Y + iOffsetY + RescaledBackground.Height, RescaledBackground.X + iOffsetX + radius, RescaledBackground.Y + iOffsetY + RescaledBackground.Height); gp.AddArc(RescaledBackground.X + iOffsetX, RescaledBackground.Y + iOffsetY + RescaledBackground.Height - diameter, diameter, diameter, 90, 90); gp.AddLine(RescaledBackground.X + iOffsetX, RescaledBackground.Y + iOffsetY + RescaledBackground.Height - radius, RescaledBackground.X + iOffsetX, RescaledBackground.Y + iOffsetY + radius); gp.CloseFigure(); Color fadingColor = m_TextDecoration.GetFadingBackColor(_fFadingFactor); Color moreFadingColor = m_TextDecoration.GetFadingBackColor(_fFadingFactor / 4); // Small dot _canvas.FillEllipse(new SolidBrush(fadingColor), m_RescaledLocation.X - 2, m_RescaledLocation.Y - 2, 4, 4); // Connector _canvas.DrawLine(new Pen(moreFadingColor), m_RescaledLocation.X, m_RescaledLocation.Y, RescaledBackground.X + iOffsetX + RescaledBackground.Width / 2, RescaledBackground.Y + iOffsetY + RescaledBackground.Height / 2); // Rounded rectangle _canvas.FillPath(new SolidBrush(fadingColor), gp); }
public override void Draw(Graphics _canvas, double _fStretchFactor, bool _bSelected, long _iCurrentTimestamp, Point _DirectZoomTopLeft) { double fOpacityFactor = m_InfosFading.GetOpacityFactor(_iCurrentTimestamp); if (fOpacityFactor > 0) { // Rescale the points. m_fStretchFactor = _fStretchFactor; m_DirectZoomTopLeft = new Point(_DirectZoomTopLeft.X, _DirectZoomTopLeft.Y); RescaleCoordinates(m_fStretchFactor, m_DirectZoomTopLeft); //---------------------------------------------------------- // Draw disk section // Unfortunately we need to compute everything at each draw // (draw may be triggered on image resize) //---------------------------------------------------------- ComputeFillRegion(); SolidBrush FillBrush = new SolidBrush(Color.FromArgb((int)((double)m_iDefaultBackgroundAlpha * fOpacityFactor), m_BackgroundFillColor)); Pen PenEdges = new Pen(m_InfosStyle.GetFadingBackColor(fOpacityFactor)); _canvas.FillPie(FillBrush, (float)m_BoundingPoint.X, (float)m_BoundingPoint.Y, (float)m_fRadius * 2, (float)m_fRadius * 2, m_fStartAngle, m_fSweepAngle); _canvas.DrawPie(PenEdges, (float)m_BoundingPoint.X, (float)m_BoundingPoint.Y, (float)m_fRadius * 2, (float)m_fRadius * 2, m_fStartAngle, m_fSweepAngle); //----------------------------- // Draw the edges //----------------------------- _canvas.DrawLine(PenEdges, RescaledPointO.X, RescaledPointO.Y, RescaledPointA.X, RescaledPointA.Y); _canvas.DrawLine(PenEdges, RescaledPointO.X, RescaledPointO.Y, RescaledPointB.X, RescaledPointB.Y); //----------------------------- // Draw handlers //----------------------------- if (_bSelected) { PenEdges.Width = 2; } _canvas.DrawEllipse(PenEdges, GetRescaledHandleRectangle(1)); _canvas.DrawEllipse(PenEdges, GetRescaledHandleRectangle(2)); _canvas.DrawEllipse(PenEdges, GetRescaledHandleRectangle(3)); //---------------------------- // Draw Measure //---------------------------- // We try to be inside the pie, so we compute the bissectrice and do some trigo. // We start the text on the bissectrice, at a distance of iTextRadius. Point TextOrigin = GetTextPosition(); SolidBrush fontBrush = new SolidBrush(m_InfosStyle.GetFadingForeColor(fOpacityFactor)); int angle = (int)Math.Floor(-m_fSweepAngle); _canvas.DrawString("α=" + angle.ToString() + "°", m_InfosStyle.GetInternalFont(), fontBrush, TextOrigin); } }