Exemplo n.º 1
0
        protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes)
        {
            if (drawingContext == null)
            {
                throw new ArgumentNullException("drawingContext");
            }
            if (null == drawingAttributes)
            {
                throw new ArgumentNullException("drawingAttributes");
            }
            Pen pen = new Pen
            {
                StartLineCap = PenLineCap.Round,
                EndLineCap   = PenLineCap.Round,
                Brush        = new SolidColorBrush(drawingAttributes.Color),
                Thickness    = drawingAttributes.Width
            };

            BrushConverter    bc         = new BrushConverter();
            Brush             BackGround = (Brush)bc.ConvertFromString(drawingAttributes.GetPropertyData(DrawAttributesGuid.BackgroundColor).ToString());
            GeometryConverter gc         = new GeometryConverter();
            Geometry          geometry   = (Geometry)gc.ConvertFromString(string.Format("M {0},{1} {2},{3} {4},{5} Z", StylusPoints[0].X, StylusPoints[1].Y, (Math.Abs(StylusPoints[1].X - StylusPoints[0].X)) / 2 + StylusPoints[0].X, StylusPoints[0].Y, StylusPoints[1].X, StylusPoints[1].Y));
            GeometryDrawing   gd         = new GeometryDrawing(BackGround, pen, geometry);

            drawingContext.DrawDrawing(gd);
        }
