mirror of
https://github.com/ppy/osu
synced 2025-01-21 05:20:50 +00:00
Fixed issues found in UprightAspectMaintainingContainer
This commit is contained in:
parent
d4a52baa56
commit
62210bce4e
@ -14,8 +14,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class UprightAspectMaintainingContainer : Container
|
public class UprightAspectMaintainingContainer : Container
|
||||||
{
|
{
|
||||||
protected override Container<Drawable> Content { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Controls how much this container scales compared to its parent (default is 1.0f).
|
/// Controls how much this container scales compared to its parent (default is 1.0f).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -30,7 +28,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
|
|
||||||
public UprightAspectMaintainingContainer()
|
public UprightAspectMaintainingContainer()
|
||||||
{
|
{
|
||||||
AddInternal(Content = new GrowToFitContainer());
|
|
||||||
AddLayout(layout);
|
AddLayout(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,6 +42,14 @@ namespace osu.Game.Graphics.Containers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Add(Drawable drawable)
|
||||||
|
{
|
||||||
|
base.Add(new GrowToFitContainer
|
||||||
|
{
|
||||||
|
Child = drawable
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keeps the drawable upright and unstretched preventing it from being rotated, sheared, scaled or flipped with its Parent.
|
/// Keeps the drawable upright and unstretched preventing it from being rotated, sheared, scaled or flipped with its Parent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -57,23 +62,23 @@ namespace osu.Game.Graphics.Containers
|
|||||||
parentMatrix.M31 = 0.0f;
|
parentMatrix.M31 = 0.0f;
|
||||||
parentMatrix.M32 = 0.0f;
|
parentMatrix.M32 = 0.0f;
|
||||||
|
|
||||||
Matrix3 reversedParrent = parentMatrix.Inverted();
|
Matrix3 reversedParent = parentMatrix.Inverted();
|
||||||
|
|
||||||
// Extract the rotation.
|
// Extract the rotation.
|
||||||
float angle = MathF.Atan2(reversedParrent.M12, reversedParrent.M11);
|
float angle = MathF.Atan2(reversedParent.M12, reversedParent.M11);
|
||||||
Rotation = MathHelper.RadiansToDegrees(angle);
|
Rotation = MathHelper.RadiansToDegrees(angle);
|
||||||
|
|
||||||
// Remove rotation from the C matrix so that it only contains shear and scale.
|
// Remove rotation from the C matrix so that it only contains shear and scale.
|
||||||
Matrix3 m = Matrix3.CreateRotationZ(-angle);
|
Matrix3 m = Matrix3.CreateRotationZ(-angle);
|
||||||
reversedParrent *= m;
|
reversedParent *= m;
|
||||||
|
|
||||||
// Extract shear.
|
// Extract shear.
|
||||||
float alpha = reversedParrent.M21 / reversedParrent.M22;
|
float alpha = reversedParent.M21 / reversedParent.M22;
|
||||||
Shear = new Vector2(-alpha, 0);
|
Shear = new Vector2(-alpha, 0);
|
||||||
|
|
||||||
// Etract scale.
|
// Etract scale.
|
||||||
float sx = reversedParrent.M11;
|
float sx = reversedParent.M11;
|
||||||
float sy = reversedParrent.M22;
|
float sy = reversedParent.M22;
|
||||||
|
|
||||||
Vector3 parentScale = parentMatrix.ExtractScale();
|
Vector3 parentScale = parentMatrix.ExtractScale();
|
||||||
|
|
||||||
@ -90,32 +95,30 @@ namespace osu.Game.Graphics.Containers
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
usedScale = 1.0f + (usedScale - 1.0f) * ScalingFactor;
|
if (Scaling != ScaleMode.NoScaling)
|
||||||
|
{
|
||||||
|
if (ScalingFactor < 1.0f)
|
||||||
|
usedScale = 1.0f + (usedScale - 1.0f) * ScalingFactor;
|
||||||
|
if (ScalingFactor > 1.0f)
|
||||||
|
usedScale = (usedScale < 1.0f) ? usedScale * (1.0f / ScalingFactor) : usedScale * ScalingFactor;
|
||||||
|
}
|
||||||
|
|
||||||
Scale = new Vector2(sx * usedScale, sy * usedScale);
|
Scale = new Vector2(sx * usedScale, sy * usedScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public class GrowToFitContainer : Container
|
||||||
/// A container that grows in size to fit its children and retains its size when its children shrink
|
|
||||||
/// </summary>
|
|
||||||
private class GrowToFitContainer : Container
|
|
||||||
{
|
{
|
||||||
protected override Container<Drawable> Content => content;
|
|
||||||
private readonly Container content;
|
|
||||||
|
|
||||||
public GrowToFitContainer()
|
|
||||||
{
|
|
||||||
InternalChild = content = new Container
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
if ((Child.RelativeSizeAxes & Axes.X) != 0)
|
||||||
Height = Math.Max(content.Height, Height);
|
RelativeSizeAxes |= Axes.X;
|
||||||
Width = Math.Max(content.Width, Width);
|
else
|
||||||
|
Width = Math.Max(Child.Width, Width);
|
||||||
|
|
||||||
|
if ((Child.RelativeSizeAxes & Axes.Y) != 0)
|
||||||
|
RelativeSizeAxes |= Axes.Y;
|
||||||
|
else
|
||||||
|
Height = Math.Max(Child.Height, Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user