diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index 133af328d..54a41ac31 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -10,6 +10,8 @@ namespace Barotrauma protected Alignment textAlignment; + private float textScale; + protected Vector2 textPos; protected Vector2 origin; @@ -88,6 +90,19 @@ namespace Barotrauma get { return textPos; } } + public float TextScale + { + get { return textScale; } + set + { + if (value != textScale) + { + textScale = value; + SetTextPos(); + } + } + } + public Vector2 Origin { get { return origin; } @@ -162,6 +177,8 @@ namespace Barotrauma SetTextPos(); + TextScale = 1.0f; + if (rect.Height == 0 && !string.IsNullOrEmpty(Text)) { this.rect.Height = (int)Font.MeasureString(wrappedText).Y; @@ -267,7 +284,7 @@ namespace Barotrauma Wrap ? wrappedText : text, new Vector2(rect.X, rect.Y) + textPos + offset, textColor * (textColor.A / 255.0f), - 0.0f, origin, 1.0f, + 0.0f, origin, TextScale, SpriteEffects.None, textDepth); } diff --git a/Subsurface/Source/Items/Components/ItemLabel.cs b/Subsurface/Source/Items/Components/ItemLabel.cs index 224c595bf..7452f2f84 100644 --- a/Subsurface/Source/Items/Components/ItemLabel.cs +++ b/Subsurface/Source/Items/Components/ItemLabel.cs @@ -36,6 +36,16 @@ namespace Barotrauma.Items.Components } } + [Editable, HasDefaultValue(1.0f, true)] + public float TextScale + { + get { return textBlock == null ? 1.0f : textBlock.TextScale; } + set + { + if (textBlock != null) textBlock.TextScale = MathHelper.Clamp(value, 0.1f, 10.0f); + } + } + private GUITextBlock TextBlock { get @@ -49,6 +59,7 @@ namespace Barotrauma.Items.Components textBlock.Font = GUI.SmallFont; textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); textBlock.TextDepth = item.Sprite.Depth - 0.0001f; + textBlock.TextScale = TextScale; } return textBlock; } diff --git a/Subsurface/Source/Utils/ToolBox.cs b/Subsurface/Source/Utils/ToolBox.cs index eb11099ec..1ac5eae40 100644 --- a/Subsurface/Source/Utils/ToolBox.cs +++ b/Subsurface/Source/Utils/ToolBox.cs @@ -464,44 +464,43 @@ namespace Barotrauma return d[n, m]; } - + public static string WrapText(string text, float lineLength, ScalableFont font) //TODO: could integrate this into the ScalableFont class directly { if (font.MeasureString(text).X < lineLength) return text; text = text.Replace("\n", " \n "); - string[] words = text.Split(' ');//, '\n'); + string[] words = text.Split(' '); StringBuilder wrappedText = new StringBuilder(); float linePos = 0f; float spaceWidth = font.MeasureString(" ").X; for (int i = 0; i < words.Length; ++i) { - if (string.IsNullOrWhiteSpace(words[i]) && words[i]!="\n") continue; + if (string.IsNullOrWhiteSpace(words[i]) && words[i] != "\n") continue; - Vector2 size; - string tempWord = words[i]; - string prevWord = words[i]; - while ((size = font.MeasureString(tempWord)).X > lineLength) + Vector2 size = font.MeasureString(words[i]); + if (size.X > lineLength) { - tempWord = tempWord.Remove(tempWord.Length - 1, 1); - } + while (words[i].Length > 0 && + (size = font.MeasureString((words[i][0]).ToString())).X + linePos < lineLength) + { + wrappedText.Append(words[i][0]); + words[i] = words[i].Remove(0, 1); - words[i] = tempWord; - if (prevWord.Length> tempWord.Length) - { - wrappedText.Append(words[i]); - wrappedText.Append(" \n"); - wrappedText.Append(prevWord.Remove(0, tempWord.Length)); - linePos = lineLength*2.0f; + linePos += size.X; + } + + wrappedText.Append("\n"); + linePos = 0.0f; + i--; continue; - } - + if (linePos + size.X < lineLength) { - wrappedText.Append(words[i]); + wrappedText.Append(words[i]); if (words[i] == "\n") { linePos = 0.0f; @@ -514,13 +513,10 @@ namespace Barotrauma } else { - //if (i>0)wrappedText.Remove(wrappedText.Length - 1, 1); + wrappedText.Append("\n"); + wrappedText.Append(words[i]); - wrappedText.Append("\n"); - wrappedText.Append(words[i]); - - linePos = size.X + spaceWidth; - + linePos = size.X + spaceWidth; } if (i < words.Length - 1) wrappedText.Append(" ");