Пример #1
0
        /// <summary>
        /// Create menu entries to distribute shapes evenly over horizontal or vertical space.
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="element"></param>
        protected void DistributeMenuItems(MenuBase menu, ShapeSizeViewModelBase element)
        {
            try
            {
                if (element != null)
                {
                    MenuItem submenu = new MenuItem()
                    {
                        Header = "Distribute"
                    };
                    menu.Items.Add(submenu);

                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Distribute Horizontally",
                        Command          = element.DestributeShapes,
                        CommandParameter = Destribute.Horizontally
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Distribute Vertically",
                        Command          = element.DestributeShapes,
                        CommandParameter = Destribute.Vertically
                    });
                }
            }
            catch
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Align all selected shapes (if any) to a given shape <paramref name="shape"/>.
        /// The actual alignment operation performed is defined by the <paramref name="alignmentOption"/> parameter.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="alignmentOption"></param>
        void IShapeParent.AlignShapes(ShapeSizeViewModelBase shape, AlignShapes alignmentOption)
        {
            if (shape == null)
            {
                return;
            }

            double YShapeCenter = shape.Top + (shape.Height / 2);
            double XShapeCenter = shape.Left + (shape.Width / 2);
            double shapeRight   = shape.Position.X + shape.Width;

            foreach (var item in this.SelectedItem.Shapes.OfType <ShapeSizeViewModelBase>())
            {
                if (shape == item) // Adjust shape to itself is a superflous operation
                {
                    continue;
                }

                switch (alignmentOption)
                {
                case AlignShapes.Bottom:
                    item.MoveEndPosition(new Point(item.EndPosition.X, shape.EndPosition.Y));
                    break;

                case AlignShapes.CenteredHorizontal:
                    item.MovePosition(new Point(item.Position.X, YShapeCenter - (item.Height / 2)));
                    break;

                case AlignShapes.CenteredVertical:
                    item.MovePosition(new Point(XShapeCenter - (item.Width / 2), item.Position.Y));
                    break;

                case AlignShapes.Left:
                    item.MovePosition(new Point(shape.Position.X, item.Position.Y));
                    break;

                case AlignShapes.Right:
                    item.MovePosition(new Point(shapeRight - item.Width, item.Position.Y));
                    break;

                case AlignShapes.Top:
                    item.MovePosition(new Point(item.Position.X, shape.Top));
                    break;

                default:
                    throw new NotImplementedException(alignmentOption.ToString());
                }
            }
        }
Пример #3
0
        private void SameHeight(ShapeSizeViewModelBase shape)
        {
            if (shape == null)
            {
                return;
            }

            foreach (var item in this.SelectedItem.Shapes.OfType <ShapeSizeViewModelBase>())
            {
                if (shape == item) // Adjust shape to itself is a superflous operation
                {
                    continue;
                }

                item.Height = shape.Height;
            }
        }
Пример #4
0
        /// <summary>
        /// Adjusts width, height, or both, of all selected shapes (if any)
        /// such that they are sized equally to the given <paramref name="shape"/>.
        /// </summary>
        /// <param name="shape"></param>
        /// <param name="option"></param>
        void IShapeParent.AdjustShapesToSameSize(ShapeSizeViewModelBase shape, SameSize option)
        {
            switch (option)
            {
            case SameSize.SameWidth:
                this.SameWidth(shape);
                break;

            case SameSize.SameHeight:
                this.SameHeight(shape);
                break;

            case SameSize.SameWidthandHeight:
                this.SameWidthandHeight(shape);
                break;

            default:
                throw new NotImplementedException(option.ToString());
            }
        }
Пример #5
0
        /// <summary>
        /// Construct commands, bindings, and menu items for shape alignment functions.
        /// (Align Top, Align Center etc).
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="element"></param>
        protected void SameSizeMenuItems(MenuBase menu, ShapeSizeViewModelBase element)
        {
            try
            {
                if (element != null)
                {
                    MenuItem submenu = new MenuItem()
                    {
                        Header = "Same Size"
                    };
                    menu.Items.Add(submenu);

                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Same Width",
                        Command          = element.AdjustShapesToSameSize,
                        CommandParameter = SameSize.SameWidth,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsLeft)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Same Height",
                        Command          = element.AdjustShapesToSameSize,
                        CommandParameter = SameSize.SameHeight,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsTop)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Same Width and Height",
                        Command          = element.AdjustShapesToSameSize,
                        CommandParameter = SameSize.SameWidthandHeight,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsRight)
                    });
                }
            }
            catch
            {
            }
        }
