Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        private void OnElementMoved(_Control element, Rect rect)
        {
            AlignCanvas.Clear();

            if (!DesginCanvas.IsAutoAlign)
            {
                return;
            }

            foreach (UIElement ui in DesginCanvas.Children)
            {
                if (DesginCanvas.SelectedControls.Contains(ui as _Control))
                {
                    continue;
                }
                if (ui is _Control)
                {
                    AutoAlignLine alignLine = AlignCanvas.MeasureAlign(element, ui as _Control);
                    if (!alignLine.IsEmpty)
                    {
                        switch (alignLine.AlignType)
                        {
                        case AlignType.Left:
                            element.Left = alignLine.X1;
                            break;

                        case AlignType.Top:
                            element.Top = alignLine.Y1;
                            break;

                        case AlignType.Right:
                            element.Left = alignLine.X1 - element.Width;
                            break;

                        case AlignType.Bottom:
                            element.Top = alignLine.Y1 - element.Height;
                            break;

                        case AlignType.HorizontalCenter:
                            element.Left = alignLine.X1 - element.Width / 2d;
                            break;

                        case AlignType.VerticalCenter:
                            element.Top = alignLine.Y1 - element.Height / 2d;
                            break;
                        }
                        break;
                    }
                }
            }
        }