コード例 #1
0
        public IEnumerator ElementRightBorderShouldNotSnapToGridLine()
        {
            // Config
            //           |          |
            //   --------+--+-------+---------
            //           |  | Node1 |
            //           |  +-------+
            //           |          |

            var actions = SetUpUIElements(new Vector2(k_ReferenceNodePos.x + k_HalfSpacing, k_ReferenceNodePos.y));

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(k_NewSize, k_NewSize, k_NewSize);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Right) + 1, 10);

            actions = MoveElementWithOffset(moveOffset);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            TestElementPosition(moveOffset, false, true, SnapToGridHelper.Edge.Right);
            yield return(null);
        }
コード例 #2
0
        public IEnumerator ElementVerticalCenterBorderShouldSnapToGridLine()
        {
            // Config
            //            |          |
            //   -----+-------+-------------
            //        | Node1 |      |
            //        +-------+      |
            //            |          |

            var actions = SetUpUIElements(new Vector2(k_ReferenceNodePos.x - (k_HalfSpacing * 0.5f), k_ReferenceNodePos.y));

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(k_NewSize, k_NewSize, k_NewSize);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.None), 10);

            actions = MoveElementWithOffset(moveOffset);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            TestElementPosition(moveOffset, true, true, SnapToGridHelper.Edge.None);
            yield return(null);
        }
コード例 #3
0
        public IEnumerator ElementTopBorderShouldSnapToGridLine()
        {
            // Config
            //           |          |
            //   --------+-------+-----------
            //           | Node1 |  |
            //           +-------+  |
            //           |          |

            var actions = SetUpUIElements(new Vector2(k_ReferenceNodePos.x, k_ReferenceNodePos.y));

            while (actions.MoveNext())
            {
                yield return(null);
            }
            actions = UpdateUINodeSizes(k_NewSize, k_NewSize, k_NewSize);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(10, SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Top) + 1); // offset is greater than max snap distance

            actions = MoveElementWithOffset(moveOffset);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            TestElementPosition(moveOffset, false, false, SnapToGridHelper.Edge.Top);
            yield return(null);
        }
コード例 #4
0
        public IEnumerator ElementShouldSnapToGridAndPort()
        {
            // Config
            //           |          |
            //   --------+-------+----+------ +
            //           | Node1 o----o Node2 |
            //           +-------+  | +-------+
            //           |          |
            GraphViewSettings.UserSettings.EnableSnapToBorders = false;
            GraphViewSettings.UserSettings.EnableSnapToSpacing = false;

            var actions = SetUpUIElements(new Vector2(k_Spacing, k_Spacing + k_QuarterSpacing), k_ReferenceNodePos, Vector2.zero, false, true);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(new Vector2(k_HalfSpacing, k_HalfSpacing), new Vector2(k_HalfSpacing, k_HalfSpacing));
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(
                SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Left),
                k_SnapDistance);

            actions = MoveElementWithOffset(moveOffset);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            // Get the UI ports
            var outputPortUI = m_OutputPort.GetUI <Port>(graphView);
            var inputPortUI  = m_InputPort.GetUI <Port>(graphView);

            Assert.IsNotNull(outputPortUI);
            Assert.IsNotNull(inputPortUI);

            // Snapped to Port
            Assert.AreEqual(inputPortUI.GetGlobalCenter().y, outputPortUI.GetGlobalCenter().y);

            // Snapped to Grid
            var borderWidth = SnapToGridStrategy.GetBorderWidth(m_SnappedNode);

            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x),
                            GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x - borderWidth.Left));
            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y), m_SnappedNode.layout.y, 0.0001);

            // Should not be dragged normally
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y),
                               m_SnappedNode.layout.y);
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x),
                               GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x - borderWidth.Left));

            yield return(null);
        }
