WIP: GridSet, add Vector2.Snapped extension method.
This commit is contained in:
@@ -8,5 +8,31 @@ namespace Voile.Extensions
|
||||
{
|
||||
return new Vector2((float)MathUtils.Lerp(a.X, b.X, t), (float)MathUtils.Lerp(a.Y, b.Y, t));
|
||||
}
|
||||
|
||||
public static Vector2 Snapped(this Vector2 a, Vector2 snap)
|
||||
{
|
||||
var x = a.X % snap.X;
|
||||
var y = a.Y % snap.Y;
|
||||
|
||||
if (x == 0)
|
||||
{
|
||||
x = a.X;
|
||||
}
|
||||
else
|
||||
{
|
||||
x = a.X - x;
|
||||
}
|
||||
|
||||
if (y == 0)
|
||||
{
|
||||
y = a.Y;
|
||||
}
|
||||
else
|
||||
{
|
||||
y = a.Y - y;
|
||||
}
|
||||
|
||||
return new Vector2(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,11 @@ public class UISystem : IUpdatableSystem, IRenderableSystem
|
||||
_elements = elements;
|
||||
}
|
||||
|
||||
public void AddElement(UIElement element) => _elements.Add(element);
|
||||
public void AddElement(UIElement element)
|
||||
{
|
||||
_elements.Add(element);
|
||||
_inputElementIndices.Add(element.GlobalPosition, _elements.Count - 1);
|
||||
}
|
||||
public void RemoveElement(UIElement element) => _elements.Remove(element);
|
||||
|
||||
public void Update(double deltaTime)
|
||||
@@ -167,5 +171,7 @@ public class UISystem : IUpdatableSystem, IRenderableSystem
|
||||
private List<UIElement> _elements = new();
|
||||
private InputSystem _input;
|
||||
|
||||
private GridSet<int> _inputElementIndices = new();
|
||||
|
||||
private Vector2 _lastMousePosition = Vector2.Zero;
|
||||
}
|
||||
Reference in New Issue
Block a user