Пример #6
0
        /// <summary>
        /// Construct commands, bindings, and menu items for shape alignment functions.
        /// (Align Top, Align Center etc).
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="element"></param>
        protected void AlignMenuItems(MenuBase menu, ShapeSizeViewModelBase element)
        {
            try
            {
                if (element != null)
                {
                    MenuItem submenu = new MenuItem()
                    {
                        Header = "Align"
                    };
                    menu.Items.Add(submenu);

                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Left",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.Left,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsLeft)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Top",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.Top,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsTop)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Right",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.Right,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsRight)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Bottom",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.Bottom,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsBottom)
                    });
                    submenu.Items.Add(new Separator());
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Centered Horizontal",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.CenteredHorizontal,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsCenteredHorizontal)
                    });
                    submenu.Items.Add(new MenuItem()
                    {
                        Header           = "Align Objects Centered Vertical",
                        Command          = element.AlignShapes,
                        CommandParameter = AlignShapes.CenteredVertical,
                        Icon             = IconImageFactory.Get(IconCommand.AlignObjectsCenteredVertical)
                    });
                }
            }
            catch
            {
            }
        }
Пример #7
0
        /// <summary>
        /// The resize shape function resizes all currently selected
        /// shapes in accordance to the delta contained in the supplied
        /// <paramref name="e"/> parameter.
        ///
        /// Method is based on resize method in
        /// http://www.codeproject.com/Articles/23871/WPF-Diagram-Designer-Part-3
        /// </summary>
        /// <param name="e"></param>
        void IShapeParent.ResizeSelectedShapes(DragDeltaThumbEvent e)
        {
            if (SelectedItem.Shapes.Count == 0)
            {
                return;
            }

            double minLeft = double.MaxValue;
            double minTop = double.MaxValue;
            double minDeltaHorizontal = double.MaxValue;
            double minDeltaVertical = double.MaxValue;
            double dragDeltaVertical, dragDeltaHorizontal;

            // filter for those items that contain a height property and
            // find the min of their min (Height, Width) properties
            foreach (var item in this.SelectedItem.Shapes)
            {
                ShapeSizeViewModelBase shape = item as ShapeSizeViewModelBase;

                if (shape == null) // filter for those items that have a height or width
                {
                    continue;
                }

                minLeft = Math.Min(shape.Left, minLeft);
                minTop  = Math.Min(shape.Top, minTop);

                minDeltaVertical   = Math.Min(minDeltaVertical, shape.Height - shape.MinHeight);
                minDeltaHorizontal = Math.Min(minDeltaHorizontal, shape.Width - shape.MinWidth);
            }

            // Resize currently selected items with regard to min height and width determined before
            foreach (var item in this.SelectedItem.Shapes)
            {
                ShapeSizeViewModelBase shape = item as ShapeSizeViewModelBase;

                if (shape == null) // filter for those items that have a height or width
                {
                    continue;
                }

                switch (e.VerticalAlignment)
                {
                // Changing an element at its bottom changes the its height only
                case VerticalAlignment.Bottom:
                    dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
                    shape.Height      = shape.Height - dragDeltaVertical;
                    break;

                // Changing an element at its top changes the Y position and the height
                case VerticalAlignment.Top:
                    dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
                    shape.Top         = shape.Top + dragDeltaVertical;
                    shape.Height      = shape.Height - dragDeltaVertical;
                    break;
                }

                switch (e.HorizontalAlignment)
                {
                // Changing an element at its left side changes the x position and its width
                case HorizontalAlignment.Left:
                    dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
                    shape.Left          = shape.Left + dragDeltaHorizontal;
                    shape.Width         = shape.Width - dragDeltaHorizontal;
                    break;

                // Changing an element at its right side changes the its width only
                case HorizontalAlignment.Right:
                    dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                    shape.Width         = shape.Width - dragDeltaHorizontal;
                    break;
                }
            }
        }