mirror of
https://github.com/ppy/osu
synced 2025-02-21 13:07:18 +00:00
Use the same code path for all scaling
This commit is contained in:
parent
6a3c58b9ad
commit
14af86d6c5
@ -34,92 +34,61 @@ namespace osu.Game.Skinning.Editor
|
|||||||
{
|
{
|
||||||
adjustScaleFromAnchor(ref scale, anchor);
|
adjustScaleFromAnchor(ref scale, anchor);
|
||||||
|
|
||||||
if (SelectedBlueprints.Count > 1)
|
var selectionQuad = GetSurroundingQuad(SelectedBlueprints.SelectMany(b =>
|
||||||
|
b.Item.ScreenSpaceDrawQuad.GetVertices().ToArray()));
|
||||||
|
|
||||||
|
// the selection quad is always upright, so use a rect to make mutating the values easier.
|
||||||
|
var adjustedRect = selectionQuad.AABBFloat;
|
||||||
|
|
||||||
|
// for now aspect lock scale adjustments that occur at corners.
|
||||||
|
if (!anchor.HasFlagFast(Anchor.x1) && !anchor.HasFlagFast(Anchor.y1))
|
||||||
|
scale.Y = scale.X / selectionQuad.Width * selectionQuad.Height;
|
||||||
|
|
||||||
|
if (anchor.HasFlagFast(Anchor.x0))
|
||||||
{
|
{
|
||||||
var selectionQuad = GetSurroundingQuad(SelectedBlueprints.SelectMany(b =>
|
adjustedRect.X -= scale.X;
|
||||||
b.Item.ScreenSpaceDrawQuad.GetVertices().ToArray()));
|
adjustedRect.Width += scale.X;
|
||||||
|
|
||||||
// the selection quad is always upright, so use a rect to make mutating the values easier.
|
|
||||||
var adjustedRect = selectionQuad.AABBFloat;
|
|
||||||
|
|
||||||
// for now aspect lock scale adjustments that occur at corners.
|
|
||||||
if (!anchor.HasFlagFast(Anchor.x1) && !anchor.HasFlagFast(Anchor.y1))
|
|
||||||
scale.Y = scale.X / selectionQuad.Width * selectionQuad.Height;
|
|
||||||
|
|
||||||
if (anchor.HasFlagFast(Anchor.x0))
|
|
||||||
{
|
|
||||||
adjustedRect.X -= scale.X;
|
|
||||||
adjustedRect.Width += scale.X;
|
|
||||||
}
|
|
||||||
else if (anchor.HasFlagFast(Anchor.x2))
|
|
||||||
{
|
|
||||||
adjustedRect.Width += scale.X;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (anchor.HasFlagFast(Anchor.y0))
|
|
||||||
{
|
|
||||||
adjustedRect.Y -= scale.Y;
|
|
||||||
adjustedRect.Height += scale.Y;
|
|
||||||
}
|
|
||||||
else if (anchor.HasFlagFast(Anchor.y2))
|
|
||||||
{
|
|
||||||
adjustedRect.Height += scale.Y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// scale adjust should match that of the quad itself.
|
|
||||||
var scaledDelta = new Vector2(
|
|
||||||
adjustedRect.Width / selectionQuad.Width - 1,
|
|
||||||
adjustedRect.Height / selectionQuad.Height - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (var b in SelectedBlueprints)
|
|
||||||
{
|
|
||||||
var drawableItem = (Drawable)b.Item;
|
|
||||||
|
|
||||||
if (SelectedBlueprints.Count > 1)
|
|
||||||
{
|
|
||||||
// each drawable's relative position should be maintained in the scaled quad.
|
|
||||||
var screenPosition = b.ScreenSpaceSelectionPoint;
|
|
||||||
|
|
||||||
var relativePositionInOriginal =
|
|
||||||
new Vector2(
|
|
||||||
(screenPosition.X - selectionQuad.TopLeft.X) / selectionQuad.Width,
|
|
||||||
(screenPosition.Y - selectionQuad.TopLeft.Y) / selectionQuad.Height
|
|
||||||
);
|
|
||||||
|
|
||||||
var newPositionInAdjusted = new Vector2(
|
|
||||||
adjustedRect.TopLeft.X + adjustedRect.Width * relativePositionInOriginal.X,
|
|
||||||
adjustedRect.TopLeft.Y + adjustedRect.Height * relativePositionInOriginal.Y
|
|
||||||
);
|
|
||||||
|
|
||||||
drawableItem.Position = drawableItem.Parent.ToLocalSpace(newPositionInAdjusted) - drawableItem.AnchorPosition;
|
|
||||||
drawableItem.Scale += scaledDelta;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else if (anchor.HasFlagFast(Anchor.x2))
|
||||||
{
|
{
|
||||||
var blueprint = SelectedBlueprints.First();
|
adjustedRect.Width += scale.X;
|
||||||
var drawableItem = (Drawable)blueprint.Item;
|
}
|
||||||
|
|
||||||
// the number of local "pixels" the drag operation resulted in.
|
if (anchor.HasFlagFast(Anchor.y0))
|
||||||
// our goal is to increase the drawable's draw size by this amount.
|
{
|
||||||
var scaledDelta = drawableItem.ScreenSpaceDeltaToParentSpace(scale);
|
adjustedRect.Y -= scale.Y;
|
||||||
|
adjustedRect.Height += scale.Y;
|
||||||
|
}
|
||||||
|
else if (anchor.HasFlagFast(Anchor.y2))
|
||||||
|
{
|
||||||
|
adjustedRect.Height += scale.Y;
|
||||||
|
}
|
||||||
|
|
||||||
scaledDelta = new Vector2(
|
// scale adjust should match that of the quad itself.
|
||||||
scaledDelta.X / drawableItem.DrawWidth,
|
var scaledDelta = new Vector2(
|
||||||
scaledDelta.Y / drawableItem.DrawHeight
|
adjustedRect.Width / selectionQuad.Width - 1,
|
||||||
|
adjustedRect.Height / selectionQuad.Height - 1
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (var b in SelectedBlueprints)
|
||||||
|
{
|
||||||
|
var drawableItem = (Drawable)b.Item;
|
||||||
|
|
||||||
|
// each drawable's relative position should be maintained in the scaled quad.
|
||||||
|
var screenPosition = b.ScreenSpaceSelectionPoint;
|
||||||
|
|
||||||
|
var relativePositionInOriginal =
|
||||||
|
new Vector2(
|
||||||
|
(screenPosition.X - selectionQuad.TopLeft.X) / selectionQuad.Width,
|
||||||
|
(screenPosition.Y - selectionQuad.TopLeft.Y) / selectionQuad.Height
|
||||||
|
);
|
||||||
|
|
||||||
|
var newPositionInAdjusted = new Vector2(
|
||||||
|
adjustedRect.TopLeft.X + adjustedRect.Width * relativePositionInOriginal.X,
|
||||||
|
adjustedRect.TopLeft.Y + adjustedRect.Height * relativePositionInOriginal.Y
|
||||||
);
|
);
|
||||||
|
|
||||||
// handle the case where scaling with a centre origin needs double the adjustments to match
|
drawableItem.Position = drawableItem.Parent.ToLocalSpace(newPositionInAdjusted) - drawableItem.AnchorPosition;
|
||||||
// user cursor movement.
|
|
||||||
if (drawableItem.Origin.HasFlagFast(Anchor.x1)) scaledDelta.X *= 2;
|
|
||||||
if (drawableItem.Origin.HasFlagFast(Anchor.y1)) scaledDelta.Y *= 2;
|
|
||||||
|
|
||||||
// for now aspect lock scale adjustments that occur at corners.
|
|
||||||
if (!anchor.HasFlagFast(Anchor.x1) && !anchor.HasFlagFast(Anchor.y1))
|
|
||||||
scaledDelta.Y = scaledDelta.X;
|
|
||||||
|
|
||||||
drawableItem.Scale += scaledDelta;
|
drawableItem.Scale += scaledDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user