diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 74924ac..34f9093 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -27,8 +27,6 @@ namespace XNodeEditor { [NonSerialized] private XNode.NodeGroup hoveredGroup = null; [NonSerialized] private XNode.NodeGroup resizingGroup = null; private bool deselectingGroup = false; - public enum NodeGroupSide { Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft } - public static NodeGroupSide resizingGroupSide; private RerouteReference hoveredReroute = new RerouteReference(); private List selectedReroutes = new List(); private Vector2 dragBoxStart; @@ -130,8 +128,7 @@ namespace XNodeEditor { } } } - } - else if(Selection.objects[i] is XNode.NodeGroup) { + } else if (Selection.objects[i] is XNode.NodeGroup) { XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup; Vector2 initial = group.position; group.position = mousePos + dragOffset[i]; @@ -165,42 +162,7 @@ namespace XNodeEditor { selectionBox = new Rect(boxStartPos, boxSize); Repaint(); } else if (currentActivity == NodeActivity.ResizeGroup) { - switch (resizingGroupSide) { - case NodeGroupSide.Top: - resizingGroup.size.y -= e.delta.y; - resizingGroup.position.y += e.delta.y; - break; - case NodeGroupSide.TopRight: - resizingGroup.size.y -= e.delta.y; - resizingGroup.position.y += e.delta.y; - resizingGroup.size.x += e.delta.x; - break; - case NodeGroupSide.Right: - resizingGroup.size.x += e.delta.x; - break; - case NodeGroupSide.BottomRight: - resizingGroup.size += e.delta; - break; - case NodeGroupSide.Bottom: - resizingGroup.size.y += e.delta.y; - break; - case NodeGroupSide.BottomLeft: - resizingGroup.size.x -= e.delta.x; - resizingGroup.position.x += e.delta.x; - resizingGroup.size.y += e.delta.y; - break; - case NodeGroupSide.Left: - resizingGroup.size.x -= e.delta.x; - resizingGroup.position.x += e.delta.x; - break; - case NodeGroupSide.TopLeft: - resizingGroup.size.x -= e.delta.x; - resizingGroup.position.x += e.delta.x; - resizingGroup.size.y -= e.delta.y; - resizingGroup.position.y += e.delta.y; - break; - } - + resizingGroup.size += e.delta; Repaint(); } } else if (e.button == 1 || e.button == 2) { @@ -257,14 +219,12 @@ namespace XNodeEditor { else if (e.control || e.shift) selectedReroutes.Remove(hoveredReroute); e.Use(); currentActivity = NodeActivity.HoldNode; - } - else if (IsHoveringGroup && !IsHoveringNode) { + } else if (IsHoveringGroup && !IsHoveringNode) { if (!Selection.Contains(hoveredGroup)) { if (e.shift) { SelectGroup(hoveredGroup, true); SelectNodesInGroup(hoveredGroup); - } - else SelectGroup(hoveredGroup, e.control || e.shift); + } else SelectGroup(hoveredGroup, e.control || e.shift); } else deselectingGroup = true; e.Use(); @@ -437,8 +397,7 @@ namespace XNodeEditor { if (Selection.objects[i] is XNode.Node) { XNode.Node node = Selection.objects[i] as XNode.Node; dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition); - } - else if (Selection.objects[i] is XNode.NodeGroup) { + } else if (Selection.objects[i] is XNode.NodeGroup) { XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup; dragOffset[i] = group.position - WindowToGridPosition(current.mousePosition); } @@ -468,8 +427,7 @@ namespace XNodeEditor { if (item is XNode.Node) { XNode.Node node = item as XNode.Node; graphEditor.RemoveNode(node); - } - else if (item is XNode.NodeGroup) { + } else if (item is XNode.NodeGroup) { XNode.NodeGroup group = item as XNode.NodeGroup; graphEditor.RemoveGroup(group); } diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index 09bddda..260e860 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -446,8 +446,7 @@ namespace XNodeEditor { } } - private void DrawGroups() - { + private void DrawGroups() { Event e = Event.current; BeginZoomed(); @@ -535,37 +534,10 @@ namespace XNodeEditor { float padding = 12; - // Resizing areas - // Follows the NodeGroupSide order - Rect[] resizeRects = new[] { - new Rect(padding, 0, groupSize.x - padding * 2, padding), - new Rect(groupSize.x - padding, 0, padding, padding), - new Rect(groupSize.x - padding, padding, padding, groupSize.y - padding * 2), - new Rect(groupSize.x - padding, groupSize.y - padding, padding, padding), - new Rect(padding, groupSize.y - padding, groupSize.x - padding * 2, padding), - new Rect(0, groupSize.y - padding, padding, padding), - new Rect(0, padding, padding, groupSize.y - padding * 2), - new Rect(0, 0, padding, padding), - }; - - // Icons for the resize area list - MouseCursor[] resizeIcons = new[] { - MouseCursor.ResizeVertical, - MouseCursor.ResizeUpRight, - MouseCursor.ResizeHorizontal, - MouseCursor.ResizeUpLeft, - MouseCursor.ResizeVertical, - MouseCursor.ResizeUpRight, - MouseCursor.ResizeHorizontal, - MouseCursor.ResizeUpLeft, - }; - - for (int i = 0; i < resizeRects.Length; i++) { - EditorGUIUtility.AddCursorRect(resizeRects[i], resizeIcons[i]); - - // Transform the locations now to gui space locations - resizeRects[i].position += groupPos; - } + // Define resize are in the bottom right corner of the NodeGroup + Rect resizeRect = new Rect(groupSize.x - padding, groupSize.y - padding, padding, padding); + EditorGUIUtility.AddCursorRect(resizeRect, MouseCursor.ResizeUpLeft); + resizeRect.position += groupPos; if (windowRect.Contains(mousePos)) { //If dragging a selection box, add nodes inside to selection @@ -574,17 +546,10 @@ namespace XNodeEditor { } else { // Check if we should resize or select bool resizeAreaClicked = false; - for (int i = 0; i < resizeRects.Length; i++) { - if (resizeRects[i].Contains(mousePos)) { - resizingGroup = group; - // i can be cast to NodeGroupSide as resizeRects - // has one element per NodeGroupSide value and - // uses the same order - resizingGroupSide = (NodeGroupSide)i; - resizeAreaClicked = true; - - break; - } + if (resizeRect.Contains(mousePos)) { + resizingGroup = group; + resizeAreaClicked = true; + break; } if (!resizeAreaClicked) hoveredGroup = group;