Browse Source

Optimize Fungus Script window repainting #75

Repaint as fast as possible only whenever a node or the script area is
being dragged.
master
chrisgregan 10 years ago
parent
commit
83d42b7453
  1. 17
      Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

17
Assets/Fungus/FungusScript/Editor/FungusScriptWindow.cs

@ -28,6 +28,8 @@ namespace Fungus
protected bool mouseOverVariables = false; protected bool mouseOverVariables = false;
protected int forceRepaintCount;
[MenuItem("Window/Fungus Script")] [MenuItem("Window/Fungus Script")]
static void Init() static void Init()
{ {
@ -68,6 +70,9 @@ namespace Fungus
sequenceInspector.sequence = fungusScript.selectedSequence; sequenceInspector.sequence = fungusScript.selectedSequence;
} }
forceRepaintCount--;
forceRepaintCount = Math.Max(0, forceRepaintCount);
Repaint(); Repaint();
} }
@ -128,8 +133,11 @@ namespace Fungus
DrawScriptView(fungusScript); DrawScriptView(fungusScript);
DrawOverlay(fungusScript); DrawOverlay(fungusScript);
// Redraw on next frame to get crisp refresh rate if (forceRepaintCount > 0)
Repaint(); {
// Redraw on next frame to get crisp refresh rate
Repaint();
}
} }
protected virtual void DrawOverlay(FungusScript fungusScript) protected virtual void DrawOverlay(FungusScript fungusScript)
@ -272,6 +280,8 @@ namespace Fungus
{ {
sequence.nodeRect.x += Event.current.delta.x; sequence.nodeRect.x += Event.current.delta.x;
sequence.nodeRect.y += Event.current.delta.y; sequence.nodeRect.y += Event.current.delta.y;
forceRepaintCount = 6;
} }
else if (Event.current.type == EventType.MouseUp && else if (Event.current.type == EventType.MouseUp &&
dragWindowId == i) dragWindowId == i)
@ -287,6 +297,7 @@ namespace Fungus
sequence.nodeRect.y = newPos.y; sequence.nodeRect.y = newPos.y;
dragWindowId = -1; dragWindowId = -1;
forceRepaintCount = 6;
} }
} }
@ -344,11 +355,13 @@ namespace Fungus
if (Event.current.button == 1 && Event.current.type == EventType.MouseDrag) if (Event.current.button == 1 && Event.current.type == EventType.MouseDrag)
{ {
fungusScript.scrollPos += Event.current.delta; fungusScript.scrollPos += Event.current.delta;
forceRepaintCount = 6;
} }
else if (Event.current.type == EventType.ScrollWheel) else if (Event.current.type == EventType.ScrollWheel)
{ {
fungusScript.zoom -= Event.current.delta.y * 0.01f; fungusScript.zoom -= Event.current.delta.y * 0.01f;
fungusScript.zoom = Mathf.Clamp(fungusScript.zoom, minZoomValue, maxZoomValue); fungusScript.zoom = Mathf.Clamp(fungusScript.zoom, minZoomValue, maxZoomValue);
forceRepaintCount = 6;
} }
GLDraw.EndGroup(); GLDraw.EndGroup();

Loading…
Cancel
Save