diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 0aa110b2..53a169db 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -22,7 +22,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; -using Vocaluxe.Base; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; @@ -496,138 +495,138 @@ namespace Vocaluxe.Base } } } -} -class CPlaylistElement -{ - private readonly CSong _Song; - - private readonly int _SongID; - public int SongID + class CPlaylistElement { - get { return _SongID; } - } + private readonly CSong _Song; - private string _MusicFilePath = String.Empty; - - public string MusicFilePath - { - get + private readonly int _SongID; + public int SongID { - if (_Song != null) - return _Song.GetMP3(); - - return _MusicFilePath; + get { return _SongID; } } - set { _MusicFilePath = value; } - } + private string _MusicFilePath = String.Empty; - public string VideoFilePath - { - get + public string MusicFilePath { - if (_Song != null) - return _Song.GetVideo(); + get + { + if (_Song != null) + return _Song.GetMP3(); - return string.Empty; + return _MusicFilePath; + } + + set { _MusicFilePath = value; } } - } - public string Title - { - get + public string VideoFilePath { - if (_Song != null) - return _Song.Title; + get + { + if (_Song != null) + return _Song.GetVideo(); - return ""; + return string.Empty; + } } - } - public string Artist - { - get + public string Title { - if (_Song != null) - return _Song.Artist; + get + { + if (_Song != null) + return _Song.Title; - return ""; + return ""; + } } - } - public float Start - { - get + public string Artist { - if (_Song != null) - return _Song.Start; + get + { + if (_Song != null) + return _Song.Artist; - return 0f; + return ""; + } } - } - public float Finish - { - get + public float Start { - if (_Song != null) - return _Song.Finish; + get + { + if (_Song != null) + return _Song.Start; - return 0f; + return 0f; + } } - } - public STexture Cover - { - get + public float Finish { - if (_Song != null) - return _Song.CoverTextureSmall; + get + { + if (_Song != null) + return _Song.Finish; - return CCover.NoCover; + return 0f; + } } - } - public float VideoGap - { - get + public STexture Cover { - if (_Song != null) - return _Song.VideoGap; + get + { + if (_Song != null) + return _Song.CoverTextureSmall; - return 0; + return CCover.NoCover; + } } - } - public bool Duet - { - get + public float VideoGap { - if (_Song != null) - return _Song.IsDuet; + get + { + if (_Song != null) + return _Song.VideoGap; - return false; + return 0; + } } - } - public CPlaylistElement(CSong song) - { - MusicFilePath = string.Empty; - _SongID = song.ID; + public bool Duet + { + get + { + if (_Song != null) + return _Song.IsDuet; - _Song = song; - } + return false; + } + } - public CPlaylistElement(string filePath) - { - MusicFilePath = filePath; - _SongID = -1; - } + public CPlaylistElement(CSong song) + { + MusicFilePath = string.Empty; + _SongID = song.ID; - public CPlaylistElement() - { - MusicFilePath = string.Empty; - _SongID = -1; + _Song = song; + } + + public CPlaylistElement(string filePath) + { + MusicFilePath = filePath; + _SongID = -1; + } + + public CPlaylistElement() + { + MusicFilePath = string.Empty; + _SongID = -1; + } } } \ No newline at end of file diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index a7f03f65..cbb268c6 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -22,7 +22,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Windows.Forms; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using Vocaluxe.Screens; using VocaluxeLib.Menu; using VocaluxeLib.PartyModes; diff --git a/Vocaluxe/Base/CMain.cs b/Vocaluxe/Base/CMain.cs index 4f959225..a2f834f7 100644 --- a/Vocaluxe/Base/CMain.cs +++ b/Vocaluxe/Base/CMain.cs @@ -21,7 +21,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Drawing; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 30ce2f20..fa7a3c2b 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -23,7 +23,7 @@ using System.IO; using System.Text; using System.Windows.Forms; using System.Xml; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; namespace Vocaluxe.Base diff --git a/Vocaluxe/Base/Font/CFont.cs b/Vocaluxe/Base/Font/CFont.cs deleted file mode 100644 index 80d6a2a6..00000000 --- a/Vocaluxe/Base/Font/CFont.cs +++ /dev/null @@ -1,173 +0,0 @@ -#region license -// /* -// This file is part of Vocaluxe. -// -// Vocaluxe is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Vocaluxe is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Vocaluxe. If not, see . -// */ -#endregion - -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Text; -using VocaluxeLib.Menu; - -namespace Vocaluxe.Base.Font -{ - class CFont : IDisposable - { - private readonly Dictionary _Glyphs; - private PrivateFontCollection _Fonts; - private FontFamily _Family; - private readonly float _Sizeh; - - private readonly string _FilePath; - - private Font _LastFont; - - public CFont(string file) - { - _FilePath = file; - - _Glyphs = new Dictionary(); - - switch (CConfig.TextureQuality) - { - case ETextureQuality.TR_CONFIG_TEXTURE_LOWEST: - _Sizeh = 25f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_LOW: - _Sizeh = 50f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_MEDIUM: - _Sizeh = 100f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_HIGH: - _Sizeh = 200f; - break; - case ETextureQuality.TR_CONFIG_TEXTURE_HIGHEST: - _Sizeh = 400f; - break; - default: - _Sizeh = 100f; - break; - } - } - - public System.Drawing.Font GetFont() - { - if (_Fonts == null) - { - _Fonts = new PrivateFontCollection(); - try - { - _Fonts.AddFontFile(_FilePath); - _Family = _Fonts.Families[0]; - } - catch (Exception e) - { - CLog.LogError("Error opening font file " + _FilePath + ": " + e.Message); - } - } - - return new System.Drawing.Font(_Family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel); - } - - public void DrawGlyph(char chr, float x, float y, float z, SColorF color) - { - STexture texture; - SRectF rect; - GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); - CDraw.DrawTexture(texture, rect, color); - } - - public void DrawGlyph(char chr, float x, float y, float z, SColorF color, float begin, float end) - { - STexture texture; - SRectF rect; - GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); - CDraw.DrawTexture(texture, rect, color, begin, end); - } - - public void DrawGlyphReflection(char chr, float x, float y, float z, SColorF color, float rspace, float rheight) - { - STexture texture; - SRectF rect; - GetOrAddGlyph(chr).GetTextureAndRect(x, y, z, out texture, out rect); - CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight); - } - - public float GetWidth(char chr) - { - return GetOrAddGlyph(chr).Width; - } - - public float GetHeight(char chr) - { - return GetOrAddGlyph(chr).Height; - } - - public CGlyph GetOrAddGlyph(char chr) - { - CGlyph glyph; - if (!_Glyphs.TryGetValue(chr, out glyph)) - { - glyph = new CGlyph(chr, _Sizeh); - _Glyphs.Add(chr, glyph); - } - return glyph; - } - - public void UnloadGlyphs() - { - foreach (CGlyph glyph in _Glyphs.Values) - glyph.UnloadTexture(); - _Glyphs.Clear(); - } - - public void Dispose() - { - if (_Fonts != null) - { - _Fonts.Dispose(); - _Fonts = null; - UnloadGlyphs(); - } - GC.SuppressFinalize(this); - } - } - - struct SFont - { - public string Name; - - public bool IsThemeFont; - public int PartyModeID; - public string ThemeName; - - public string Folder; - public string FileNormal; - public string FileItalic; - public string FileBold; - public string FileBoldItalic; - - public float Outline; //0..1, 0=not outline 1=100% outline - public SColorF OutlineColor; - - public CFont Normal; - public CFont Italic; - public CFont Bold; - public CFont BoldItalic; - } -} \ No newline at end of file diff --git a/Vocaluxe/Base/Font/CFonts.cs b/Vocaluxe/Base/Font/CFonts.cs deleted file mode 100644 index 72dd9cc3..00000000 --- a/Vocaluxe/Base/Font/CFonts.cs +++ /dev/null @@ -1,474 +0,0 @@ -#region license -// /* -// This file is part of Vocaluxe. -// -// Vocaluxe is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Vocaluxe is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Vocaluxe. If not, see . -// */ -#endregion - -using System.Collections.Generic; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Text; -using System.Xml; -using VocaluxeLib.Menu; - -namespace Vocaluxe.Base.Font -{ - static class CFonts - { - private static readonly XmlWriterSettings _Settings = new XmlWriterSettings(); - - private static List _Fonts; - private static int _CurrentFont; - private static float _Height = 1f; - - 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 float Outline - { - get { return _Fonts[_CurrentFont].Outline; } - } - - public static SColorF OutlineColor - { - get { return _Fonts[_CurrentFont].OutlineColor; } - } - - public static void Init() - { - _Settings.Indent = true; - _Settings.Encoding = Encoding.UTF8; - _Settings.ConformanceLevel = ConformanceLevel.Document; - - _CurrentFont = 0; - PartyModeID = -1; - BuildFonts(); - } - - public static void BuildFonts() - { - _Fonts = new List(); - _CurrentFont = 0; - - _LoadFontList(); - } - - public static System.Drawing.Font GetFont() - { - return _GetCurrentFont().GetFont(); - } - - private static CFont _GetCurrentFont() - { - switch (Style) - { - case EStyle.Normal: - return _Fonts[_CurrentFont].Normal; - case EStyle.Italic: - return _Fonts[_CurrentFont].Italic; - case EStyle.Bold: - return _Fonts[_CurrentFont].Bold; - case EStyle.BoldItalic: - return _Fonts[_CurrentFont].BoldItalic; - } - //Just in case... - return _Fonts[_CurrentFont].Normal; - } - - #region DrawText - public static void DrawText(string text, int x, int y, int h) - { - 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)); - } - - public static void DrawText(string text, float h, float x, float y, float z, SColorF color) - { - if (h <= 0f) - return; - - if (text == "") - return; - - Height = h; - CFont font = _GetCurrentFont(); - - float dx = x; - foreach (char chr in text) - { - font.DrawGlyph(chr, dx, y, z, color); - dx += font.GetWidth(chr); - } - } - - public static void DrawTextReflection(string text, float h, float x, float y, float z, SColorF color, float rspace, float rheight) - { - if (h <= 0f) - return; - - if (text == "") - return; - - Height = h; - CFont font = _GetCurrentFont(); - - float dx = x; - foreach (char chr in text) - { - font.DrawGlyphReflection(chr, dx, y, z, color, rspace, rheight); - dx += font.GetWidth(chr); - } - } - - public static void DrawText(string text, float h, float x, float y, float z, SColorF color, float begin, float end) - { - if (h <= 0f) - return; - - if (text == "") - return; - - Height = h; - - float dx = x; - float w = GetTextWidth(text); - if (w <= 0f) - return; - - float x1 = x + w * begin; - float x2 = x + w * end; - - CFont font = _GetCurrentFont(); - - foreach (char chr in text) - { - float w2 = font.GetWidth(chr); - float b = (x1 - dx) / w2; - - if (b < 1f) - { - if (b < 0f) - b = 0f; - float e = (x2 - dx) / w2; - if (e > 0f) - { - if (e > 1f) - e = 1f; - font.DrawGlyph(chr, dx, y, z, color, b, e); - } - } - dx += w2; - } - } - #endregion DrawText - - public static FontStyle GetFontStyle() - { - switch (Style) - { - case EStyle.Normal: - return FontStyle.Regular; - case EStyle.Italic: - return FontStyle.Italic; - case EStyle.Bold: - return FontStyle.Bold; - case EStyle.BoldItalic: - return FontStyle.Bold | FontStyle.Italic; - default: - return FontStyle.Regular; - } - } - - public static void SetFont(string fontName) - { - int index = _GetPartyFontIndex(PartyModeID, fontName); - if (index < 0) - index = _GetThemeFontIndex(CConfig.Theme, fontName); - if (index < 0) - index = _GetFontIndex(fontName); - if (index >= 0) - _CurrentFont = index; - } - - public static RectangleF GetTextBounds(CText text) - { - return GetTextBounds(text, text.Height); - } - - public static RectangleF GetTextBounds(CText text, float height) - { - Height = height; - return new RectangleF(text.X, text.Y, GetTextWidth(CLanguage.Translate(text.Text, text.TranslationID)), - GetTextHeight(CLanguage.Translate(text.Text, text.TranslationID))); - } - - public static float GetTextWidth(string text) - { - CFont font = _GetCurrentFont(); - return text.Sum(chr => font.GetWidth(chr)); - } - - public static float GetTextHeight(string text) - { - //return TextRenderer.MeasureText(text, GetFont()).Height; - CFont font = _GetCurrentFont(); - return text == "" ? 0 : text.Select(font.GetHeight).Max(); - } - - private static void _LoadFontFiles(CXMLReader xmlReader, string fontFolder, string themeName = "", int partyModeId = -1) - { - string value = string.Empty; - int i = 1; - while (xmlReader.GetValue("//root/Fonts/Font" + i + "/Folder", out value, value)) - { - SFont sf = new SFont {Folder = value, IsThemeFont = themeName != "", ThemeName = themeName, PartyModeID = partyModeId}; - - bool ok = true; - - string name; - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/Name", out name, value); - sf.Name = name; - - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileNormal", out value, value); - sf.FileNormal = value; - value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); - CFont f = new CFont(value); - sf.Normal = f; - - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileItalic", out value, value); - sf.FileItalic = value; - value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); - f = new CFont(value); - sf.Italic = f; - - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBold", out value, value); - sf.FileBold = value; - value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); - f = new CFont(value); - sf.Bold = f; - - ok &= xmlReader.GetValue("//root/Fonts/Font" + i + "/FileBoldItalic", out value, value); - sf.FileBoldItalic = value; - value = Path.Combine(fontFolder, Path.Combine(sf.Folder, value)); - f = new CFont(value); - sf.BoldItalic = f; - - sf.Outline = 0f; - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/Outline", ref sf.Outline); - - sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorR", ref sf.OutlineColor.R); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorG", ref sf.OutlineColor.G); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorB", ref sf.OutlineColor.B); - ok &= xmlReader.TryGetFloatValue("//root/Fonts/Font" + i + "/OutlineColorA", ref sf.OutlineColor.A); - - if (ok) - _Fonts.Add(sf); - else - { - string fontTypes; - if (partyModeId >= 0) - fontTypes = "theme fonts for party mode"; - else if (themeName != "") - fontTypes = "theme fonts for theme \"" + themeName + "\""; - else - fontTypes = "basic fonts"; - CLog.LogError("Error loading " + fontTypes + ": Error in Font" + i); - } - i++; - } - } - - /// - /// Load default fonts - /// - /// - private static bool _LoadFontList() - { - CXMLReader xmlReader = CXMLReader.OpenFile(Path.Combine(CSettings.FolderFonts, CSettings.FileFonts)); - if (xmlReader == null) - return false; - - _Fonts.Clear(); - - _LoadFontFiles(xmlReader, Path.Combine(Directory.GetCurrentDirectory(), CSettings.FolderFonts)); - return true; - } - - /// - /// Loads theme fonts from skin file - /// - public static void LoadThemeFonts(string themeName, string fontFolder, CXMLReader xmlReader) - { - _LoadFontFiles(xmlReader, fontFolder, themeName); - CLog.StartBenchmark(1, "BuildGlyphs"); - _BuildGlyphs(); - CLog.StopBenchmark(1, "BuildGlyphs"); - } - - /// - /// Loads party mode fonts from skin file - /// - public static void LoadPartyModeFonts(int partyModeID, string fontFolder, CXMLReader xmlReader) - { - _LoadFontFiles(xmlReader, fontFolder, "", partyModeID); - CLog.StartBenchmark(1, "BuildGlyphs"); - _BuildGlyphs(); - CLog.StopBenchmark(1, "BuildGlyphs"); - } - - public static void SaveThemeFonts(string themeName, XmlWriter writer) - { - if (_Fonts.Count == 0) - return; - - int index = 0; - int fontNr = 1; - bool setStart = false; - while (index < _Fonts.Count) - { - if (_Fonts[index].IsThemeFont && _Fonts[index].ThemeName == themeName) - { - if (!setStart) - { - writer.WriteStartElement("Fonts"); - setStart = true; - } - - writer.WriteStartElement("Font" + fontNr); - - writer.WriteElementString("Name", _Fonts[index].Name); - writer.WriteElementString("Folder", _Fonts[index].Folder); - - writer.WriteElementString("Outline", _Fonts[index].Outline.ToString("#0.00")); - writer.WriteElementString("OutlineColorR", _Fonts[index].OutlineColor.R.ToString("#0.00")); - writer.WriteElementString("OutlineColorG", _Fonts[index].OutlineColor.G.ToString("#0.00")); - writer.WriteElementString("OutlineColorB", _Fonts[index].OutlineColor.B.ToString("#0.00")); - writer.WriteElementString("OutlineColorA", _Fonts[index].OutlineColor.A.ToString("#0.00")); - - writer.WriteElementString("FileNormal", _Fonts[index].FileNormal); - writer.WriteElementString("FileBold", _Fonts[index].FileBold); - writer.WriteElementString("FileItalic", _Fonts[index].FileItalic); - writer.WriteElementString("FileBoldItalic", _Fonts[index].FileBoldItalic); - - writer.WriteEndElement(); - - fontNr++; - } - index++; - } - - if (setStart) - writer.WriteEndElement(); - } - - public static void UnloadThemeFonts(string themeName) - { - if (_Fonts.Count == 0) - return; - - int index = 0; - while (index < _Fonts.Count) - { - if (_Fonts[index].IsThemeFont && _Fonts[index].ThemeName == themeName) - { - _Fonts[index].Normal.UnloadGlyphs(); - _Fonts[index].Italic.UnloadGlyphs(); - _Fonts[index].Bold.UnloadGlyphs(); - _Fonts[index].BoldItalic.UnloadGlyphs(); - _Fonts.RemoveAt(index); - } - else - index++; - } - } - - private static int _GetFontIndex(string fontName) - { - for (int i = 0; i < _Fonts.Count; i++) - { - if (!_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName) - return i; - } - - return -1; - } - - private static int _GetThemeFontIndex(string themeName, string fontName) - { - if (themeName == "" || fontName == "") - return -1; - - for (int i = 0; i < _Fonts.Count; i++) - { - if (_Fonts[i].IsThemeFont && _Fonts[i].Name == fontName && _Fonts[i].ThemeName == themeName) - return i; - } - - return -1; - } - - private static int _GetPartyFontIndex(int partyModeID, string fontName) - { - if (partyModeID == -1 || fontName == "") - return -1; - - for (int i = 0; i < _Fonts.Count; i++) - { - if (!_Fonts[i].IsThemeFont && _Fonts[i].PartyModeID == partyModeID && _Fonts[i].Name == fontName) - return i; - } - - return -1; - } - - private static void _BuildGlyphs() - { - const string text = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - - for (int i = 0; i < _Fonts.Count; i++) - { - _CurrentFont = i; - - foreach (char chr in text) - { - Style = EStyle.Normal; - _Fonts[_CurrentFont].Normal.GetOrAddGlyph(chr); - Style = EStyle.Bold; - _Fonts[_CurrentFont].Bold.GetOrAddGlyph(chr); - Style = EStyle.Italic; - _Fonts[_CurrentFont].Italic.GetOrAddGlyph(chr); - Style = EStyle.BoldItalic; - _Fonts[_CurrentFont].BoldItalic.GetOrAddGlyph(chr); - } - } - Style = EStyle.Normal; - SetFont("Normal"); - } - } -} \ No newline at end of file diff --git a/Vocaluxe/Base/Font/CGlyph.cs b/Vocaluxe/Base/Font/CGlyph.cs deleted file mode 100644 index 915a56bf..00000000 --- a/Vocaluxe/Base/Font/CGlyph.cs +++ /dev/null @@ -1,214 +0,0 @@ -#region license -// /* -// This file is part of Vocaluxe. -// -// Vocaluxe is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Vocaluxe is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Vocaluxe. If not, see . -// */ -#endregion - -using System; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Imaging; -using System.Drawing.Text; -using System.Runtime.InteropServices; -using System.Windows.Forms; -using VocaluxeLib.Menu; - -namespace Vocaluxe.Base.Font -{ - class CGlyph - { - private STexture _Texture; - private readonly SizeF _BoundingBox; - private readonly RectangleF _DrawBounding; - - public float Width - { - get { return _BoundingBox.Width * _GetFactor(); } - } - - public float Height - { - get { return _BoundingBox.Height * _GetFactor(); } - } - - public CGlyph(char chr, float maxHeight) - { - float oldHeight = CFonts.Height; - float outline = CFonts.Outline; - float outlineSize = outline * maxHeight; - string chrString = chr.ToString(); - - CFonts.Height = maxHeight; // *factor; - //float factor = _GetFactor(chr, flags); - System.Drawing.Font fo = CFonts.GetFont(); - SizeF fullSize, boundingSize; - Size bmpSize; - using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) - { - fullSize = g.MeasureString(chrString, fo); - fullSize.Width += outlineSize; - if (chr != ' ') - { - //Gets exact height and width for drawing more than 1 char. But width is to small to draw char on bitmap as e.g. italic chars will get cropped - boundingSize = g.MeasureString(chrString, fo, -1, new StringFormat(StringFormat.GenericTypographic)); - boundingSize.Width += outlineSize; - if (boundingSize.Height > 0) - boundingSize.Height += outlineSize; - else - boundingSize.Height = fullSize.Height; - bmpSize = new Size((int)fullSize.Width, (int)Math.Round(boundingSize.Height)); - } - else - { - boundingSize = fullSize; - bmpSize = new Size(1, 1); - } - _BoundingBox = boundingSize; - } - using (Bitmap bmp = new Bitmap(bmpSize.Width, bmpSize.Height, PixelFormat.Format32bppArgb)) - using (Graphics g = Graphics.FromImage(bmp)) - { - g.Clear(Color.Transparent); - - if (chr == ' ') - { - _Texture = CDraw.AddTexture(bmp); - _DrawBounding = new RectangleF(0, 0, 1, 1); - } - else - { - g.SmoothingMode = SmoothingMode.AntiAlias; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; - - PointF point = new PointF(outlineSize / 2, outlineSize / 2); - - using (GraphicsPath path = new GraphicsPath()) - { - //Have to use size in em not pixels! - float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); - path.AddString(chrString, fo.FontFamily, (int)fo.Style, emSize, point, new StringFormat()); - - using (Pen pen = new Pen(CFonts.OutlineColor.AsColor(), outlineSize)) - { - pen.LineJoin = LineJoin.Round; - g.DrawPath(pen, path); - g.FillPath(Brushes.White, path); - } - } - Rectangle realBounds = _GetRealBounds(bmp); - _DrawBounding = realBounds; - float dx = (fullSize.Width - boundingSize.Width - 1) / 2; - _DrawBounding.X -= dx; - using (Bitmap bmpCropped = bmp.Clone(realBounds, PixelFormat.Format32bppArgb)) - { - _Texture = CDraw.AddTexture(bmpCropped); - if (false) - { - if (outline > 0) - bmpCropped.Save("font/" + chr + "o" + CFonts.Style + "2.png", ImageFormat.Png); - else - bmpCropped.Save("font/" + chr + CFonts.Style + "2.png", ImageFormat.Png); - } - } - } - } - fo.Dispose(); - CFonts.Height = oldHeight; - } - - private float _GetFactor() - { - return CFonts.Height / _BoundingBox.Height; - } - - public void UnloadTexture() - { - CDraw.RemoveTexture(ref _Texture); - } - - public void GetTextureAndRect(float x, float y, float z, out STexture texture, out SRectF rect) - { - texture = _Texture; - float factor = _GetFactor(); - x += _DrawBounding.X * factor; - y += _DrawBounding.Y * factor; - float w = _DrawBounding.Width * factor; - float h = _DrawBounding.Height * factor; - rect = new SRectF(x, y, w, h, z); - } - - private static Rectangle _GetRealBounds(Bitmap bmp) - { - int minX = 0, maxX = bmp.Width - 1, minY = 0; - BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); - int values = bmpData.Width * bmp.Height; - Int32[] rgbValues = new Int32[values]; - Marshal.Copy(bmpData.Scan0, rgbValues, 0, values); - int index = 0; - bool found = false; - //find from top - for (int y = 0; y < bmp.Height && !found; y++) - { - for (int x = 0; x < bmp.Width; x++) - { - if (rgbValues[index] != 0) - { - minX = x; - maxX = x; - minY = y; - found = true; - break; - } - index++; - } - } - found = false; - //find left - for (int x = 0; x < minX && !found; x++) - { - index = x + minY * bmp.Width; - for (int y = minY; y < bmp.Height; y++) - { - if (rgbValues[index] != 0) - { - found = true; - minX = x; - break; - } - index += bmp.Width; - } - } - found = false; - //find right - for (int x = bmp.Width - 1; x > maxX && !found; x--) - { - index = x + minY * bmp.Width; - for (int y = minY; y < bmp.Height; y++) - { - if (rgbValues[index] != 0) - { - found = true; - maxX = x; - break; - } - index += bmp.Width; - } - } - return new Rectangle(minX, minY, maxX - minX + 1, bmp.Height - minY); - } - } -} \ No newline at end of file diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index bda3026b..48ca7a32 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -31,7 +31,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using SlimDX.Windows; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index 6032aeb6..08a4eeb0 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -27,7 +27,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Draw diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index f04a87c0..18795432 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -30,7 +30,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Windows.Forms; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; using BeginMode = OpenTK.Graphics.OpenGL.BeginMode; using BlendingFactorDest = OpenTK.Graphics.OpenGL.BlendingFactorDest; diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index 5f204724..f45e8866 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -25,7 +25,7 @@ using System.Reflection; using System.Windows.Forms; using Vocaluxe.Base; using System.Runtime.ExceptionServices; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; namespace Vocaluxe { diff --git a/Vocaluxe/Screens/CScreenCredits.cs b/Vocaluxe/Screens/CScreenCredits.cs index b37fdeb3..ce02561c 100644 --- a/Vocaluxe/Screens/CScreenCredits.cs +++ b/Vocaluxe/Screens/CScreenCredits.cs @@ -24,87 +24,87 @@ using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib.Menu; -enum EDirection -{ - Left, - Right, - Up -} - -class CCreditName -{ - private readonly CStatic _Image; - private readonly CStatic _ImgDot; - private readonly CParticleEffect _Particle; - private readonly int _ParticleOffsetX; - private readonly int _ParticleOffsetY; - public EDirection Direction; - public float StartTimeUp; - public bool Active; - - public CCreditName(CStatic image, CStatic imgDot, CParticleEffect particle, int particleOffsetX, int particleOffsetY) - { - _Image = image; - _ImgDot = imgDot; - _Particle = particle; - _ParticleOffsetX = (int)Math.Round(particleOffsetX * image.Rect.W / image.Texture.Width - particle.Rect.W / 2); - _ParticleOffsetY = (int)Math.Round(particleOffsetY * image.Rect.H / image.Texture.Height - particle.Rect.H / 2); - Active = true; - } - - public float X - { - get { return _Image.Rect.X; } - set - { - _Image.Rect.X = value; - _ImgDot.Rect.X = value + _ParticleOffsetX; - _Particle.Rect.X = value + _ParticleOffsetX; - } - } - public float Y - { - get { return _Image.Rect.Y; } - set - { - _Image.Rect.Y = value; - _ImgDot.Rect.Y = value + _ParticleOffsetY; - _Particle.Rect.Y = value + _ParticleOffsetY; - } - } - - public float W - { - get { return _Image.Rect.W; } - } - public float H - { - get { return _Image.Rect.H; } - } - - public float Alpha - { - get { return _Image.Alpha; } - set - { - _Image.Alpha = value; - _ImgDot.Alpha = value; - } - } - - public void Draw() - { - if (Active) - { - _Image.Draw(); - _ImgDot.Draw(); - _Particle.Draw(); - } - } -} - namespace Vocaluxe.Screens { + enum EDirection + { + Left, + Right, + Up + } + + class CCreditName + { + private readonly CStatic _Image; + private readonly CStatic _ImgDot; + private readonly CParticleEffect _Particle; + private readonly int _ParticleOffsetX; + private readonly int _ParticleOffsetY; + public EDirection Direction; + public float StartTimeUp; + public bool Active; + + public CCreditName(CStatic image, CStatic imgDot, CParticleEffect particle, int particleOffsetX, int particleOffsetY) + { + _Image = image; + _ImgDot = imgDot; + _Particle = particle; + _ParticleOffsetX = (int)Math.Round(particleOffsetX * image.Rect.W / image.Texture.Width - particle.Rect.W / 2); + _ParticleOffsetY = (int)Math.Round(particleOffsetY * image.Rect.H / image.Texture.Height - particle.Rect.H / 2); + Active = true; + } + + public float X + { + get { return _Image.Rect.X; } + set + { + _Image.Rect.X = value; + _ImgDot.Rect.X = value + _ParticleOffsetX; + _Particle.Rect.X = value + _ParticleOffsetX; + } + } + public float Y + { + get { return _Image.Rect.Y; } + set + { + _Image.Rect.Y = value; + _ImgDot.Rect.Y = value + _ParticleOffsetY; + _Particle.Rect.Y = value + _ParticleOffsetY; + } + } + + public float W + { + get { return _Image.Rect.W; } + } + public float H + { + get { return _Image.Rect.H; } + } + + public float Alpha + { + get { return _Image.Alpha; } + set + { + _Image.Alpha = value; + _ImgDot.Alpha = value; + } + } + + public void Draw() + { + if (Active) + { + _Image.Draw(); + _ImgDot.Draw(); + _Particle.Draw(); + } + } + } + class CScreenCredits : CMenu { // Version number for theme files. Increment it, if you've changed something on the theme files! diff --git a/Vocaluxe/Screens/CScreenMain.cs b/Vocaluxe/Screens/CScreenMain.cs index 977cb417..e5f6ca13 100644 --- a/Vocaluxe/Screens/CScreenMain.cs +++ b/Vocaluxe/Screens/CScreenMain.cs @@ -19,7 +19,7 @@ using System.Windows.Forms; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; namespace Vocaluxe.Screens diff --git a/Vocaluxe/Screens/CScreenOptionsTheme.cs b/Vocaluxe/Screens/CScreenOptionsTheme.cs index a0570294..10dfbc49 100644 --- a/Vocaluxe/Screens/CScreenOptionsTheme.cs +++ b/Vocaluxe/Screens/CScreenOptionsTheme.cs @@ -19,7 +19,7 @@ using System.Windows.Forms; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; namespace Vocaluxe.Screens diff --git a/Vocaluxe/Screens/CScreenSing.cs b/Vocaluxe/Screens/CScreenSing.cs index 43772d45..4a93a260 100644 --- a/Vocaluxe/Screens/CScreenSing.cs +++ b/Vocaluxe/Screens/CScreenSing.cs @@ -25,7 +25,7 @@ using System.IO; using System.Linq; using System.Windows.Forms; using Vocaluxe.Base; -using Vocaluxe.Base.Font; +using Vocaluxe.Base.Fonts; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SingNotes; using VocaluxeLib.Menu.SongMenu; diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index 46d4c11c..53c2b29b 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -176,7 +176,7 @@ - + @@ -195,8 +195,8 @@ - - + + Form