コード例 #5
0
        public IEnumerator ElementShouldSnapToSpacingAndGrid()
        {
            // Config
            //
            //---+-------+-----------------------------
            //   | Node1 |     +-------+     +-------+
            //   +-------+     | Node2 |     | Node3 |
            //                 +-------+     +-------+
            //

            GraphViewSettings.UserSettings.EnableSnapToPort    = false;
            GraphViewSettings.UserSettings.EnableSnapToBorders = false;

            var actions = SetUpUIElements(new Vector2(k_HalfSpacing + k_QuarterSpacing, k_ReferenceNodePos.y + k_QuarterSpacing), k_ReferenceNodePos, k_ReferenceNodePos + new Vector2(k_Spacing + k_QuarterSpacing, 0));

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(new Vector2(k_HalfSpacing, k_HalfSpacing), new Vector2(k_HalfSpacing, k_HalfSpacing), new Vector2(k_HalfSpacing, k_HalfSpacing));
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(k_SnapDistance, -k_HalfSpacing + SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Top));

            actions = MoveElementWithOffset(moveOffset);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            // Snapped to top grid line
            var borderWidth = SnapToGridStrategy.GetBorderWidth(m_SnappedNode);

            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(k_Spacing),
                            m_SnappedNode.layout.yMin - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top));

            // The three nodes should be evenly spaced horizontally
            float distanceBetweenNode1AndNode2 = m_ReferenceNode1.layout.xMin - m_SnappedNode.layout.xMax;
            float distanceBetweenNode2AndNode3 = m_ReferenceNode2.layout.xMin - m_ReferenceNode1.layout.xMax;

            Assert.AreEqual(distanceBetweenNode1AndNode2, distanceBetweenNode2AndNode3);

            // Should not be dragged normally
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y), m_SnappedNode.layout.y);
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x), m_SnappedNode.layout.x);

            yield return(null);
        }
コード例 #6
0
        public IEnumerator ElementShouldSnapToMultipleGridLines()
        {
            // Config
            //           |          |
            //   --------+--+-------+---------
            //           |  | Node1 |
            //           |  +-------+
            //           |          |

            var actions = SetUpUIElements(new Vector2(k_ReferenceNodePos.x + k_HalfSpacing, k_ReferenceNodePos.y));

            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(k_NewSize, k_NewSize, k_NewSize);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Right), SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Top));

            actions = MoveElementWithOffset(moveOffset);

            while (actions.MoveNext())
            {
                yield return(null);
            }

            // The snapping node's top and right border should snap to the corresponding grid lines
            var borderWidth = SnapToGridStrategy.GetBorderWidth(m_SnappedNode);

            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x),
                            GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x + borderWidth.Right));
            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y),
                            m_SnappedNode.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top));
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y),
                               m_SnappedNode.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top));
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x),
                               GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x + borderWidth.Right));

            yield return(null);
        }
コード例 #7
0
        public IEnumerator ElementShouldSnapToBorderAndGridAndSpacingAndPort()
        {
            // Config
            //   |              |             |
            // --+--------------+-------------+
            //   |              |             |
            //   +-------+      +-------+     +-------+
            //   | Node3 |      | Node2 o-----o Node1 |
            //   +-------+      +-------+     +-------+
            //   |              |             |
            // --+--------------+-------------+
            //   |              |             |
            //   |              |             |

            var actions = SetUpUIElements(new Vector2(3f * k_Spacing, k_ReferenceNodePos.y),
                                          k_ReferenceNodePos,
                                          new Vector2(k_ReferenceNodePos.x - k_Spacing, k_ReferenceNodePos.y), false, true);


            while (actions.MoveNext())
            {
                yield return(null);
            }

            actions = UpdateUINodeSizes(new Vector2(k_HalfSpacing, k_HalfSpacing), new Vector2(k_HalfSpacing, k_HalfSpacing), new Vector2(k_HalfSpacing, k_HalfSpacing));
            while (actions.MoveNext())
            {
                yield return(null);
            }

            Vector2 moveOffset = new Vector2(SnapToGridHelper.GetSnapDistance(m_SnappedNode, SnapToGridHelper.Edge.Left), k_SnapDistance);

            actions = MoveElementWithOffset(moveOffset);
            while (actions.MoveNext())
            {
                yield return(null);
            }

            // Snapped to first grid line (positioned at k_Spacing)
            var borderWidth = SnapToGridStrategy.GetBorderWidth(m_SnappedNode);

            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(3f * k_Spacing),
                            GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x - borderWidth.Left));

            // Snapped to borders
            Assert.AreEqual(m_SnappedNode.layout.y, m_ReferenceNode1.layout.y);

            // Get the UI ports
            var outputPortUI = m_OutputPort.GetUI <Port>(graphView);
            var inputPortUI  = m_InputPort.GetUI <Port>(graphView);

            Assert.IsNotNull(outputPortUI);
            Assert.IsNotNull(inputPortUI);

            // Snapped to Port
            Assert.AreEqual(inputPortUI.GetGlobalCenter().y, outputPortUI.GetGlobalCenter().y);

            // The three nodes should be evenly spaced horizontally up to one pixel difference
            float distanceBetweenNode1AndNode2 = m_SnappedNode.layout.xMin - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Right) - m_ReferenceNode1.layout.xMax;
            float distanceBetweenNode2AndNode3 = m_ReferenceNode1.layout.xMin - m_ReferenceNode2.layout.xMax;

            var pixelSize = 1f / GraphViewStaticBridge.PixelPerPoint;

            Assert.AreEqual(distanceBetweenNode1AndNode2, distanceBetweenNode2AndNode3, pixelSize + 0.0001f);

            // Should not be dragged normally
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y),
                               m_SnappedNode.layout.y);
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x),
                               m_SnappedNode.layout.x);

            yield return(null);
        }
