mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 22:18:34 +01:00
clean up GenericFont changes
This commit is contained in:
parent
73f2e1c565
commit
64b9246aa5
5 changed files with 18 additions and 17 deletions
|
@ -33,7 +33,7 @@ namespace MLEM.Extended.Font {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override Vector2 CalcCharSize(char c) {
|
protected override Vector2 MeasureChar(char c) {
|
||||||
var region = this.Font.GetCharacterRegion(c);
|
var region = this.Font.GetCharacterRegion(c);
|
||||||
return region != null ? new Vector2(region.XAdvance, region.Height) : Vector2.Zero;
|
return region != null ? new Vector2(region.XAdvance, region.Height) : Vector2.Zero;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace MLEM.Ui.Style {
|
||||||
public override GenericFont Italic => this;
|
public override GenericFont Italic => this;
|
||||||
public override float LineHeight => 1;
|
public override float LineHeight => 1;
|
||||||
|
|
||||||
protected override Vector2 CalcCharSize(char c) {
|
protected override Vector2 MeasureChar(char c) {
|
||||||
return Vector2.Zero;
|
return Vector2.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace MLEM.Font {
|
||||||
public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
|
public abstract void DrawString(SpriteBatch batch, StringBuilder text, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth);
|
||||||
|
|
||||||
///<inheritdoc cref="SpriteFont.MeasureString(string)"/>
|
///<inheritdoc cref="SpriteFont.MeasureString(string)"/>
|
||||||
protected abstract Vector2 CalcCharSize(char c);
|
protected abstract Vector2 MeasureChar(char c);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws a string with the given text alignment.
|
/// Draws a string with the given text alignment.
|
||||||
|
@ -85,23 +85,23 @@ namespace MLEM.Font {
|
||||||
this.DrawString(batch, text, position, color, rotation, origin, scale, effects, layerDepth);
|
this.DrawString(batch, text, position, color, rotation, origin, scale, effects, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
///<inheritdoc cref="SpriteFont.MeasureString(string)"/>
|
|
||||||
public Vector2 MeasureChar(char c) {
|
|
||||||
return c == OneEmSpace ? new Vector2(this.LineHeight) : this.CalcCharSize(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
///<inheritdoc cref="SpriteFont.MeasureString(string)"/>
|
///<inheritdoc cref="SpriteFont.MeasureString(string)"/>
|
||||||
public Vector2 MeasureString(string text) {
|
public Vector2 MeasureString(string text) {
|
||||||
var size = Vector2.Zero;
|
var size = Vector2.Zero;
|
||||||
var xOffset = 0F;
|
var xOffset = 0F;
|
||||||
foreach (var c in text) {
|
foreach (var c in text) {
|
||||||
if (c == '\n') {
|
switch (c) {
|
||||||
xOffset = 0;
|
case '\n':
|
||||||
size.Y += this.LineHeight;
|
xOffset = 0;
|
||||||
continue;
|
size.Y += this.LineHeight;
|
||||||
|
break;
|
||||||
|
case OneEmSpace:
|
||||||
|
xOffset += this.LineHeight;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
xOffset += this.MeasureChar(c).X;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
xOffset += this.MeasureChar(c).X;
|
|
||||||
// increase x size if this line is the longest
|
// increase x size if this line is the longest
|
||||||
if (xOffset > size.X)
|
if (xOffset > size.X)
|
||||||
size.X = xOffset;
|
size.X = xOffset;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace MLEM.Font {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override Vector2 CalcCharSize(char c) {
|
protected override Vector2 MeasureChar(char c) {
|
||||||
return this.Font.MeasureString(c.ToString());
|
return this.Font.MeasureString(c.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,9 @@ namespace MLEM.Formatting {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
token.DrawSelf(time, batch, pos + innerOffset, font, color, scale, depth);
|
token.DrawSelf(time, batch, pos + innerOffset, font, color, scale, depth);
|
||||||
|
|
||||||
token.DrawCharacter(time, batch, c, c.ToString(), i, pos + innerOffset, drawFont, drawColor, scale, depth);
|
var cString = c.ToString();
|
||||||
innerOffset.X += font.MeasureChar(c).X * scale;
|
token.DrawCharacter(time, batch, c, cString, i, pos + innerOffset, drawFont, drawColor, scale, depth);
|
||||||
|
innerOffset.X += font.MeasureString(cString).X * scale;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue