override protected void CollectGridSnapResults(GraphSnapContext context, CollectSnapResultsEventArgs args, RectD suggestedLayout, INode node)
        {
            // node.Layout isn't updated, yet, so we have to calculate the delta between the the new suggested layout and the current node.Layout
            PointD delta = suggestedLayout.TopLeft - node.Layout.GetTopLeft();

            // get outline of the shape and iterate over it's path point
            IShapeGeometry geometry = node.Style.Renderer.GetShapeGeometry(node, node.Style);
            GeneralPath    outline  = geometry.GetOutline();

            if (outline != null)
            {
                GeneralPath.PathCursor cursor = outline.CreateCursor();
                while (cursor.MoveNext())
                {
                    // ignore PathType.Close as we had the path point as first point
                    // and cursor.CurrentEndPoint is always (0, 0) for PathType.Close
                    if (cursor.PathType != PathType.Close)
                    {
                        // adjust path point by the delta calculated above and add an according SnapResult
                        PointD endPoint = cursor.CurrentEndPoint + delta;
                        AddGridSnapResultCore(context, args, endPoint, node, GridSnapTypes.GridPoints, SnapPolicy.ToNearest, SnapPolicy.ToNearest);
                    }
                }
            }
        }
            private void CollectSnapResults(object sender, CollectSnapResultsEventArgs args)
            {
                var lastEvent        = args.Context.CanvasControl.LastInputEvent;
                var fixedAspectRatio = Handle.RatioReshapeRecognizer.Invoke(this, lastEvent);
                var centered         = Handle.CenterReshapeRecognizer.Invoke(this, lastEvent);

                var reshapePolicy = fixedAspectRatio ? Handle.ReshapePolicy : ReshapePolicy.None;
                var ratio         = OriginalBounds.Width / OriginalBounds.Height;

                var minScaleX = Handle.MinimumSize.Width / this.OriginalBounds.Width;
                var minScaleY = Handle.MinimumSize.Height / this.OriginalBounds.Height;
                var maxScaleX = Handle.MaximumSize.Width / this.OriginalBounds.Width;
                var maxScaleY = Handle.MaximumSize.Height / this.OriginalBounds.Height;

                foreach (var pair in reshapeSnapResultProviders)
                {
                    // for each selected node that has an INodeReshapeSnapResultProvider we have to create
                    // a suiting ReshapeRectangleContext
                    var node   = pair.Key;
                    var layout = originalNodeLayouts[node];

                    // get factors that determine how the node layout changes depending on the mouse delta
                    var topLeftChangeFactor     = FixZero(GetFactor(layout.MinX, layout.MinY, layout, centered, Handle.Position));
                    var bottomRightChangeFactor = FixZero(GetFactor(layout.MaxX, layout.MaxY, layout, centered, Handle.Position));

                    // the SizeChangeFactor can be calculated using those two factors
                    var pointDiffFactor  = FixZero(bottomRightChangeFactor - topLeftChangeFactor);
                    var sizeChangeFactor = new SizeD(pointDiffFactor.X, pointDiffFactor.Y);

                    var reshapeRectangleContext = new ReshapeRectangleContext(
                        layout,
                        new SizeD(layout.Width * minScaleX, layout.Height * minScaleY),
                        new SizeD(layout.Width * maxScaleX, layout.Height * maxScaleY),
                        RectD.Empty, RectD.Infinite,
                        Handle.Position,
                        topLeftChangeFactor,
                        bottomRightChangeFactor,
                        sizeChangeFactor,
                        reshapePolicy,
                        ratio);

                    // call the INodeReshapeSnapResultProvider
                    pair.Value.CollectSnapResults((GraphSnapContext)sender, args, node, reshapeRectangleContext);
                }
            }
Esempio n. 3
0
 protected override void CollectGridSnapResults(GraphSnapContext context, CollectSnapResultsEventArgs args, RectD suggestedLayout, INode node)
 {
     AddGridSnapResult(context, args, suggestedLayout.GetTopLeft(), node);
 }