public override Cursor GetCursor(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, Point point) { switch (DrawingState) { case DrawingState.Building: return(Cursors.Pen); case DrawingState.Moving: return(IsLocked ? Cursors.No : Cursors.SizeAll); case DrawingState.Editing: if (IsLocked) { return(Cursors.No); } if (editingAnchor == TextAnchor) { return(Cursors.SizeNESW); } return(editingAnchor == StartAnchor ? Cursors.SizeNESW : Cursors.SizeNWSE); default: // see if we are near an anchor right away. this is is cheap so no big deal to do often ChartAnchor closest = GetClosestAnchor(chartControl, chartPanel, chartScale, cursorSensitivity, point); if (closest != null) { if (IsLocked) { return(Cursors.Arrow); } return(closest == StartAnchor ? Cursors.SizeNESW : Cursors.SizeNWSE); } // draw move cursor if cursor is near line path anywhere Point startAnchorPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale); Point endAnchorPoint = EndAnchor.GetPoint(chartControl, chartPanel, chartScale); Point txtAnchorPoint = TextAnchor.GetPoint(chartControl, chartPanel, chartScale); Vector startEndVector = endAnchorPoint - startAnchorPoint; Vector endToTextVector = txtAnchorPoint - endAnchorPoint; //Text Outline Box Path as well UpdateTextLayout(chartControl, ChartPanel, chartScale); Point bottomLeft = new Point(txtAnchorPoint.X - textLayout.MaxWidth - textMargin, txtAnchorPoint.Y); Point topLeft = new Point(bottomLeft.X, txtAnchorPoint.Y - textLayout.MaxHeight - 2 * textMargin); Point topRight = new Point(txtAnchorPoint.X, txtAnchorPoint.Y - textLayout.MaxHeight - 2 * textMargin); Vector txtBottomLeft = bottomLeft - txtAnchorPoint; Vector bottomLeftTopLeft = topLeft - bottomLeft; Vector topLeftTopRight = topRight - topLeft; Vector topRightTxt = txtAnchorPoint - topRight; if (MathHelper.IsPointAlongVector(point, startAnchorPoint, startEndVector, cursorSensitivity) || MathHelper.IsPointAlongVector(point, endAnchorPoint, endToTextVector, cursorSensitivity) || MathHelper.IsPointAlongVector(point, txtAnchorPoint, txtBottomLeft, cursorSensitivity) || MathHelper.IsPointAlongVector(point, bottomLeft, bottomLeftTopLeft, cursorSensitivity) || MathHelper.IsPointAlongVector(point, topLeft, topLeftTopRight, cursorSensitivity) || MathHelper.IsPointAlongVector(point, topRight, topRightTxt, cursorSensitivity)) { return(IsLocked ? Cursors.Arrow : Cursors.SizeAll); } return(null); } }
public override void OnRender(ChartControl chartControl, ChartScale chartScale) { LineColor.RenderTarget = RenderTarget; // first of all, turn on anti-aliasing to smooth out our line RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.PerPrimitive; ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex]; // draw a line from start measure point to end measure point. Point lineStartPoint = StartAnchor.GetPoint(chartControl, panel, chartScale); Point lineEndPoint = EndAnchor.GetPoint(chartControl, panel, chartScale); // align to full pixel to avoid unneeded aliasing double strokePixAdjust = (LineColor.Width % 2).ApproxCompare(0) == 0 ? 0.5d : 0d; Vector strokePixAdjustVec = new Vector(strokePixAdjust, strokePixAdjust); SharpDX.Vector2 endVec = (lineEndPoint + strokePixAdjustVec).ToVector2(); SharpDX.Direct2D1.Brush tmpBrush = IsInHitTest ? chartControl.SelectionBrush : LineColor.BrushDX; RenderTarget.DrawLine((lineStartPoint + strokePixAdjustVec).ToVector2(), endVec, tmpBrush, LineColor.Width, LineColor.StrokeStyle); if (ShouldDrawText) { UpdateTextLayout(chartControl, ChartPanel, chartScale); textDeviceBrush.RenderTarget = RenderTarget; // Text rec uses same settings as mini data box textBackgroundDeviceBrush.Brush = Application.Current.FindResource("ChartControl.DataBoxBackground") as Brush; textBackgroundDeviceBrush.RenderTarget = RenderTarget; Brush borderBrush = Application.Current.FindResource("BorderThinBrush") as Brush; object thicknessResource = Application.Current.FindResource("BorderThinThickness"); double thickness = thicknessResource as double? ?? 1; Stroke textBorderStroke = new Stroke(borderBrush ?? LineColor.Brush, DashStyleHelper.Solid, Convert.ToSingle(thickness)) { RenderTarget = RenderTarget }; Point textEndPoint = TextAnchor.GetPoint(chartControl, panel, chartScale); SharpDX.Vector2 textEndVec = (textEndPoint + strokePixAdjustVec).ToVector2(); RenderTarget.DrawLine(endVec, textEndVec, LineColor.BrushDX, LineColor.Width, LineColor.StrokeStyle); float rectPixAdjust = (float)(strokePixAdjust / 2f); SharpDX.RectangleF rect = new SharpDX.RectangleF((float)(textEndPoint.X - textLayout.MaxWidth - textMargin + rectPixAdjust), (float)(textEndPoint.Y - textLayout.MaxHeight - textMargin + rectPixAdjust), textLayout.MaxWidth + textMargin * 2f, textLayout.MaxHeight + textMargin); if (textBackgroundDeviceBrush.BrushDX != null && !IsInHitTest) { RenderTarget.FillRectangle(rect, textBackgroundDeviceBrush.BrushDX); } RenderTarget.DrawRectangle(rect, textBorderStroke.BrushDX, textBorderStroke.Width, textBorderStroke.StrokeStyle); if (textDeviceBrush.BrushDX != null && !IsInHitTest) { RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)(rect.X + textMargin + strokePixAdjust), (float)(rect.Y + textMargin + strokePixAdjust)), textLayout, textDeviceBrush.BrushDX); } } }
public sealed override Point[] GetSelectionPoints(ChartControl chartControl, ChartScale chartScale) { ChartPanel chartPanel = chartControl.ChartPanels[chartScale.PanelIndex]; Point startPoint = StartAnchor.GetPoint(chartControl, chartPanel, chartScale); Point endPoint = EndAnchor.GetPoint(chartControl, chartPanel, chartScale); if (!ShouldDrawText) { return new[] { startPoint, endPoint } } ; Point textPoint = TextAnchor.GetPoint(chartControl, chartPanel, chartScale); return(new[] { startPoint, textPoint, endPoint }); }