Browse Source

Merge pull request #558 from zvinless/zoom-updates

Flowchart window improvements - zoom updates
master
Chris Gregan 8 years ago committed by GitHub
parent
commit
10b16bdbb5
  1. 29
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

29
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -35,9 +35,9 @@ namespace Fungus.EditorUtils
protected Texture2D addTexture; protected Texture2D addTexture;
protected Rect selectionBox; protected Rect selectionBox;
protected Vector2 startSelectionBoxPosition; protected Vector2 startSelectionBoxPosition = new Vector2(-1.0f, -1.0f);
protected List<Block> mouseDownSelectionState; protected List<Block> mouseDownSelectionState = new List<Block>();
[MenuItem("Tools/Fungus/Flowchart Window")] [MenuItem("Tools/Fungus/Flowchart Window")]
static void Init() static void Init()
{ {
@ -173,7 +173,8 @@ namespace Fungus.EditorUtils
GUILayout.Space(8); GUILayout.Space(8);
flowchart.Zoom = GUILayout.HorizontalSlider(flowchart.Zoom, minZoomValue, maxZoomValue, GUILayout.Width(100)); var newZoom = GUILayout.HorizontalSlider(flowchart.Zoom, minZoomValue, maxZoomValue, GUILayout.Width(100));
DoZoom(flowchart, newZoom - flowchart.Zoom, Vector2.one * 0.5f);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
@ -581,12 +582,26 @@ namespace Fungus.EditorUtils
if (zoom && selectionBox.size == Vector2.zero) if (zoom && selectionBox.size == Vector2.zero)
{ {
flowchart.Zoom -= Event.current.delta.y * 0.01f; Vector2 zoomCenter;
flowchart.Zoom = Mathf.Clamp(flowchart.Zoom, minZoomValue, maxZoomValue); zoomCenter.x = Event.current.mousePosition.x / position.width;
forceRepaintCount = 6; zoomCenter.y = Event.current.mousePosition.y / position.height;
zoomCenter *= flowchart.Zoom;
DoZoom(flowchart, -Event.current.delta.y * 0.01f, zoomCenter);
} }
} }
protected virtual void DoZoom(Flowchart flowchart, float delta, Vector2 center)
{
var prevZoom = flowchart.Zoom;
flowchart.Zoom += delta;
flowchart.Zoom = Mathf.Clamp(flowchart.Zoom, minZoomValue, maxZoomValue);
var deltaSize = position.size / prevZoom - position.size / flowchart.Zoom;
var offset = -Vector2.Scale(deltaSize, center);
flowchart.ScrollPos += offset;
forceRepaintCount = 6;
}
protected virtual void DrawGrid(Flowchart flowchart) protected virtual void DrawGrid(Flowchart flowchart)
{ {
float width = this.position.width / flowchart.Zoom; float width = this.position.width / flowchart.Zoom;

Loading…
Cancel
Save