Combine drag and clicky interactions

This commit is contained in:
OliBomby 2024-09-28 17:26:39 +02:00
parent 3e4cd0aeac
commit 4568af8fda
1 changed files with 32 additions and 2 deletions

View File

@ -47,12 +47,31 @@ public override void EndPlacement(bool commit)
protected override bool OnClick(ClickEvent e)
{
if (e.Button == MouseButton.Left)
{
switch (PlacementActive)
{
case PlacementState.Waiting:
BeginPlacement(true);
return true;
case PlacementState.Active:
EndPlacement(true);
return true;
}
}
return base.OnClick(e);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == MouseButton.Right)
{
EndPlacement(true);
return true;
}
return base.OnClick(e);
return base.OnMouseDown(e);
}
protected override bool OnDragStart(DragStartEvent e)
@ -83,7 +102,18 @@ public override void UpdateTimeAndPosition(SnapResult result)
if (PlacementActive != PlacementState.Active)
gridToolboxGroup.StartPosition.Value = pos;
else
gridToolboxGroup.SetGridFromPoints(gridToolboxGroup.StartPosition.Value, pos);
{
// Default to the original spacing and rotation if the distance is too small.
if (Vector2.Distance(gridToolboxGroup.StartPosition.Value, pos) < 2)
{
gridToolboxGroup.Spacing.Value = originalSpacing;
gridToolboxGroup.GridLinesRotation.Value = originalRotation;
}
else
{
gridToolboxGroup.SetGridFromPoints(gridToolboxGroup.StartPosition.Value, pos);
}
}
}
}
}