Use CFont class to define the font to use
This commit is contained in:
1 parent
7f60e6f321
commit
94be5ce97b
13 files changed
+242
-255
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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!";
|
||||
|
||||
@@ -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" />
|
||||
|
||||
Reference in new issue
Block a user