mirror of
https://github.com/ppy/osu
synced 2025-02-09 22:57:37 +00:00
refactor CanScale properties
This commit is contained in:
parent
26c0d1077a
commit
a4f771ec08
@ -30,9 +30,8 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
Quad quad = selectedMovableObjects.Length > 0 ? GeometryUtils.GetSurroundingQuad(selectedMovableObjects) : new Quad();
|
||||
|
||||
SelectionBox.CanFlipX = SelectionBox.CanScaleX = quad.Width > 0;
|
||||
SelectionBox.CanFlipY = SelectionBox.CanScaleY = quad.Height > 0;
|
||||
SelectionBox.CanScaleDiagonally = SelectionBox.CanScaleX && SelectionBox.CanScaleY;
|
||||
SelectionBox.CanFlipX = quad.Width > 0;
|
||||
SelectionBox.CanFlipY = quad.Height > 0;
|
||||
SelectionBox.CanReverse = EditorBeatmap.SelectedHitObjects.Count > 1 || EditorBeatmap.SelectedHitObjects.Any(s => s is Slider);
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,10 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
private void updateState()
|
||||
{
|
||||
var quad = GeometryUtils.GetSurroundingQuad(selectedMovableObjects);
|
||||
CanScale.Value = quad.Width > 0 || quad.Height > 0;
|
||||
|
||||
CanScaleX.Value = quad.Width > 0;
|
||||
CanScaleY.Value = quad.Height > 0;
|
||||
CanScaleDiagonally.Value = CanScaleX.Value && CanScaleY.Value;
|
||||
}
|
||||
|
||||
private OsuHitObject[]? objectsInScale;
|
||||
@ -98,7 +101,7 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
|
||||
foreach (var ho in objectsInScale)
|
||||
{
|
||||
ho.Position = GeometryUtils.GetScaledPositionMultiply(scale, actualOrigin, originalPositions[ho]);
|
||||
ho.Position = GeometryUtils.GetScaledPosition(scale, actualOrigin, originalPositions[ho]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,9 +218,6 @@ namespace osu.Game.Overlays.SkinEditor
|
||||
{
|
||||
base.OnSelectionChanged();
|
||||
|
||||
SelectionBox.CanScaleX = allSelectedSupportManualSizing(Axes.X);
|
||||
SelectionBox.CanScaleY = allSelectedSupportManualSizing(Axes.Y);
|
||||
SelectionBox.CanScaleDiagonally = true;
|
||||
SelectionBox.CanFlipX = true;
|
||||
SelectionBox.CanFlipY = true;
|
||||
SelectionBox.CanReverse = false;
|
||||
|
@ -27,6 +27,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
[Resolved]
|
||||
private SelectionRotationHandler? rotationHandler { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private SelectionScaleHandler? scaleHandler { get; set; }
|
||||
|
||||
public Func<Direction, bool, bool>? OnFlip;
|
||||
public Func<bool>? OnReverse;
|
||||
|
||||
@ -56,60 +59,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
private readonly IBindable<bool> canRotate = new BindableBool();
|
||||
|
||||
private bool canScaleX;
|
||||
private readonly IBindable<bool> canScaleX = new BindableBool();
|
||||
|
||||
/// <summary>
|
||||
/// Whether horizontal scaling (from the left or right edge) support should be enabled.
|
||||
/// </summary>
|
||||
public bool CanScaleX
|
||||
{
|
||||
get => canScaleX;
|
||||
set
|
||||
{
|
||||
if (canScaleX == value) return;
|
||||
private readonly IBindable<bool> canScaleY = new BindableBool();
|
||||
|
||||
canScaleX = value;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool canScaleY;
|
||||
|
||||
/// <summary>
|
||||
/// Whether vertical scaling (from the top or bottom edge) support should be enabled.
|
||||
/// </summary>
|
||||
public bool CanScaleY
|
||||
{
|
||||
get => canScaleY;
|
||||
set
|
||||
{
|
||||
if (canScaleY == value) return;
|
||||
|
||||
canScaleY = value;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool canScaleDiagonally;
|
||||
|
||||
/// <summary>
|
||||
/// Whether diagonal scaling (from a corner) support should be enabled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There are some cases where we only want to allow proportional resizing, and not allow
|
||||
/// one or both explicit directions of scale.
|
||||
/// </remarks>
|
||||
public bool CanScaleDiagonally
|
||||
{
|
||||
get => canScaleDiagonally;
|
||||
set
|
||||
{
|
||||
if (canScaleDiagonally == value) return;
|
||||
|
||||
canScaleDiagonally = value;
|
||||
recreate();
|
||||
}
|
||||
}
|
||||
private readonly IBindable<bool> canScaleDiagonally = new BindableBool();
|
||||
|
||||
private bool canFlipX;
|
||||
|
||||
@ -175,7 +129,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
if (rotationHandler != null)
|
||||
canRotate.BindTo(rotationHandler.CanRotate);
|
||||
|
||||
canRotate.BindValueChanged(_ => recreate(), true);
|
||||
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);
|
||||
}
|
||||
|
||||
protected override bool OnKeyDown(KeyDownEvent e)
|
||||
@ -264,9 +228,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
}
|
||||
};
|
||||
|
||||
if (CanScaleX) addXScaleComponents();
|
||||
if (CanScaleDiagonally) addFullScaleComponents();
|
||||
if (CanScaleY) addYScaleComponents();
|
||||
if (canScaleX.Value) addXScaleComponents();
|
||||
if (canScaleDiagonally.Value) addFullScaleComponents();
|
||||
if (canScaleY.Value) addYScaleComponents();
|
||||
if (CanFlipX) addXFlipComponents();
|
||||
if (CanFlipY) addYFlipComponents();
|
||||
if (canRotate.Value) addRotationComponents();
|
||||
|
@ -14,9 +14,23 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
public partial class SelectionScaleHandler : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the scale can currently be performed.
|
||||
/// Whether horizontal scaling (from the left or right edge) support should be enabled.
|
||||
/// </summary>
|
||||
public Bindable<bool> CanScale { get; private set; } = new BindableBool();
|
||||
public Bindable<bool> CanScaleX { get; private set; } = new BindableBool();
|
||||
|
||||
/// <summary>
|
||||
/// Whether vertical scaling (from the top or bottom edge) support should be enabled.
|
||||
/// </summary>
|
||||
public Bindable<bool> CanScaleY { get; private set; } = new BindableBool();
|
||||
|
||||
/// <summary>
|
||||
/// Whether diagonal scaling (from a corner) support should be enabled.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// There are some cases where we only want to allow proportional resizing, and not allow
|
||||
/// one or both explicit directions of scale.
|
||||
/// </remarks>
|
||||
public Bindable<bool> CanScaleDiagonally { get; private set; } = new BindableBool();
|
||||
|
||||
public Quad? OriginalSurroundingQuad { get; protected set; }
|
||||
|
||||
|
@ -83,7 +83,7 @@ namespace osu.Game.Utils
|
||||
/// Given a scale multiplier, an origin, and a position,
|
||||
/// will return the scaled position in screen space coordinates.
|
||||
/// </summary>
|
||||
public static Vector2 GetScaledPositionMultiply(Vector2 scale, Vector2 origin, Vector2 position)
|
||||
public static Vector2 GetScaledPosition(Vector2 scale, Vector2 origin, Vector2 position)
|
||||
{
|
||||
return origin + (position - origin) * scale;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user