private void _DrawText(Graphics g, Size bmpSize, CFont font, List <CTextElement> elements) { Font fo = CFonts.GetSystemFont(font); float maxHeight = elements.Select(el => el.Height).Max(); int lineCount = elements.Last().Line + 1; //Have to use size in em not pixels! float emSize = fo.Size * fo.FontFamily.GetCellAscent(fo.Style) / fo.FontFamily.GetEmHeight(fo.Style); float outlineSize = CFonts.GetOutlineSize(font) * font.Height; SColorF outlineColorF = CFonts.GetOutlineColor(font); outlineColorF.A = outlineColorF.A * _TextColor.A; using (var path = new GraphicsPath()) using (var pen = new Pen(outlineColorF.AsColor(), outlineSize / 2)) { pen.LineJoin = LineJoin.Round; pen.Alignment = PenAlignment.Outset; float top = (bmpSize.Height - _MarginBottom - _MarginTop - maxHeight * lineCount) / 2 + _MarginTop; int nextLineEl = 0; for (int i = 0; i < lineCount; i++) { int firstEl = nextLineEl; for (; nextLineEl < elements.Count; nextLineEl++) { if (elements[nextLineEl].Line > i) { break; } } string line = elements.GetRange(firstEl, nextLineEl - firstEl).Aggregate("", (current, element) => current + element.Text); float left; if (lineCount == 1 || (i == 1 && lineCount == 3)) { //Center Text if this is the only line or the middle line float width = _GetWidth(elements, firstEl, nextLineEl - 1); left = (bmpSize.Width - _MarginLeft - _MarginRight - width) / 2 + _MarginLeft; } else if (i == lineCount - 1) { //Place last line at right float width = _GetWidth(elements, firstEl, nextLineEl - 1); left = bmpSize.Width - width - _MarginRight; } else { left = _MarginLeft; } //g.DrawString(line, fo, new SolidBrush(_TextColor.AsColor()), left, top, StringFormat.GenericTypographic); path.AddString(line, fo.FontFamily, (int)fo.Style, emSize, new PointF(left, top), StringFormat.GenericTypographic); top += maxHeight + _LineSpace; } g.DrawPath(pen, path); g.FillPath(new SolidBrush(_TextColor.AsColor()), path); } }
private static void _DrawDebugInfos() { if (CConfig.Config.Debug.DebugLevel == EDebugLevel.TR_CONFIG_OFF) { return; } List <String> debugOutput = new List <string> { CTime.GetFPS().ToString("FPS: 000") }; if (CConfig.Config.Debug.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL1) { debugOutput.Add(CSound.GetStreamCount().ToString(CLanguage.Translate("TR_DEBUG_AUDIO_STREAMS") + ": 00")); debugOutput.Add(CVideo.GetNumStreams().ToString(CLanguage.Translate("TR_DEBUG_VIDEO_STREAMS") + ": 00")); debugOutput.Add(CDraw.TextureCount().ToString(CLanguage.Translate("TR_DEBUG_TEXTURES") + ": 00000")); long memory = GC.GetTotalMemory(false); debugOutput.Add((memory / 1000000L).ToString(CLanguage.Translate("TR_DEBUG_MEMORY") + ": 00000 MB")); if (CConfig.Config.Debug.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL2) { debugOutput.Add(CRecord.GetToneAbs(0).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P1: 00")); debugOutput.Add(CRecord.GetMaxVolume(0).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P1: 0.000")); debugOutput.Add(CRecord.GetToneAbs(1).ToString(CLanguage.Translate("TR_DEBUG_TONE_ABS") + " P2: 00")); debugOutput.Add(CRecord.GetMaxVolume(1).ToString(CLanguage.Translate("TR_DEBUG_MAX_VOLUME") + " P2: 0.000")); if (CConfig.Config.Debug.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL3) { debugOutput.Add(CSongs.NumSongsWithCoverLoaded.ToString(CLanguage.Translate("TR_DEBUG_SONGS") + ": 00000")); if (CConfig.Config.Debug.DebugLevel >= EDebugLevel.TR_CONFIG_LEVEL_MAX) { debugOutput.Add(_Cursor.X.ToString(CLanguage.Translate("TR_DEBUG_MOUSE") + " : (0000/") + _Cursor.Y.ToString("0000)")); } } } } 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) { float textWidth = CFonts.GetTextWidth(txt, font); RectangleF rect = new RectangleF(CSettings.RenderW - textWidth, y, textWidth, CFonts.GetTextHeight(txt, font)); CDraw.DrawRect(gray, new SRectF(rect.X, rect.Top, rect.Width, rect.Height, CSettings.ZNear)); CFonts.DrawText(txt, font, rect.X, rect.Y, CSettings.ZNear); y += rect.Height; } }
public Bitmap GetCover(string text, string firstCoverPath) { if (!_Valid) { return(null); } text = CLanguage.Translate(_Theme.Text.Text.Replace("%TEXT%", text)); using (Bitmap bmpImage = new Bitmap(_Image)) { Bitmap bmp = new Bitmap(bmpImage.Width, bmpImage.Height, PixelFormat.Format32bppArgb); try { using (Graphics g = Graphics.FromImage(bmp)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.TextRenderingHint = TextRenderingHint.AntiAlias; _DrawBackground(g, bmpImage, firstCoverPath); if (text != "") { CFont font = new CFont(_Theme.Text.Font); Font fo = CFonts.GetSystemFont(font); IEnumerable <string> textParts = _SplitText(text); List <CTextElement> elements = textParts.Select(line => new CTextElement(line, g, fo)).ToList(); float factor = _DistributeText(elements, bmp.Width, bmp.Height); foreach (CTextElement element in elements) { element.AdjustSize(factor); } font.Height *= factor / (1f + CFonts.GetOutlineSize(font)); //Adjust for outline size _DrawText(g, bmp.GetSize(), font, elements); } } return(bmp); } catch (Exception) { bmp.Dispose(); } } return(null); }
/// <summary> /// Loads theme fonts from skin file /// </summary> public static void LoadThemeFonts(string ThemeName, string FontFolder, XPathNavigator navigator) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { SFont sf = new SFont(); sf.Folder = value; sf.IsThemeFont = true; sf.ThemeName = ThemeName; bool ok = true; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); sf.FileNormal = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); CFont f = new CFont(value); sf.Normal = f; string name = String.Empty; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); sf.FileItalic = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Italic = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBold", navigator, ref value, value); sf.FileBold = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Bold = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", navigator, ref 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 &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); if (ok) _Fonts.Add(sf); else { CLog.LogError("Error loading theme fonts for theme \"" + ThemeName + "\": Error in Font" + i.ToString()); } i++; } CLog.StartBenchmark(1, "BuildGlyphs"); BuildGlyphs(); CLog.StopBenchmark(1, "BuildGlyphs"); }
/// <summary> /// Load default fonts /// </summary> /// <returns></returns> private static bool LoadFontList() { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(System.IO.Path.Combine(CSettings.sFolderFonts, CSettings.sFileFonts)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading default fonts: " + e.Message); loaded = false; if (navigator != null) navigator = null; if (xPathDoc != null) xPathDoc = null; } _Fonts.Clear(); if (loaded) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { string Folder = value; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); CFont f = new CFont(value); SFont sf = new SFont(); sf.Normal = f; string name = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; sf.IsThemeFont = false; sf.ThemeName = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Italic = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBold", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Bold = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.BoldItalic = f; sf.Outline = 0f; CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); _Fonts.Add(sf); i++; } } return loaded; }
public void DrawText(string text, CFont font, float x, float y, float z, SColorF color, float begin, float end) { CFonts.DrawText(text, font, x, y, z, color, begin, end); }
public void DrawTextReflection(string text, CFont font, float x, float y, float z, SColorF color, float reflectionSpace, float reflectionHeight) { CFonts.DrawTextReflection(text, font, x, y, z, color, reflectionSpace, reflectionHeight); }
public void DrawText(string text, CFont font, float x, float y, float z, SColorF color, bool allMonitors = true) { CFonts.DrawText(text, font, x, y, z, color, allMonitors); }
public void DrawText(string text, CFont font, float x, float y, float z, SColorF color) { CFonts.DrawText(text, font, x, y, z, color); }
/// <summary> /// Loads theme fonts from skin file /// </summary> public static void LoadThemeFonts(string ThemeName, string FontFolder, XPathNavigator navigator) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { SFont sf = new SFont(); sf.Folder = value; sf.IsThemeFont = true; sf.ThemeName = ThemeName; bool ok = true; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); sf.FileNormal = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); CFont f = new CFont(value); sf.Normal = f; string name = String.Empty; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); sf.FileItalic = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Italic = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBold", navigator, ref value, value); sf.FileBold = value; value = Path.Combine(FontFolder, Path.Combine(sf.Folder, value)); f = new CFont(value); sf.Bold = f; ok &= CHelper.GetValueFromXML("//root/Fonts/Font" + i.ToString() + "/FileBoldItalic", navigator, ref 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 &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); ok &= CHelper.TryGetFloatValueFromXML("//root/Fonts/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); if (ok) { _Fonts.Add(sf); } else { CLog.LogError("Error loading theme fonts for theme \"" + ThemeName + "\": Error in Font" + i.ToString()); } i++; } CLog.StartBenchmark(1, "BuildGlyphs"); BuildGlyphs(); CLog.StopBenchmark(1, "BuildGlyphs"); }
/// <summary> /// Load default fonts /// </summary> /// <returns></returns> private static bool LoadFontList() { bool loaded = false; XPathDocument xPathDoc = null; XPathNavigator navigator = null; try { xPathDoc = new XPathDocument(System.IO.Path.Combine(CSettings.sFolderFonts, CSettings.sFileFonts)); navigator = xPathDoc.CreateNavigator(); loaded = true; } catch (Exception e) { CLog.LogError("Error loading default fonts: " + e.Message); loaded = false; if (navigator != null) { navigator = null; } if (xPathDoc != null) { xPathDoc = null; } } _Fonts.Clear(); if (loaded) { string value = string.Empty; int i = 1; while (CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Folder", navigator, ref value, value)) { string Folder = value; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileNormal", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); CFont f = new CFont(value); SFont sf = new SFont(); sf.Normal = f; string name = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/Name", navigator, ref name, value); sf.Name = name; sf.IsThemeFont = false; sf.ThemeName = String.Empty; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Italic = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBold", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.Bold = f; CHelper.GetValueFromXML("//root/Font" + i.ToString() + "/FileBoldItalic", navigator, ref value, value); value = Path.Combine(Directory.GetCurrentDirectory(), Path.Combine(CSettings.sFolderFonts, Path.Combine(Folder, value))); f = new CFont(value); sf.BoldItalic = f; sf.Outline = 0f; CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/Outline", navigator, ref sf.Outline); sf.OutlineColor = new SColorF(0f, 0f, 0f, 1f); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorR", navigator, ref sf.OutlineColor.R); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorG", navigator, ref sf.OutlineColor.G); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorB", navigator, ref sf.OutlineColor.B); CHelper.TryGetFloatValueFromXML("//root/Font" + i.ToString() + "/OutlineColorA", navigator, ref sf.OutlineColor.A); _Fonts.Add(sf); i++; } } return(loaded); }