Crop oversized gameplay textures instead of downscaling them

This commit is contained in:
Salman Ahmed 2023-09-30 01:16:56 +03:00
parent 09c9baadec
commit 0bcb99f2c4
1 changed files with 6 additions and 3 deletions

View File

@ -9,6 +9,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;
@ -112,9 +113,11 @@ public static Texture WithMaximumSize(this Texture texture, Vector2 maxSize)
if (texture.DisplayWidth <= maxSize.X && texture.DisplayHeight <= maxSize.Y)
return texture;
// use scale adjust property for downscaling the texture in order to meet the specified maximum dimensions.
texture.ScaleAdjust *= Math.Max(texture.DisplayWidth / maxSize.X, texture.DisplayHeight / maxSize.Y);
return texture;
maxSize *= texture.ScaleAdjust;
var croppedTexture = texture.Crop(new RectangleF(texture.Width / 2f - maxSize.X / 2f, texture.Height / 2f - maxSize.Y / 2f, maxSize.X, maxSize.Y));
croppedTexture.ScaleAdjust = texture.ScaleAdjust;
return croppedTexture;
}
public static bool HasFont(this ISkin source, LegacyFont font)