Add key bindings for flip and reverse patterns

This commit is contained in:
Dean Herbert 2020-11-03 21:10:31 +09:00
parent 2d1db6a22d
commit 83c004bbde
2 changed files with 33 additions and 11 deletions

View File

@ -7,17 +7,19 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osuTK; using osuTK;
using osuTK.Input;
namespace osu.Game.Screens.Edit.Compose.Components namespace osu.Game.Screens.Edit.Compose.Components
{ {
public class SelectionBox : CompositeDrawable public class SelectionBox : CompositeDrawable
{ {
public Action<float> OnRotation; public Func<float, bool> OnRotation;
public Action<Vector2, Anchor> OnScale; public Func<Vector2, Anchor, bool> OnScale;
public Action<Direction> OnFlip; public Func<Direction, bool> OnFlip;
public Action OnReverse; public Func<bool> OnReverse;
public Action OperationStarted; public Action OperationStarted;
public Action OperationEnded; public Action OperationEnded;
@ -105,6 +107,26 @@ namespace osu.Game.Screens.Edit.Compose.Components
recreate(); recreate();
} }
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Repeat || !e.ControlPressed)
return false;
switch (e.Key)
{
case Key.G:
return OnReverse?.Invoke() == true;
case Key.H:
return OnFlip?.Invoke(Direction.Horizontal) == true;
case Key.J:
return OnFlip?.Invoke(Direction.Vertical) == true;
}
return base.OnKeyDown(e);
}
private void recreate() private void recreate()
{ {
if (LoadState < LoadState.Loading) if (LoadState < LoadState.Loading)
@ -143,7 +165,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (CanScaleX && CanScaleY) addFullScaleComponents(); if (CanScaleX && CanScaleY) addFullScaleComponents();
if (CanScaleY) addYScaleComponents(); if (CanScaleY) addYScaleComponents();
if (CanRotate) addRotationComponents(); if (CanRotate) addRotationComponents();
if (CanReverse) addButton(FontAwesome.Solid.Backward, "Reverse pattern", () => OnReverse?.Invoke()); if (CanReverse) addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
} }
private void addRotationComponents() private void addRotationComponents()
@ -178,7 +200,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addYScaleComponents() private void addYScaleComponents()
{ {
addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical)); addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically (Ctrl-J)", () => OnFlip?.Invoke(Direction.Vertical));
addDragHandle(Anchor.TopCentre); addDragHandle(Anchor.TopCentre);
addDragHandle(Anchor.BottomCentre); addDragHandle(Anchor.BottomCentre);
@ -194,7 +216,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void addXScaleComponents() private void addXScaleComponents()
{ {
addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally", () => OnFlip?.Invoke(Direction.Horizontal)); addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally (Ctrl-H)", () => OnFlip?.Invoke(Direction.Horizontal));
addDragHandle(Anchor.CentreLeft); addDragHandle(Anchor.CentreLeft);
addDragHandle(Anchor.CentreRight); addDragHandle(Anchor.CentreRight);

View File

@ -99,10 +99,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
OperationStarted = OnOperationBegan, OperationStarted = OnOperationBegan,
OperationEnded = OnOperationEnded, OperationEnded = OnOperationEnded,
OnRotation = angle => HandleRotation(angle), OnRotation = HandleRotation,
OnScale = (amount, anchor) => HandleScale(amount, anchor), OnScale = HandleScale,
OnFlip = direction => HandleFlip(direction), OnFlip = HandleFlip,
OnReverse = () => HandleReverse(), OnReverse = HandleReverse,
}; };
/// <summary> /// <summary>