public override void Draw(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { base.Draw(canvas, canvasProxy); //检查两个关键位置是否为空; if (MousePositionTracker.LastMouseDownPosition == null || MousePositionTracker.CurrentHoverPosition == null) { return; } //绘制当前随鼠标位置移动的编辑线段; //绘制本次尚未完成的线段的起始点小正方形; var lastMouseDownScreenPosition = canvasProxy.ToScreen(MousePositionTracker.LastMouseDownPosition); var sideLength = HighLightRectLength; var startEditRect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(lastMouseDownScreenPosition, sideLength, sideLength); canvas.NativeDrawRectangle(startEditRect, HighLightRectColorBrush, LinePen); //在外部加入了动态输入,此时显示线段编辑状态多余; //DrawEditingLineState(canvas, canvasProxy); }
/// <summary> /// 绘制选择状态; /// </summary> /// <param name="canvas"></param> private void DrawSelectedState(ICanvas canvas, ICanvasScreenConvertable canvasProxy) { if (!IsSelected) { return; } if (Ellipse2D == null) { return; } if (Ellipse2D.Center == null) { return; } var centerScreenPoint = canvasProxy.ToScreen(Ellipse2D.Center); var screenRadiusX = canvasProxy.ToScreen(Ellipse2D.RadiusX); var screenRadiusY = canvasProxy.ToScreen(Ellipse2D.RadiusY); var rectLength = TolerantedScreenLength; //依次绘制左、下、右、上、圆心的矩形; var points = new Vector2D[] { new Vector2D(centerScreenPoint.X - screenRadiusX, centerScreenPoint.Y), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y - screenRadiusY), new Vector2D(centerScreenPoint.X + screenRadiusX, centerScreenPoint.Y), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y + screenRadiusY), new Vector2D(centerScreenPoint.X, centerScreenPoint.Y), }; foreach (var point in points) { var rect = NativeGeometryExtensions.GetNativeSuroundingScreenRect(point, rectLength, rectLength); canvas.NativeDrawRectangle(rect, HighLightEllipseColorBrush, HighLightLinePen); } }