Merge branch 'develop' into Better_Graphics_Handling

Conflicts:
	VocaluxeLib/Menu/CNameSelection.cs
	VocaluxeLib/Menu/CPlaylist.cs
	VocaluxeLib/Menu/CText.cs
	VocaluxeLib/Menu/SongMenu/CSongMenuFramework.cs
	VocaluxeLib/Structs.cs
	VocaluxeLib/VocaluxeLib.csproj
	VocaluxeLib/Xml/CXMLReader.cs
This commit is contained in:
Flamefire committed 2014-10-05 15:09:52 +02:00
commit 355d7b4b5f
52 files changed
+1407 -653

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace VocaluxeLib
{
public interface IFontObserver
{
void FontChanged();
}
public struct SThemeFont
{
public string Name;
public EStyle Style;
public float Size;
}
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(SThemeFont font)
{
_Name = font.Name;
_Style = font.Style;
_Height = font.Size;
}
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);
}
}
}
+5 -18
View File
@@ -22,6 +22,7 @@ using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
namespace VocaluxeLib
{
@@ -77,6 +78,7 @@ namespace VocaluxeLib
/// <returns></returns>
public static bool IsInRange<T>(this T val, T min, T max) where T : IComparable<T>
{
Debug.Assert(min.CompareTo(max) <= 0);
return min.CompareTo(val) <= 0 && max.CompareTo(val) >= 0;
}
@@ -147,28 +149,13 @@ namespace VocaluxeLib
return value.IndexOf(other, StringComparison.CurrentCultureIgnoreCase) >= 0;
}
private static Regex _MultipleWhiteSpaceRegEx = new Regex(@" {2,}");
public static string TrimMultipleWs(this string value)
{
if (string.IsNullOrEmpty(value))
return "";
int start = 0;
int len = value.Length;
while (value[start] == ' ')
{
start++;
if (start >= len)
return "";
}
if (start > 0)
start--;
int end = --len;
while (value[end] == ' ')
end--;
if (end < len)
end++;
if (end - start < len)
value = value.Substring(start, end - start + 1);
return value;
return _MultipleWhiteSpaceRegEx.Replace(value, " ");
}
/// <summary>
+3 -7
View File
@@ -174,15 +174,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
+1
View File
@@ -20,6 +20,7 @@ using System.Xml.Serialization;
using System.Diagnostics;
using System.Collections.Generic;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -19,6 +19,7 @@ using System;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -18,6 +18,7 @@
using System;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+6 -8
View File
@@ -18,6 +18,7 @@
using System;
using System.Xml.Serialization;
using VocaluxeLib.Songs;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
@@ -187,10 +188,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()
@@ -332,11 +330,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;
@@ -346,7 +344,7 @@ namespace VocaluxeLib.Menu
_Text.Draw();
_Text.Y = ty;
_Text.Height = th;
_Text.Font.Height = th;
_Text.Z = tz;
}
}
@@ -438,7 +436,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;
}
+1
View File
@@ -25,6 +25,7 @@ using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Menu.SingNotes;
using VocaluxeLib.Menu.SongMenu;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -22,6 +22,7 @@ using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Profile;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -21,6 +21,7 @@ using System.Diagnostics;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -20,6 +20,7 @@ using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using VocaluxeLib.Songs;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -19,6 +19,7 @@ using System;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -20,6 +20,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -19,6 +19,7 @@ using System;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+46 -79
View File
@@ -17,8 +17,8 @@
using System;
using System.Drawing;
using System.Xml;
using System.Xml.Serialization;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
@@ -30,19 +30,19 @@ namespace VocaluxeLib.Menu
[XmlElement("X")] public float X;
[XmlElement("Y")] public float Y;
[XmlElement("Z")] public float Z;
[XmlElement("H")] public float Height;
[XmlElement("H")] public float FontHeight;
[XmlElement("MaxW")] public float MaxWidth;
public SThemeColor Color;
public SThemeColor SColor; //for Buttons
[XmlElement("Align")] public EAlignment Align;
[XmlElement("ResizeAlign")] public EHAlignment ResizeAlign;
[XmlElement("Style")] public EStyle Style;
[XmlElement("Font")] public string Font;
[XmlElement("Style")] public EStyle FontStyle;
[XmlElement("Font")] public string FontFamily;
[XmlElement("Text")] public string Text;
public SReflection Reflection;
}
public class CText : IMenuElement
public class CText : IMenuElement, IFontObserver
{
private SThemeText _Theme;
private bool _ThemeLoaded;
@@ -99,20 +99,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
{
@@ -155,29 +141,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;
}
}
@@ -216,10 +190,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
{
@@ -263,7 +243,7 @@ namespace VocaluxeLib.Menu
{
_PartyModeID = partyModeID;
_TranslationID = _PartyModeID;
_Font = "Normal";
_Font.AddObserver(this);
}
public CText(CText text)
@@ -274,12 +254,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);
@@ -294,24 +272,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);
@@ -351,7 +328,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.Color.Name, String.Empty))
@@ -378,8 +354,9 @@ 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);
_ThemeLoaded &= xmlReader.GetValue(item + "/Text", out _Theme.Text, String.Empty);
@@ -396,15 +373,12 @@ namespace VocaluxeLib.Menu
_Theme.Name = elementName;
_Theme.Align = _Align;
_Theme.Color.Color = Color;
_Theme.Font = _Font;
_Theme.ResizeAlign = _ResizeAlign;
_Theme.SColor.Color = SelColor;
_Theme.Style = _Style;
_Theme.MaxWidth = _MaxWidth;
_Theme.X = _X;
_Theme.Y = _Y;
_Theme.Z = _Z;
_Theme.Height = _Height;
_ButtonText = buttonText;
_PositionNeedsUpdate = true;
@@ -422,16 +396,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.DrawRect(new SColorF(0.5f, 1f, 0.5f, 0.5f), new SRectF(Rect.X, Rect.Y, Rect.W, Rect.H, Z));
@@ -439,13 +410,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)
{
@@ -486,12 +454,10 @@ namespace VocaluxeLib.Menu
_X = _Theme.X;
_Y = _Theme.Y;
_Z = _Theme.Z;
_Height = _Theme.Height;
_MaxWidth = _Theme.MaxWidth;
_Align = _Theme.Align;
_ResizeAlign = _Theme.ResizeAlign;
_Style = _Theme.Style;
_Font = _Theme.Font;
Font = new CFont(_Theme.FontFamily, _Theme.FontStyle, _Theme.FontHeight);
if (_Theme.Reflection.Enabled)
{
@@ -522,17 +488,16 @@ namespace VocaluxeLib.Menu
X += stepX;
Y += stepY;
_Theme.X += stepX;
_Theme.Y += stepY;
_Theme.X = X;
_Theme.Y = Y;
}
public void ResizeElement(int stepW, int stepH)
{
Height += stepH;
if (Height <= 0)
Height = 1;
_Theme.Height = _Height;
_Theme.FontHeight += stepH;
if (_Theme.FontHeight <= 0)
_Theme.FontHeight = 1;
_Font.Height = _Theme.FontHeight;
}
#endregion ThemeEdit
@@ -541,10 +506,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);
@@ -565,8 +527,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;
@@ -587,5 +549,10 @@ namespace VocaluxeLib.Menu
_PositionNeedsUpdate = false;
}
public void FontChanged()
{
_PositionNeedsUpdate = true;
}
}
}
+1
View File
@@ -16,6 +16,7 @@
#endregion
using System.Xml;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu
{
+1
View File
@@ -21,6 +21,7 @@ using System.Diagnostics;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.Songs;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu.SingNotes
{
+1
View File
@@ -17,6 +17,7 @@
using System.Xml;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu.SongMenu
{
+14 -13
View File
@@ -23,6 +23,7 @@ using System.Xml.Serialization;
using VocaluxeLib.Draw;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Songs;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu.SongMenu
{
@@ -60,35 +61,35 @@ namespace VocaluxeLib.Menu.SongMenu
public struct SThemeSongMenuTileBoard
{
[XmlElement("NumW")] /// <summary>
/// <summary>
/// Number of tiles horizontal
/// </summary>
public int NumW;
[XmlElement("NumW")] public int NumW;
[XmlElement("NumH")] /// <summary>
/// <summary>
/// Number of tiles vertical
/// </summary>
public int NumH;
[XmlElement("NumH")] public int NumH;
[XmlElement("NumWsmall")] /// <summary>
/// <summary>
/// Number of tiles horizontal in small-modus
/// </summary>
public int NumWsmall;
[XmlElement("NumWsmall")] public int NumWsmall;
[XmlElement("NumHsmall")] /// <summary>
/// <summary>
/// Number of tiles vertical in small-modus
/// </summary>
public int NumHsmall;
[XmlElement("NumHsmall")] public int NumHsmall;
[XmlElement("SpaceW")] /// <summary>
/// <summary>
/// Space between tiles horizontal
/// </summary>
public float SpaceW;
[XmlElement("SpaceW")] public float SpaceW;
[XmlElement("SpaceH")] /// <summary>
/// <summary>
/// Space between tiles vertical
/// </summary>
public float SpaceH;
[XmlElement("SpaceH")] public float SpaceH;
[XmlElement("TileRect")] public SRectF TileRect;
[XmlElement("TileRectSmall")] public SRectF TileRectSmall;
@@ -270,7 +271,7 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual void OnHide()
{
if (CBase.Graphics.GetNextScreen() != EScreens.ScreenNames)
if(CBase.Graphics.GetNextScreen() != EScreens.ScreenNames || CBase.Config.GetBackgroundMusicStatus() == EBackgroundMusicOffOn.TR_CONFIG_OFF)
_ResetPreview();
}
@@ -23,6 +23,7 @@ using System.Xml;
using VocaluxeLib.Draw;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Songs;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Menu.SongMenu
{
+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
@@ -18,6 +18,7 @@
using System;
using System.IO;
using System.Xml;
using VocaluxeLib.Xml;
namespace VocaluxeLib.Profile
{
+38
View File
@@ -26,6 +26,44 @@ using VocaluxeLib.Songs;
namespace VocaluxeLib
{
public enum ECoverGeneratorType
{
Default,
Folder,
Artist,
Letter,
Edition,
Genre,
Language,
Year,
Decade,
Date
}
public struct SMargin
{
public int Default;
public int Left, Right, Top, Bottom;
}
public struct SThemeCoverGeneratorText
{
public string Text;
public SThemeFont Font;
public SThemeColor Color;
public SMargin Margin;
public int Indent;
}
public struct SThemeCoverGenerator
{
public ECoverGeneratorType Type;
public SThemeCoverGeneratorText Text;
public SThemeColor BackgroundColor;
public string Image;
public float ImageAlpha;
public bool ShowFirstCover;
}
#region Drawing
public struct SColorF
+4 -1
View File
@@ -78,6 +78,7 @@
<ItemGroup>
<Compile Include="CEncoding.cs" />
<Compile Include="CFading.cs" />
<Compile Include="CFont.cs" />
<Compile Include="CVideoStream.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
@@ -103,7 +104,8 @@
<Compile Include="Menu\CText.cs" />
<Compile Include="Menu\CScreenSetting.cs" />
<Compile Include="Draw\CTextureRef.cs" />
<Compile Include="CXMLReader.cs" />
<Compile Include="Xml\CXmlDeserializer.cs" />
<Compile Include="Xml\CXMLReader.cs" />
<Compile Include="Enums.cs" />
<Compile Include="Menu\IMenu.cs" />
<Compile Include="Menu\IMenuElement.cs" />
@@ -139,6 +141,7 @@
<Compile Include="Utils\CWavFile.cs" />
<Compile Include="Utils\Player\CSongPlayer.cs" />
<Compile Include="Utils\Player\CSoundPlayer.cs" />
<Compile Include="Xml\CXmlReaderBase.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@@ -19,9 +19,9 @@ using System;
using System.Collections.Generic;
using System.Xml.XPath;
namespace VocaluxeLib
namespace VocaluxeLib.Xml
{
public class CXMLReader
public class CXMLReader : CXmlDeserializer
{
private readonly XPathNavigator _Navigator;
private readonly String _FilePath;
@@ -57,56 +57,18 @@ namespace VocaluxeLib
}
}
public bool TryGetEnumValue<T>(string xPath, ref T value)
where T : struct
{
string val;
if (GetValue(xPath, out val, Enum.GetName(typeof(T), value)))
return CHelper.TryParse(val, out value, true);
return false;
}
public bool TryGetIntValue(string xPath, ref int value)
{
string val;
if (GetValue(xPath, out val, value.ToString()))
return int.TryParse(val, out value);
return false;
}
public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100)
{
bool result = TryGetIntValue(xPath, ref value);
if (result)
value = value.Clamp(min, max);
return result;
}
public bool TryGetFloatValue(string xPath, ref float value)
{
string val;
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
}
public bool TryGetColorFromRGBA(string xPath, out SColorF value)
{
value = new SColorF();
bool result = true;
result &= TryGetFloatValue(xPath + "/R", ref value.R);
result &= TryGetFloatValue(xPath + "/G", ref value.G);
result &= TryGetFloatValue(xPath + "/B", ref value.B);
result &= TryGetFloatValue(xPath + "/A", ref value.A);
if (result)
{
value.R = value.R.Clamp(0f, 1f);
value.G = value.G.Clamp(0f, 1f);
value.B = value.B.Clamp(0f, 1f);
value.A = value.A.Clamp(0f, 1f);
}
result &= TryGetNormalizedFloatValue(xPath + "/R", ref value.R);
result &= TryGetNormalizedFloatValue(xPath + "/G", ref value.G);
result &= TryGetNormalizedFloatValue(xPath + "/B", ref value.B);
result &= TryGetNormalizedFloatValue(xPath + "/A", ref value.A);
return result;
}
public bool GetValue(string xPath, out string value, string defaultValue = "")
public override bool GetValue(string xPath, out string value, string defaultValue = "")
{
int resultCt = 0;
string val = string.Empty;
@@ -129,6 +91,19 @@ namespace VocaluxeLib
return true;
}
public override bool GetAttribute(string xPath, string attribute, out string value)
{
_Navigator.MoveToRoot();
XPathNodeIterator iterator = _Navigator.Select(xPath);
if (iterator.MoveNext())
{
value = iterator.Current.GetAttribute(attribute, "");
return true;
}
value = "";
return false;
}
public List<string> GetNames(string xPath)
{
var values = new List<string>();
+68
View File
@@ -0,0 +1,68 @@
using System.Linq;
namespace VocaluxeLib.Xml
{
public abstract class CXmlDeserializer : CXmlReaderBase
{
public bool Read(string xPath, out SThemeFont el)
{
el = new SThemeFont();
bool ok = true;
ok &= GetValue(xPath + "/Name", out el.Name);
ok &= TryGetFloatValue(xPath + "/Size", ref el.Size);
ok &= TryGetEnumValue(xPath + "/Style", ref el.Style);
return ok;
}
public bool Read(string xPath, out SMargin el)
{
el = new SMargin();
bool ok = true;
bool defOk = TryGetIntValue(xPath + "/Default", ref el.Default);
ok &= TryGetIntValue(xPath + "/Left", ref el.Left, el.Default);
ok &= TryGetIntValue(xPath + "/Right", ref el.Right, el.Default);
ok &= TryGetIntValue(xPath + "/Top", ref el.Top, el.Default);
ok &= TryGetIntValue(xPath + "/Bottom", ref el.Bottom, el.Default);
return ok || defOk;
}
public bool Read(string xPath, out SThemeCoverGeneratorText el)
{
el = new SThemeCoverGeneratorText();
bool ok = true;
ok &= GetValue(xPath + "/Text", out el.Text);
ok &= Read(xPath + "/Font", out el.Font);
ok &= Read(xPath + "/Color", out el.Color);
ok &= Read(xPath + "/Margin", out el.Margin);
if (ok)
TryGetIntValue(xPath + "/Indent", ref el.Indent, 6 * (el.Margin.Left + el.Margin.Right) / 2);
return ok;
}
public bool Read(string xPath, out SThemeColor el)
{
el = new SThemeColor();
bool ok = true;
ok &= TryGetNormalizedFloatValue(xPath + "/R", ref el.Color.R);
ok &= TryGetNormalizedFloatValue(xPath + "/G", ref el.Color.G);
ok &= TryGetNormalizedFloatValue(xPath + "/B", ref el.Color.B);
ok &= TryGetNormalizedFloatValue(xPath + "/A", ref el.Color.A);
if (!ok)
ok = GetValue(xPath, out el.Name) && !el.Name.Contains('<');
return ok;
}
public bool Read(string xPath, out SThemeCoverGenerator el)
{
el = new SThemeCoverGenerator();
bool ok = true;
ok &= TryGetEnumValue(xPath + "/Type", ref el.Type);
ok &= Read(xPath + "/Text", out el.Text);
ok &= Read(xPath + "/BackgroundColor", out el.BackgroundColor);
ok &= GetValue(xPath + "/Image", out el.Image);
TryGetNormalizedFloatValue(xPath + "/ImageAlpha", ref el.ImageAlpha, 0.5f);
TryGetBoolValue(xPath + "/ShowFirstCover", out el.ShowFirstCover);
return ok;
}
}
}
+61
View File
@@ -0,0 +1,61 @@
using System;
namespace VocaluxeLib.Xml
{
/// <summary>
/// Base class that provides basic methods for reading xml, while the actual XML implementation is still abstract to allow different implementations
/// </summary>
public abstract class CXmlReaderBase
{
public abstract bool GetValue(string xPath, out string value, string defaultValue = "");
public abstract bool GetAttribute(string xPath, string attribute, out string value);
public bool TryGetBoolValue(string xPath, out bool value, bool defaultValue = false)
{
value = defaultValue;
string val;
return GetValue(xPath, out val) && bool.TryParse(val, out value);
}
public bool TryGetIntValue(string xPath, ref int value, int? defaultValue = null)
{
string val;
bool ok = GetValue(xPath, out val) && int.TryParse(val, out value);
if (!ok && defaultValue.HasValue)
value = defaultValue.Value;
return ok;
}
public bool TryGetFloatValue(string xPath, ref float value)
{
string val;
return GetValue(xPath, out val, value.ToString()) && CHelper.TryParse(val, out value);
}
public bool TryGetEnumValue<T>(string xPath, ref T value) where T : struct
{
string val;
return GetValue(xPath, out val, Enum.GetName(typeof(T), value)) && CHelper.TryParse(val, out value, true);
}
public bool TryGetIntValueRange(string xPath, ref int value, int min = 0, int max = 100)
{
return TryGetIntValue(xPath, ref value) && value.IsInRange(min, max);
}
/// <summary>
/// Gets a normalized (0&lt;=x&lt;=1) float value
/// </summary>
/// <param name="xPath"></param>
/// <param name="value"></param>
/// <param name="defaultValue"></param>
/// <returns>True if exists and is normalized</returns>
public bool TryGetNormalizedFloatValue(string xPath, ref float value, float defaultValue = 0)
{
bool ok = TryGetFloatValue(xPath, ref value) && value.IsInRange(0f, 1f);
if (!ok)
value = defaultValue;
return ok;
}
}
}