Exemplo n.º 2
0
        private ModernButton GetBackButton()
        {
            GeometryConverter geomConvert = new GeometryConverter();
            Geometry          iconData    = (Geometry)geomConvert.ConvertFromString("F1 M 57,42L 57,34L 32.25,34L 42.25,24L 31.75,24L 17.75,38L 31.75,52L 42.25,52L 32.25,42L 57,42 Z ");
            ModernButton      buttonBack  = new ModernButton();

            buttonBack.EllipseDiameter = 30;
            buttonBack.IconHeight      = 20;
            buttonBack.IconWidth       = 20;
            buttonBack.ToolTip         = "Atrás";
            buttonBack.IconData        = iconData;
            buttonBack.IsEnabled       = false;

            return(buttonBack);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 绘制线
        /// </summary>
        /// <param name="point">数据</param>
        public virtual void ShowLine(ObservableCollection <Point> points)
        {
            bool  isFirstPoint      = true;
            Point lastPointPosition = new Point();//上一个点的位置

            if (points != null)
            {
                foreach (Point point in points)
                {
                    Ellipse p1 = new Ellipse();
                    p1.Height    = 1;
                    p1.Width     = 1;
                    p1.MaxHeight = 1;
                    p1.MaxWidth  = 1;
                    p1.Fill      = Brushes.Black;
                    //位置坐标对齐圆心所以要减去0.5
                    Point pointPosition = DataToPrintPoint(point, 0, 0);
                    //Canvas.SetLeft(p1, pointPosition.X);
                    //Canvas.SetBottom(p1, pointPosition.Y);
                    //ChartArea.DataArea.Children.Add(p1);

                    if (!isFirstPoint)
                    {
                        #region create method3

                        Path pp3 = new Path();

                        //pp3.Data

                        pp3.Stroke = new SolidColorBrush(Colors.Black);

                        pp3.StrokeThickness = 0.8;

                        GeometryConverter gc = new GeometryConverter();
                        pp3.Data = (Geometry)gc.ConvertFromString("M " + lastPointPosition.X + "," + lastPointPosition.Y + " " + pointPosition.X + "," + pointPosition.Y);
                        ChartArea.DataArea.Children.Add(pp3);
                    }
                    else
                    {
                        isFirstPoint = false;
                    }
                    #endregion

                    lastPointPosition = pointPosition;
                }
            }
        }
Exemplo n.º 4
0
 void drawWidthPath(string strPath)
 {
     if (mazeWidthPath == null || gc2 == null)
     {
         mazeWidthPath                 = new Path();
         gc2                           = new GeometryConverter();
         mazeWidthPath.Stroke          = Brushes.Blue;
         mazeWidthPath.StrokeThickness = 3;
         Grid.SetRowSpan(mazeWidthPath, md.Height);
         Grid.SetColumnSpan(mazeWidthPath, md.Width);
     }
     if (!gMaze.Children.Contains(mazeWidthPath))
     {
         gMaze.Children.Add(mazeWidthPath);
     }
     mazeWidthPath.Data = (Geometry)gc2.ConvertFromString(strPath);
 }
Exemplo n.º 5
0
        private GeometryDrawing ConvertPath(XElement path)
        {
            var data = path.Attribute("d")?.Value;

            if (geometryConverter.ConvertFromString(data) is Geometry geometry)
            {
                double.TryParse(path.Attribute("stroke-width")?.Value, out var strokeWidth);
                var fill   = GetColorBrush(path, "fill");
                var stroke = GetColorBrush(path, "stroke");
                var pen    = stroke != null && strokeWidth > 0 ? new Pen(stroke, strokeWidth) : null;
                return(new GeometryDrawing(fill, pen, geometry));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        void DrawLine(FrameworkElement element, Point newpoint)
        {
            double left, top, right, bottom;

            if (element == null)
            {
                return;
            }
            double a1, a2, a3, a4, a5, a6;

            a1 = grid.Margin.Left + grid.ActualWidth * 0.25;
            a2 = grid.Margin.Top + grid.ActualHeight * 0.5;
            a3 = newpoint.X;
            a4 = newpoint.Y;
            a5 = grid.Margin.Left + grid.ActualWidth * 0.75;
            a6 = grid.Margin.Top + grid.ActualHeight * 0.5;

            left   = newpoint.X;
            top    = newpoint.Y;
            right  = this.ActualWidth - (left + element.ActualWidth);
            bottom = this.ActualHeight - (top + element.ActualHeight);

            if (bottom < 0)
            {
                path.Margin = new Thickness(path.Margin.Left, path.Margin.Top, path.Margin.Right, bottom);
            }
            if (right < 0)
            {
                path.Margin = new Thickness(path.Margin.Left, path.Margin.Top, right, path.Margin.Bottom);
            }

            element.Margin = new Thickness(left, top, right, bottom);


            GeometryConverter gc = new GeometryConverter();

            path.Data = (Geometry)gc.ConvertFromString(string.Format("M{0},{1} L{2},{3} L{4},{5}", a1, a2, a3, a4, a5, a6));
        }
Exemplo n.º 7
0
        public void NewMethod()
        {
            //#region create method 1

            //Path path = new Path();

            //PathGeometry pathGeometry = new PathGeometry();

            //PathFigure pathFigure = new PathFigure();

            //pathFigure.StartPoint = new Point(400, 300);

            //PathSegmentCollection segmentCollection = new PathSegmentCollection();

            //segmentCollection.Add(new LineSegment() { Point = new Point(600, 100) });

            //pathFigure.Segments = segmentCollection;

            //pathGeometry.Figures = new PathFigureCollection() { pathFigure };

            //path.Data = pathGeometry;

            //path.Stroke = new SolidColorBrush(Colors.BlueViolet);

            //path.StrokeThickness = 3;

            //main.Children.Add(path);

            //#endregion



            //#region create method2

            //Path pp = new Path();

            //pp.Stroke = new SolidColorBrush(Colors.Blue);

            //pp.StrokeThickness = 3;

            //StreamGeometry geometry = new StreamGeometry();

            //geometry.FillRule = FillRule.Nonzero; //声前F0还是F1,现在是F1

            //using (StreamGeometryContext ctx = geometry.Open())

            //{

            //    ctx.BeginFigure(new Point(30, 60), true, true);

            //    ctx.LineTo(new Point(150, 600), true, false);

            //}

            //geometry.Freeze();

            //pp.Data = geometry;

            //main.Children.Add(pp);

            //#endregion



            #region create method3

            Path pp3 = new Path();

            //pp3.Data

            pp3.Stroke = new SolidColorBrush(Colors.Red);

            pp3.StrokeThickness = 3;

            GeometryConverter gc = new GeometryConverter();

            pp3.Data = (Geometry)gc.ConvertFromString("M 20,30 500,100");

            main.Children.Add(pp3);

            #endregion
        }
Exemplo n.º 8
0
        public void Connect()
        {
            Rect bb1 = new Rect(Start.GetShowItem().Margin.Left,
                                Start.GetShowItem().Margin.Top,
                                Start.GetShowItem().Width,
                                Start.GetShowItem().Height);
            Rect bb2 = new Rect(End.GetShowItem().Margin.Left,
                                End.GetShowItem().Margin.Top,
                                End.GetShowItem().Width,
                                End.GetShowItem().Height);

            Point[] p = new Point[] {
                new Point {
                    X = bb1.X + bb1.Width / 2, Y = bb1.Y - 1
                },
                new Point {
                    X = bb1.X + bb1.Width / 2, Y = bb1.Y + bb1.Height + 1
                },
                new Point {
                    X = bb1.X - 1, Y = bb1.Y + bb1.Height / 2
                },
                new Point {
                    X = bb1.X + bb1.Width + 1, Y = bb1.Y + bb1.Height / 2
                },
                new Point {
                    X = bb2.X + bb2.Width / 2, Y = bb2.Y - 1
                },
                new Point {
                    X = bb2.X + bb2.Width / 2, Y = bb2.Y + bb2.Height + 1
                },
                new Point {
                    X = bb2.X - 1, Y = bb2.Y + bb2.Height / 2
                },
                new Point {
                    X = bb2.X + bb2.Width + 1, Y = bb2.Y + bb2.Height / 2
                }
            };

            List <double> dis            = new List <double>();
            Dictionary <double, int[]> d = new Dictionary <double, int[]>();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 4; j < 8; j++)
                {
                    double dx = Math.Abs(p[i].X - p[j].X),
                           dy = Math.Abs(p[i].Y - p[j].Y);

                    if ((i == j - 4) || (((i != 3 && j != 6) || p[i].X < p[j].X) && ((i != 2 && j != 7) || p[i].X > p[j].X) && ((i != 0 && j != 5) || p[i].Y > p[j].Y) && ((i != 1 && j != 4) || p[i].Y < p[j].Y)))
                    {
                        dis.Add(dx + dy);
                        d[dis[dis.Count - 1]] = new int[] { i, j };
                    }
                }
            }
            int[] res = { 0, 4 };
            if (dis.Count == 0)
            {
                res[0] = 0; res[1] = 4;
            }
            else
            {
                res = d[dis.Min()];
            }
            double x1  = p[res[0]].X,
                   y1  = p[res[0]].Y,
                   x4  = p[res[1]].X,
                   y4  = p[res[1]].Y;
            double dx1 = Math.Max(Math.Abs(x1 - x4) / 2, 10),
                   dy1 = Math.Max(Math.Abs(y1 - y4) / 2, 10);

            double x2 = (new double[] { x1, x1, x1 - dx1, x1 + dx1 })[res[0]],
                   y2 = (new double[] { y1 - dy1, y1 + dy1, y1, y1 })[res[0]],
                   x3 = (new double[] { 0, 0, 0, 0, x4, x4, x4 - dx1, x4 + dx1 })[res[1]],
                   y3 = (new double[] { 0, 0, 0, 0, y1 + dy1, y1 - dy1, y4, y4 })[res[1]];

            string strPath = "M " + x1 + ", " + y1 + " C " + x2 + ", " + y2 + " " + x3 + ", " + y3 + " " + x4 + ", " + y4 + "";

            //画箭头
            double arr_angle = (30.0 / 180) * Math.PI;
            double angle     = Math.Atan((y3 - y4) / (x3 - x4));

            if (angle == 0.0 && (x3 - x4) < 0)
            {
                angle = Math.PI;
            }

            double sin1 = Math.Sin(angle - arr_angle);
            double cos1 = Math.Cos(angle - arr_angle);
            double sin2 = Math.Sin(angle + arr_angle);
            double cos2 = Math.Cos(angle + arr_angle);
            double x5   = x4 + 10 * cos1,
                   y5   = y4 + 10 * sin1,
                   x6   = x4 + 10 * cos2,
                   y6   = y4 + 10 * sin2;

            strPath += " L " + x5 + ", " + y5 + " M " + x4 + ", " + y4 + " L " + x6 + ", " + y6 + "";
            //strPath += " L " + x5 + ", " + y5;

            GeometryConverter gc = new GeometryConverter();

            (Show_item as Path).Data = (Geometry)gc.ConvertFromString(strPath);
        }
Exemplo n.º 9
0
        public void DynamicDraw(Point dest)
        {
            GeometryConverter gc = new GeometryConverter();

            (Show_item as Path).Data = (Geometry)gc.ConvertFromString("M " + start_pt.X + "," + start_pt.Y + " " + dest.X + ", " + dest.Y);
        }