Example #1
0
        private Point OnLineMoved(_Line source, Point point1, Point point2)
        {
            if (!DesginCanvas.IsAutoAlign)
            {
                return(point1);
            }
            Point a = new Point(point1.X + source.Left, point1.Y + source.Top);
            Point b = new Point(point2.X + source.Left, point2.Y + source.Top);

            AlignCanvas.Clear();
            Point point = new Point(double.NaN, double.NaN);

            foreach (UIElement ui in DesginCanvas.Children)
            {
                if (DesginCanvas.SelectedControls.Contains(ui as _Control))
                {
                    continue;
                }
                if (ui is _Line)
                {
                    _Line line = ui as _Line;
                    point = AlignCanvas.MeasurePoint(a, b, new Point(line.Line.X1 + line.Left, line.Line.Y1 + line.Top), new Point(line.Line.X2 + line.Left, line.Line.Y2 + line.Top));
                    if (!double.IsNaN(point.X))
                    {
                        return(new Point(point.X - source.Left, point.Y - source.Top));
                    }
                }
                else if (ui is _Rectangle)
                {
                    _Control element = ui as _Control;
                    Point    a1      = new Point(element.Left, element.Top);
                    Point    b1      = new Point(element.Left + element.Width, element.Top);
                    Point    c1      = new Point(element.Left + element.Width, element.Top + element.Height);
                    Point    d1      = new Point(element.Left, element.Top + element.Height);
                    point = AlignCanvas.MeasurePoint(a, b, a1, b1);
                    if (!double.IsNaN(point.X))
                    {
                        return(new Point(point.X - source.Left, point.Y - source.Top));
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, b1, c1)).X))
                    {
                        return(new Point(point.X - source.Left, point.Y - source.Top));
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, c1, d1)).X))
                    {
                        return(new Point(point.X - source.Left, point.Y - source.Top));
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b, d1, a1)).X))
                    {
                        return(new Point(point.X - source.Left, point.Y - source.Top));
                    }
                }
            }

            return(AlignCanvas.Orthogonal(point1, point2));
        }
Example #2
0
        private void OnLinePoint1Adding(_Line source, Point a)
        {
            if (!DesginCanvas.IsAutoAlign)
            {
                return;
            }
            List <Point> points = new List <Point>();

            foreach (UIElement ui in DesginCanvas.Children)
            {
                if (DesginCanvas.SelectedControls.Contains(ui as _Control))
                {
                    continue;
                }
                if (ui is _Line)
                {
                    _Line line  = ui as _Line;
                    Point point = AlignCanvas.MeasurePoint(a, new Point(line.Line.X1 + line.Left, line.Line.Y1 + line.Top), new Point(line.Line.X2 + line.Left, line.Line.Y2 + line.Top));
                    if (!double.IsNaN(point.X))
                    {
                        points.Add(point);
                    }
                }
                else if (ui is _Rectangle)
                {
                    _Control element = ui as _Control;
                    Point    a1      = new Point(element.Left, element.Top);
                    Point    b1      = new Point(element.Left + element.Width, element.Top);
                    Point    c1      = new Point(element.Left + element.Width, element.Top + element.Height);
                    Point    d1      = new Point(element.Left, element.Top + element.Height);
                    Point    point   = AlignCanvas.MeasurePoint(a, a1, b1);
                    if (!double.IsNaN(point.X))
                    {
                        points.Add(point);
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, b1, c1)).X))
                    {
                        points.Add(point);
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, c1, d1)).X))
                    {
                        points.Add(point);
                    }
                    else if (!double.IsNaN((point = AlignCanvas.MeasurePoint(a, d1, a1)).X))
                    {
                        points.Add(point);
                    }
                }
            }

            AlignCanvas.DrawAlignPoints(points);
        }