From 94be5ce97b307ff3499ee55906c95fe4fc472a22 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Sun, 7 Sep 2014 10:21:42 +0200 Subject: [PATCH] Use CFont class to define the font to use --- .../CPartyScreenChallengeMain.cs | 6 +- .../CPartyScreenChallengeMedleyMain.cs | 4 +- Vocaluxe/Base/CGraphics.cs | 9 +- Vocaluxe/Base/CMain.cs | 27 +-- Vocaluxe/Base/Fonts/CFontStyle.cs | 2 +- Vocaluxe/Base/Fonts/CFonts.cs | 210 +++++++----------- Vocaluxe/Screens/CScreenSing.cs | 10 +- VocaluxeLib/CFont.cs | 87 ++++++++ VocaluxeLib/IBasic.cs | 10 +- VocaluxeLib/Menu/CLyric.cs | 13 +- VocaluxeLib/Menu/CText.cs | 114 ++++------ VocaluxeLib/PartyModes/CScreenPartyDummy.cs | 4 +- VocaluxeLib/VocaluxeLib.csproj | 1 + 13 files changed, 242 insertions(+), 255 deletions(-) create mode 100644 VocaluxeLib/CFont.cs diff --git a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs index 22945876..ea025b8e 100644 --- a/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs +++ b/PartyModes/PartyModeChallenge/CPartyScreenChallengeMain.cs @@ -446,7 +446,7 @@ namespace VocaluxeLib.PartyModes.Challenge _RoundsTableScrollArea.Y = numberY; _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; - float delta = _Texts[_TextRoundNumber].Height; + float delta = _Texts[_TextRoundNumber].Rect.H; //Update statics and texts for rounds foreach (CRoundsTableRow roundRow in _RoundsTable) @@ -479,7 +479,7 @@ namespace VocaluxeLib.PartyModes.Challenge roundRow.TextScores[column].Y = numberY + delta; roundRow.TextScores[column].MaxWidth = maxw; } - numberY = numberY + delta + delta; + numberY = numberY + 2*delta; } numberY = numberY + delta / 2; } @@ -532,7 +532,7 @@ namespace VocaluxeLib.PartyModes.Challenge _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTable = new List(); - float delta = _Texts[_TextPosition].Height * 1.2f; + float delta = _Texts[_TextPosition].Rect.H * 1.2f; float h = 0; diff --git a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs index 47dcb43c..0a0240f1 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyScreenChallengeMedleyMain.cs @@ -446,7 +446,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _RoundsTableScrollArea.Y = numberY; _RoundsTableScrollArea.W = CBase.Settings.GetRenderW() - _Texts[_TextRoundNumber].X - 20; - float delta = _Texts[_TextRoundNumber].Height; + float delta = _Texts[_TextRoundNumber].Rect.H; //Update statics and texts for rounds foreach (CRoundsTableRow roundRow in _RoundsTable) @@ -532,7 +532,7 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley _PlayerTableScrollArea = new SRectF {X = _Texts[_TextPosition].X, Y = _Texts[_TextPosition].Y, W = _Texts[_TextGamePoints].X - _Texts[_TextPosition].X}; _PlayerTable = new List(); - float delta = _Texts[_TextPosition].Height * 1.2f; + float delta = _Texts[_TextPosition].Rect.H * 1.2f; float h = 0; diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index eb53d99a..454ff698 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -624,16 +624,15 @@ namespace Vocaluxe.Base } } } - CFonts.Style = EStyle.Normal; - CFonts.SetFont("Normal"); - CFonts.Height = 25; + CFont font=new CFont("Normal",EStyle.Normal, 25); SColorF gray = new SColorF(1f, 1f, 1f, 0.5f); float y = 0; foreach (string txt in debugOutput) { - RectangleF rect = new RectangleF(CSettings.RenderW - CFonts.GetTextWidth(txt), y, CFonts.GetTextWidth(txt), CFonts.GetTextHeight(txt)); + float textWidth = CFonts.GetTextWidth(txt, font); + RectangleF rect = new RectangleF(CSettings.RenderW - textWidth, y, textWidth, CFonts.GetTextHeight(txt,font)); CDraw.DrawColor(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); - CFonts.DrawText(txt, rect.X, rect.Y, CSettings.ZNear); + CFonts.DrawText(txt, font, rect.X, rect.Y, CSettings.ZNear); y += rect.Height; } } diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 5856bab5..4b4575b5 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -452,39 +452,24 @@ namespace Vocaluxe.Base class CBfonts : IFonts { - public void SetFont(string fontName) - { - CFonts.SetFont(fontName); - } - - public void SetStyle(EStyle fontStyle) - { - CFonts.Style = fontStyle; - } - public RectangleF GetTextBounds(CText text) { return CFonts.GetTextBounds(text); } - public RectangleF GetTextBounds(CText text, float textHeight) + public void DrawText(string text, CFont font, float x, float y, float z, SColorF color) { - return CFonts.GetTextBounds(text, textHeight); + CFonts.DrawText(text, font, x, y, z, color); } - public void DrawText(string text, float textHeight, float x, float y, float z, SColorF color) + public void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight) { - CFonts.DrawText(text, textHeight, x, y, z, color); + CFonts.DrawTextReflection(text, font, x, y, z, color, reflectionSpace, reflectionHeight); } - public void DrawTextReflection(string text, float textHeight, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight) + public void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end) { - CFonts.DrawTextReflection(text, textHeight, x, y, z, color, reflectionSpace, reflectionHeight); - } - - public void DrawText(string text, float textHeight, float x, float y, float z, SColorF color, float begin, float end) - { - CFonts.DrawText(text, textHeight, x, y, z, color, begin, end); + CFonts.DrawText(text, font, x, y, z, color, begin, end); } } diff --git a/Vocaluxe/Base/Fonts/CFontStyle.cs b/Vocaluxe/Base/Fonts/CFontStyle.cs index 360323ad..0c80c0c1 100644 --- a/Vocaluxe/Base/Fonts/CFontStyle.cs +++ b/Vocaluxe/Base/Fonts/CFontStyle.cs @@ -138,7 +138,7 @@ namespace Vocaluxe.Base.Fonts CGlyph glyph; if (!_Glyphs.TryGetValue(chr, out glyph)) { - float maxHeight = (_MaxGlyphHeight + 50 >= height) ? _MaxGlyphHeight : (float)Math.Round(height / 50) * 50; + float maxHeight = (height < 0 || _MaxGlyphHeight + 50 >= height) ? _MaxGlyphHeight : (float)Math.Round(height / 50) * 50; glyph = new CGlyph(chr, this, maxHeight); _Glyphs.Add(chr, glyph); } diff --git a/Vocaluxe/Base/Fonts/CFonts.cs b/Vocaluxe/Base/Fonts/CFonts.cs index 2a9525c1..e7ac6bdb 100644 --- a/Vocaluxe/Base/Fonts/CFonts.cs +++ b/Vocaluxe/Base/Fonts/CFonts.cs @@ -26,13 +26,6 @@ using VocaluxeLib.Menu; namespace Vocaluxe.Base.Fonts { - struct SFont - { - public string Name; - public EStyle Style; - public float Height; - } - /// /// Struct used for describing a font family (a type of text with 4 different styles) /// @@ -62,24 +55,14 @@ namespace Vocaluxe.Base.Fonts { private static bool _IsInitialized; private static readonly List _FontFamilies = new List(); - private static int _CurrentFont; - private static float _Height = 1f; + private static readonly List _LoggedMissingFonts = new List(); public static int PartyModeID { get; set; } - public static EStyle Style = EStyle.Normal; - - public static float Height - { - get { return _Height; } - set { _Height = value < 0f ? 0f : value; } - } - public static bool Init() { if (_IsInitialized) return false; - _CurrentFont = 0; PartyModeID = -1; return _LoadDefaultFonts(); } @@ -97,133 +80,96 @@ namespace Vocaluxe.Base.Fonts _IsInitialized = false; } - private static CFontStyle _GetCurrentFont() - { - switch (Style) - { - case EStyle.Normal: - return _FontFamilies[_CurrentFont].Normal; - case EStyle.Italic: - return _FontFamilies[_CurrentFont].Italic; - case EStyle.Bold: - return _FontFamilies[_CurrentFont].Bold; - case EStyle.BoldItalic: - return _FontFamilies[_CurrentFont].BoldItalic; - } - throw new ArgumentException("Invalid Style: " + Style); - } - #region DrawText - public static void DrawText(string text, int x, int y, int h) + /// + /// Draws a black text + /// + /// The text to be drawn + /// The texts font + /// The texts x-position + /// The texts y-position + /// The texts z-position + public static void DrawText(string text, CFont font, float x, float y, float z) { - DrawText(text, h, x, y, 0f, new SColorF(0f, 0f, 0f, 1f)); - } - - public static void DrawText(string text, float x, float y, float z) - { - DrawText(text, Height, x, y, z, new SColorF(0f, 0f, 0f, 1f)); + DrawText(text, font, x, y, z, new SColorF(0f, 0f, 0f, 1f)); } /// - /// Draws a text string + /// Draws a text /// /// The text to be drawn - /// The text's x-position - /// The text's y-position - /// The text's height - /// The text's z-position + /// The texts font + /// The texts x-position + /// The texts y-position + /// The texts z-position /// The text color - public static void DrawText(string text, float h, float x, float y, float z, SColorF color) + public static void DrawText(string text, CFont font, float x, float y, float z, SColorF color) { - if (h <= 0f) + if (font.Height <= 0f || text == "") return; - if (text == "") - return; - - Height = h; - CFontStyle font = _GetCurrentFont(); + CFontStyle fontStyle = _GetFontStyle(font); float dx = x; foreach (char chr in text) { - font.DrawGlyph(chr, h, dx, y, z, color); - dx += font.GetWidth(chr, h); + fontStyle.DrawGlyph(chr, font.Height, dx, y, z, color); + dx += fontStyle.GetWidth(chr, font.Height); } } - public static void DrawTextReflection(string text, float h, float x, float y, float z, SColorF color, float rspace, float rheight) + public static void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float rspace, float rheight) { - if (h <= 0f) + if (font.Height <= 0f || text == "") return; - if (text == "") - return; - - Height = h; - CFontStyle font = _GetCurrentFont(); + CFontStyle fontStyle = _GetFontStyle(font); float dx = x; foreach (char chr in text) { - font.DrawGlyphReflection(chr, h, dx, y, z, color, rspace, rheight); - dx += font.GetWidth(chr, h); + fontStyle.DrawGlyphReflection(chr, font.Height, dx, y, z, color, rspace, rheight); + dx += fontStyle.GetWidth(chr, font.Height); } } - public static void DrawText(string text, float h, float x, float y, float z, SColorF color, float begin, float end) + public static void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end) { - if (h <= 0f) + if (font.Height <= 0f || text == "") return; - if (text == "") - return; - - Height = h; - - float dx = x; - float w = GetTextWidth(text); + float w = GetTextWidth(text, font); if (w <= 0f) return; - float x1 = x + w * begin; - float x2 = x + w * end; + float xStart = x + w * begin; + float xEnd = x + w * end; + float xCur = x; - CFontStyle font = _GetCurrentFont(); + CFontStyle fontStyle = _GetFontStyle(font); foreach (char chr in text) { - float w2 = font.GetWidth(chr, h); - float b = (x1 - dx) / w2; + float w2 = fontStyle.GetWidth(chr, font.Height); + float b = (xStart - xCur) / w2; if (b < 1f) { if (b < 0f) b = 0f; - float e = (x2 - dx) / w2; + float e = (xEnd - xCur) / w2; if (e > 0f) { if (e > 1f) e = 1f; - font.DrawGlyph(chr, h, dx, y, z, color, b, e); + fontStyle.DrawGlyph(chr, font.Height, xCur, y, z, color, b, e); } } - dx += w2; + xCur += w2; } } #endregion DrawText - public static void SetFont(string fontName) - { - int index = _GetPartyFontIndex(fontName, PartyModeID); - if (index < 0) - index = _GetThemeFontIndex(fontName, CConfig.Theme); - if (index < 0) - index = _GetFontIndex(fontName); - if (index >= 0) - _CurrentFont = index; - } - /// /// Calculates the bounds for a CText object /// @@ -231,42 +177,50 @@ namespace Vocaluxe.Base.Fonts /// RectangleF object containing the bounds public static RectangleF GetTextBounds(CText text) { - return GetTextBounds(text, text.Height); + return new RectangleF(text.X, text.Y, GetTextWidth(text.TranslatedText, text.Font), GetTextHeight(text.TranslatedText, text.Font)); } - /// - /// Calculates the bounds for a CText object - /// - /// The CText object of which the bounds should be calculated for - /// The height of the CText object - /// RectangleF object containing the bounds - public static RectangleF GetTextBounds(CText text, float height) + private static CFontStyle _GetFontStyle(CFont font) { - float oldHeight = Height; - int oldFont = _CurrentFont; - EStyle oldStyle = Style; - Height = height; - SetFont(text.Font); - Style = text.Style; - var result = new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text, text.TranslationID)), - GetTextHeight(CLanguage.Translate(text.Text, text.TranslationID))); - //restore old values - Height = oldHeight; - _CurrentFont = oldFont; - Style = oldStyle; - return result; + int index = _GetPartyFontIndex(font.Name, PartyModeID); + if (index < 0) + index = _GetThemeFontIndex(font.Name, CConfig.Theme); + if (index < 0) + index = _GetFontIndex(font.Name); + if (index < 0) + { + if (!_LoggedMissingFonts.Contains(font.Name)) + { + _LoggedMissingFonts.Add(font.Name); + CLog.LogError("Font \"" + font.Name + "\" not found!"); + } + index = 0; + } + + switch (font.Style) + { + case EStyle.Normal: + return _FontFamilies[index].Normal; + case EStyle.Italic: + return _FontFamilies[index].Italic; + case EStyle.Bold: + return _FontFamilies[index].Bold; + case EStyle.BoldItalic: + return _FontFamilies[index].BoldItalic; + } + throw new ArgumentException("Invalid Style: " + font.Style); } - public static float GetTextWidth(string text) + public static float GetTextWidth(string text, CFont font) { - CFontStyle font = _GetCurrentFont(); - return text.Sum(chr => font.GetWidth(chr, Height)); + CFontStyle fontStyle = _GetFontStyle(font); + return text.Sum(chr => fontStyle.GetWidth(chr, font.Height)); } - public static float GetTextHeight(string text) + public static float GetTextHeight(string text, CFont font) { - CFontStyle font = _GetCurrentFont(); - return text == "" ? 0 : text.Select(chr => font.GetHeight(chr, Height)).Max(); + CFontStyle fontStyle = _GetFontStyle(font); + return text == "" ? 0 : text.Select(chr => fontStyle.GetHeight(chr, font.Height)).Max(); } private static int _GetFontIndex(string fontName) @@ -448,24 +402,16 @@ namespace Vocaluxe.Base.Fonts { const string text = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - for (int i = 0; i < _FontFamilies.Count; i++) + foreach (SFontFamily fontFamily in _FontFamilies) { - _CurrentFont = i; - foreach (char chr in text) { - Style = EStyle.Normal; - _FontFamilies[_CurrentFont].Normal.GetOrAddGlyph(chr, Height); - Style = EStyle.Bold; - _FontFamilies[_CurrentFont].Bold.GetOrAddGlyph(chr, Height); - Style = EStyle.Italic; - _FontFamilies[_CurrentFont].Italic.GetOrAddGlyph(chr, Height); - Style = EStyle.BoldItalic; - _FontFamilies[_CurrentFont].BoldItalic.GetOrAddGlyph(chr, Height); + fontFamily.Normal.GetOrAddGlyph(chr, -1); + fontFamily.Bold.GetOrAddGlyph(chr, -1); + fontFamily.Italic.GetOrAddGlyph(chr, -1); + fontFamily.BoldItalic.GetOrAddGlyph(chr, -1); } } - Style = EStyle.Normal; - SetFont("Normal"); } } } \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index d9a44b1a..7190397e 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -991,13 +991,13 @@ namespace Vocaluxe.Screens float partSeconds = timeDiff - fullSeconds; _Texts[_TextMedleyCountdown].Visible = true; _Texts[_TextMedleyCountdown].Text = fullSeconds.ToString(); - float h = partSeconds * CSettings.RenderH; - float w = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown], h).Width; - float x = CSettings.RenderW / 2 - w / 2; - float y = CSettings.RenderH / 2 - h / 2; + _Texts[_TextMedleyCountdown].Font.Height = partSeconds * CSettings.RenderH; + + RectangleF textBounds = CFonts.GetTextBounds(_Texts[_TextMedleyCountdown]); + float x = CSettings.RenderW / 2 - textBounds.Width / 2; + float y = CSettings.RenderH / 2 - textBounds.Height / 2; _Texts[_TextMedleyCountdown].X = x; _Texts[_TextMedleyCountdown].Y = y; - _Texts[_TextMedleyCountdown].Height = h; } else _Texts[_TextMedleyCountdown].Visible = false; diff --git a/VocaluxeLib/CFont.cs b/VocaluxeLib/CFont.cs new file mode 100644 index 00000000..00524ec5 --- /dev/null +++ b/VocaluxeLib/CFont.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; + +namespace VocaluxeLib +{ + public interface IFontObserver + { + void FontChanged(); + } + + public class CFont + { + private string _Name; + private EStyle _Style; + private float _Height; + private readonly List _Observers = new List(); + + public string Name + { + get { return _Name; } + set + { + if (_Name == value) + return; + _Name = value; + foreach (IFontObserver observer in _Observers) + observer.FontChanged(); + } + } + public EStyle Style + { + get { return _Style; } + set + { + if (_Style == value) + return; + _Style = value; + foreach (IFontObserver observer in _Observers) + observer.FontChanged(); + } + } + public float Height + { + get { return _Height; } + set + { + if (Math.Abs(_Height - value) < 0.001) + return; + _Height = value; + foreach (IFontObserver observer in _Observers) + observer.FontChanged(); + } + } + + public CFont() + { + _Name = "Normal"; + _Style = EStyle.Normal; + _Height = 25f; + } + + public CFont(CFont font) + { + _Name = font.Name; + _Style = font.Style; + _Height = font.Height; + } + + public CFont(string fontFamily, EStyle style, float h) + { + _Name = fontFamily; + _Style = style; + _Height = h; + } + + public void AddObserver(IFontObserver observer) + { + if (!_Observers.Contains(observer)) + _Observers.Add(observer); + } + + public void RemoveObserver(IFontObserver observer) + { + _Observers.Remove(observer); + } + } +} \ No newline at end of file diff --git a/VocaluxeLib/IBasic.cs b/VocaluxeLib/IBasic.cs index ef14e905..32bd781f 100644 --- a/VocaluxeLib/IBasic.cs +++ b/VocaluxeLib/IBasic.cs @@ -159,15 +159,11 @@ namespace VocaluxeLib public interface IFonts { - void SetFont(string fontName); - void SetStyle(EStyle fontStyle); - RectangleF GetTextBounds(CText text); - RectangleF GetTextBounds(CText text, float textHeight); - void DrawText(string text, float textHeight, float x, float y, float z, SColorF color); - void DrawTextReflection(string text, float textHeight, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight); - void DrawText(string text, float textHeight, float x, float y, float z, SColorF color, float begin, float end); + void DrawText(string text, CFont font, float x, float y, float z, SColorF color); + void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight); + void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end); } public interface ILanguage diff --git a/VocaluxeLib/Menu/CLyric.cs b/VocaluxeLib/Menu/CLyric.cs index 68b26136..f496330f 100644 --- a/VocaluxeLib/Menu/CLyric.cs +++ b/VocaluxeLib/Menu/CLyric.cs @@ -205,10 +205,7 @@ namespace VocaluxeLib.Menu private void _SetText(CSongNote note) { _Text.Text = note.Text; - _Text.Style = EStyle.Bold; - - if (note.Type == ENoteType.Freestyle) - _Text.Style = EStyle.BoldItalic; + _Text.Font.Style = (note.Type == ENoteType.Freestyle)? EStyle.BoldItalic:EStyle.Bold; } public void Clear() @@ -350,11 +347,11 @@ namespace VocaluxeLib.Menu p = 1f - p; float ty = _Text.Y; - float th = _Text.Height; + float th = _Text.Font.Height; float tz = _Text.Z; SRectF normalRect = _Text.Rect; - _Text.Height += _Text.Height * p * 0.4f; + _Text.Font.Height *= 1f+ p * 0.4f; _Text.X -= (_Text.Rect.W - normalRect.W) / 2f; _Text.Y -= (_Text.Rect.H - normalRect.H) / 2f; _Text.Z -= 0.1f; @@ -364,7 +361,7 @@ namespace VocaluxeLib.Menu _Text.Draw(); _Text.Y = ty; - _Text.Height = th; + _Text.Font.Height = th; _Text.Z = tz; } } @@ -456,7 +453,7 @@ namespace VocaluxeLib.Menu else { float y = _Text.Y; - _Text.Y -= _Text.Height * 0.1f * p; + _Text.Y -= _Text.Font.Height * 0.1f * p; _Text.Draw(); _Text.Y = y; } diff --git a/VocaluxeLib/Menu/CText.cs b/VocaluxeLib/Menu/CText.cs index 711cc930..70389fe0 100644 --- a/VocaluxeLib/Menu/CText.cs +++ b/VocaluxeLib/Menu/CText.cs @@ -28,9 +28,12 @@ namespace VocaluxeLib.Menu public string Text; public string ColorName; public string SelColorName; //for Buttons + public string FontFamily; + public EStyle FontStyle; + public float FontHeight; } - public class CText : IMenuElement + public class CText : IMenuElement, IFontObserver { private SThemeText _Theme; private bool _ThemeLoaded; @@ -82,20 +85,6 @@ namespace VocaluxeLib.Menu set { _Z = value; } } - private float _Height; - public float Height - { - get { return _Height; } - set - { - if (Math.Abs(_Height - value) > 0.01) - { - _Height = value; - _PositionNeedsUpdate = true; - } - } - } - private float _MaxWidth; public float MaxWidth { @@ -138,29 +127,17 @@ namespace VocaluxeLib.Menu } } - private EStyle _Style = EStyle.Normal; - public EStyle Style - { - get { return _Style; } - set - { - if (_Style != value) - { - _Style = value; - _PositionNeedsUpdate = true; - } - } - } - - private string _Font = String.Empty; - public string Font + private CFont _Font = new CFont(); + public CFont Font { get { return _Font; } set { - if (_Font != value) + if (!_Font.Equals(value)) { + _Font.RemoveObserver(this); _Font = value; + _Font.AddObserver(this); _PositionNeedsUpdate = true; } } @@ -199,10 +176,16 @@ namespace VocaluxeLib.Menu _Text = translation; if (_EditMode) _Text += "|"; + //Reset height, it might have been reduced in _UpdatePosition + Font.Height = _Theme.FontHeight; _PositionNeedsUpdate = true; } } } + public string TranslatedText + { + get { return _Text; } + } public int PartyModeID { @@ -246,7 +229,7 @@ namespace VocaluxeLib.Menu { _PartyModeID = partyModeID; _TranslationID = _PartyModeID; - _Font = "Normal"; + _Font.AddObserver(this); } public CText(CText text) @@ -257,12 +240,10 @@ namespace VocaluxeLib.Menu _X = text._X; _Y = text._Y; _Z = text._Z; - _Height = text._Height; _MaxWidth = text._MaxWidth; _Align = text._Align; _ResizeAlign = text._ResizeAlign; - _Style = text._Style; - _Font = text._Font; + Font = text.Font; //Use setter to set observer Color = new SColorF(text.Color); SelColor = new SColorF(text.SelColor); @@ -277,24 +258,23 @@ namespace VocaluxeLib.Menu _EditMode = text._EditMode; } - public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string font, SColorF col, string text, int partyModeID = -1, float rheight = 0, - float rspace = 0) + public CText(float x, float y, float z, float h, float mw, EAlignment align, EStyle style, string fontFamily, SColorF col, string text, int partyModeID = -1, + float rheight = 0, + float rspace = 0) : this(partyModeID) { - _Theme = new SThemeText(); + _Theme = new SThemeText {FontFamily = fontFamily, FontStyle = style, FontHeight = h, Text = text}; _ThemeLoaded = false; _ButtonText = false; - _PartyModeID = partyModeID; - _TranslationID = _PartyModeID; X = x; Y = y; Z = z; - Height = h; MaxWidth = mw; Align = align; ResizeAlign = EHAlignment.Center; - Style = style; - Font = font; + _Font.Name = fontFamily; + _Font.Style = style; + _Font.Height = h; Color = col; SelColor = new SColorF(col); @@ -323,7 +303,6 @@ namespace VocaluxeLib.Menu if (!buttonText) _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/Z", ref _Z); - _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Height); xmlReader.TryGetFloatValue(item + "/MaxW", ref _MaxWidth); if (xmlReader.GetValue(item + "/Color", out _Theme.ColorName, String.Empty)) @@ -350,8 +329,10 @@ namespace VocaluxeLib.Menu _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Align", ref _Align); xmlReader.TryGetEnumValue(item + "/ResizeAlign", ref _ResizeAlign); - _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Style); - _ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Font, "Normal"); + _ThemeLoaded &= xmlReader.TryGetFloatValue(item + "/H", ref _Theme.FontHeight); + _ThemeLoaded &= xmlReader.TryGetEnumValue(item + "/Style", ref _Theme.FontStyle); + _ThemeLoaded &= xmlReader.GetValue(item + "/Font", out _Theme.FontFamily); + Font = new CFont(_Theme.FontFamily, _Theme.FontStyle, _Theme.FontHeight); _ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty); @@ -388,7 +369,7 @@ namespace VocaluxeLib.Menu } writer.WriteComment(": Text height"); - writer.WriteElementString("H", Height.ToString("#0")); + writer.WriteElementString("H", _Theme.FontHeight.ToString("#0")); writer.WriteComment(": Maximum text width (if exists)"); if (MaxWidth > 0) @@ -425,10 +406,10 @@ namespace VocaluxeLib.Menu writer.WriteElementString("ResizeAlign", Enum.GetName(typeof(EHAlignment), ResizeAlign)); writer.WriteComment("