1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 16:13:34 +08:00

refactor CanScaleFromPlayfieldOrigin and GetClampedScale to derived class

This commit is contained in:
OliBomby 2024-05-28 17:12:16 +02:00
parent 7cdc755c16
commit d143a697d2
5 changed files with 16 additions and 19 deletions

View File

@ -104,7 +104,7 @@ namespace osu.Game.Rulesets.Osu.Edit
new TransformToolboxGroup
{
RotationHandler = BlueprintContainer.SelectionHandler.RotationHandler,
ScaleHandler = BlueprintContainer.SelectionHandler.ScaleHandler,
ScaleHandler = (OsuSelectionScaleHandler)BlueprintContainer.SelectionHandler.ScaleHandler,
},
FreehandlSliderToolboxGroup
}

View File

@ -24,6 +24,11 @@ namespace osu.Game.Rulesets.Osu.Edit
{
public partial class OsuSelectionScaleHandler : SelectionScaleHandler
{
/// <summary>
/// Whether scaling anchored by the center of the playfield can currently be performed.
/// </summary>
public Bindable<bool> CanScaleFromPlayfieldOrigin { get; private set; } = new BindableBool();
[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }
@ -156,7 +161,13 @@ namespace osu.Game.Rulesets.Osu.Edit
return (xInBounds, yInBounds);
}
public override Vector2 GetClampedScale(Vector2 scale, Vector2? origin = null)
/// <summary>
/// Clamp scale for multi-object-scaling where selection does not exceed playfield bounds or flip.
/// </summary>
/// <param name="origin">The origin from which the scale operation is performed</param>
/// <param name="scale">The scale to be clamped</param>
/// <returns>The clamped scale vector</returns>
public Vector2 GetClampedScale(Vector2 scale, Vector2? origin = null)
{
//todo: this is not always correct for selections involving sliders. This approximation assumes each point is scaled independently, but sliderends move with the sliderhead.
if (objectsInScale == null)

View File

@ -12,14 +12,13 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Compose.Components;
using osuTK;
namespace osu.Game.Rulesets.Osu.Edit
{
public partial class PreciseScalePopover : OsuPopover
{
private readonly SelectionScaleHandler scaleHandler;
private readonly OsuSelectionScaleHandler scaleHandler;
private readonly Bindable<PreciseScaleInfo> scaleInfo = new Bindable<PreciseScaleInfo>(new PreciseScaleInfo(1, ScaleOrigin.PlayfieldCentre, true, true));
@ -37,7 +36,7 @@ namespace osu.Game.Rulesets.Osu.Edit
private bool scaleInProgress;
public PreciseScalePopover(SelectionScaleHandler scaleHandler)
public PreciseScalePopover(OsuSelectionScaleHandler scaleHandler)
{
this.scaleHandler = scaleHandler;

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Edit
private Bindable<bool> canScalePlayfieldOrigin = null!;
public SelectionRotationHandler RotationHandler { get; init; } = null!;
public SelectionScaleHandler ScaleHandler { get; init; } = null!;
public OsuSelectionScaleHandler ScaleHandler { get; init; } = null!;
public TransformToolboxGroup()
: base("transform")

View File

@ -32,21 +32,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks>
public Bindable<bool> CanScaleDiagonally { get; private set; } = new BindableBool();
/// <summary>
/// Whether scaling anchored by the center of the playfield can currently be performed.
/// </summary>
public Bindable<bool> CanScaleFromPlayfieldOrigin { get; private set; } = new BindableBool();
public Quad? OriginalSurroundingQuad { get; protected set; }
/// <summary>
/// Clamp scale where selection does not exceed playfield bounds or flip.
/// </summary>
/// <param name="origin">The origin from which the scale operation is performed</param>
/// <param name="scale">The scale to be clamped</param>
/// <returns>The clamped scale vector</returns>
public virtual Vector2 GetClampedScale(Vector2 scale, Vector2? origin = null) => scale;
/// <summary>
/// Performs a single, instant, atomic scale operation.
/// </summary>