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>
|
||||
public event Action onLateGUI;
|
||||
|
||||
private Matrix4x4 prevGuiMatrix;
|
||||
|
||||
private void OnGUI() {
|
||||
Event e = Event.current;
|
||||
Matrix4x4 m = GUI.matrix;
|
||||
@ -44,27 +42,24 @@ namespace XNodeEditor {
|
||||
GUI.matrix = m;
|
||||
}
|
||||
|
||||
public void BeginZoomed() {
|
||||
GUI.EndGroup();
|
||||
public static void BeginZoomed(Rect rect, float zoom, float topPadding) {
|
||||
GUI.EndClip();
|
||||
|
||||
Rect position = new Rect(this.position);
|
||||
position.x = 0;
|
||||
position.y = topPadding;
|
||||
|
||||
Vector2 topLeft = new Vector2(position.xMin, position.yMin - topPadding);
|
||||
Rect clippedArea = ScaleSizeBy(position, zoom, topLeft);
|
||||
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;
|
||||
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 void EndZoomed() {
|
||||
GUI.matrix = prevGuiMatrix;
|
||||
GUI.EndGroup();
|
||||
GUI.BeginGroup(new Rect(0.0f, topPadding - (topPadding * zoom), Screen.width, Screen.height));
|
||||
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);
|
||||
}
|
||||
|
||||
/// <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));
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
rect.position = Vector2.zero;
|
||||
@ -168,7 +150,8 @@ namespace XNodeEditor {
|
||||
|
||||
p = new Vector2(-p.y, p.x) * Mathf.Sign(side) * tangentLength;
|
||||
inputTangent = p;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@ -414,7 +403,12 @@ namespace XNodeEditor {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user