mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Fixed Begin- & EndZoomed to allow usage multiple times in one frame
Updated comment selecting code for better ux
This commit is contained in:
parent
4730f6a0df
commit
76dcbb94c6
@ -23,6 +23,7 @@ namespace XNodeEditor {
|
||||
[NonSerialized] private XNode.NodePort draggedOutputTarget = null;
|
||||
[NonSerialized] private List<Vector2> draggedOutputReroutes = new List<Vector2>();
|
||||
[NonSerialized] private XNode.NodeGraphComment hoveredComment = null;
|
||||
[NonSerialized] private bool deselectingComment = false;
|
||||
[NonSerialized] private XNode.NodeGraphComment resizingComment = null;
|
||||
public enum NodeGraphCommentSide { Top, TopRight, Right, BottomRight, Bottom, BottomLeft, Left, TopLeft }
|
||||
public static NodeGraphCommentSide resizingCommentSide;
|
||||
@ -75,6 +76,7 @@ namespace XNodeEditor {
|
||||
}
|
||||
Repaint();
|
||||
} else if (currentActivity == NodeActivity.HoldNode || currentActivity == NodeActivity.HoldComment) {
|
||||
deselectingComment = false;
|
||||
RecalculateDragOffsets(e);
|
||||
currentActivity = NodeActivity.DragNode;
|
||||
Repaint();
|
||||
@ -251,14 +253,7 @@ namespace XNodeEditor {
|
||||
SelectNodesInComment(hoveredComment);
|
||||
}
|
||||
else SelectComment(hoveredComment, e.control || e.shift);
|
||||
}
|
||||
else if (e.control || e.shift) {
|
||||
DeselectComment(hoveredComment);
|
||||
if (e.shift)
|
||||
{
|
||||
DeselectNodesInComment(hoveredComment);
|
||||
}
|
||||
} else SelectComment(hoveredComment, false);
|
||||
} else deselectingComment = true;
|
||||
|
||||
e.Use();
|
||||
currentActivity = NodeActivity.HoldComment;
|
||||
@ -319,6 +314,15 @@ namespace XNodeEditor {
|
||||
SelectNode(hoveredNode, false);
|
||||
}
|
||||
|
||||
if (currentActivity == NodeActivity.HoldComment && deselectingComment) {
|
||||
DeselectComment(hoveredComment);
|
||||
if (e.shift) {
|
||||
DeselectNodesInComment(hoveredComment);
|
||||
}
|
||||
|
||||
deselectingComment = false;
|
||||
}
|
||||
|
||||
// If click reroute, select it.
|
||||
if (IsHoveringReroute && !(e.control || e.shift)) {
|
||||
selectedReroutes = new List<RerouteReference>() { hoveredReroute };
|
||||
|
||||
@ -15,6 +15,7 @@ namespace XNodeEditor {
|
||||
public event Action onLateGUI;
|
||||
public XNode.NodeGraphComment renamingComment;
|
||||
public bool renamingStarted = false;
|
||||
private Matrix4x4 _prevGuiMatrix;
|
||||
|
||||
private void OnGUI() {
|
||||
Event e = Event.current;
|
||||
@ -48,24 +49,40 @@ namespace XNodeEditor {
|
||||
GUI.matrix = m;
|
||||
}
|
||||
|
||||
public static void BeginZoomed(Rect rect, float zoom, float topPadding) {
|
||||
GUI.EndClip();
|
||||
|
||||
GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f);
|
||||
Vector4 padding = new Vector4(0, topPadding, 0, 0);
|
||||
padding *= zoom;
|
||||
GUI.BeginClip(new Rect(-((rect.width * zoom) - rect.width) * 0.5f, -(((rect.height * zoom) - rect.height) * 0.5f) + (topPadding * zoom),
|
||||
rect.width * zoom,
|
||||
rect.height * zoom));
|
||||
public static Rect ScaleSizeBy(Rect rect, float scale, Vector2 pivotPoint) {
|
||||
Rect result = rect;
|
||||
result.x -= pivotPoint.x;
|
||||
result.y -= pivotPoint.y;
|
||||
result.xMin *= scale;
|
||||
result.xMax *= scale;
|
||||
result.yMin *= scale;
|
||||
result.yMax *= scale;
|
||||
result.x += pivotPoint.x;
|
||||
result.y += pivotPoint.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void EndZoomed(Rect rect, float zoom, float topPadding) {
|
||||
GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f);
|
||||
Vector3 offset = new Vector3(
|
||||
(((rect.width * zoom) - rect.width) * 0.5f),
|
||||
(((rect.height * zoom) - rect.height) * 0.5f) + (-topPadding * zoom) + topPadding,
|
||||
0);
|
||||
GUI.matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one);
|
||||
public static Vector2 TopLeft(Rect rect) {
|
||||
return new Vector2(rect.xMin, rect.yMin);
|
||||
}
|
||||
|
||||
public void BeginZoomed() {
|
||||
GUI.EndGroup();
|
||||
|
||||
Rect clippedArea = ScaleSizeBy(position, zoom, TopLeft(position));
|
||||
GUI.BeginGroup(clippedArea);
|
||||
|
||||
_prevGuiMatrix = GUI.matrix;
|
||||
Matrix4x4 translation = Matrix4x4.TRS(TopLeft(clippedArea), Quaternion.identity, Vector3.one);
|
||||
Matrix4x4 scale = Matrix4x4.Scale(new Vector3(1.0f / zoom, 1.0f / zoom, 1.0f));
|
||||
GUI.matrix = translation * scale * translation.inverse * GUI.matrix;
|
||||
|
||||
}
|
||||
|
||||
public void EndZoomed() {
|
||||
GUI.matrix = _prevGuiMatrix;
|
||||
GUI.EndGroup();
|
||||
GUI.BeginGroup(new Rect(0.0f, topPadding, Screen.width, Screen.height));
|
||||
}
|
||||
|
||||
public void DrawGrid(Rect rect, float zoom, Vector2 panOffset) {
|
||||
@ -254,7 +271,7 @@ namespace XNodeEditor {
|
||||
if (onValidate != null) nodeHash = Selection.activeObject.GetHashCode();
|
||||
}
|
||||
|
||||
BeginZoomed(position, zoom, topPadding);
|
||||
BeginZoomed();
|
||||
|
||||
Vector2 mousePos = Event.current.mousePosition;
|
||||
|
||||
@ -386,7 +403,7 @@ namespace XNodeEditor {
|
||||
}
|
||||
|
||||
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
||||
EndZoomed(position, zoom, topPadding);
|
||||
EndZoomed();
|
||||
|
||||
//If a change in hash is detected in the selected node, call OnValidate method.
|
||||
//This is done through reflection because OnValidate is only relevant in editor,
|
||||
@ -429,7 +446,7 @@ namespace XNodeEditor {
|
||||
{
|
||||
Event e = Event.current;
|
||||
|
||||
BeginZoomed(position, zoom, topPadding);
|
||||
BeginZoomed();
|
||||
Vector2 mousePos = Event.current.mousePosition;
|
||||
|
||||
if (e.type != EventType.Layout) {
|
||||
@ -502,7 +519,6 @@ namespace XNodeEditor {
|
||||
GUI.Label(lastRect, comment.comment, NodeEditorResources.styles.commentHeader);
|
||||
}
|
||||
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
GUILayout.EndVertical();
|
||||
@ -582,7 +598,7 @@ namespace XNodeEditor {
|
||||
}
|
||||
|
||||
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
||||
EndZoomed(position, zoom, topPadding);
|
||||
EndZoomed();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user