From 1cda55393ed7b25874c8a3fe7bf77dc33b136035 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 May 2021 17:51:57 +0900 Subject: [PATCH 1/4] Add aspect ratio locking and flip support to skin editor --- .../Skinning/Editor/SkinSelectionHandler.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs index ad783a9c0e..3dc0ca340b 100644 --- a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs +++ b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using osu.Framework.Extensions.EnumExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.UserInterface; using osu.Game.Extensions; @@ -36,6 +37,20 @@ namespace osu.Game.Skinning.Editor return true; } + public override bool HandleFlip(Direction direction) + { + // TODO: this is temporary as well. + foreach (var c in SelectedBlueprints) + { + ((Drawable)c.Item).Scale *= new Vector2( + direction == Direction.Horizontal ? -1 : 1, + direction == Direction.Vertical ? -1 : 1 + ); + } + + return true; + } + public override bool HandleMovement(MoveSelectionEvent moveEvent) { foreach (var c in SelectedBlueprints) @@ -116,6 +131,15 @@ namespace osu.Game.Skinning.Editor // reverse the scale direction if dragging from top or left. if ((reference & Anchor.x0) > 0) scale.X = -scale.X; if ((reference & Anchor.y0) > 0) scale.Y = -scale.Y; + + // for now aspect lock scale adjustments that occur at corners. + if (!reference.HasFlagFast(Anchor.x1) && !reference.HasFlagFast(Anchor.y1)) + { + if (reference.HasFlagFast(Anchor.x0) || reference.HasFlagFast(Anchor.x2)) + scale.Y = scale.X; + else + scale.X = scale.Y; + } } public class AnchorMenuItem : TernaryStateMenuItem From 9f8e6979dd90e23bf5b7936bb536eeb312fbb3f1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 May 2021 18:00:25 +0900 Subject: [PATCH 2/4] Fix display of skin blueprints when flipped --- osu.Game/Skinning/Editor/SkinBlueprint.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game/Skinning/Editor/SkinBlueprint.cs b/osu.Game/Skinning/Editor/SkinBlueprint.cs index 58fa255508..1d029c39d6 100644 --- a/osu.Game/Skinning/Editor/SkinBlueprint.cs +++ b/osu.Game/Skinning/Editor/SkinBlueprint.cs @@ -112,8 +112,13 @@ namespace osu.Game.Skinning.Editor drawableQuad = drawable.ScreenSpaceDrawQuad; var quad = ToLocalSpace(drawable.ScreenSpaceDrawQuad); - box.Position = quad.TopLeft; + box.Position = new Vector2( + drawable.Scale.X < 0 ? quad.TopRight.X : quad.TopLeft.X, + drawable.Scale.Y < 0 ? quad.BottomLeft.Y : quad.TopLeft.Y + ); + box.Size = quad.Size; + box.Rotation = drawable.Rotation; } From 07e475cd132cde77478a45ac976173bb4abfdf67 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 May 2021 18:54:40 +0900 Subject: [PATCH 3/4] Fix skin blueprint box drawing incorrectly when both scale and rotation are applied --- osu.Game/Skinning/Editor/SkinBlueprint.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinBlueprint.cs b/osu.Game/Skinning/Editor/SkinBlueprint.cs index 1d029c39d6..b2a1b1c9d8 100644 --- a/osu.Game/Skinning/Editor/SkinBlueprint.cs +++ b/osu.Game/Skinning/Editor/SkinBlueprint.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using osu.Framework.Allocation; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; @@ -112,14 +113,10 @@ namespace osu.Game.Skinning.Editor drawableQuad = drawable.ScreenSpaceDrawQuad; var quad = ToLocalSpace(drawable.ScreenSpaceDrawQuad); - box.Position = new Vector2( - drawable.Scale.X < 0 ? quad.TopRight.X : quad.TopLeft.X, - drawable.Scale.Y < 0 ? quad.BottomLeft.Y : quad.TopLeft.Y - ); - + box.Position = drawable.ToSpaceOfOtherDrawable(Vector2.Zero, this); box.Size = quad.Size; - box.Rotation = drawable.Rotation; + box.Scale = new Vector2(MathF.Sign(drawable.Scale.X), MathF.Sign(drawable.Scale.Y)); } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => drawable.ReceivePositionalInputAt(screenSpacePos); From 25b1443c5011fb7c5e3144e05159a92434206cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 13 May 2021 17:50:12 +0200 Subject: [PATCH 4/4] Remove dead branch and mark implementation as temporary The previous implementation was checking if the `x0` or `x2` anchors were selected to decide on which way to transfer the drawable's scale, but that check actually ends up being always true for corner anchors. To visualise, this is how the corner anchors correspond to `Anchor` flags: x0 x1 x2 | | | y0 -O---O---O- | | | y1 -O---+---O- | | | y2 -O---O---O- | | | The Os indicate where the reference anchors are on a selection box. The first conditional eliminates the middle ones, which makes sense. But after excluding them from further deliberations (marking via X): x0 x1 x2 | | | y0 -O---X---O- | | | y1 -X---+---X- | | | y2 -O---X---O- | | | The remaining anchors always have `x0` or `x2` set. So to avoid confusion, just always transfer one way for now. At some point this should be torn out in favour of an actual implementation of the desired behaviour. --- osu.Game/Skinning/Editor/SkinSelectionHandler.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs index 485cd3fe93..9bcdc6e08b 100644 --- a/osu.Game/Skinning/Editor/SkinSelectionHandler.cs +++ b/osu.Game/Skinning/Editor/SkinSelectionHandler.cs @@ -158,10 +158,8 @@ namespace osu.Game.Skinning.Editor // for now aspect lock scale adjustments that occur at corners. if (!reference.HasFlagFast(Anchor.x1) && !reference.HasFlagFast(Anchor.y1)) { - if (reference.HasFlagFast(Anchor.x0) || reference.HasFlagFast(Anchor.x2)) - scale.Y = scale.X; - else - scale.X = scale.Y; + // TODO: temporary implementation - only dragging the corner handles across the X axis changes size. + scale.Y = scale.X; } }