38f1ddb...178a853: v0.8.9.1, removed content folder
This commit is contained in:
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using SharpFont;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -45,7 +46,12 @@ namespace Barotrauma
|
||||
public Rectangle texCoords;
|
||||
}
|
||||
|
||||
public ScalableFont(string filename, uint size, GraphicsDevice gd=null)
|
||||
public ScalableFont(XElement element, GraphicsDevice gd = null)
|
||||
: this (element.GetAttributeString("file", ""), (uint)element.GetAttributeInt("size", 14), gd)
|
||||
{
|
||||
}
|
||||
|
||||
public ScalableFont(string filename, uint size, GraphicsDevice gd = null)
|
||||
{
|
||||
if (Lib == null) Lib = new Library();
|
||||
this.filename = filename;
|
||||
@@ -260,24 +266,39 @@ namespace Barotrauma
|
||||
|
||||
public Vector2 MeasureString(string text)
|
||||
{
|
||||
if (text == null)
|
||||
{
|
||||
return Vector2.Zero;
|
||||
}
|
||||
|
||||
float currentLineX = 0.0f;
|
||||
Vector2 retVal = Vector2.Zero;
|
||||
retVal.Y = baseHeight*1.8f;
|
||||
retVal.Y = baseHeight * 1.8f;
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
if (text[i] == '\n')
|
||||
{
|
||||
currentLineX = 0.0f;
|
||||
retVal.Y += baseHeight*18/10;
|
||||
retVal.Y += baseHeight * 18 / 10;
|
||||
continue;
|
||||
}
|
||||
uint charIndex = text[i];
|
||||
GlyphData gd;
|
||||
if (texCoords.TryGetValue(charIndex, out gd))
|
||||
if (texCoords.TryGetValue(charIndex, out GlyphData gd))
|
||||
{
|
||||
currentLineX += gd.advance;
|
||||
}
|
||||
retVal.X = Math.Max(retVal.X,currentLineX);
|
||||
retVal.X = Math.Max(retVal.X, currentLineX);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public Vector2 MeasureChar(char c)
|
||||
{
|
||||
Vector2 retVal = Vector2.Zero;
|
||||
retVal.Y = baseHeight * 1.8f;
|
||||
if (texCoords.TryGetValue(c, out GlyphData gd))
|
||||
{
|
||||
retVal.X = gd.advance;
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user