1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-29 23:58:34 +01:00

allow paragraph fonts to be changed

This commit is contained in:
Ellpeck 2019-09-26 22:28:48 +02:00
parent 36204e40cb
commit bc6ad3adef

View file

@ -16,9 +16,9 @@ namespace MLEM.Ui.Elements {
private string text; private string text;
private string splitText; private string splitText;
private Dictionary<int, FormattingCode> codeLocations; private Dictionary<int, FormattingCode> codeLocations;
private IGenericFont regularFont; public IGenericFont RegularFont;
private IGenericFont boldFont; public IGenericFont BoldFont;
private IGenericFont italicFont; public IGenericFont ItalicFont;
public NinePatch Background; public NinePatch Background;
public Color BackgroundColor; public Color BackgroundColor;
@ -59,10 +59,10 @@ namespace MLEM.Ui.Elements {
var size = base.CalcActualSize(parentArea); var size = base.CalcActualSize(parentArea);
var sc = this.TextScale * this.Scale; var sc = this.TextScale * this.Scale;
this.splitText = this.regularFont.SplitString(this.text.RemoveFormatting(), size.X - this.ScaledPadding.X * 2, sc); this.splitText = this.RegularFont.SplitString(this.text.RemoveFormatting(), size.X - this.ScaledPadding.X * 2, sc);
this.codeLocations = this.text.GetFormattingCodes(); this.codeLocations = this.text.GetFormattingCodes();
var textDims = this.regularFont.MeasureString(this.splitText) * sc; var textDims = this.RegularFont.MeasureString(this.splitText) * sc;
return new Point(this.AutoAdjustWidth ? textDims.X.Ceil() + this.ScaledPadding.X * 2 : size.X, textDims.Y.Ceil() + this.ScaledPadding.Y * 2); return new Point(this.AutoAdjustWidth ? textDims.X.Ceil() + this.ScaledPadding.X * 2 : size.X, textDims.Y.Ceil() + this.ScaledPadding.Y * 2);
} }
@ -82,10 +82,10 @@ namespace MLEM.Ui.Elements {
// if we don't have any formatting codes, then we don't need to do complex drawing // if we don't have any formatting codes, then we don't need to do complex drawing
if (this.codeLocations.Count <= 0) { if (this.codeLocations.Count <= 0) {
this.regularFont.DrawString(batch, this.splitText, pos, this.TextColor * alpha, 0, Vector2.Zero, sc, SpriteEffects.None, 0); this.RegularFont.DrawString(batch, this.splitText, pos, this.TextColor * alpha, 0, Vector2.Zero, sc, SpriteEffects.None, 0);
} else { } else {
// if we have formatting codes, we should do it // if we have formatting codes, we should do it
this.regularFont.DrawFormattedString(batch, pos, this.splitText, this.codeLocations, this.TextColor * alpha, sc, this.boldFont, this.italicFont, 0, this.TimeIntoAnimation); this.RegularFont.DrawFormattedString(batch, pos, this.splitText, this.codeLocations, this.TextColor * alpha, sc, this.BoldFont, this.ItalicFont, 0, this.TimeIntoAnimation);
} }
base.Draw(time, batch, alpha, blendState, samplerState, matrix); base.Draw(time, batch, alpha, blendState, samplerState, matrix);
} }
@ -93,9 +93,9 @@ namespace MLEM.Ui.Elements {
protected override void InitStyle(UiStyle style) { protected override void InitStyle(UiStyle style) {
base.InitStyle(style); base.InitStyle(style);
this.TextScale = style.TextScale; this.TextScale = style.TextScale;
this.regularFont = style.Font; this.RegularFont = style.Font;
this.boldFont = style.BoldFont ?? style.Font; this.BoldFont = style.BoldFont ?? style.Font;
this.italicFont = style.ItalicFont ?? style.Font; this.ItalicFont = style.ItalicFont ?? style.Font;
} }
public delegate string TextCallback(Paragraph paragraph); public delegate string TextCallback(Paragraph paragraph);