/// <summary>
 /// Returns a <see cref="PortReshapeHandle"/> for the port at the <paramref name="position"/> and
 /// sets its <see cref="PortReshapeHandle.MinimumSize"/> to <see cref="MinimumSize"/>.
 /// </summary>
 /// <param name="context">The context the handles are created in.</param>
 /// <param name="position">The position the handle shall be created for.</param>
 /// <returns>A <see cref="PortReshapeHandle"/> for the port at the <paramref name="position"/>.</returns>
 public IHandle GetHandle(IInputModeContext context, HandlePositions position)
 {
     return(new PortReshapeHandle(context, port, adapter, position)
     {
         MinimumSize = MinimumSize
     });
 }
        private IHandle CreateHandle(HandlePositions position, Func <ReshapeHandlerBase> reshapeHandlerFactory)
        {
            var reshapeHandler = reshapeHandlerFactory.Invoke();
            var handle         = new NodeGroupHandle(InputModeContext, position, reshapeHandler, Margins);

            reshapeHandler.Handle = handle;
            return(handle);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new instance for <paramref name="port"/> and its <paramref name="adapter"/>.
 /// </summary>
 /// <param name="context">The context of the reshape gesture.</param>
 /// <param name="port">The port whose visualization shall be resized.</param>
 /// <param name="adapter">The adapter whose render size shall be changed.</param>
 /// <param name="position">The position of the handle.</param>
 public PortReshapeHandle(IInputModeContext context, IPort port, NodeStylePortStyleAdapter adapter, HandlePositions position)
 {
     this.context  = context;
     this.position = position;
     this.adapter  = adapter;
     this.port     = port;
     this.Margins  = 4;
 }
Esempio n. 4
0
 public RotatedNodeResizeHandle(HandlePositions position, INode node, IReshapeHandler reshapeHandler, bool symmetricResize)
 {
     this.position        = position;
     this.node            = node;
     this.reshapeHandler  = reshapeHandler;
     this.symmetricResize = symmetricResize;
     portHandles          = new List <IHandle>();
     initialLayout        = new OrientedRectangle(GetNodeBasedOrientedRectangle());
 }
            public NodeGroupHandle(IInputModeContext context, HandlePositions position, IReshapeHandler reshapeHandler, InsetsD margins)
                : base(position, reshapeHandler)
            {
                this.margins = margins;
                this.context = context;

                if ((position & HandlePositions.Vertical) != 0)
                {
                    ReshapePolicy = ReshapePolicy.Vertical;
                }
                else if ((position & HandlePositions.Horizontal) != 0)
                {
                    ReshapePolicy = ReshapePolicy.Horizontal;
                }
                else
                {
                    ReshapePolicy = ReshapePolicy.Projection;
                }
            }
Esempio n. 6
0
            public override IHandle GetHandle(IInputModeContext inputModeContext, HandlePositions position)
            {
                var handle = new NodeReshapeHandlerHandle(Node, ReshapeHandler, position);

                var atCorner = (position & HandlePositions.Corners) != HandlePositions.None;

                if (atCorner)
                {
                    // handles at corners shall always keep the aspect ratio
                    handle.ReshapePolicy          = ReshapePolicy.Projection;
                    handle.RatioReshapeRecognizer = EventRecognizers.Always;
                    handle.Type = HandleTypes.Resize;
                }
                else
                {
                    // handles at the sides shall ignore the aspect ratio and use another handle visualization
                    handle.ReshapePolicy          = ReshapePolicy.None;
                    handle.RatioReshapeRecognizer = EventRecognizers.Never;
                    handle.Type = HandleTypes.Warp;
                }

                return(handle);
            }
Esempio n. 7
0
        /// <summary>
        /// Returns the location of the specified position on the border of the oriented rectangle.
        /// </summary>
        private PointD GetLocation(IOrientedRectangle layout, HandlePositions position)
        {
            if (layout == null)
            {
                return(node.Layout.ToPointD());
            }
            switch (position)
            {
            case HandlePositions.NorthWest:
                return(GetLocation(layout, 0.0, 1.0));

            case HandlePositions.North:
                return(GetLocation(layout, 0.5, 1.0));

            case HandlePositions.NorthEast:
                return(GetLocation(layout, 1.0, 1.0));

            case HandlePositions.East:
                return(GetLocation(layout, 1.0, 0.5));

            case HandlePositions.SouthEast:
                return(GetLocation(layout, 1.0, 0.0));

            case HandlePositions.South:
                return(GetLocation(layout, 0.5, 0.0));

            case HandlePositions.SouthWest:
                return(layout.GetAnchorLocation());

            case HandlePositions.West:
                return(GetLocation(layout, 0.0, 0.5));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 /// <summary>
 /// Returns a <see cref="RotatedNodeResizeHandle"/> for the given position and node.
 /// </summary>
 public IHandle GetHandle(IInputModeContext inputModeContext, HandlePositions position)
 {
     return(new RotatedNodeResizeHandle(position, node, reshapeHandler, false));
 }
 /// <summary>
 /// Calculates the horizontal and vertical factor the mouse movement has to be multiplied with to get the
 /// horizontal and vertical delta for the point (x,y) inside the <paramref name="originalNodeLayout"/>.
 /// </summary>
 /// <param name="x">The horizontal location inside <paramref name="originalNodeLayout"/>.</param>
 /// <param name="y">The vertical location inside <paramref name="originalNodeLayout"/>.</param>
 /// <param name="originalNodeLayout">The original layout of the node to calculate the factors for.</param>
 /// <param name="centered">Whether center resizing is active.</param>
 /// <param name="position">The handle position to calculate the factor for.</param>
 protected abstract PointD GetFactor(double x, double y, RectD originalNodeLayout, bool centered, HandlePositions position);
            protected override PointD GetFactor(double x, double y, RectD originalNodeLayout, bool centered, HandlePositions position)
            {
                var xRatio = centered
            ? 2 * (x - OriginalBounds.CenterX) / OriginalBounds.Width
            : (x - OriginalBounds.X) / OriginalBounds.Width;
                var yRatio = centered
            ? 2 * (y - OriginalBounds.CenterY) / OriginalBounds.Height
            : (y - OriginalBounds.Y) / OriginalBounds.Height;

                double fx = 0;

                if (position.IsAnyWest())
                {
                    fx = centered ? -xRatio : 1 - xRatio;
                }
                else if (position.IsAnyEast())
                {
                    fx = xRatio;
                }
                double fy = 0;

                if (position.IsAnyNorth())
                {
                    fy = centered ? -yRatio : 1 - yRatio;
                }
                else if (position.IsAnySouth())
                {
                    fy = yRatio;
                }
                return(new PointD(fx, fy));
            }
            protected override PointD GetFactor(double x, double y, RectD originalNodeLayout, bool centered, HandlePositions position)
            {
                double fx = 0;

                if ((position & HandlePositions.Vertical) == 0)
                {
                    var boundsWidth = (OriginalBounds.Width - originalNodeLayout.Width);
                    if (boundsWidth <= 0)
                    {
                        fx = centered ? 0 : 0.5;
                    }
                    else
                    {
                        var xRatio = centered
                ? 2 * (originalNodeLayout.CenterX - OriginalBounds.CenterX) / boundsWidth
                : (originalNodeLayout.MinX - OriginalBounds.X) / boundsWidth;
                        if (position.IsAnyWest())
                        {
                            fx = centered ? -xRatio : 1 - xRatio;
                        }
                        else if (position.IsAnyEast())
                        {
                            fx = xRatio;
                        }
                    }
                }
                double fy = 0;

                if ((position & HandlePositions.Horizontal) == 0)
                {
                    var boundsHeight = (OriginalBounds.Height - originalNodeLayout.Height);
                    if (boundsHeight <= 0)
                    {
                        fy = centered ? 0 : 0.5;
                    }
                    else
                    {
                        var yRatio = centered
                ? 2 * (originalNodeLayout.CenterY - OriginalBounds.CenterY) / boundsHeight
                : (originalNodeLayout.MinY - OriginalBounds.Y) / boundsHeight;
                        if (position.IsAnyNorth())
                        {
                            fy = centered ? -yRatio : 1 - yRatio;
                        }
                        else if (position.IsAnySouth())
                        {
                            fy = yRatio;
                        }
                    }
                }

                return(new PointD(fx, fy));
            }
 /// <summary>
 /// Returns if <paramref name="position"/> is <see cref="HandlePositions.NorthEast"/>,
 /// <see cref="HandlePositions.East"/> or <see cref="HandlePositions.SouthEast"/>
 /// </summary>
 /// <param name="position">The position to check.</param>
 /// <returns>If the position is at any of the east sides.</returns>
 public static bool IsAnyEast(this HandlePositions position)
 {
     return((position & (HandlePositions.NorthEast | HandlePositions.East | HandlePositions.SouthEast)) != 0);
 }
 /// <summary>
 /// Returns if <paramref name="position"/> is <see cref="HandlePositions.SouthWest"/>,
 /// <see cref="HandlePositions.South"/> or <see cref="HandlePositions.SouthEast"/>
 /// </summary>
 /// <param name="position">The position to check.</param>
 /// <returns>If the position is at any of the south sides.</returns>
 public static bool IsAnySouth(this HandlePositions position)
 {
     return((position & (HandlePositions.SouthWest | HandlePositions.South | HandlePositions.SouthEast)) != 0);
 }