Beispiel #1
0
        private void SetEditControl(UIElement toolObject, bool isDragObject)
        {
            if (toolObject.GetType() == typeof(ResizeHandle))
            {
                this.isHandle = true;

                ResizeHandles.SelectedElement = toolObject;

                return;
            }

            if (!KeyActions.IsCtrlPressed)
            {
                ResizeHandles.RemoveHandles();
            }

            ResizeHandles.SelectedElement = toolObject;

            ResizeHandles.SelectedElement.ShowHandles(this);

            if (!isDragObject)
            {
                this.AddReportToolItem(toolObject);

                toolObject.UpdateLayout();

                toolObject.MoveHandles();
            }

            Guid elementId = toolObject.GetElementId();

            this.ReportObjectSelected?.Invoke(toolObject);
        }
Beispiel #2
0
        private void SectionCanvas_Seleced(object sender, MouseButtonEventArgs e)
        {
            ResizeHandles.RemoveHandles();

            ResizeHandles.SelectedElement = null;

            this.ReportObjectSelected?.Invoke(null);
        }
Beispiel #3
0
        protected override void OnPreviewMouseMove(MouseEventArgs e)
        {
            base.OnPreviewMouseMove(e);

            if (this.IsMouseCaptured)
            {
                if (this.isDragging)
                {
                    Point currentPosition = e.GetPosition(this);

                    double originalLeft = Canvas.GetLeft(ResizeHandles.SelectedElement);

                    double originalTop = Canvas.GetTop(ResizeHandles.SelectedElement);

                    double elementWidth = ResizeHandles.SelectedElement.GetPropertyValue("ActualWidth").ToDouble();

                    double elementHeigth = ResizeHandles.SelectedElement.GetPropertyValue("ActualHeight").ToDouble();

                    double elementLeft = (currentPosition.X - this.startPoint.X) + this.selectedElementOrigins.X;

                    double elementTop = (currentPosition.Y - this.startPoint.Y) + this.selectedElementOrigins.Y;

                    double offsetLeft = elementLeft - originalLeft;

                    double offsetTop = elementTop - originalTop;

                    if (elementLeft < 0)
                    {
                        elementLeft = this.isHandle ? ResizeHandles.HandleSize * -1 : 0;
                    }

                    if (elementTop < 0)
                    {
                        elementTop = this.isHandle ? ResizeHandles.HandleSize * -1 : 0;
                    }

                    if (this.isHandle)
                    {
                        // This moves the handle block
                        ResizeHandles.MoveObject(base.ActualWidth, base.ActualHeight, elementLeft, elementWidth, elementTop, elementHeigth);

                        ResizeHandles.SelectedElement.ResizeElements(elementTop, elementLeft);
                    }
                    else
                    {
                        ResizeHandles.MoveObjects(base.ActualWidth, base.ActualHeight,
                                                  elementLeft, elementWidth, elementTop, elementHeigth,
                                                  offsetLeft, offsetTop);
                    }
                }
            }
        }
Beispiel #4
0
        public static void MoveObjects(double canvasWidth,
                                       double canvasHeight,
                                       double elementLeft,
                                       double elementWidth,
                                       double elementTop,
                                       double elementHeigth,
                                       double offsetLeft,
                                       double offsetTop
                                       )
        {
            ResizeHandles.MoveObject(canvasWidth, canvasHeight, elementLeft, elementWidth, elementTop, elementHeigth);

            ResizeHandles.SelectedElement.MoveHandles();

            Guid elementId = SelectedElement.GetElementId();

            foreach (UIElement item in canvaselements.Values)
            {
                if (elementId == item.GetElementId())
                {
                    continue;
                }

                SectionCanvas itemCanvas = item.FindParentControlBase(typeof(SectionCanvas)) as SectionCanvas;

                double canvasItemWidth = ResizeHandles.SelectedElement.GetPropertyValue("ActualWidth").ToDouble();

                double canvasItemHeigth = ResizeHandles.SelectedElement.GetPropertyValue("ActualHeight").ToDouble();

                double canvasItemLeft = Canvas.GetLeft(item) + offsetLeft;

                double canvasItemTop = Canvas.GetTop(item) + offsetTop;

                if (canvasItemLeft <= 0 ||
                    canvasItemTop <= 0 ||
                    (canvasItemLeft + canvasItemWidth) > itemCanvas.ActualWidth ||
                    (canvasItemTop + canvasItemHeigth) > itemCanvas.ActualHeight)
                {
                    continue;
                }

                Canvas.SetLeft(item, canvasItemLeft);

                Canvas.SetTop(item, canvasItemTop);

                item.MoveHandles();
            }
        }