Skip to content

Commit

Permalink
Crop oversized gameplay textures instead of downscaling them
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte committed Sep 29, 2023
1 parent 09c9baa commit 0bcb99f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions osu.Game/Skinning/LegacySkinExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0bcb99f

Please sign in to comment.