Пример #1
0
        private void DragTop(double scale, DesignerItem item, SelectionService selectionService)
        {
            IEnumerable <DesignerItem> groupItems = selectionService.GetGroupMembers(item).Cast <DesignerItem>();
            double groupBottom = Canvas.GetTop(item) + item.Height;

            foreach (DesignerItem groupItem in groupItems)
            {
                double groupItemTop = Canvas.GetTop(groupItem);
                double delta        = (groupBottom - groupItemTop) * (scale - 1);
                Canvas.SetTop(groupItem, groupItemTop - delta);
                groupItem.Height = groupItem.ActualHeight * scale;
            }
        }
Пример #2
0
        private void DragLeft(double scale, DesignerItem item, SelectionService selectionService)
        {
            IEnumerable <DesignerItem> groupItems = selectionService.GetGroupMembers(item).Cast <DesignerItem>();

            double groupLeft = Canvas.GetLeft(item) + item.Width;

            foreach (DesignerItem groupItem in groupItems)
            {
                double groupItemLeft = Canvas.GetLeft(groupItem);
                double delta         = (groupLeft - groupItemLeft) * (scale - 1);
                Canvas.SetLeft(groupItem, groupItemLeft - delta);
                groupItem.Width = groupItem.ActualWidth * scale;
            }
        }
Пример #3
0
        void DragThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = this.DataContext as DesignerItem;
            DesignerCanvas designer     = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft = double.MaxValue;
                double minTop  = double.MaxValue;

                // we only move DesignerItems
                var designerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>();

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    minLeft = double.IsNaN(left) ? 0 : Math.Min(left, minLeft);
                    minTop  = double.IsNaN(top) ? 0 : Math.Min(top, minTop);
                }

                double deltaHorizontal = Math.Max(-minLeft, e.HorizontalChange);
                double deltaVertical   = Math.Max(-minTop, e.VerticalChange);

                foreach (DesignerItem item in designerItems)
                {
                    double left = Canvas.GetLeft(item);
                    double top  = Canvas.GetTop(item);

                    if (double.IsNaN(left))
                    {
                        left = 0;
                    }
                    if (double.IsNaN(top))
                    {
                        top = 0;
                    }

                    Canvas.SetLeft(item, left + deltaHorizontal);
                    Canvas.SetTop(item, top + deltaVertical);
                }

                designer.InvalidateMeasure();
                e.Handled = true;
            }
        }
Пример #4
0
        void ResizeThumb_DragDelta(object sender, DragDeltaEventArgs e)
        {
            DesignerItem   designerItem = this.DataContext as DesignerItem;
            DesignerCanvas designer     = VisualTreeHelper.GetParent(designerItem) as DesignerCanvas;

            if (designerItem != null && designer != null && designerItem.IsSelected)
            {
                double minLeft, minTop, minDeltaHorizontal, minDeltaVertical;
                double dragDeltaVertical, dragDeltaHorizontal, scale;

                IEnumerable <DesignerItem> selectedDesignerItems = designer.SelectionService.CurrentSelection.OfType <DesignerItem>();

                CalculateDragLimits(selectedDesignerItems, out minLeft, out minTop,
                                    out minDeltaHorizontal, out minDeltaVertical);

                foreach (DesignerItem item in selectedDesignerItems)
                {
                    if (item != null && item.ParentID == Guid.Empty)
                    {
                        switch (base.VerticalAlignment)
                        {
                        case VerticalAlignment.Bottom:
                            dragDeltaVertical = Math.Min(-e.VerticalChange, minDeltaVertical);
                            scale             = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight;
                            DragBottom(scale, item, designer.SelectionService);
                            break;

                        case VerticalAlignment.Top:
                            double top = Canvas.GetTop(item);
                            dragDeltaVertical = Math.Min(Math.Max(-minTop, e.VerticalChange), minDeltaVertical);
                            scale             = (item.ActualHeight - dragDeltaVertical) / item.ActualHeight;
                            DragTop(scale, item, designer.SelectionService);
                            break;

                        default:
                            break;
                        }

                        switch (base.HorizontalAlignment)
                        {
                        case HorizontalAlignment.Left:
                            double left = Canvas.GetLeft(item);
                            dragDeltaHorizontal = Math.Min(Math.Max(-minLeft, e.HorizontalChange), minDeltaHorizontal);
                            scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth;
                            DragLeft(scale, item, designer.SelectionService);
                            break;

                        case HorizontalAlignment.Right:
                            dragDeltaHorizontal = Math.Min(-e.HorizontalChange, minDeltaHorizontal);
                            scale = (item.ActualWidth - dragDeltaHorizontal) / item.ActualWidth;
                            DragRight(scale, item, designer.SelectionService);
                            break;

                        default:
                            break;
                        }
                    }
                }
                e.Handled = true;
            }
        }