Esempio n. 1
0
        private float GetFactor(char chr, TextFormatFlags flags)
        {
            if (CFonts.Style == EStyle.Normal)
            {
                return(1f);
            }

            EStyle style = CFonts.Style;

            CFonts.Style  = EStyle.Normal;
            CFonts.Height = SIZEh;
            Bitmap bmp = new Bitmap(10, 10);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            Font fo    = CFonts.GetFont();
            Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
            //SizeF size = g.MeasureString(chr.ToString(), fo);
            float h_normal = sizeB.Height;

            CFonts.Style = style;
            bmp          = new Bitmap(10, 10);
            g            = System.Drawing.Graphics.FromImage(bmp);

            fo    = CFonts.GetFont();
            sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);
            //size = g.MeasureString(chr.ToString(), fo);
            float h_style = sizeB.Height;

            g.Dispose();
            return(h_normal / h_style);
        }
Esempio n. 2
0
        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);
                }
        }
Esempio n. 3
0
        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;
            }
        }
Esempio n. 4
0
        public static void LoadTheme()
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;
            int            index     = 0;

            for (int i = 0; i < _Themes.Count; i++)
            {
                if (_Themes[i].Name == CConfig.Theme)
                {
                    index = i;
                }
            }

            try
            {
                xPathDoc  = new XPathDocument(Path.Combine(_Themes[index].Path, _Themes[index].FileName));
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                CLog.LogError("Error loading theme " + _Themes[index].FileName + ": " + e.Message);
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }
            }

            if (loaded)
            {
                int skinIndex = GetSkinIndex();

                // Load Cursor
                LoadCursor(navigator, skinIndex);

                // load fonts
                CFonts.LoadThemeFonts(
                    _Themes[index].Name,
                    Path.Combine(Path.Combine(_Themes[index].Path, _Themes[index].SkinFolder), CSettings.sFolderThemeFonts),
                    navigator);
            }
        }
Esempio n. 5
0
        public static void SaveTheme()
        {
            SaveSkin();

            int ThemeIndex = 0;

            for (int i = 0; i < _Themes.Count; i++)
            {
                if (_Themes[i].Name == CConfig.Theme)
                {
                    ThemeIndex = i;
                }
            }

            #region ThemeMainFile
            XmlWriter writer = XmlWriter.Create(Path.Combine(_Themes[ThemeIndex].Path, _Themes[ThemeIndex].FileName), _settings);
            writer.WriteStartDocument();
            writer.WriteStartElement("root");

            // ThemeSystemVersion
            writer.WriteElementString("ThemeSystemVersion", ThemeSystemVersion.ToString());

            #region Info
            writer.WriteStartElement("Info");

            writer.WriteElementString("Name", _Themes[ThemeIndex].Name);
            writer.WriteElementString("Author", _Themes[ThemeIndex].Author);
            writer.WriteElementString("SkinFolder", _Themes[ThemeIndex].SkinFolder);
            writer.WriteElementString("ThemeVersionMajor", _Themes[ThemeIndex].ThemeVersionMajor.ToString());
            writer.WriteElementString("ThemeVersionMinor", _Themes[ThemeIndex].ThemeVersionMinor.ToString());

            writer.WriteEndElement();
            #endregion Info

            // Cursor
            SaveCursor(writer);

            // save fonts
            CFonts.SaveThemeFonts(_Themes[ThemeIndex].Name, writer);


            // End of File
            writer.WriteEndElement(); //end of root
            writer.WriteEndDocument();

            writer.Flush();
            writer.Close();
            #endregion ThemeMainFile
        }
Esempio n. 6
0
        public 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 Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel));
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
 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);
 }
Esempio n. 10
0
 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);
 }
Esempio n. 11
0
 public RectangleF GetTextBounds(CText text)
 {
     return(CFonts.GetTextBounds(text));
 }
Esempio n. 12
0
 public void DrawText(string text, CFont font, float x, float y, float z, SColorF color)
 {
     CFonts.DrawText(text, font, x, y, z, color);
 }
Esempio n. 13
0
        public CGlyph(char chr, float MaxHigh)
        {
            _SIZEh = MaxHigh;

            float           outline = CFonts.Outline;
            TextFormatFlags flags   = TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix;

            float factor = GetFactor(chr, flags);

            CFonts.Height = SIZEh * factor;
            Bitmap bmp = new Bitmap(10, 10);

            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);

            Font fo    = CFonts.GetFont();
            Size sizeB = TextRenderer.MeasureText(g, chr.ToString(), fo, new Size(int.MaxValue, int.MaxValue), flags);

            SizeF size = g.MeasureString(chr.ToString(), fo);

            g.Dispose();
            bmp.Dispose();

            bmp = new Bitmap((int)(sizeB.Width * 2f), sizeB.Height);
            g   = System.Drawing.Graphics.FromImage(bmp);
            g.Clear(System.Drawing.Color.Transparent);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            CFonts.Height       = SIZEh;
            fo = CFonts.GetFont();

            PointF point = new PointF(
                outline * Math.Abs(sizeB.Width - size.Width) + (sizeB.Width - size.Width) / 2f + SIZEh / 5f,
                (sizeB.Height - size.Height - (size.Height + SIZEh / 4f) * (1f - factor)) / 2f);

            GraphicsPath path = new GraphicsPath();

            path.AddString(
                chr.ToString(),
                fo.FontFamily,
                (int)fo.Style,
                SIZEh,
                point,
                new StringFormat());

            Pen pen = new Pen(
                Color.FromArgb(
                    (int)CFonts.OutlineColor.A * 255,
                    (int)CFonts.OutlineColor.R * 255,
                    (int)CFonts.OutlineColor.G * 255,
                    (int)CFonts.OutlineColor.B * 255),
                SIZEh * outline);

            pen.LineJoin = LineJoin.Round;
            g.DrawPath(pen, path);
            g.FillPath(Brushes.White, path);

            /*
             * g.DrawString(
             *  chr.ToString(),
             *  fo,
             *  Brushes.White,
             *  point);
             * */

            Texture = CDraw.AddTexture(bmp);
            //bmp.Save("test.png", ImageFormat.Png);
            Chr   = chr;
            width = (int)((1f + outline / 2f) * sizeB.Width * Texture.width / factor / bmp.Width);

            bmp.Dispose();
            g.Dispose();
            fo.Dispose();
        }