Exemplo n.º 1
0
        /// <summary>
        /// Sets the bounds of the item</summary>
        /// <param name="item">Item</param>
        /// <param name="bounds">New item bounds, in world coordinates</param>
        /// <param name="specified">Which parts of bounds to set</param>
        void ILayoutContext.SetBounds(object item, Rectangle bounds, BoundsSpecified specified)
        {
            var element = item.As <Element>();

            // Currently we have CanvasAdapter and D2dGridAdapter attached to the circuit adaptable control for layout constraints.
            // When setting a dragging module’s bounds and the module belongs to a group, we are either moving around the module
            // inside its owner, or moving out of its current owner. In either case, it seems more desirable to skip these 2
            // layout constrains: the CanvasAdapter by default have (0,0) for Location which will clip away negative bounds,
            // but negative location will be generated if we drag a sub-element to the left or above the group that owns it;
            // D2dGridAdapter seems not needed to layout sub-elements inside its owner as the layout occurs at a lower level.
            bool applyConstraints = !IsDraggingSubNode(element);

            if (applyConstraints)
            {
                bounds = ConstrainBounds(bounds, specified);
            }

            if (element != null)
            {
                element.Bounds = WinFormsUtil.UpdateBounds(element.Bounds, bounds, specified);
            }
            else
            {
                var annotation = item.As <Annotation>();
                if (annotation != null)
                {
                    annotation.Bounds = WinFormsUtil.UpdateBounds(annotation.Bounds, bounds, specified);
                }
            }
        }
Exemplo n.º 2
0
        void ILayoutContext.SetBounds(object item, Rectangle bounds, BoundsSpecified specified)
        {
            var element = item.As <HyperGraph.Node>();

            if (element != null)
            {
                Rectangle workingBounds;
                var       bs = GetNodeBounds(element, out workingBounds);
                if (bs == BoundsSpecified.Location || bs == BoundsSpecified.All)
                {
                    workingBounds    = WinFormsUtil.UpdateBounds(workingBounds, bounds, specified);
                    element.Location = workingBounds.Location;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the bounds of the item</summary>
        /// <param name="item">Item</param>
        /// <param name="bounds">New item bounds, in world coordinates</param>
        /// <param name="specified">Which parts of bounds to set</param>
        void ILayoutContext.SetBounds(object item, Rectangle bounds, BoundsSpecified specified)
        {
            bounds = ConstrainBounds(bounds, specified);

            var state = item.As <State>();

            if (state != null)
            {
                state.Bounds = WinFormsUtil.UpdateBounds(state.Bounds, bounds, specified);
            }
            else
            {
                var annotation = item.As <Annotation>();
                if (annotation != null)
                {
                    annotation.Bounds = WinFormsUtil.UpdateBounds(annotation.Bounds, bounds, specified);
                }
            }
        }
Exemplo n.º 4
0
        public void TestUpdateBounds()
        {
            var       original    = new Rectangle(1, 2, 3, 4);
            var       replacement = new Rectangle(5, 6, 7, 8);
            Rectangle updated;

            updated = WinFormsUtil.UpdateBounds(original, replacement, BoundsSpecified.All);
            Assert.True(updated == replacement);

            updated = WinFormsUtil.UpdateBounds(original, replacement, BoundsSpecified.Location);
            Assert.True(updated.Location == replacement.Location);
            Assert.True(updated.Size == original.Size);

            updated = WinFormsUtil.UpdateBounds(original, replacement, BoundsSpecified.Width | BoundsSpecified.Height);
            Assert.True(updated.Size == replacement.Size);
            Assert.True(updated.Location == original.Location);

            updated = WinFormsUtil.UpdateBounds(original, replacement, BoundsSpecified.X);
            Assert.True(updated.X == replacement.X);
            Assert.True(updated.Y == original.Y);
            Assert.True(updated.Width == original.Width);
            Assert.True(updated.Y == original.Y);
        }