Browse Source

Make focusing only move the camera the first time (#194)

Focusing a second time without changing the selection will change the
scale too.
Note that this currently applies to all ways of focusing on an element (keyboard
shortcut "F", double click in the scene tree and double click on the
element in the scene view)
Leonardo Jeanteur 4 years ago
parent
commit
0dd47c8725
1 changed files with 17 additions and 2 deletions
  1. 17 2
      hide/comp/SceneEditor.hx

+ 17 - 2
hide/comp/SceneEditor.hx

@@ -169,6 +169,8 @@ class SceneEditor {
 	var sceneData : PrefabElement;
 	var lastRenderProps : hrt.prefab.RenderProps;
 
+	var focusedSinceSelect = false;
+
 	public function new(view, data) {
 		ide = hide.Ide.inst;
 		this.view = view;
@@ -325,7 +327,8 @@ class SceneEditor {
 			}
 			if(!bnds.isEmpty()) {
 				var s = bnds.toSphere();
-				cameraController.set(s.r * 4.0, null, null, s.getCenter());
+				var r = focusedSinceSelect ? s.r * 4.0 : null;
+				cameraController.set(r, null, null, s.getCenter());
 			}
 			else {
 				centroid.scale3(1.0 / curEdit.rootObjects.length);
@@ -334,6 +337,7 @@ class SceneEditor {
 		}
 		for(obj in curEdit.rootElements)
 			tree.revealNode(obj);
+		focusedSinceSelect = true;
 	}
 
 	function getAvailableTags(p: PrefabElement) : Array<{id: String, color: String}>{
@@ -1539,8 +1543,9 @@ class SceneEditor {
 			setupGizmo();
 		}
 
+		var prev : Array<PrefabElement> = null;
 		if( curEdit != null && mode.match(Default|NoTree) ) {
-			var prev = curEdit.rootElements.copy();
+			prev = curEdit.rootElements.copy();
 			undo.change(Custom(function(u) {
 				if(u) impl(prev,NoHistory);
 				else impl(elts,NoHistory);
@@ -1548,6 +1553,16 @@ class SceneEditor {
 		}
 
 		impl(elts,mode);
+		if( prev == null || curEdit.rootElements.length != prev.length ) {
+			focusedSinceSelect = false;
+			return;
+		}
+		for( i in 0...curEdit.rootElements.length ) {
+			if( curEdit.rootElements[i] != prev[i] ) {
+				focusedSinceSelect = false;
+				return;
+			}
+		}
 	}
 
 	function hasBeenRemoved( e : hrt.prefab.Prefab ) {