mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 01:36:03 +08:00
Node hover update
This commit is contained in:
parent
94b9318858
commit
23a3e0e732
@ -31,14 +31,12 @@ public partial class NodeEditorWindow {
|
|||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case EventType.MouseMove:
|
case EventType.MouseMove:
|
||||||
UpdateHovered();
|
|
||||||
break;
|
break;
|
||||||
case EventType.ScrollWheel:
|
case EventType.ScrollWheel:
|
||||||
if (e.delta.y > 0) zoom += 0.1f * zoom;
|
if (e.delta.y > 0) zoom += 0.1f * zoom;
|
||||||
else zoom -= 0.1f * zoom;
|
else zoom -= 0.1f * zoom;
|
||||||
break;
|
break;
|
||||||
case EventType.MouseDrag:
|
case EventType.MouseDrag:
|
||||||
UpdateHovered();
|
|
||||||
if (e.button == 0) {
|
if (e.button == 0) {
|
||||||
if (IsDraggingPort) {
|
if (IsDraggingPort) {
|
||||||
if (IsHoveringPort && hoveredPort.IsInput) {
|
if (IsHoveringPort && hoveredPort.IsInput) {
|
||||||
@ -62,7 +60,6 @@ public partial class NodeEditorWindow {
|
|||||||
if (e.keyCode == KeyCode.F) Home();
|
if (e.keyCode == KeyCode.F) Home();
|
||||||
break;
|
break;
|
||||||
case EventType.MouseDown:
|
case EventType.MouseDown:
|
||||||
UpdateHovered();
|
|
||||||
Repaint();
|
Repaint();
|
||||||
SelectNode(hoveredNode);
|
SelectNode(hoveredNode);
|
||||||
if (IsHoveringPort) {
|
if (IsHoveringPort) {
|
||||||
@ -103,7 +100,6 @@ public partial class NodeEditorWindow {
|
|||||||
if (!isPanning) ShowContextMenu();
|
if (!isPanning) ShowContextMenu();
|
||||||
isPanning = false;
|
isPanning = false;
|
||||||
}
|
}
|
||||||
UpdateHovered();
|
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -133,49 +129,6 @@ public partial class NodeEditorWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Updates <see cref="hoveredNode"/> and <see cref="hoveredPort"/> </summary>
|
|
||||||
void UpdateHovered() {
|
|
||||||
Vector2 mousePos = Event.current.mousePosition;
|
|
||||||
Node newHoverNode = null;
|
|
||||||
foreach (Node node in graph.nodes) {
|
|
||||||
if (node == null) return;
|
|
||||||
//Get node position
|
|
||||||
Vector2 nodePos = GridToWindowPosition(node.rect.position);
|
|
||||||
Rect windowRect = new Rect(nodePos, new Vector2(node.rect.size.x / zoom, node.rect.size.y / zoom));
|
|
||||||
if (windowRect.Contains(mousePos)) {
|
|
||||||
newHoverNode = node;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newHoverNode != hoveredNode) {
|
|
||||||
hoveredNode = newHoverNode;
|
|
||||||
Repaint();
|
|
||||||
}
|
|
||||||
//If we are hovering a node, check if we are also hovering a port
|
|
||||||
NodePort newHoverPort = null;
|
|
||||||
//Check all input ports
|
|
||||||
for (int k = 0; k < graph.nodes.Count; k++) {
|
|
||||||
|
|
||||||
for (int i = 0; i < graph.nodes[k].InputCount; i++) {
|
|
||||||
NodePort port = graph.nodes[k].inputs[i];
|
|
||||||
//Check if port rect is available
|
|
||||||
if (!portConnectionPoints.ContainsKey(port)) continue;
|
|
||||||
Rect r = GridToWindowRect(portConnectionPoints[port]);
|
|
||||||
if (r.Contains(mousePos)) newHoverPort = port;
|
|
||||||
}
|
|
||||||
//Check all output ports
|
|
||||||
for (int i = 0; i < graph.nodes[k].OutputCount; i++) {
|
|
||||||
NodePort port = graph.nodes[k].outputs[i];
|
|
||||||
//Check if port rect is available
|
|
||||||
if (!portConnectionPoints.ContainsKey(port)) continue;
|
|
||||||
Rect r = GridToWindowRect(portConnectionPoints[port]);
|
|
||||||
if (r.Contains(mousePos)) newHoverPort = port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newHoverPort != hoveredPort) {
|
|
||||||
hoveredPort = newHoverPort;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsHoveringTitle(Node node) {
|
bool IsHoveringTitle(Node node) {
|
||||||
Vector2 mousePos = Event.current.mousePosition;
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
//Get node position
|
//Get node position
|
||||||
|
|||||||
@ -151,6 +151,9 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
BeginZoomed(position, zoom);
|
BeginZoomed(position, zoom);
|
||||||
|
|
||||||
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
|
|
||||||
|
|
||||||
foreach (Node node in graph.nodes) {
|
foreach (Node node in graph.nodes) {
|
||||||
if (node == null) return;
|
if (node == null) return;
|
||||||
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
NodeEditor nodeEditor = GetNodeEditor(node.GetType());
|
||||||
@ -169,7 +172,6 @@ public partial class NodeEditorWindow {
|
|||||||
//Draw node contents
|
//Draw node contents
|
||||||
Dictionary<NodePort, Vector2> portHandlePoints;
|
Dictionary<NodePort, Vector2> portHandlePoints;
|
||||||
nodeEditor.OnNodeGUI(out portHandlePoints);
|
nodeEditor.OnNodeGUI(out portHandlePoints);
|
||||||
EditorGUILayout.Space();
|
|
||||||
|
|
||||||
if (e.type == EventType.Repaint) {
|
if (e.type == EventType.Repaint) {
|
||||||
foreach (var kvp in portHandlePoints) {
|
foreach (var kvp in portHandlePoints) {
|
||||||
@ -182,7 +184,31 @@ public partial class NodeEditorWindow {
|
|||||||
|
|
||||||
GUILayout.EndVertical();
|
GUILayout.EndVertical();
|
||||||
|
|
||||||
//if (e.type == EventType.Repaint) node.rect.size = GUILayoutUtility.GetLastRect().size;
|
//Check if we are hovering this node
|
||||||
|
Vector2 nodeSize = GUILayoutUtility.GetLastRect().size / zoom;
|
||||||
|
Rect windowRect = new Rect(nodePos, nodeSize);
|
||||||
|
if (windowRect.Contains(mousePos)) hoveredNode = node;
|
||||||
|
|
||||||
|
//Check if we are hovering any of this nodes ports
|
||||||
|
//Check input ports
|
||||||
|
for (int i = 0; i < node.InputCount; i++)
|
||||||
|
{
|
||||||
|
NodePort port = node.inputs[i];
|
||||||
|
//Check if port rect is available
|
||||||
|
if (!portConnectionPoints.ContainsKey(port)) continue;
|
||||||
|
Rect r = GridToWindowRect(portConnectionPoints[port]);
|
||||||
|
if (r.Contains(mousePos)) hoveredPort = port;
|
||||||
|
}
|
||||||
|
//Check all output ports
|
||||||
|
for (int i = 0; i < node.OutputCount; i++)
|
||||||
|
{
|
||||||
|
NodePort port = node.outputs[i];
|
||||||
|
//Check if port rect is available
|
||||||
|
if (!portConnectionPoints.ContainsKey(port)) continue;
|
||||||
|
Rect r = GridToWindowRect(portConnectionPoints[port]);
|
||||||
|
if (r.Contains(mousePos)) hoveredPort = port;
|
||||||
|
}
|
||||||
|
|
||||||
GUILayout.EndArea();
|
GUILayout.EndArea();
|
||||||
}
|
}
|
||||||
EndZoomed(position, zoom);
|
EndZoomed(position, zoom);
|
||||||
|
|||||||
@ -48,13 +48,10 @@ public static class NodeEditorResources {
|
|||||||
nodeBody = new GUIStyle();
|
nodeBody = new GUIStyle();
|
||||||
nodeBody.normal.background = NodeEditorResources.nodeBody;
|
nodeBody.normal.background = NodeEditorResources.nodeBody;
|
||||||
nodeBody.border = new RectOffset(32, 32, 32, 32);
|
nodeBody.border = new RectOffset(32, 32, 32, 32);
|
||||||
nodeBody.padding = new RectOffset(16, 16, 4, 6);
|
nodeBody.padding = new RectOffset(16, 16, 4, 16);
|
||||||
|
|
||||||
tooltip = new GUIStyle("helpBox");
|
tooltip = new GUIStyle("helpBox");
|
||||||
tooltip.alignment = TextAnchor.MiddleCenter;
|
tooltip.alignment = TextAnchor.MiddleCenter;
|
||||||
//tooltip.border = new RectOffset(0, 0, 0, 0);
|
|
||||||
//tooltip.normal.background
|
|
||||||
//tooltip.padding = new RectOffset(0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user