Exemplo n.º 1
0
        private void DrawFormattedTextCore(SystemMedia.FormattedText formattedText, Vector2D origin, double angle = 0)
        {
            var originScreenPoint       = _canvasProxy.ToScreen(origin);
            var nativeOriginScreenPoint = Vector2DAdapter.ConvertToSystemPoint(originScreenPoint);

            //若偏转角度数不为圆周整数整除,则应用偏转角变化;
            if (angle % Math.PI * 2 != 0)
            {
                var rotateTransform = new SystemMedia.RotateTransform {
                    Angle = Extension.RadToDeg(angle),

                    CenterX = nativeOriginScreenPoint.X,
                    CenterY = nativeOriginScreenPoint.Y
                };

                //推入;
                DrawingContext.PushTransform(rotateTransform);

                DrawingContext.DrawText(formattedText, nativeOriginScreenPoint);

                //出栈;
                DrawingContext.Pop();
            }
            else
            {
                DrawingContext.DrawText(formattedText, nativeOriginScreenPoint);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 以视图坐标为标准,绘制椭圆;
        /// </summary>
        /// <param name="rectangle">以视图坐标为准的矩形</param>
        /// <param name="brush">填充色</param>
        /// <param name="pen">笔</param>
        public void NativeDrawEllipse(Brush brush, Pen pen, Vector2D center, double radiusX, double radiusY)
        {
            if (center == null)
            {
                throw new ArgumentNullException(nameof(center));
            }

            var centerPoint = Vector2DAdapter.ConvertToSystemPoint(center);

            DrawingContext.DrawEllipse(
                BrushAdapter.ConvertToSystemBrush(brush),
                PenAdapter.ConverterToSystemPen(pen),
                centerPoint,
                radiusX,
                radiusY
                );
        }
Exemplo n.º 3
0
        /// <summary>
        /// 以视图坐标为标准,绘制矩形;
        /// </summary>
        /// <param name="rectangle">以视图坐标为准的矩形</param>
        /// <param name="brush">填充色</param>
        /// <param name="pen">笔</param>
        public void NativeDrawRectangle(Rectangle2D2 rectangle, Brush brush, Pen pen)
        {
            if (rectangle == null)
            {
                throw new ArgumentNullException(nameof(rectangle));
            }

            ValidateDrawingContext();

            var vertexes = rectangle.GetVertexes();

            NativeDrawFill(
                vertexes.Select(p => Vector2DAdapter.ConvertToSystemPoint(p)),
                BrushAdapter.ConvertToSystemBrush(brush),
                PenAdapter.ConverterToSystemPen(pen)
                );
        }
Exemplo n.º 4
0
        /// <summary>
        /// 绘制文字;
        /// </summary>
        /// <param name="text"></param>
        /// <param name="emSize"></param>
        /// <param name="foreground"></param>
        /// <param name="origin"></param>
        public void DrawText(string text, double emSize, Brush foreground, Vector2D origin, double angle = 0)
        {
            ValidateDrawingContext();

            var originScreenPoint       = _canvasProxy.ToScreen(origin);
            var nativeOriginScreenPoint = Vector2DAdapter.ConvertToSystemPoint(originScreenPoint);

            var ft = new SystemMedia.FormattedText(
                text,
                System.Globalization.CultureInfo.CurrentCulture,
                FlowDirection.LeftToRight, TypeFace,
                emSize,
                BrushAdapter.ConvertToSystemBrush(foreground)
                );

            DrawFormattedTextCore(ft, origin, angle);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 以视图坐标为标准,绘制线段;
        /// </summary>
        /// <param name="rectangle">以视图坐标为准的矩形</param>
        /// <param name="brush">填充色</param>
        /// <param name="pen">笔</param>
        public void NativeDrawLine(Pen pen, Line2D line2D)
        {
            if (pen == null)
            {
                return;
            }

            if (line2D == null)
            {
                throw new ArgumentNullException(nameof(line2D));
            }

            ValidateDrawingContext();

            //平台转换后再进行绘制;
            DrawingContext.DrawLine(
                PenAdapter.ConverterToSystemPen(pen),
                Vector2DAdapter.ConvertToSystemPoint(line2D.Start),
                Vector2DAdapter.ConvertToSystemPoint(line2D.End)
                );
        }
Exemplo n.º 6
0
        /// <summary>
        /// 绘制线段;
        /// </summary>
        /// <param name="pen"></param>
        /// <param name="line"></param>
        public void DrawLine(Pen pen, Line2D line)
        {
            if (pen == null)
            {
                return;
            }

            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            ValidateDrawingContext();

            var screenPoint1 = _canvasProxy.ToScreen(line.Start);
            var screenPoint2 = _canvasProxy.ToScreen(line.End);

            //平台转换后再进行绘制;
            DrawingContext.DrawLine(
                PenAdapter.ConverterToSystemPen(pen),
                Vector2DAdapter.ConvertToSystemPoint(screenPoint1),
                Vector2DAdapter.ConvertToSystemPoint(screenPoint2)
                );
        }
Exemplo n.º 7
0
 /// <summary>
 /// 从坐标节点转换为以当前画布视图为标准的屏幕(系统)节点;
 /// </summary>
 /// <returns></returns>
 private Point ConvertVectorToScreenPoint(Vector2D point) => Vector2DAdapter.ConvertToSystemPoint(_canvasProxy.ToScreen(point));
Exemplo n.º 8
0
 public Vector2D GetNativePosition()
 {
     return(Vector2DAdapter.ConverterToVector2D(
                SystemInput.Mouse.GetPosition(_inputElement)
                ));
 }