2020-10-01 15:34:34 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2024-09-24 22:42:37 +08:00
|
|
|
using System.Linq;
|
2020-10-01 15:34:34 +08:00
|
|
|
using osu.Framework.Allocation;
|
2023-07-24 02:01:30 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-10-01 15:34:34 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2020-11-03 20:10:31 +08:00
|
|
|
using osu.Framework.Input.Events;
|
2020-10-01 15:34:34 +08:00
|
|
|
using osu.Game.Graphics;
|
2021-05-03 16:34:34 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-10-01 15:34:34 +08:00
|
|
|
using osuTK;
|
2020-11-03 20:10:31 +08:00
|
|
|
using osuTK.Input;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2022-01-09 00:19:52 +08:00
|
|
|
[Cached]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class SelectionBox : CompositeDrawable
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
2021-05-03 16:34:34 +08:00
|
|
|
public const float BORDER_RADIUS = 3;
|
|
|
|
|
2023-05-24 18:16:51 +08:00
|
|
|
private const float button_padding = 5;
|
|
|
|
|
2023-07-31 02:21:41 +08:00
|
|
|
[Resolved]
|
|
|
|
private SelectionRotationHandler? rotationHandler { get; set; }
|
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
[Resolved]
|
|
|
|
private SelectionScaleHandler? scaleHandler { get; set; }
|
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
public Func<Direction, bool, bool>? OnFlip;
|
|
|
|
public Func<bool>? OnReverse;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
public Action? OperationStarted;
|
|
|
|
public Action? OperationEnded;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
private SelectionBoxButton? reverseButton;
|
|
|
|
private SelectionBoxButton? rotateClockwiseButton;
|
|
|
|
private SelectionBoxButton? rotateCounterClockwiseButton;
|
2023-06-27 16:01:06 +08:00
|
|
|
|
2020-10-09 05:32:23 +08:00
|
|
|
private bool canReverse;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether pattern reversing support should be enabled.
|
|
|
|
/// </summary>
|
|
|
|
public bool CanReverse
|
|
|
|
{
|
|
|
|
get => canReverse;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (canReverse == value) return;
|
|
|
|
|
|
|
|
canReverse = value;
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-26 13:04:16 +08:00
|
|
|
private readonly IBindable<bool> canRotate = new BindableBool();
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
private readonly IBindable<bool> canScaleX = new BindableBool();
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
private readonly IBindable<bool> canScaleY = new BindableBool();
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
private readonly IBindable<bool> canScaleDiagonally = new BindableBool();
|
2023-11-10 13:17:11 +08:00
|
|
|
|
2021-07-21 14:59:25 +08:00
|
|
|
private bool canFlipX;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether horizontal flipping support should be enabled.
|
|
|
|
/// </summary>
|
|
|
|
public bool CanFlipX
|
|
|
|
{
|
|
|
|
get => canFlipX;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (canFlipX == value) return;
|
|
|
|
|
|
|
|
canFlipX = value;
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool canFlipY;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether vertical flipping support should be enabled.
|
|
|
|
/// </summary>
|
|
|
|
public bool CanFlipY
|
|
|
|
{
|
|
|
|
get => canFlipY;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (canFlipY == value) return;
|
|
|
|
|
|
|
|
canFlipY = value;
|
|
|
|
recreate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
private string text = string.Empty;
|
2021-05-03 16:34:34 +08:00
|
|
|
|
|
|
|
public string Text
|
|
|
|
{
|
|
|
|
get => text;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
text = value;
|
|
|
|
if (selectionDetailsText != null)
|
|
|
|
selectionDetailsText.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
private SelectionBoxDragHandleContainer dragHandles = null!;
|
|
|
|
private FillFlowContainer buttons = null!;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2023-06-28 04:01:44 +08:00
|
|
|
private OsuSpriteText? selectionDetailsText;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
|
|
|
[Resolved]
|
2023-06-28 04:01:44 +08:00
|
|
|
private OsuColour colours { get; set; } = null!;
|
2020-10-01 15:34:34 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-07-24 02:01:30 +08:00
|
|
|
private void load()
|
|
|
|
{
|
2023-07-31 02:21:41 +08:00
|
|
|
if (rotationHandler != null)
|
2024-05-29 15:40:29 +08:00
|
|
|
canRotate.BindTo(rotationHandler.CanRotateAroundSelectionOrigin);
|
2023-07-24 02:01:30 +08:00
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
if (scaleHandler != null)
|
|
|
|
{
|
|
|
|
canScaleX.BindTo(scaleHandler.CanScaleX);
|
|
|
|
canScaleY.BindTo(scaleHandler.CanScaleY);
|
|
|
|
canScaleDiagonally.BindTo(scaleHandler.CanScaleDiagonally);
|
|
|
|
}
|
|
|
|
|
|
|
|
canRotate.BindValueChanged(_ => recreate());
|
|
|
|
canScaleX.BindValueChanged(_ => recreate());
|
|
|
|
canScaleY.BindValueChanged(_ => recreate());
|
|
|
|
canScaleDiagonally.BindValueChanged(_ => recreate(), true);
|
2023-07-24 02:01:30 +08:00
|
|
|
}
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2020-11-03 20:10:31 +08:00
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
{
|
|
|
|
if (e.Repeat || !e.ControlPressed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (e.Key)
|
|
|
|
{
|
|
|
|
case Key.G:
|
2024-10-11 02:14:11 +08:00
|
|
|
if (!CanReverse || reverseButton == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
reverseButton.TriggerAction();
|
|
|
|
return true;
|
2023-06-27 16:01:40 +08:00
|
|
|
|
|
|
|
case Key.Comma:
|
2024-10-11 02:14:11 +08:00
|
|
|
if (!canRotate.Value || rotateCounterClockwiseButton == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
rotateCounterClockwiseButton.TriggerAction();
|
|
|
|
return true;
|
2023-06-27 16:01:40 +08:00
|
|
|
|
|
|
|
case Key.Period:
|
2024-10-11 02:14:11 +08:00
|
|
|
if (!canRotate.Value || rotateClockwiseButton == null)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
rotateClockwiseButton.TriggerAction();
|
|
|
|
return true;
|
2020-11-03 20:10:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
}
|
|
|
|
|
2023-05-24 18:16:51 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
ensureButtonsOnScreen();
|
|
|
|
}
|
|
|
|
|
2020-10-01 15:34:34 +08:00
|
|
|
private void recreate()
|
|
|
|
{
|
|
|
|
if (LoadState < LoadState.Loading)
|
|
|
|
return;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2021-05-03 16:34:34 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Name = "info text",
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = colours.YellowDark,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
selectionDetailsText = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding(2),
|
|
|
|
Colour = colours.Gray0,
|
|
|
|
Font = OsuFont.Default.With(size: 11),
|
|
|
|
Text = text,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-10-01 15:34:34 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
BorderThickness = BORDER_RADIUS,
|
|
|
|
BorderColour = colours.YellowDark,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
|
|
|
AlwaysPresent = true,
|
|
|
|
Alpha = 0
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2021-04-26 00:59:08 +08:00
|
|
|
dragHandles = new SelectionBoxDragHandleContainer
|
2020-12-19 06:45:42 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
// ensures that the centres of all drag handles line up with the middle of the selection box border.
|
|
|
|
Padding = new MarginPadding(BORDER_RADIUS / 2)
|
|
|
|
},
|
2020-10-01 15:34:34 +08:00
|
|
|
buttons = new FillFlowContainer
|
|
|
|
{
|
2023-05-24 18:16:51 +08:00
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Height = 30,
|
2020-10-01 15:34:34 +08:00
|
|
|
Direction = FillDirection.Horizontal,
|
2023-05-24 18:16:51 +08:00
|
|
|
Margin = new MarginPadding(button_padding),
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-20 08:13:01 +08:00
|
|
|
if (canScaleX.Value) addXScaleComponents();
|
|
|
|
if (canScaleDiagonally.Value) addFullScaleComponents();
|
|
|
|
if (canScaleY.Value) addYScaleComponents();
|
2021-07-21 14:59:25 +08:00
|
|
|
if (CanFlipX) addXFlipComponents();
|
|
|
|
if (CanFlipY) addYFlipComponents();
|
2023-07-24 02:01:30 +08:00
|
|
|
if (canRotate.Value) addRotationComponents();
|
2023-06-27 16:01:06 +08:00
|
|
|
if (CanReverse) reverseButton = addButton(FontAwesome.Solid.Backward, "Reverse pattern (Ctrl-G)", () => OnReverse?.Invoke());
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addRotationComponents()
|
|
|
|
{
|
2023-07-31 02:21:41 +08:00
|
|
|
rotateCounterClockwiseButton = addButton(FontAwesome.Solid.Undo, "Rotate 90 degrees counter-clockwise (Ctrl-<)", () => rotationHandler?.Rotate(-90));
|
|
|
|
rotateClockwiseButton = addButton(FontAwesome.Solid.Redo, "Rotate 90 degrees clockwise (Ctrl->)", () => rotationHandler?.Rotate(90));
|
2020-10-01 15:34:34 +08:00
|
|
|
|
2021-04-24 13:18:46 +08:00
|
|
|
addRotateHandle(Anchor.TopLeft);
|
|
|
|
addRotateHandle(Anchor.TopRight);
|
|
|
|
addRotateHandle(Anchor.BottomLeft);
|
|
|
|
addRotateHandle(Anchor.BottomRight);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addYScaleComponents()
|
|
|
|
{
|
2021-04-24 13:18:46 +08:00
|
|
|
addScaleHandle(Anchor.TopCentre);
|
|
|
|
addScaleHandle(Anchor.BottomCentre);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addFullScaleComponents()
|
|
|
|
{
|
2021-04-24 13:18:46 +08:00
|
|
|
addScaleHandle(Anchor.TopLeft);
|
|
|
|
addScaleHandle(Anchor.TopRight);
|
|
|
|
addScaleHandle(Anchor.BottomLeft);
|
|
|
|
addScaleHandle(Anchor.BottomRight);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addXScaleComponents()
|
|
|
|
{
|
2021-04-24 13:18:46 +08:00
|
|
|
addScaleHandle(Anchor.CentreLeft);
|
|
|
|
addScaleHandle(Anchor.CentreRight);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
2021-07-21 14:59:25 +08:00
|
|
|
private void addXFlipComponents()
|
|
|
|
{
|
2022-01-05 15:46:34 +08:00
|
|
|
addButton(FontAwesome.Solid.ArrowsAltH, "Flip horizontally", () => OnFlip?.Invoke(Direction.Horizontal, false));
|
2021-07-21 14:59:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void addYFlipComponents()
|
|
|
|
{
|
2022-01-05 15:46:34 +08:00
|
|
|
addButton(FontAwesome.Solid.ArrowsAltV, "Flip vertically", () => OnFlip?.Invoke(Direction.Vertical, false));
|
2021-07-21 14:59:25 +08:00
|
|
|
}
|
|
|
|
|
2023-06-27 16:01:06 +08:00
|
|
|
private SelectionBoxButton addButton(IconUsage icon, string tooltip, Action action)
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
2021-04-24 13:18:46 +08:00
|
|
|
var button = new SelectionBoxButton(icon, tooltip)
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
|
|
|
Action = action
|
2021-04-24 13:18:46 +08:00
|
|
|
};
|
|
|
|
|
2024-10-11 02:14:11 +08:00
|
|
|
button.Clicked += freezeButtonPosition;
|
2024-09-21 20:59:47 +08:00
|
|
|
button.HoverLost += unfreezeButtonPosition;
|
|
|
|
|
2021-04-24 13:18:46 +08:00
|
|
|
button.OperationStarted += operationStarted;
|
|
|
|
button.OperationEnded += operationEnded;
|
2024-09-21 20:59:47 +08:00
|
|
|
|
2021-04-24 13:18:46 +08:00
|
|
|
buttons.Add(button);
|
2023-06-27 16:01:06 +08:00
|
|
|
|
|
|
|
return button;
|
2021-04-24 13:18:46 +08:00
|
|
|
}
|
|
|
|
|
2023-09-01 19:01:51 +08:00
|
|
|
/// <remarks>
|
|
|
|
/// This method should be called when a selection needs to be flipped
|
|
|
|
/// because of an ongoing scale handle drag that would otherwise cause width or height to go negative.
|
|
|
|
/// </remarks>
|
|
|
|
public void PerformFlipFromScaleHandles(Axes axes)
|
|
|
|
{
|
2024-07-02 23:19:04 +08:00
|
|
|
if (axes.HasFlag(Axes.X))
|
2023-09-01 19:01:51 +08:00
|
|
|
{
|
|
|
|
dragHandles.FlipScaleHandles(Direction.Horizontal);
|
|
|
|
OnFlip?.Invoke(Direction.Horizontal, false);
|
|
|
|
}
|
|
|
|
|
2024-07-02 23:19:04 +08:00
|
|
|
if (axes.HasFlag(Axes.Y))
|
2023-09-01 19:01:51 +08:00
|
|
|
{
|
|
|
|
dragHandles.FlipScaleHandles(Direction.Vertical);
|
|
|
|
OnFlip?.Invoke(Direction.Vertical, false);
|
|
|
|
}
|
|
|
|
}
|
2023-08-28 22:41:55 +08:00
|
|
|
|
2021-04-24 13:18:46 +08:00
|
|
|
private void addScaleHandle(Anchor anchor)
|
|
|
|
{
|
|
|
|
var handle = new SelectionBoxScaleHandle
|
|
|
|
{
|
|
|
|
Anchor = anchor,
|
|
|
|
};
|
|
|
|
|
|
|
|
handle.OperationStarted += operationStarted;
|
|
|
|
handle.OperationEnded += operationEnded;
|
|
|
|
dragHandles.AddScaleHandle(handle);
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
|
2021-04-24 13:18:46 +08:00
|
|
|
private void addRotateHandle(Anchor anchor)
|
2020-10-01 15:34:34 +08:00
|
|
|
{
|
2021-04-24 13:18:46 +08:00
|
|
|
var handle = new SelectionBoxRotationHandle
|
|
|
|
{
|
|
|
|
Anchor = anchor,
|
|
|
|
};
|
|
|
|
|
|
|
|
handle.OperationStarted += operationStarted;
|
|
|
|
handle.OperationEnded += operationEnded;
|
|
|
|
dragHandles.AddRotationHandle(handle);
|
|
|
|
}
|
2020-10-01 15:34:34 +08:00
|
|
|
|
|
|
|
private int activeOperations;
|
|
|
|
|
2020-12-13 20:58:58 +08:00
|
|
|
private float convertDragEventToAngleOfRotation(DragEvent e)
|
|
|
|
{
|
|
|
|
// Adjust coordinate system to the center of SelectionBox
|
|
|
|
float startAngle = MathF.Atan2(e.LastMousePosition.Y - DrawHeight / 2, e.LastMousePosition.X - DrawWidth / 2);
|
|
|
|
float endAngle = MathF.Atan2(e.MousePosition.Y - DrawHeight / 2, e.MousePosition.X - DrawWidth / 2);
|
|
|
|
|
|
|
|
return (endAngle - startAngle) * 180 / MathF.PI;
|
|
|
|
}
|
|
|
|
|
2020-10-01 15:34:34 +08:00
|
|
|
private void operationEnded()
|
|
|
|
{
|
|
|
|
if (--activeOperations == 0)
|
|
|
|
OperationEnded?.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void operationStarted()
|
|
|
|
{
|
|
|
|
if (activeOperations++ == 0)
|
|
|
|
OperationStarted?.Invoke();
|
|
|
|
}
|
2023-05-24 18:16:51 +08:00
|
|
|
|
2024-09-21 21:25:37 +08:00
|
|
|
private Vector2? frozenButtonsPosition;
|
2024-09-21 20:59:47 +08:00
|
|
|
|
|
|
|
private void freezeButtonPosition()
|
|
|
|
{
|
2024-09-21 21:25:37 +08:00
|
|
|
frozenButtonsPosition = buttons.ScreenSpaceDrawQuad.TopLeft;
|
2024-09-21 20:59:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unfreezeButtonPosition()
|
|
|
|
{
|
2024-09-24 22:42:37 +08:00
|
|
|
if (frozenButtonsPosition != null)
|
|
|
|
{
|
|
|
|
frozenButtonsPosition = null;
|
|
|
|
ensureButtonsOnScreen(true);
|
|
|
|
}
|
2024-09-21 20:59:47 +08:00
|
|
|
}
|
|
|
|
|
2024-09-24 22:42:37 +08:00
|
|
|
private void ensureButtonsOnScreen(bool animated = false)
|
2023-05-24 18:16:51 +08:00
|
|
|
{
|
2024-09-21 21:25:37 +08:00
|
|
|
if (frozenButtonsPosition != null)
|
2024-09-21 20:59:47 +08:00
|
|
|
{
|
|
|
|
buttons.Anchor = Anchor.TopLeft;
|
|
|
|
buttons.Origin = Anchor.TopLeft;
|
|
|
|
|
2024-09-21 21:25:37 +08:00
|
|
|
buttons.Position = ToLocalSpace(frozenButtonsPosition.Value) - new Vector2(button_padding);
|
2024-09-21 20:59:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-24 22:42:37 +08:00
|
|
|
if (!animated && buttons.Transforms.Any())
|
|
|
|
return;
|
2023-05-24 18:16:51 +08:00
|
|
|
|
|
|
|
var thisQuad = ScreenSpaceDrawQuad;
|
|
|
|
|
|
|
|
// Shrink the parent quad to give a bit of padding so the buttons don't stick *right* on the border.
|
|
|
|
// AABBFloat assumes no rotation. one would hope the whole editor is not being rotated.
|
2023-10-17 16:40:44 +08:00
|
|
|
var parentQuad = Parent!.ScreenSpaceDrawQuad.AABBFloat.Shrink(ToLocalSpace(thisQuad.TopLeft + new Vector2(button_padding * 2)));
|
2023-05-24 18:16:51 +08:00
|
|
|
|
2023-05-25 22:17:44 +08:00
|
|
|
float topExcess = thisQuad.TopLeft.Y - parentQuad.TopLeft.Y;
|
|
|
|
float bottomExcess = parentQuad.BottomLeft.Y - thisQuad.BottomLeft.Y;
|
|
|
|
float leftExcess = thisQuad.TopLeft.X - parentQuad.TopLeft.X;
|
|
|
|
float rightExcess = parentQuad.TopRight.X - thisQuad.TopRight.X;
|
2023-05-24 18:16:51 +08:00
|
|
|
|
2023-07-02 03:30:41 +08:00
|
|
|
float minHeight = buttons.ScreenSpaceDrawQuad.Height;
|
|
|
|
|
2024-09-24 22:42:37 +08:00
|
|
|
Anchor targetAnchor;
|
|
|
|
Anchor targetOrigin;
|
|
|
|
Vector2 targetPosition = Vector2.Zero;
|
|
|
|
|
2023-07-02 03:30:41 +08:00
|
|
|
if (topExcess < minHeight && bottomExcess < minHeight)
|
2023-05-25 22:39:54 +08:00
|
|
|
{
|
2024-09-24 22:42:37 +08:00
|
|
|
targetAnchor = Anchor.BottomCentre;
|
|
|
|
targetOrigin = Anchor.BottomCentre;
|
|
|
|
targetPosition.Y = Math.Min(0, ToLocalSpace(Parent!.ScreenSpaceDrawQuad.BottomLeft).Y - DrawHeight);
|
2023-05-25 22:39:54 +08:00
|
|
|
}
|
|
|
|
else if (topExcess > bottomExcess)
|
2023-05-25 22:17:44 +08:00
|
|
|
{
|
2024-09-24 22:42:37 +08:00
|
|
|
targetAnchor = Anchor.TopCentre;
|
|
|
|
targetOrigin = Anchor.BottomCentre;
|
2023-05-25 22:17:44 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-09-24 22:42:37 +08:00
|
|
|
targetAnchor = Anchor.BottomCentre;
|
|
|
|
targetOrigin = Anchor.TopCentre;
|
2023-05-25 22:17:44 +08:00
|
|
|
}
|
2023-05-24 18:16:51 +08:00
|
|
|
|
2024-09-24 22:42:37 +08:00
|
|
|
targetPosition.X += ToLocalSpace(thisQuad.TopLeft - new Vector2(Math.Min(0, leftExcess)) + new Vector2(Math.Min(0, rightExcess))).X;
|
|
|
|
|
|
|
|
if (animated)
|
|
|
|
{
|
|
|
|
var originalPosition = ToLocalSpace(buttons.ScreenSpaceDrawQuad.TopLeft);
|
|
|
|
|
|
|
|
buttons.Origin = targetOrigin;
|
|
|
|
buttons.Anchor = targetAnchor;
|
|
|
|
buttons.Position = targetPosition;
|
|
|
|
|
|
|
|
var newPosition = ToLocalSpace(buttons.ScreenSpaceDrawQuad.TopLeft);
|
|
|
|
|
|
|
|
var delta = newPosition - originalPosition;
|
|
|
|
|
|
|
|
buttons.Position -= delta;
|
|
|
|
|
|
|
|
buttons.MoveTo(targetPosition, 300, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttons.Anchor = targetAnchor;
|
|
|
|
buttons.Origin = targetOrigin;
|
|
|
|
buttons.Position = targetPosition;
|
|
|
|
}
|
2023-05-24 18:16:51 +08:00
|
|
|
}
|
2020-10-01 15:34:34 +08:00
|
|
|
}
|
|
|
|
}
|