mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Revert "Improved zoom with the help of Jeroenimoo0's PR"
This commit caused issues with the selection box
This commit is contained in:
parent
ba48e32a22
commit
d45f396ebf
@ -18,8 +18,6 @@ namespace XNodeEditor {
|
|||||||
/// <summary> Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run.</summary>
|
/// <summary> Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run.</summary>
|
||||||
public event Action onLateGUI;
|
public event Action onLateGUI;
|
||||||
|
|
||||||
private Matrix4x4 prevGuiMatrix;
|
|
||||||
|
|
||||||
private void OnGUI() {
|
private void OnGUI() {
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
Matrix4x4 m = GUI.matrix;
|
Matrix4x4 m = GUI.matrix;
|
||||||
@ -44,27 +42,24 @@ namespace XNodeEditor {
|
|||||||
GUI.matrix = m;
|
GUI.matrix = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BeginZoomed() {
|
public static void BeginZoomed(Rect rect, float zoom, float topPadding) {
|
||||||
GUI.EndGroup();
|
GUI.EndClip();
|
||||||
|
|
||||||
Rect position = new Rect(this.position);
|
GUIUtility.ScaleAroundPivot(Vector2.one / zoom, rect.size * 0.5f);
|
||||||
position.x = 0;
|
Vector4 padding = new Vector4(0, topPadding, 0, 0);
|
||||||
position.y = topPadding;
|
padding *= zoom;
|
||||||
|
GUI.BeginClip(new Rect(-((rect.width * zoom) - rect.width) * 0.5f, -(((rect.height * zoom) - rect.height) * 0.5f) + (topPadding * zoom),
|
||||||
Vector2 topLeft = new Vector2(position.xMin, position.yMin - topPadding);
|
rect.width * zoom,
|
||||||
Rect clippedArea = ScaleSizeBy(position, zoom, topLeft);
|
rect.height * zoom));
|
||||||
GUI.BeginGroup(clippedArea);
|
|
||||||
|
|
||||||
prevGuiMatrix = GUI.matrix;
|
|
||||||
Matrix4x4 translation = Matrix4x4.TRS(Vector3.zero, 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() {
|
public static void EndZoomed(Rect rect, float zoom, float topPadding) {
|
||||||
GUI.matrix = prevGuiMatrix;
|
GUIUtility.ScaleAroundPivot(Vector2.one * zoom, rect.size * 0.5f);
|
||||||
GUI.EndGroup();
|
Vector3 offset = new Vector3(
|
||||||
GUI.BeginGroup(new Rect(0.0f, topPadding - (topPadding * zoom), Screen.width, Screen.height));
|
(((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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Ends the GUI Group temporarily to draw any additional elements in the NodeGraphEditor. </summary>
|
/// <summary> Ends the GUI Group temporarily to draw any additional elements in the NodeGraphEditor. </summary>
|
||||||
@ -77,19 +72,6 @@ namespace XNodeEditor {
|
|||||||
GUI.BeginGroup(new Rect(0.0f, topPadding - (topPadding * zoom), Screen.width, Screen.height));
|
GUI.BeginGroup(new Rect(0.0f, topPadding - (topPadding * zoom), Screen.width, Screen.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
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 void DrawGrid(Rect rect, float zoom, Vector2 panOffset) {
|
public void DrawGrid(Rect rect, float zoom, Vector2 panOffset) {
|
||||||
|
|
||||||
rect.position = Vector2.zero;
|
rect.position = Vector2.zero;
|
||||||
@ -168,7 +150,8 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
p = new Vector2(-p.y, p.x) * Mathf.Sign(side) * tangentLength;
|
p = new Vector2(-p.y, p.x) * Mathf.Sign(side) * tangentLength;
|
||||||
inputTangent = p;
|
inputTangent = p;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
inputTangent = Vector2.left * Vector2.Distance(windowPoints[i], windowPoints[i + 1]) * 0.01f * zoom;
|
inputTangent = Vector2.left * Vector2.Distance(windowPoints[i], windowPoints[i + 1]) * 0.01f * zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,7 +266,13 @@ namespace XNodeEditor {
|
|||||||
selectionCache = new List<UnityEngine.Object>(Selection.objects);
|
selectionCache = new List<UnityEngine.Object>(Selection.objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginZoomed();
|
System.Reflection.MethodInfo onValidate = null;
|
||||||
|
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
|
||||||
|
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
|
||||||
|
if (onValidate != null) EditorGUI.BeginChangeCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
BeginZoomed(position, zoom, topPadding);
|
||||||
|
|
||||||
Vector2 mousePos = Event.current.mousePosition;
|
Vector2 mousePos = Event.current.mousePosition;
|
||||||
|
|
||||||
@ -414,7 +403,12 @@ namespace XNodeEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
||||||
EndZoomed();
|
EndZoomed(position, zoom, topPadding);
|
||||||
|
|
||||||
|
//If a change in is detected in the selected node, call OnValidate method.
|
||||||
|
//This is done through reflection because OnValidate is only relevant in editor,
|
||||||
|
//and thus, the code should not be included in build.
|
||||||
|
if (onValidate != null && EditorGUI.EndChangeCheck()) onValidate.Invoke(Selection.activeObject, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldBeCulled(XNode.Node node) {
|
private bool ShouldBeCulled(XNode.Node node) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user