public IEnumerator AlignElementsToVerticalCenter() { // Config: // // +-----+ +-----+ +-----+ +-----+ // --Node2----stick----place----Node1-- vertical center // +-----+ +-----+ +-----+ +-----+ Vector2 firstNodePos = new Vector2(0, 400); Vector2 secondNodePos = new Vector2(200, 100); Vector2 placematPos = new Vector2(400, 300); Vector2 stickyNotePos = new Vector2(600, 200); var actions = SetupElements(false, firstNodePos, secondNodePos, placematPos, stickyNotePos); while (actions.MoveNext()) { yield return(null); } float expectedVerticalCenterValue = GraphViewStaticBridge.RoundToPixelGrid((m_FirstNode.layout.center.y + m_SecondNode.layout.center.y + m_Placemat.layout.center.y + m_StickyNote.layout.center.y) / 4); actions = AlignElements(AutoAlignmentHelper.AlignmentReference.VerticalCenter); while (actions.MoveNext()) { yield return(null); } Assert.AreEqual(expectedVerticalCenterValue, m_FirstNode.layout.center.y); Assert.AreEqual(expectedVerticalCenterValue, m_SecondNode.layout.center.y); Assert.AreEqual(expectedVerticalCenterValue, m_Placemat.layout.center.y); Assert.AreEqual(expectedVerticalCenterValue, m_StickyNote.layout.center.y); }
void OnWheel(WheelEvent evt) { var graphView = target as GraphView; if (graphView == null) return; IPanel panel = (evt.target as VisualElement)?.panel; if (panel.GetCapturingElement(PointerId.mousePointerId) != null) return; Vector3 position = graphView.viewTransform.position; Vector3 scale = graphView.viewTransform.scale; // TODO: augment the data to have the position as well, so we don't have to read in data from the target. // 0-1 ranged center relative to size Vector2 zoomCenter = target.ChangeCoordinatesTo(graphView.contentViewContainer, evt.localMousePosition); float x = zoomCenter.x + graphView.contentViewContainer.layout.x; float y = zoomCenter.y + graphView.contentViewContainer.layout.y; position += Vector3.Scale(new Vector3(x, y, 0), scale); // Apply the new zoom. float zoom = CalculateNewZoom(scale.y, -evt.delta.y, scaleStep, referenceScale, minScale, maxScale); scale.x = zoom; scale.y = zoom; scale.z = 1; position -= Vector3.Scale(new Vector3(x, y, 0), scale); position.x = GraphViewStaticBridge.RoundToPixelGrid(position.x); position.y = GraphViewStaticBridge.RoundToPixelGrid(position.y); graphView.UpdateViewTransform(position, scale); evt.StopPropagation(); }
public IEnumerator AlignElementsToBottom() { // Config: // // +-----+ +-----+ +-----+ +-----+ // |Node1| |Node2| |place| |stick| // --+-----+--+-----+--+-----+--+-----+-- bottom float expectedBottomValue = 300; Vector2 firstNodePos = new Vector2(0, 50); Vector2 secondNodePos = new Vector2(200, 100); Vector2 placematPos = new Vector2(400, expectedBottomValue); Vector2 stickyNotePos = new Vector2(600, 200); var actions = SetupElements(false, firstNodePos, secondNodePos, placematPos, stickyNotePos); while (actions.MoveNext()) { yield return(null); } actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Bottom); while (actions.MoveNext()) { yield return(null); } Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(expectedBottomValue + m_FirstNode.layout.height), m_FirstNode.layout.yMax); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(expectedBottomValue + m_SecondNode.layout.height), m_SecondNode.layout.yMax); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(expectedBottomValue + m_Placemat.layout.height), m_Placemat.layout.yMax); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(expectedBottomValue + m_StickyNote.layout.height), m_StickyNote.layout.yMax); }
protected override void ImmediateRepaint() { var pointCount = points.Count; if (pointCount < 1) { return; } var lineColor = (deleteModifier) ? deleteSegmentColor : segmentColor; GraphViewStaticBridge.ApplyWireMaterial(); GL.Begin(GL.LINES); GL.Color(lineColor); for (int i = 1; i < pointCount; i++) { // Apply offset Vector2 start = points[i - 1] + parent.layout.position; Vector2 end = points[i] + parent.layout.position; DrawDottedLine(start, end, segmentSize); } GL.End(); }
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); }
public IEnumerator ElementShouldSnapToSpacingAndPort() { // Config // // +-------+ +-------+ +-------+ // | Node2 | | Node2 o-----o Node1 | // +-------+ +-------+ +-------+ // GraphViewSettings.UserSettings.EnableSnapToGrid = false; GraphViewSettings.UserSettings.EnableSnapToBorders = false; var actions = SetUpUIElements(k_ReferenceNodePos + new Vector2(k_HalfSpacing + k_QuarterSpacing, k_QuarterSpacing), k_ReferenceNodePos, new Vector2(k_ReferenceNodePos.x - k_HalfSpacing - k_QuarterSpacing, 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(k_SnapDistance, k_SnapDistance - k_QuarterSpacing); 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); // 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); }
public void RunBeforeAnyTests() { SetDisableInputEventsOnAllWindows(true); MouseCaptureController.ReleaseMouse(); Debug.Assert(!GraphViewStaticBridge.GetDisableThrottling()); GraphViewStaticBridge.SetDisableThrottling(true); }
private void OnGenerateVisualContent(MeshGenerationContext mgc) { // This control begs to be fully rewritten and it shouldn't use immediate // mode rendering at all. It should maintain its vertex/index lists and only // update affected vertices when their respective elements are changed. This // way the cost of GenerateVisualContent becomes effectively only two memcpys. GraphViewStaticBridge.DrawImmediate(mgc, DrawMinimapContent); }
/// <summary> /// Queries a VisualElement for a descendant that matches some criteria. Same as VisualElement.SafeQ(), /// but throws when no element is found or <paramref name="e"/> is null. /// </summary> /// <param name="e">The VisualElement to search.</param> /// <param name="name">The name of the descendant to find. Null if this criterion should be ignored.</param> /// <param name="className">The USS class name of the descendant to find. Null if this criterion should be ignored.</param> /// <returns>The VisualElement that matches the search criteria.</returns> /// <exception cref="ArgumentNullException">If <paramref name="e"/> is null.</exception> /// <exception cref="Exception">If no element is found.</exception> public static VisualElement MandatoryQ(this VisualElement e, string name = null, string className = null) { if (e == null) { throw new ArgumentNullException(nameof(e)); } return(GraphViewStaticBridge.MandatoryQ(e, name, className)); }
public IEnumerator ElementShouldSnapToBorderAndPort() { // Config // +-----==+ // | Node3 | // +-------+ // +-------+ +-------+ // | Node1 o----o Node2 | // +-------+ +-------+ // GraphViewSettings.UserSettings.EnableSnapToGrid = false; GraphViewSettings.UserSettings.EnableSnapToSpacing = false; var actions = SetUpUIElements(new Vector2(k_Spacing, 2f * k_Spacing + k_QuarterSpacing), k_ReferenceNodePos, new Vector2(k_Spacing, 0), 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(k_SnapDistance, -(k_Spacing + 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); // Left and right borders of snapped node are snapped to left and right border of second reference node Assert.AreEqual(m_ReferenceNode2.layout.xMax, m_SnappedNode.layout.xMax); Assert.AreEqual(m_ReferenceNode2.layout.xMin, m_SnappedNode.layout.xMin); // 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); }
public static void ShowGraphViewWindowWithTools <T>() where T : GraphViewEditorWindow { var windows = GraphViewStaticBridge.ShowGraphViewWindowWithTools(typeof(GraphViewBlackboardWindow), typeof(T)); var graphView = (windows[0] as T)?.graphViews.FirstOrDefault(); if (graphView != null) { (windows[1] as GraphViewBlackboardWindow)?.SelectGraphViewFromWindow((windows[0] as T), graphView); } }
protected virtual void BuildContextualMenu(ContextualMenuPopulateEvent evt) { var placemat = evt.target as Placemat; if (placemat != null) { evt.menu.AppendAction("Edit Title", a => placemat.StartEditTitle()); evt.menu.AppendSeparator(); evt.menu.AppendAction("Change Color...", a => { GraphViewStaticBridge.ShowColorPicker(c => placemat.Color = c, placemat.Color, false); }); // Resizing section evt.menu.AppendSeparator(); evt.menu.AppendAction(placemat.Collapsed ? "Expand" : "Collapse", a => placemat.Collapsed = !placemat.Collapsed); // Gather nodes here so that we don't recycle this code in the resize functions. List <GraphElement> hoveringNodes = placemat.GetHoveringNodes(); evt.menu.AppendAction("Resize/Grow To Fit", a => placemat.GrowToFitElements(hoveringNodes), hoveringNodes.Count > 0 ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); evt.menu.AppendAction("Resize/Shrink To Fit", a => placemat.ShrinkToFitElements(hoveringNodes), hoveringNodes.Count > 0 ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled); evt.menu.AppendAction("Resize/Grow To Fit Selection", a => placemat.ResizeToIncludeSelectedNodes(), s => { foreach (ISelectable sel in placemat.m_GraphView.selection) { var node = sel as Node; if (node != null && !hoveringNodes.Contains(node)) { return(DropdownMenuAction.Status.Normal); } } return(DropdownMenuAction.Status.Disabled); }); var status = placemat.Container.Placemats.Any() ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled; evt.menu.AppendAction("Order/Bring To Front", a => Container.BringToFront(placemat), status); evt.menu.AppendAction("Order/Bring Forward", a => Container.CyclePlacemat(placemat, PlacematContainer.CycleDirection.Up), status); evt.menu.AppendAction("Order/Send Backward", a => Container.CyclePlacemat(placemat, PlacematContainer.CycleDirection.Down), status); evt.menu.AppendAction("Order/Send To Back", a => Container.SendToBack(placemat), status); } }
public IEnumerator ElementShouldSnapToBorderAndGrid() { // Config // | | // --+------------+-------- // | | // +-------+ +-------+ // | Node1 o----o Node2 | // +-------+ +-------+ // | | // --+------------+-------| // | | // | | GraphViewSettings.UserSettings.EnableSnapToPort = false; GraphViewSettings.UserSettings.EnableSnapToSpacing = false; var actions = SetUpUIElements(new Vector2(k_Spacing + k_QuarterSpacing, 2f * 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(k_SnapDistance - k_QuarterSpacing, -(k_Spacing + 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(k_Spacing), GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x - borderWidth.Left)); // Snapped to borders Assert.AreEqual(m_SnappedNode.layout.y, m_ReferenceNode1.layout.y); // Should not be dragged normally Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y), GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.y - borderWidth.Top)); Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x), GraphViewStaticBridge.RoundToPixelGrid(m_SnappedNode.layout.x - borderWidth.Left)); yield return(null); }
public IEnumerator ChangingGraphViewTransformRoundsToPixelGrid() { var pos = new Vector3(10.3f, 10.6f, 10.0f); CommandDispatcher.Dispatch(new ReframeGraphViewCommand(pos, new Vector3(10, 10))); yield return(null); Vector3 p = graphView.ContentViewContainer.transform.position; Assert.AreEqual(new Vector3(GraphViewStaticBridge.RoundToPixelGrid(pos.x), GraphViewStaticBridge.RoundToPixelGrid(pos.y), 10.0f), p); }
public static IGraphElement CreateToken(this ElementBuilder elementBuilder, IStore store, IVariableModel model) { var isExposed = model.DeclarationModel?.IsExposed; Texture2D icon = (isExposed != null && isExposed.Value) ? GraphViewStaticBridge.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png") : null; var ui = new Token(); ui.Setup(model, store, elementBuilder.GraphView, icon); return(ui); }
public IEnumerator SpaceConnectedNodes() { // Config: // +-----+ // |Node1o--+ // +-----+ | +-----+ +-----+ // |--oNode3o-----oNode4| // +-----+ | +-----+ +-----+ // |Node2o--+ // +-----+ // GraphViewSettings.UserSettings.SpacingMarginValue = 10f; float expectedSpacingMargin = GraphViewStaticBridge.RoundToPixelGrid(GraphViewSettings.UserSettings.SpacingMarginValue); Vector2 firstNodePos = new Vector2(0, 50); Vector2 secondNodePos = new Vector2(0, 350); Vector2 thirdNodePos = new Vector2(300, 300); Vector2 fourthNodePos = new Vector2(600, 100); var actions = CreateConnectedNodes(firstNodePos, secondNodePos, thirdNodePos, fourthNodePos, false); while (actions.MoveNext()) { yield return(null); } SelectConnectedNodes(); yield return(null); float expectedDistanceBetweenFirstSecond = m_SecondNode.layout.xMin - m_FirstNode.layout.xMax; actions = SpaceElements(PortOrientation.Horizontal); while (actions.MoveNext()) { yield return(null); } float marginBetweenFirstSecondNodes = m_SecondNode.layout.xMin - m_FirstNode.layout.xMax; float marginBetweenFirstThirdNodes = m_ThirdNode.layout.xMin - m_FirstNode.layout.xMax; float marginBetweenSecondThirdNodes = m_ThirdNode.layout.xMin - m_SecondNode.layout.xMax; float marginBetweenThirdFourthNodes = m_FourthNode.layout.xMin - m_ThirdNode.layout.xMax; Assert.AreNotEqual(expectedSpacingMargin, marginBetweenFirstSecondNodes); Assert.AreEqual(expectedDistanceBetweenFirstSecond, marginBetweenFirstSecondNodes); Assert.AreEqual(expectedSpacingMargin, marginBetweenFirstThirdNodes); Assert.AreEqual(expectedSpacingMargin, marginBetweenSecondThirdNodes); Assert.AreEqual(expectedSpacingMargin, marginBetweenThirdFourthNodes); }
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); }
void RefreshPanelChoices() { m_GraphViewChoices.Clear(); var usedGraphViews = new HashSet <GraphView>(); foreach (var toolWindow in GraphViewStaticBridge.GetGraphViewWindows <GraphViewToolWindow>(GetType())) { if (toolWindow.m_SelectedGraphView != null) { usedGraphViews.Add(toolWindow.m_SelectedGraphView); } } foreach (var window in GraphViewStaticBridge.GetGraphViewWindows <GraphViewEditorWindow>(null)) { int idx = 0; foreach (var graphView in window.graphViews.Where(IsGraphViewSupported)) { m_GraphViewChoices.Add(new GraphViewChoice { window = window, idx = idx++, graphView = graphView, canUse = !usedGraphViews.Contains(graphView) }); } } var menu = m_SelectorMenu.menu; var menuItemsCount = menu.MenuItems().Count; // Clear previous items (but not the "none" one at the top of the list) for (int i = menuItemsCount - 1; i > 0; i--) { menu.RemoveItemAt(i); } foreach (var graphView in m_GraphViewChoices) { menu.AppendAction(graphView.graphView.name, OnSelectGraphView, a => { var gvc = (GraphViewChoice)a.userData; return(gvc.graphView == m_SelectedGraphView ? DropdownMenuAction.Status.Checked : (gvc.canUse ? DropdownMenuAction.Status.Normal : DropdownMenuAction.Status.Disabled)); }, graphView); } }
public IEnumerator SpaceOnlySelectedElements() { // Config: // +-----+ // |Node2| +-----+ // +-----+ +-----+ |stick| // |Node1| +-----+ +-----+ // +-----+ |place| // +-----+ GraphViewSettings.UserSettings.SpacingMarginValue = 10f; float expectedSpacingMargin = GraphViewStaticBridge.RoundToPixelGrid(GraphViewSettings.UserSettings.SpacingMarginValue); Vector2 firstNodePos = new Vector2(50, 200); Vector2 secondNodePos = new Vector2(200, 0); Vector2 stickyNotePos = new Vector2(350, 100); Vector2 placematPos = new Vector2(600, 300); var actions = SetupElements(true, firstNodePos, secondNodePos, placematPos, stickyNotePos); while (actions.MoveNext()) { yield return(null); } Vector2 selectionPosStickyNote = graphView.ContentViewContainer.LocalToWorld(m_StickyNote.layout.position) + k_SelectionOffset; // Unselect StickyNote actions = SelectElement(selectionPosStickyNote); while (actions.MoveNext()) { yield return(null); } actions = SpaceElements(PortOrientation.Horizontal); while (actions.MoveNext()) { yield return(null); } float marginBetweenFirstNodeSecondNode = m_SecondNode.layout.xMin - m_FirstNode.layout.xMax; float marginBetweenSecondNodePlacemat = m_Placemat.layout.xMin - m_SecondNode.layout.xMax; Assert.AreEqual(expectedSpacingMargin, marginBetweenFirstNodeSecondNode); Assert.AreEqual(expectedSpacingMargin, marginBetweenSecondNodePlacemat); // Sticky note was not selected, it doesn't move Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(stickyNotePos.x), m_StickyNote.layout.x); }
public IEnumerator AlignConnectedNodesCenterHorizontal() { // Config: // // +-----+ // |Node1o-------+ // +-----+ | // | | // +---------+ | // |Nodes3&4 o--+ // +---------+ | // | | // +-----+ | // |Node2o-+ // +-----+ // | // center horizontal Vector2 firstNodePos = new Vector2(0, 0); Vector2 secondNodePos = new Vector2(100, 400); Vector2 thirdNodePos = new Vector2(300, 300); Vector2 fourthNodePos = new Vector2(400, 100); var actions = CreateConnectedNodes(firstNodePos, secondNodePos, thirdNodePos, fourthNodePos, false); while (actions.MoveNext()) { yield return(null); } SelectConnectedNodes(); yield return(null); float expectedDistanceBetweenFirstSecond = m_SecondNode.layout.xMin - m_FirstNode.layout.xMax; float expectedCenter = GraphViewStaticBridge.RoundToPixelGrid(((m_SecondNode.layout.center.x + m_FirstNode.layout.center.x) / 2 + m_ThirdNode.layout.center.x + m_FourthNode.layout.center.x) / 3); actions = AlignElements(AutoAlignmentHelper.AlignmentReference.HorizontalCenter); while (actions.MoveNext()) { yield return(null); } Assert.AreNotEqual(expectedCenter, m_FirstNode.layout.center.x); Assert.AreNotEqual(expectedCenter, m_SecondNode.layout.center.x); Assert.AreEqual(expectedDistanceBetweenFirstSecond, m_SecondNode.layout.xMin - m_FirstNode.layout.xMax); Assert.AreEqual(expectedCenter, m_ThirdNode.layout.center.x); Assert.AreEqual(expectedCenter, m_FourthNode.layout.center.x); }
public IEnumerator AlignConnectedNodesRight() { // Config: // | // +-----+ | // |Node1o---+ // +-----+ | | // | | // +--------+ | // |Nodes3&4o-+ // +--------+ | // | | // +-----+ | // |Node2o-+ // +-----+ // | // right Vector2 firstNodePos = new Vector2(0, 200); Vector2 secondNodePos = new Vector2(10, 400); Vector2 thirdNodePos = new Vector2(200, 100); Vector2 fourthNodePos = new Vector2(400, 100); var actions = CreateConnectedNodes(firstNodePos, secondNodePos, thirdNodePos, fourthNodePos, false); while (actions.MoveNext()) { yield return(null); } SelectConnectedNodes(); yield return(null); float expectedDistanceBetweenFirstSecond = GraphViewStaticBridge.RoundToPixelGrid(secondNodePos.x - firstNodePos.x); float expectedXmax = GraphViewStaticBridge.RoundToPixelGrid(fourthNodePos.x + m_FourthNode.layout.width); actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Right); while (actions.MoveNext()) { yield return(null); } Assert.AreNotEqual(expectedXmax, m_FirstNode.layout.xMax); Assert.AreEqual(expectedXmax, m_SecondNode.layout.xMax); Assert.AreEqual(expectedDistanceBetweenFirstSecond, m_SecondNode.layout.x - m_FirstNode.layout.x); Assert.AreEqual(expectedXmax, m_ThirdNode.layout.xMax); Assert.AreEqual(expectedXmax, m_FourthNode.layout.xMax); }
public virtual void SetUp() { window = EditorWindow.GetWindowWithRect <TestGraphViewWindow>(k_WindowRect); if (!m_EnablePersistence) { GraphViewStaticBridge.DisableViewDataPersistence(window); } else { GraphViewStaticBridge.ClearPersistentViewData(window); } graphView = window.graphView as TestGraphView; helpers = new TestEventHelpers(window); }
public IEnumerator ChangingGraphViewTransformRoundsToPixelGrid() { var capturedPos = Vector3.zero; graphView.viewTransformChanged += graphView => capturedPos = graphView.contentViewContainer.transform.position; var pos = new Vector3(10.3f, 10.6f, 10.0f); graphView.UpdateViewTransform(pos, new Vector3(10, 10)); yield return(null); Assert.AreEqual(new Vector3(GraphViewStaticBridge.RoundToPixelGrid(pos.x), GraphViewStaticBridge.RoundToPixelGrid(pos.y), 10.0f), capturedPos); yield return(null); }
public TokenDeclaration(Store store, IVariableDeclarationModel model, GraphView graphView) { m_Pill = new Pill(); Add(m_Pill); if (model is IObjectReference modelReference) { if (modelReference is IExposeTitleProperty titleProperty) { var titleLabel = m_Pill.Q <Label>("title-label"); titleLabel.bindingPath = titleProperty.TitlePropertyName; } } styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.templatePath + "Token.uss")); Setup(model as IGTFGraphElementModel, store, graphView); m_Pill.icon = Declaration.IsExposed ? GraphViewStaticBridge.LoadIconRequired("GraphView/Nodes/BlackboardFieldExposed.png") : null; m_Pill.text = Declaration.Title; var variableModel = model as VariableDeclarationModel; Stencil stencil = store.GetState().CurrentGraphModel?.Stencil; if (variableModel != null && stencil != null && variableModel.DataType.IsValid) { string friendlyTypeName = variableModel.DataType.GetMetadata(stencil).FriendlyName; Assert.IsTrue(!string.IsNullOrEmpty(friendlyTypeName)); tooltip = $"{variableModel.VariableString} declaration of type {friendlyTypeName}"; if (!string.IsNullOrEmpty(variableModel.Tooltip)) { tooltip += "\n" + variableModel.Tooltip; } } SetClasses(); this.EnableRename(); if (model != null) { viewDataKey = model.GetId(); } }
public IEnumerator AlignOnlySelectedElements() { // Config: // // +-----+--+-----+--+-----+------- top // |Node1| |Node2| |place| // +-----+ +-----+ +-----+ // // +-----+ // |stick| <- not selected // +-----+ // float expectedTopValue = GraphViewStaticBridge.RoundToPixelGrid(0); Vector2 firstNodePos = new Vector2(0, expectedTopValue); Vector2 secondNodePos = new Vector2(200, 200); Vector2 placematPos = new Vector2(400, 400); Vector2 stickyNotePos = new Vector2(600, 400); var actions = SetupElements(false, firstNodePos, secondNodePos, placematPos, stickyNotePos); while (actions.MoveNext()) { yield return(null); } Vector2 selectionPosStickyNote = graphView.ContentViewContainer.LocalToWorld(m_StickyNote.layout.position) + k_SelectionOffset; // Unselect StickyNote actions = SelectElement(selectionPosStickyNote); while (actions.MoveNext()) { yield return(null); } actions = AlignElements(AutoAlignmentHelper.AlignmentReference.Top); while (actions.MoveNext()) { yield return(null); } Assert.AreEqual(expectedTopValue, m_FirstNode.layout.yMin); Assert.AreEqual(expectedTopValue, m_SecondNode.layout.yMin); Assert.AreEqual(expectedTopValue, m_Placemat.layout.yMin); Assert.AreNotEqual(expectedTopValue, m_StickyNote.layout.yMin); }
protected IEnumerator SetUpUIElements(Vector2 snappingNodePos, Vector2 referenceNode1Pos = default, Vector2 referenceNode2Pos = default, bool isVerticalPort = false, bool isPortSnapping = false) { m_SnappingNodePos = snappingNodePos; m_ReferenceNode1Pos = referenceNode1Pos; m_ReferenceNode2Pos = referenceNode2Pos; snappingNodeModel = CreateNode("Snapping Node", GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos), inCount: 1, orientation: isVerticalPort ? PortOrientation.Vertical : PortOrientation.Horizontal); referenceNode1Model = CreateNode("Reference Node 1", GraphViewStaticBridge.RoundToPixelGrid(m_ReferenceNode1Pos), outCount: 1, orientation: isVerticalPort ? PortOrientation.Vertical : PortOrientation.Horizontal); referenceNode2Model = CreateNode("Reference Node 2", GraphViewStaticBridge.RoundToPixelGrid(m_ReferenceNode2Pos), orientation: isVerticalPort ? PortOrientation.Vertical : PortOrientation.Horizontal); if (isPortSnapping) { m_InputPort = snappingNodeModel.InputsByDisplayOrder[0]; m_OutputPort = referenceNode1Model.OutputsByDisplayOrder[0]; Assert.IsNotNull(m_OutputPort); Assert.IsNotNull(m_InputPort); MarkGraphViewStateDirty(); yield return(null); // Connect the ports together var actions = ConnectPorts(m_OutputPort, m_InputPort); while (actions.MoveNext()) { yield return(null); } } MarkGraphViewStateDirty(); yield return(null); // Get the UI nodes m_SnappedNode = snappingNodeModel.GetUI <Node>(graphView); m_ReferenceNode1 = referenceNode1Model.GetUI <Node>(graphView); m_ReferenceNode2 = referenceNode2Model.GetUI <Node>(graphView); m_SnappingNodePos = m_SnappedNode?.layout.position ?? Vector2.zero; m_ReferenceNode1Pos = m_ReferenceNode1?.layout.position ?? Vector2.zero; m_ReferenceNode2Pos = m_ReferenceNode2?.layout.position ?? Vector2.zero; Assert.IsNotNull(m_SnappedNode); Assert.IsNotNull(m_ReferenceNode1); Assert.IsNotNull(m_ReferenceNode2); }
public IEnumerator VerticalPortNotWithinSnappingDistanceShouldNotSnap() { // Config (both ports are connected vertically) // +-------+ // | Node1 o // +-------+ // +-------+ // o Node2 | // +-------+ // var actions = SetUpUIElements(new Vector2(k_ReferenceNodePos.x, k_ReferenceNodePos.y + k_NodeSize.y), k_ReferenceNodePos, Vector2.zero, true, true); while (actions.MoveNext()) { yield return(null); } var outputPortUI = m_OutputPort.GetUI <Port>(graphView); var inputPortUI = m_InputPort.GetUI <Port>(graphView); Assert.IsNotNull(outputPortUI); Assert.IsNotNull(inputPortUI); m_OutputPort.Orientation = PortOrientation.Vertical; m_InputPort.Orientation = PortOrientation.Vertical; float outputPortInputPortDistance = Math.Abs(outputPortUI.GetGlobalCenter().x - inputPortUI.GetGlobalCenter().x); float offSetX = outputPortInputPortDistance - (k_SnapDistance + 1); Vector2 moveOffset = new Vector2(offSetX, 10); actions = MoveElementWithOffset(moveOffset); while (actions.MoveNext()) { yield return(null); } // The node should not snap to the reference node's position in X: the X and Y should be dragged normally Assert.AreNotEqual(outputPortUI.GetGlobalCenter().x, inputPortUI.GetGlobalCenter().x); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y), m_SnappedNode.layout.y); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.x + moveOffset.x), m_SnappedNode.layout.x); yield return(null); }
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); }
public IEnumerator ElementShouldNotSnapToVerticalSpacingPositionC() { // Config (snapped node should not snap to C) // // +-----+ // | 1 | // +-----+ // // +-----+ // | 1 | // +-----+ // // C // var actions = SetUpUIElements(new Vector2(100, 0), new Vector2(100, 100), new Vector2(100, 250)); while (actions.MoveNext()) { yield return(null); } actions = UpdateUINodeSizes(new Vector2(k_NodeSize, k_NodeSize), new Vector2(k_NodeSize, k_NodeSize), new Vector2(k_NodeSize, k_NodeSize)); while (actions.MoveNext()) { yield return(null); } float node1Node2Spacing = Math.Abs(m_ReferenceNode1.layout.yMax - m_ReferenceNode2.layout.yMin); float positionC = m_ReferenceNode2.layout.yMax + node1Node2Spacing; float offSetY = positionC - m_SnappedNode.layout.yMin + k_SnapDistance + 1; Vector2 moveOffset = new Vector2(0, offSetY); actions = MoveElementWithOffset(moveOffset); while (actions.MoveNext()) { yield return(null); } Assert.AreNotEqual(GraphViewStaticBridge.RoundToPixelGrid(positionC), m_SnappedNode.layout.yMin); Assert.AreEqual(GraphViewStaticBridge.RoundToPixelGrid(m_SnappingNodePos.y + moveOffset.y), m_SnappedNode.layout.y); yield return(null); }
public IEnumerator SpaceElementsVertically() { // Config: // +-----+ // |Node1| // +-----+ // +-----+ // |Node2| // +-----+ // +-----+ // |stick| // +-----+ // +-----+ // |place| // +-----+ GraphViewSettings.UserSettings.SpacingMarginValue = 0f; float expectedSpacingMargin = GraphViewStaticBridge.RoundToPixelGrid(GraphViewSettings.UserSettings.SpacingMarginValue); Vector2 firstNodePos = new Vector2(50, 0); Vector2 secondNodePos = new Vector2(200, 100); Vector2 stickyNotePos = new Vector2(350, 350); Vector2 placematPos = new Vector2(600, 450); var actions = SetupElements(true, firstNodePos, secondNodePos, placematPos, stickyNotePos); while (actions.MoveNext()) { yield return(null); } actions = SpaceElements(PortOrientation.Vertical); while (actions.MoveNext()) { yield return(null); } float marginBetweenFirstNodeSecondNode = m_SecondNode.layout.yMin - m_FirstNode.layout.yMax; float marginBetweenSecondNodeStickyNote = m_StickyNote.layout.yMin - m_SecondNode.layout.yMax; float marginBetweenStickyNotePlacemat = m_Placemat.layout.yMin - m_StickyNote.layout.yMax; Assert.AreEqual(expectedSpacingMargin, marginBetweenFirstNodeSecondNode); Assert.AreEqual(expectedSpacingMargin, marginBetweenSecondNodeStickyNote); Assert.AreEqual(expectedSpacingMargin, marginBetweenStickyNotePlacemat); }