コード例 #8
0
        public IEnumerator ElementUnderMouseShouldSnapWhenMultipleSelectedElements()
        {
            // Config
            //
            //    |               |
            //----+-------+-----------------
            //    | Node1 | +-----|----+
            //    +-------+ | Placemat |
            //    |         +----------+
            //    |               |

            m_SnappingNodePos = new Vector2(k_ReferenceNodePos.x, k_ReferenceNodePos.y);
            snappingNodeModel = CreateNode("Node1", m_SnappingNodePos);

            Vector2 secondElementPos   = new Vector2(m_SnappingNodePos.x + k_HalfSpacing, m_SnappingNodePos.y + 10);
            var     secondElementModel = CreatePlacemat(new Rect(secondElementPos, new Vector2(k_HalfSpacing, k_HalfSpacing)), "Placemat");

            MarkGraphViewStateDirty();
            yield return(null);

            // Get the UI nodes
            var      snappingNode  = snappingNodeModel.GetUI <Node>(graphView);
            Placemat secondElement = secondElementModel.GetUI <Placemat>(graphView);

            Assert.IsNotNull(snappingNode);
            Assert.IsNotNull(secondElement);

            // Changing the node' size to make it easier to test the snapping
            SetUINodeSize(ref snappingNode, k_HalfSpacing, k_HalfSpacing);
            yield return(null);

            Vector2 worldPosSnappingNode  = graphView.ContentViewContainer.LocalToWorld(m_SnappingNodePos);
            Vector2 worldPosSecondElement = graphView.ContentViewContainer.LocalToWorld(secondElementPos);

            Vector2 selectionPosSnappingNode  = worldPosSnappingNode + m_SelectionOffset;
            Vector2 selectionPosSecondElement = worldPosSecondElement + m_SelectionOffset;

            // Select placemat by clicking on it and pressing Ctrl
            helpers.MouseDownEvent(selectionPosSecondElement, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            helpers.MouseUpEvent(selectionPosSecondElement, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            // Move mouse to Node2
            helpers.MouseMoveEvent(selectionPosSecondElement, selectionPosSnappingNode, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            // Select Node1 by clicking on it and pressing Ctrl
            helpers.MouseDownEvent(selectionPosSnappingNode, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            // Move Node1 within snapping distance
            Vector2 moveOffset = new Vector2(10, SnapToGridHelper.GetSnapDistance(snappingNode, SnapToGridHelper.Edge.Top));
            Vector2 end        = selectionPosSnappingNode + moveOffset;

            helpers.MouseDragEvent(selectionPosSnappingNode, end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            helpers.MouseUpEvent(end, MouseButton.LeftMouse, TestEventHelpers.multiSelectModifier);
            yield return(null);

            // The snapping Node1 top border should snap but X should be dragged normally
            var borderWidth = SnapToGridStrategy.GetBorderWidth(snappingNode);

            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y),
                            snappingNode.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top));
            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x),
                            snappingNode.layout.x);
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y),
                               snappingNode.layout.y);

            // placemat should follow the same offset as Node1
            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.y),
                            secondElement.layout.y - GraphViewStaticBridge.RoundToPixelGrid(borderWidth.Top));
            Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.x + moveOffset.x),
                            secondElement.layout.x);
            Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(secondElementPos.y + moveOffset.y),
                               secondElement.layout.y);

            yield return(null);
        }