Add Ctrl to snap points to grid in Multi Blend editor

This commit is contained in:
Wojtek Figat
2024-04-18 17:04:23 +02:00
parent f8f1c02338
commit 83b9e6e32a
2 changed files with 13 additions and 3 deletions

View File

@@ -128,7 +128,17 @@ namespace FlaxEditor.Surface.Archetypes
_mouseMoveStartValues = _editor._node.Surface.Undo != null ? (object[])_editor._node.Values.Clone() : null;
}
_editor.SetLocation(_index, _editor.BlendPointPosToBlendSpacePos(Location + location));
var newLocation = Location + location;
newLocation = _editor.BlendPointPosToBlendSpacePos(newLocation);
if (Root != null && Root.GetKey(KeyboardKeys.Control))
{
var data0 = (Float4)_editor._node.Values[0];
var rangeX = new Float2(data0.X, data0.Y);
var rangeY = _editor._is2D ? new Float2(data0.Z, data0.W) : Float2.One;
var grid = new Float2(Mathf.Abs(rangeX.Y - rangeX.X) * 0.01f, Mathf.Abs(rangeY.X - rangeY.Y) * 0.01f);
newLocation = Float2.SnapToGrid(newLocation, grid);
}
_editor.SetLocation(_index, newLocation);
}
base.OnMouseMove(location);

View File

@@ -1281,8 +1281,8 @@ namespace FlaxEngine
/// <returns>The position snapped to the grid.</returns>
public static Float2 SnapToGrid(Float2 pos, Float2 gridSize)
{
pos.X = Mathf.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.Y) * gridSize.X;
pos.Y = Mathf.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.X) * gridSize.Y;
pos.X = Mathf.Ceil((pos.X - (gridSize.X * 0.5f)) / gridSize.X) * gridSize.X;
pos.Y = Mathf.Ceil((pos.Y - (gridSize.Y * 0.5f)) / gridSize.Y) * gridSize.Y;
return pos;
}