Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aspect ratio locking and flip support to skin editor #12780

Merged
merged 6 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion osu.Game/Skinning/Editor/SkinBlueprint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ protected override void Update()
drawableQuad = drawable.ScreenSpaceDrawQuad;
var quad = ToLocalSpace(drawable.ScreenSpaceDrawQuad);

box.Position = quad.TopLeft;
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);
Expand Down
22 changes: 22 additions & 0 deletions osu.Game/Skinning/Editor/SkinSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +37,20 @@ public override bool HandleScale(Vector2 scale, Anchor anchor)
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<ISkinnableDrawable> moveEvent)
{
foreach (var c in SelectedBlueprints)
Expand Down Expand Up @@ -139,6 +154,13 @@ private static void adjustScaleFromAnchor(ref Vector2 scale, Anchor reference)
// 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))
{
// TODO: temporary implementation - only dragging the corner handles across the X axis changes size.
scale.Y = scale.X;
}
}

public class AnchorMenuItem : TernaryStateMenuItem
Expand Down