Exemplo n.º 1
0
        public void OnMouseDown(Point mousePosition, EditorOperationHitTest hitTest, IEditorOperationalContext context)
        {
            if (hitTest.ResizeHandle == null || element == null)
            {
                // Not resizing
                element = null;
                return;
            }

            Log.LogInformation($"Starting resize on {hitTest.ResizeHandle.Value} handle");

            initialMousePosition = mousePosition;
            initialLocation      = element.Layout.Location;
            initialSize          = element.Layout.Size;
            mode       = hitTest.ResizeHandle.Value;
            isResizing = true;
        }
Exemplo n.º 2
0
        protected void SizeComponent(PositionalComponent component, Primitives.Point start, Primitives.Point end, double gridSize)
        {
            // reverse points if necessary
            Primitives.Point newStart = start;
            Primitives.Point newEnd   = end;
            bool             switched = false;

            if (start.X < end.X)
            {
                newStart = end;
                newEnd   = start;
                switched = true;
            }

            if (true) // snap to grid
            {
                if (Math.IEEERemainder(newStart.X, 20d) != 0)
                {
                    newStart = newStart.WithNewX(newStart.SnapToGrid(gridSize).X);
                }
                if (Math.IEEERemainder(newStart.Y, 20d) != 0)
                {
                    newStart = newStart.WithNewY(newStart.SnapToGrid(gridSize).Y);
                }
                if (Math.IEEERemainder(newEnd.X, 20d) != 0)
                {
                    newEnd = newEnd.WithNewX(newEnd.SnapToGrid(gridSize).X);
                }
                if (Math.IEEERemainder(newEnd.Y, 20d) != 0)
                {
                    newEnd = newEnd.WithNewY(newEnd.SnapToGrid(gridSize).Y);
                }
            }
            if (true) // snap to horizontal or vertical
            {
                double height  = Math.Max(newStart.Y, newEnd.Y) - Math.Min(newStart.Y, newEnd.Y);
                double length  = Math.Sqrt(Math.Pow(newEnd.X - newStart.X, 2d) + Math.Pow(newEnd.Y - newStart.Y, 2d));
                double bearing = Math.Acos(height / length) * (180 / Math.PI);

                if (bearing <= 45 && switched)
                {
                    newStart = newStart.WithNewX(newEnd.X);
                }
                else if (bearing <= 45 && !switched)
                {
                    newEnd = newEnd.WithNewX(newStart.X);
                }
                else if (bearing > 45 && switched)
                {
                    newStart = newStart.WithNewY(newEnd.Y);
                }
                else
                {
                    newEnd = newEnd.WithNewY(newStart.Y);
                }
            }

            if (newStart.X > newEnd.X || newStart.Y > newEnd.Y)
            {
                component.Layout.Location = new Primitives.Point(newEnd.X, newEnd.Y);
                if (newStart.X == newEnd.X)
                {
                    component.Layout.Size        = newStart.Y - newEnd.Y;
                    component.Layout.Orientation = Orientation.Vertical;
                }
                else
                {
                    component.Layout.Size        = newStart.X - newEnd.X;
                    component.Layout.Orientation = Orientation.Horizontal;
                }
            }
            else
            {
                component.Layout.Location = new Primitives.Point(newStart.X, newStart.Y);
                if (newStart.X == newEnd.X)
                {
                    component.Layout.Size        = newEnd.Y - newStart.Y;
                    component.Layout.Orientation = Orientation.Vertical;
                }
                else
                {
                    component.Layout.Size        = newEnd.X - newStart.X;
                    component.Layout.Orientation = Orientation.Horizontal;
                }
            }

            var description = descriptionLookup.GetDescription(component.Type);

            //FlagOptions flagOptions = ApplyFlags(component);
            //if ((flagOptions & FlagOptions.HorizontalOnly) == FlagOptions.HorizontalOnly && component.Layout.Orientation == Orientation.Vertical)
            //{
            //    component.Layout.Orientation = Orientation.Horizontal;
            //    component.Layout.Size = component.Layout.Description.MinSize;
            //}
            //else if ((flagOptions & FlagOptions.VerticalOnly) == FlagOptions.VerticalOnly && component.Layout.Orientation == Orientation.Horizontal)
            //{
            //    component.Layout.Orientation = Orientation.Vertical;
            //    component.Layout.Size = component.Layout.Description.MinSize;
            //}

            double minAllowedSize = Math.Max(description.MinSize, gridSize);

            if (component.Layout.Size < minAllowedSize)
            {
                component.Layout.Size = minAllowedSize;
            }
        }