mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 06:42:56 +08:00
Prevent TextSprites inside SongProgressInfo from being stretched or flipped
This commit is contained in:
parent
df85bd74d7
commit
78a98cdb9c
@ -82,11 +82,12 @@ namespace osu.Game.Extensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Keeps the drawable upright no matter the Rotation of its parents.
|
/// Keeps the drawable upright and prevents it from being scaled or flipped with its Parent.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="drawable">The drawable.</param>
|
/// <param name="drawable">The drawable.</param>
|
||||||
public static void KeepUpright(this Drawable drawable)
|
public static void KeepUprightAndUnstretched(this Drawable drawable)
|
||||||
{
|
{
|
||||||
|
// Fix the rotation
|
||||||
var result = drawable.Parent.DrawInfo;
|
var result = drawable.Parent.DrawInfo;
|
||||||
var scale = result.Matrix.ExtractScale();
|
var scale = result.Matrix.ExtractScale();
|
||||||
var rotation = new Matrix3(
|
var rotation = new Matrix3(
|
||||||
@ -94,9 +95,30 @@ namespace osu.Game.Extensions
|
|||||||
result.Matrix.Row1 / scale.Y,
|
result.Matrix.Row1 / scale.Y,
|
||||||
new Vector3(0.0f, 0.0f, 1.0f)
|
new Vector3(0.0f, 0.0f, 1.0f)
|
||||||
);
|
);
|
||||||
float angle = MathF.Atan2(rotation.M12, rotation.M11);
|
rotation.Invert();
|
||||||
|
float angle = MathF.Atan(rotation.M12 / rotation.M11);
|
||||||
angle *= (360 / (2 * MathF.PI));
|
angle *= (360 / (2 * MathF.PI));
|
||||||
drawable.Rotation = -angle;
|
drawable.Rotation = angle;
|
||||||
|
|
||||||
|
// Fix the scale (includes flip)
|
||||||
|
var containerOriginToSpaceOrigin = new Matrix3(
|
||||||
|
new Vector3(1.0f, 0.0f, 0.0f),
|
||||||
|
new Vector3(0.0f, 1.0f, 0.0f),
|
||||||
|
new Vector3(drawable.DrawSize.X / 2, drawable.DrawSize.Y / 2, 1.0f)
|
||||||
|
);
|
||||||
|
var containerOriginToSpaceOriginInverse = containerOriginToSpaceOrigin;
|
||||||
|
containerOriginToSpaceOriginInverse.Invert();
|
||||||
|
Matrix3 rotatedBack = (containerOriginToSpaceOriginInverse * (rotation * (containerOriginToSpaceOrigin * result.Matrix)));
|
||||||
|
|
||||||
|
bool xFliped = rotation.M11 < 0;
|
||||||
|
bool yFliped = rotation.M22 < 0;
|
||||||
|
|
||||||
|
var rotatedBackScale = rotatedBack.ExtractScale();
|
||||||
|
|
||||||
|
drawable.Scale = new Vector2(
|
||||||
|
(xFliped ? -1 : 1) / rotatedBackScale.X,
|
||||||
|
(yFliped ? -1 : 1) / rotatedBackScale.Y
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
@ -16,7 +17,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public class DefaultSongProgress : SongProgress
|
public class DefaultSongProgress : SongProgress
|
||||||
{
|
{
|
||||||
private const float info_height = 20;
|
|
||||||
private const float bottom_bar_height = 5;
|
private const float bottom_bar_height = 5;
|
||||||
private const float graph_height = SquareGraph.Column.WIDTH * 6;
|
private const float graph_height = SquareGraph.Column.WIDTH * 6;
|
||||||
private const float handle_height = 18;
|
private const float handle_height = 18;
|
||||||
@ -67,7 +67,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Origin = Anchor.BottomLeft,
|
Origin = Anchor.BottomLeft,
|
||||||
Anchor = Anchor.BottomLeft,
|
Anchor = Anchor.BottomLeft,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Height = info_height,
|
|
||||||
},
|
},
|
||||||
graph = new SongProgressGraph
|
graph = new SongProgressGraph
|
||||||
{
|
{
|
||||||
@ -180,7 +179,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
base.Update();
|
base.Update();
|
||||||
Height = bottom_bar_height + graph_height + handle_size.Y + info_height - graph.Y;
|
Height = bottom_bar_height + graph_height + handle_size.Y + info.Height - graph.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBarVisibility()
|
private void updateBarVisibility()
|
||||||
|
@ -46,6 +46,7 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
if (clock != null)
|
if (clock != null)
|
||||||
gameplayClock = clock;
|
gameplayClock = clock;
|
||||||
|
|
||||||
|
AutoSizeAxes = Axes.Y;
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
new Container
|
||||||
@ -138,9 +139,9 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
|
|
||||||
private void keepTextSpritesUpright()
|
private void keepTextSpritesUpright()
|
||||||
{
|
{
|
||||||
timeCurrent.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUpright(timeCurrent); };
|
timeCurrent.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
|
||||||
progress.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUpright(timeCurrent); };
|
progress.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
|
||||||
timeLeft.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUpright(timeCurrent); };
|
timeLeft.OnUpdate += (timeCurrent) => { Extensions.DrawableExtensions.KeepUprightAndUnstretched(timeCurrent); };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user