From 3ba0b13c77c50a91b278b44f9cdd21cf7b389f8b Mon Sep 17 00:00:00 2001 From: Adsitoz Date: Tue, 18 Jun 2019 19:34:23 +1000 Subject: [PATCH] Zoom System Fixes (#155) - Due to the OnGUI method being called last to draw over everything else in the window, the GUI.Group being created in the new zoom system was also moving around the GUI elements created in the NodeGraphEditor OnGUI method. --- Scripts/Editor/NodeEditorGUI.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs index aa88505..7447b8a 100644 --- a/Scripts/Editor/NodeEditorGUI.cs +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -12,6 +12,8 @@ namespace XNodeEditor { private List culledNodes; /// 19 if docked, 22 if not private int topPadding { get { return isDocked() ? 19 : 22; } } + /// 0 if docked, 3 if not + private int leftPadding { get { return isDocked() ? 2 : 0; } } /// Executed after all other window GUI. Useful if Zoom is ruining your day. Automatically resets after being run. public event Action onLateGUI; @@ -30,7 +32,7 @@ namespace XNodeEditor { DrawNodes(); DrawSelectionBox(); DrawTooltip(); - graphEditor.OnGUI(); + DrawGraphOnGUI(); // Run and reset onLateGUI if (onLateGUI != null) { @@ -64,6 +66,16 @@ namespace XNodeEditor { GUI.BeginGroup(new Rect(0.0f, topPadding - (topPadding * zoom), Screen.width, Screen.height)); } + /// Ends the GUI Group temporarily to draw any additional elements in the NodeGraphEditor. + private void DrawGraphOnGUI() { + GUI.EndGroup(); + Rect rect = new Rect(new Vector2(leftPadding, topPadding), new Vector2(Screen.width, Screen.height)); + GUI.BeginGroup(rect); + graphEditor.OnGUI(); + GUI.EndGroup(); + 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;