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. 25
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

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

@ -35,8 +35,8 @@ namespace Fungus.EditorUtils
protected Texture2D addTexture;
protected Rect selectionBox;
protected Vector2 startSelectionBoxPosition;
protected List<Block> mouseDownSelectionState;
protected Vector2 startSelectionBoxPosition = new Vector2(-1.0f, -1.0f);
protected List<Block> mouseDownSelectionState = new List<Block>();
[MenuItem("Tools/Fungus/Flowchart Window")]
static void Init()
@ -173,7 +173,8 @@ namespace Fungus.EditorUtils
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();
@ -581,11 +582,25 @@ namespace Fungus.EditorUtils
if (zoom && selectionBox.size == Vector2.zero)
{
flowchart.Zoom -= Event.current.delta.y * 0.01f;
Vector2 zoomCenter;
zoomCenter.x = Event.current.mousePosition.x / position.width;
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)
{

Loading…
Cancel
Save