SharpFont + ScalableFont implementation

https://github.com/Robmaister/SharpFont

TODO: replace Code Bold.otf with the full version, fix any bugs, build on Linux, possibly move ToolBox string wrapping and limiting logic to ScalableFont class for better results.
This commit is contained in:
juanjp600
2017-03-07 13:44:42 -03:00
parent 88a76f0c9f
commit d6c292a2cc
231 changed files with 28528 additions and 94 deletions
+8 -7
View File
@@ -14,6 +14,7 @@ namespace Barotrauma
protected Vector2 origin;
protected Vector2 caretPos;
protected int caretAt;
protected Color textColor;
@@ -103,8 +104,8 @@ namespace Barotrauma
{
get { return caretPos; }
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, SpriteFont font)
public GUITextBlock(Rectangle rect, string text, GUIStyle style, GUIComponent parent, ScalableFont font)
: this(rect, text, style, Alignment.TopLeft, Alignment.TopLeft, parent, false, font)
{
}
@@ -142,7 +143,7 @@ namespace Barotrauma
if (textColor != null) this.textColor = (Color)textColor;
}
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, SpriteFont font = null)
public GUITextBlock(Rectangle rect, string text, GUIStyle style, Alignment alignment = Alignment.TopLeft, Alignment textAlignment = Alignment.TopLeft, GUIComponent parent = null, bool wrap = false, ScalableFont font = null)
:base (style)
{
this.Font = font == null ? GUI.Font : font;
@@ -174,7 +175,7 @@ namespace Barotrauma
wrappedText = text;
Vector2 size = MeasureText(text);
Vector2 size = MeasureText(text);
if (Wrap && rect.Width>0)
{
@@ -184,7 +185,7 @@ namespace Barotrauma
size = newSize;
}
if (LimitText && text.Length>1 && size.Y > rect.Height)
{
string[] lines = text.Split('\n');
@@ -205,7 +206,7 @@ namespace Barotrauma
if (textAlignment.HasFlag(Alignment.Bottom))
origin.Y -= (rect.Height / 2.0f - padding.W) - size.Y / 2;
origin.X = (int)origin.X;
origin.Y = (int)origin.Y;
@@ -263,7 +264,7 @@ namespace Barotrauma
if (!string.IsNullOrEmpty(text))
{
spriteBatch.DrawString(Font,
Font.DrawString(spriteBatch,
Wrap ? wrappedText : text,
new Vector2(rect.X, rect.Y) + textPos + offset,
textColor * (textColor.A / 255.0f),