diff --git a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs
index 55bf217..dfbaed8 100644
--- a/RecrownedAthenaeum/UI/Modular/Modules/Text.cs
+++ b/RecrownedAthenaeum/UI/Modular/Modules/Text.cs
@@ -13,7 +13,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
public class Text : UIModule
{
private SpriteFont font;
- private float scale;
+ private float scale = 1f;
private Vector2 position;
private string originalText;
private string displayedText;
@@ -106,14 +106,20 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
///
public void AttemptToScaleFont()
{
- if (modifiedTextSize.X * scale > bounds.Width || modifiedTextSize.X * scale < bounds.Width - 5)
- {
- scale = bounds.Width / modifiedTextSize.X;
- }
- if (modifiedTextSize.Y * scale > bounds.Height || modifiedTextSize.Y * scale < bounds.Height - 5)
+ if (bounds.Width < bounds.Height)
{
- scale = bounds.Height / modifiedTextSize.Y;
+ if (Math.Round(modifiedTextSize.X * scale ) != bounds.Width)
+ {
+ scale = bounds.Width / modifiedTextSize.X;
+ }
+ }
+ else
+ {
+ if (Math.Round(modifiedTextSize.Y * scale ) != bounds.Height)
+ {
+ scale = bounds.Height / (modifiedTextSize.Y);
+ }
}
}
@@ -166,5 +172,35 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
ModifiedText = stringBuilder.ToString();
}
}
+
+ ///
+ /// Centers this text in the given rectangle if possible.
+ ///
+ ///
+ /// True if succeeded and false if there isn't enough space.
+ public bool CenterIn(Rectangle rectangle)
+ {
+ Vector2 textSize = new Vector2(modifiedTextSize.X * scale, modifiedTextSize.Y * scale);
+
+ if (textSize.X <= rectangle.Width)
+ {
+ position.X = rectangle.X + (rectangle.Width - textSize.X) / 2f;
+ }
+ else
+ {
+ return false;
+ }
+
+ if (textSize.Y <= rectangle.Height)
+ {
+ position.Y = rectangle.Y + (rectangle.Height - textSize.Y) / 2f;
+ }
+ else
+ {
+ return false;
+ }
+
+ return true;
+ }
}
}