Răsfoiți Sursa

[shgraph] added snap to grid toolbar

Clément Espeute 1 an în urmă
părinte
comite
e7cff05f2f
4 a modificat fișierele cu 39 adăugiri și 4 ștergeri
  1. 6 0
      bin/style.css
  2. 7 0
      bin/style.less
  3. 4 0
      hide/comp/Toolbar.hx
  4. 22 4
      hide/view/GraphEditor.hx

+ 6 - 0
bin/style.css

@@ -2090,6 +2090,12 @@ input[type=checkbox]:checked:after {
   outline: none !important;
   position: relative;
 }
+.graph-view .hide-toolbar2 {
+  position: absolute;
+  top: 10px;
+  left: 10px;
+  z-index: 999;
+}
 .graph-view .mini-preview {
   position: absolute;
   top: 0px;

+ 7 - 0
bin/style.less

@@ -2339,6 +2339,13 @@ input[type=checkbox] {
 	outline: none !important;
 	position: relative;
 
+	.hide-toolbar2 {
+		position: absolute;
+		top: 10px;
+		left: 10px;
+		z-index: 999;
+	}
+
 	.mini-preview {
 		position: absolute;
 		top: 0px;

+ 4 - 0
hide/comp/Toolbar.hx

@@ -112,6 +112,10 @@ class Toolbar extends Component {
 		if( (saveToggleState && Ide.inst.currentConfig.get('sceneeditor.${id}', def)) || (!saveToggleState && def) )
 			tog();
 
+		if (saveToggleState) {
+			onToggle(Ide.inst.currentConfig.get('sceneeditor.${id}', def));
+		}
+
 		return {
 			id : id,
 			element : e,

+ 22 - 4
hide/view/GraphEditor.hx

@@ -77,6 +77,7 @@ class GraphEditor extends hide.comp.Component {
 	var edgeCreationMode : EdgeState = None;
 	var lastCurveX : Float = 0;
 	var lastCurveY : Float = 0;
+	var snapToGrid : Bool = true;
 
 	public var currentUndoBuffer : UndoBuffer = [];
 
@@ -202,7 +203,7 @@ class GraphEditor extends hide.comp.Component {
 			e.preventDefault();
 			e.cancelBubble=true;
     		e.returnValue=false;
-			mouseMoveFunction(e.clientX, e.clientY);
+			mouseMoveFunction(e);
 		});
 
 		var document = new Element(js.Browser.document);
@@ -262,11 +263,24 @@ class GraphEditor extends hide.comp.Component {
 		boxes = [];
 		outputsToInputs.clear();
 
+		var toolbar = new hide.comp.Toolbar(heapsScene);
+		toolbar.element.on("pointerdown", (e) -> e.stopPropagation());
+		toolbar.element.on("pointerup", (e) -> e.stopPropagation());
+		var toolsDefs = new Array<hide.comp.Toolbar.ToolDef>();
+
+		toolsDefs.push({id: "snapToGrid", title: "Snap to grid", icon: "magnet", type : Toggle(setSnapToGrid), defaultValue: true});
+		toolbar.makeToolbar(toolsDefs,config, keys);
+
+		toolbar.refreshToggles();
 		updateMatrix();
 
 		reloadInternal();
 	}
 
+	function setSnapToGrid(b: Bool) {
+		snapToGrid = b;
+	}
+
 	public function cancelAll() {
 		closeAddMenu();
 		cleanupCreateEdge();
@@ -701,7 +715,10 @@ class GraphEditor extends hide.comp.Component {
 		}
 	}
 
-	function mouseMoveFunction(clientX : Int, clientY : Int) {
+	function mouseMoveFunction(e: js.jquery.Event) {
+		var clientX = e.clientX;
+		var clientY = e.clientY;
+
 		if (addMenu?.is(":visible"))
 			return;
 		if (edgeCreationInput != null || edgeCreationOutput != null) {
@@ -778,13 +795,14 @@ class GraphEditor extends hide.comp.Component {
 			if (dx == 0 && dy == 0)
 				return;
 
+			var snap = snapToGrid == !e.altKey;
 
 			for (id => _  in boxesToMove) {
 				var b = boxes.get(id);
 				b.node.getPos(Box.tmpPoint);
 
 				// Snap origin of move
-				if (true /*snap*/) {
+				if (snap) {
 					Box.tmpPoint.x = std.Math.round(Box.tmpPoint.x / Box.NODE_MARGIN) * Box.NODE_MARGIN;
 					Box.tmpPoint.y = std.Math.round(Box.tmpPoint.y / Box.NODE_MARGIN) * Box.NODE_MARGIN;
 				}
@@ -793,7 +811,7 @@ class GraphEditor extends hide.comp.Component {
 				var newY = Box.tmpPoint.y + dy;
 
 				// Snap movement
-				if (true /*snap*/) {
+				if (snap) {
 					newX = std.Math.round(newX / Box.NODE_MARGIN) * Box.NODE_MARGIN;
 					newY = std.Math.round(newY / Box.NODE_MARGIN) * Box.NODE_MARGIN;
 				}