Use CFont class to define the font to use

This commit is contained in:
Flamefire committed 2014-09-07 10:35:41 +02:00
1 parent 7f60e6f321
commit 94be5ce97b
13 files changed
+242 -255

No files matched your search

@@ -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<STableRow>();
float delta = _Texts[_TextPosition].Height * 1.2f;
float delta = _Texts[_TextPosition].Rect.H * 1.2f;
float h = 0;
@@ -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<STableRow>();
float delta = _Texts[_TextPosition].Height * 1.2f;
float delta = _Texts[_TextPosition].Rect.H * 1.2f;
float h = 0;
+4 -5
View File
@@ -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;
}
}
+6 -21
View File
@@ -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);
}
}
+1 -1
View File
@@ -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);
}
+78 -132
View File
@@ -26,13 +26,6 @@ using VocaluxeLib.Menu;
namespace Vocaluxe.Base.Fonts
{
struct SFont
{
public string Name;
public EStyle Style;
public float Height;
}
/// <summary>
/// Struct used for describing a font family (a type of text with 4 different styles)
/// </summary>
@@ -62,24 +55,14 @@ namespace Vocaluxe.Base.Fonts
{
private static bool _IsInitialized;
private static readonly List<SFontFamily> _FontFamilies = new List<SFontFamily>();
private static int _CurrentFont;
private static float _Height = 1f;
private static readonly List<String> _LoggedMissingFonts = new List<string>();
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)
/// <summary>
/// Draws a black text
/// </summary>
/// <param name="text">The text to be drawn</param>
/// <param name="font">The texts font</param>
/// <param name="x">The texts x-position</param>
/// <param name="y">The texts y-position</param>
/// <param name="z">The texts z-position</param>
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));
}
/// <summary>
/// Draws a text string
/// Draws a text
/// </summary>
/// <param name="text">The text to be drawn</param>
/// <param name="x">The text's x-position</param>
/// <param name="y">The text's y-position</param>
/// <param name="h">The text's height</param>
/// <param name="z">The text's z-position</param>
/// <param name="font">The texts font</param>
/// <param name="x">The texts x-position</param>
/// <param name="y">The texts y-position</param>
/// <param name="z">The texts z-position</param>
/// <param name="color">The text color</param>
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;
}
/// <summary>
/// Calculates the bounds for a CText object
/// </summary>
@@ -231,42 +177,50 @@ namespace Vocaluxe.Base.Fonts
/// <returns>RectangleF object containing the bounds</returns>
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));
}
/// <summary>
/// Calculates the bounds for a CText object
/// </summary>
/// <param name="text">The CText object of which the bounds should be calculated for</param>
/// <param name="height">The height of the CText object</param>
/// <returns>RectangleF object containing the bounds</returns>
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");
}
}
}
+5 -5
View File
@@ -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;
+87
View File
@@ -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<IFontObserver> _Observers = new List<IFontObserver>();
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);
}
}
}
+3 -7
View File
@@ -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
+5 -8
View File
@@ -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;
}
+46 -68
View File
@@ -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("<H>: Text height");
writer.WriteElementString("H", Height.ToString("#0"));
writer.WriteElementString("H", _Theme.FontHeight.ToString("#0"));
writer.WriteComment("<MaxW>: 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("<Style>: Text style: " + CHelper.ListStrings(Enum.GetNames(typeof(EStyle))));
writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), Style));
writer.WriteElementString("Style", Enum.GetName(typeof(EStyle), _Theme.FontStyle));
writer.WriteComment("<Font>: Text font name");
writer.WriteElementString("Font", Font);
writer.WriteElementString("Font", _Theme.FontFamily);
writer.WriteComment("<Text>: Nothing or translation tag");
writer.WriteElementString("Text", CBase.Language.TranslationExists(_Theme.Text) ? _Theme.Text : string.Empty);
@@ -463,16 +444,13 @@ namespace VocaluxeLib.Menu
// Update Text
Text = Text;
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(_Text, Rect.H, Rect.X, Rect.Y, Z, color);
CBase.Fonts.DrawText(_Text, Font, Rect.X, Rect.Y, Z, color);
if (ReflectionHeight > 0)
CBase.Fonts.DrawTextReflection(_Text, Rect.H, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
CBase.Fonts.DrawTextReflection(_Text, Font, Rect.X, Rect.Y, Z, color, ReflectionSpace, ReflectionHeight);
if (Selected && (CBase.Settings.GetProgramState() == EProgramState.EditTheme))
CBase.Drawing.DrawColor(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
@@ -480,13 +458,10 @@ namespace VocaluxeLib.Menu
public void Draw(float begin, float end)
{
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
SColorF currentColor = (Selected) ? SelColor : Color;
var color = new SColorF(currentColor.R, currentColor.G, currentColor.B, currentColor.A * Alpha);
CBase.Fonts.DrawText(Text, Rect.H, Rect.X, Rect.Y, Z, color, begin, end);
CBase.Fonts.DrawText(Text, Font, Rect.X, Rect.Y, Z, color, begin, end);
if (ReflectionHeight > 0)
{
@@ -543,9 +518,10 @@ namespace VocaluxeLib.Menu
public void ResizeElement(int stepW, int stepH)
{
Height += stepH;
if (Height <= 0)
Height = 1;
_Theme.FontHeight += stepH;
if (_Theme.FontHeight <= 0)
_Theme.FontHeight = 1;
_Font.Height = _Theme.FontHeight;
}
#endregion ThemeEdit
@@ -554,10 +530,7 @@ namespace VocaluxeLib.Menu
if (_Text == "")
return;
CBase.Fonts.SetFont(Font);
CBase.Fonts.SetStyle(Style);
float h = Height;
float h = Font.Height;
float y = Y;
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
@@ -578,8 +551,8 @@ namespace VocaluxeLib.Menu
y += step * 0.75f;
break;
}
bounds = CBase.Fonts.GetTextBounds(this, h);
Font.Height = h;
bounds = CBase.Fonts.GetTextBounds(this);
}
float x = X;
@@ -600,5 +573,10 @@ namespace VocaluxeLib.Menu
_PositionNeedsUpdate = false;
}
public void FontChanged()
{
_PositionNeedsUpdate = true;
}
}
}
+1 -3
View File
@@ -32,11 +32,9 @@ namespace VocaluxeLib.PartyModes
public override void LoadTheme(string xmlPath)
{
_Warning = GetNewText();
_Warning.Height = 100f;
_Warning.Font.Height = 100f;
_Warning.X = 150;
_Warning.Y = 300;
_Warning.Font = "Normal";
_Warning.Style = EStyle.Normal;
_Warning.Color = new SColorF(1f, 0f, 0f, 1f);
_Warning.SelColor = new SColorF(1f, 0f, 0f, 1f);
_Warning.Text = "SOMETHING WENT WRONG!";
+1
View File
@@ -77,6 +77,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CFading.cs" />
<Compile Include="CFont.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IBasic.cs" />