mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 01:06:01 +08:00
Limited NodeGroup resize to lower right corner
This commit is contained in:
parent
884878c638
commit
a01d913152
@ -27,8 +27,6 @@ namespace XNodeEditor {
|
|||||||
[NonSerialized] private XNode.NodeGroup hoveredGroup = null;
|
[NonSerialized] private XNode.NodeGroup hoveredGroup = null;
|
||||||
[NonSerialized] private XNode.NodeGroup resizingGroup = null;
|
[NonSerialized] private XNode.NodeGroup resizingGroup = null;
|
||||||
private bool deselectingGroup = false;
|
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 RerouteReference hoveredReroute = new RerouteReference();
|
||||||
private List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
private List<RerouteReference> selectedReroutes = new List<RerouteReference>();
|
||||||
private Vector2 dragBoxStart;
|
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;
|
XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup;
|
||||||
Vector2 initial = group.position;
|
Vector2 initial = group.position;
|
||||||
group.position = mousePos + dragOffset[i];
|
group.position = mousePos + dragOffset[i];
|
||||||
@ -165,42 +162,7 @@ namespace XNodeEditor {
|
|||||||
selectionBox = new Rect(boxStartPos, boxSize);
|
selectionBox = new Rect(boxStartPos, boxSize);
|
||||||
Repaint();
|
Repaint();
|
||||||
} else if (currentActivity == NodeActivity.ResizeGroup) {
|
} else if (currentActivity == NodeActivity.ResizeGroup) {
|
||||||
switch (resizingGroupSide) {
|
resizingGroup.size += e.delta;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Repaint();
|
Repaint();
|
||||||
}
|
}
|
||||||
} else if (e.button == 1 || e.button == 2) {
|
} else if (e.button == 1 || e.button == 2) {
|
||||||
@ -257,14 +219,12 @@ namespace XNodeEditor {
|
|||||||
else if (e.control || e.shift) selectedReroutes.Remove(hoveredReroute);
|
else if (e.control || e.shift) selectedReroutes.Remove(hoveredReroute);
|
||||||
e.Use();
|
e.Use();
|
||||||
currentActivity = NodeActivity.HoldNode;
|
currentActivity = NodeActivity.HoldNode;
|
||||||
}
|
} else if (IsHoveringGroup && !IsHoveringNode) {
|
||||||
else if (IsHoveringGroup && !IsHoveringNode) {
|
|
||||||
if (!Selection.Contains(hoveredGroup)) {
|
if (!Selection.Contains(hoveredGroup)) {
|
||||||
if (e.shift) {
|
if (e.shift) {
|
||||||
SelectGroup(hoveredGroup, true);
|
SelectGroup(hoveredGroup, true);
|
||||||
SelectNodesInGroup(hoveredGroup);
|
SelectNodesInGroup(hoveredGroup);
|
||||||
}
|
} else SelectGroup(hoveredGroup, e.control || e.shift);
|
||||||
else SelectGroup(hoveredGroup, e.control || e.shift);
|
|
||||||
} else deselectingGroup = true;
|
} else deselectingGroup = true;
|
||||||
|
|
||||||
e.Use();
|
e.Use();
|
||||||
@ -437,8 +397,7 @@ namespace XNodeEditor {
|
|||||||
if (Selection.objects[i] is XNode.Node) {
|
if (Selection.objects[i] is XNode.Node) {
|
||||||
XNode.Node node = Selection.objects[i] as XNode.Node;
|
XNode.Node node = Selection.objects[i] as XNode.Node;
|
||||||
dragOffset[i] = node.position - WindowToGridPosition(current.mousePosition);
|
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;
|
XNode.NodeGroup group = Selection.objects[i] as XNode.NodeGroup;
|
||||||
dragOffset[i] = group.position - WindowToGridPosition(current.mousePosition);
|
dragOffset[i] = group.position - WindowToGridPosition(current.mousePosition);
|
||||||
}
|
}
|
||||||
@ -468,8 +427,7 @@ namespace XNodeEditor {
|
|||||||
if (item is XNode.Node) {
|
if (item is XNode.Node) {
|
||||||
XNode.Node node = item as XNode.Node;
|
XNode.Node node = item as XNode.Node;
|
||||||
graphEditor.RemoveNode(node);
|
graphEditor.RemoveNode(node);
|
||||||
}
|
} else if (item is XNode.NodeGroup) {
|
||||||
else if (item is XNode.NodeGroup) {
|
|
||||||
XNode.NodeGroup group = item as XNode.NodeGroup;
|
XNode.NodeGroup group = item as XNode.NodeGroup;
|
||||||
graphEditor.RemoveGroup(group);
|
graphEditor.RemoveGroup(group);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -446,8 +446,7 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawGroups()
|
private void DrawGroups() {
|
||||||
{
|
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
|
|
||||||
BeginZoomed();
|
BeginZoomed();
|
||||||
@ -535,37 +534,10 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
float padding = 12;
|
float padding = 12;
|
||||||
|
|
||||||
// Resizing areas
|
// Define resize are in the bottom right corner of the NodeGroup
|
||||||
// Follows the NodeGroupSide order
|
Rect resizeRect = new Rect(groupSize.x - padding, groupSize.y - padding, padding, padding);
|
||||||
Rect[] resizeRects = new[] {
|
EditorGUIUtility.AddCursorRect(resizeRect, MouseCursor.ResizeUpLeft);
|
||||||
new Rect(padding, 0, groupSize.x - padding * 2, padding),
|
resizeRect.position += groupPos;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (windowRect.Contains(mousePos)) {
|
if (windowRect.Contains(mousePos)) {
|
||||||
//If dragging a selection box, add nodes inside to selection
|
//If dragging a selection box, add nodes inside to selection
|
||||||
@ -574,17 +546,10 @@ namespace XNodeEditor {
|
|||||||
} else {
|
} else {
|
||||||
// Check if we should resize or select
|
// Check if we should resize or select
|
||||||
bool resizeAreaClicked = false;
|
bool resizeAreaClicked = false;
|
||||||
for (int i = 0; i < resizeRects.Length; i++) {
|
if (resizeRect.Contains(mousePos)) {
|
||||||
if (resizeRects[i].Contains(mousePos)) {
|
resizingGroup = group;
|
||||||
resizingGroup = group;
|
resizeAreaClicked = true;
|
||||||
// i can be cast to NodeGroupSide as resizeRects
|
break;
|
||||||
// has one element per NodeGroupSide value and
|
|
||||||
// uses the same order
|
|
||||||
resizingGroupSide = (NodeGroupSide)i;
|
|
||||||
resizeAreaClicked = true;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!resizeAreaClicked) hoveredGroup = group;
|
if (!resizeAreaClicked) hoveredGroup = group;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user