示例#1
0
        /// <summary>
        /// Fully renders colorful/fancy text (unless the text is not marked as fancy, or fancy rendering is disabled)
        /// </summary>
        /// <param name="Text">The text to render</param>
        /// <param name="Position">Where to render the text at</param>
        /// <param name="MaxY">The maximum Y location to render text at.</param>
        /// <param name="transmod">Transparency modifier (EG, 0.5 = half opacity) (0.0 - 1.0)</param>
        /// <param name="extrashadow">Whether to always have a mini drop-shadow</param>
        public void DrawColoredText(string Text, Location Position, int MaxY = int.MaxValue, float transmod = 1, bool extrashadow = false)
        {
            string[] lines     = Text.Replace('\r', ' ').Replace(' ', (char)0x00A0).Replace("^q", "\"").Split('\n');
            int      color     = DefaultColor;
            int      trans     = (int)(255 * transmod);
            bool     bold      = false;
            bool     italic    = false;
            bool     underline = false;
            bool     strike    = false;
            bool     overline  = false;
            bool     highlight = false;
            bool     emphasis  = false;
            int      ucolor    = DefaultColor;
            int      scolor    = DefaultColor;
            int      ocolor    = DefaultColor;
            int      hcolor    = DefaultColor;
            int      ecolor    = DefaultColor;
            bool     super     = false;
            bool     sub       = false;
            bool     flip      = false;
            bool     pseudo    = false;
            bool     jello     = false;
            bool     obfu      = false;
            bool     random    = false;
            bool     shadow    = false;
            int      otrans    = (int)(255 * transmod);
            int      etrans    = (int)(255 * transmod);
            int      htrans    = (int)(255 * transmod);
            int      strans    = (int)(255 * transmod);
            int      utrans    = (int)(255 * transmod);
            float    X         = (float)Position.X;
            float    Y         = (float)Position.Y;
            GLFont   font      = font_default;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.Length == 0)
                {
                    Y += font_default.Height;
                    continue;
                }
                int start = 0;
                for (int x = 0; x < line.Length; x++)
                {
                    if ((line[x] == '^' && x + 1 < line.Length && IsColorSymbol(line[x + 1])) || (x + 1 == line.Length))
                    {
                        string drawme = line.Substring(start, (x - start) + ((x + 1 < line.Length) ? 0 : 1));
                        start = x + 2;
                        x++;
                        if (drawme.Length > 0 && Y >= -font.Height && Y - (sub ? font.Height : 0) <= MaxY)
                        {
                            float width = font.MeasureString(drawme);
                            if (highlight)
                            {
                                DrawRectangle(X, Y, width, font.Height, font, ColorFor(hcolor, htrans));
                            }
                            if (underline)
                            {
                                DrawRectangle(X, Y + ((float)font.Height * 4f / 5f), width, 1, font, ColorFor(ucolor, utrans));
                            }
                            if (overline)
                            {
                                DrawRectangle(X, Y + 2f, width, 1f, font, ColorFor(ocolor, otrans));
                            }
                            if (extrashadow)
                            {
                                foreach (Point point in ShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, trans / 2, flip);
                                }
                            }
                            if (shadow)
                            {
                                foreach (Point point in ShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, 255, flip);
                                }
                                foreach (Point point in BetterShadowPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, 0, 255, flip);
                                }
                            }
                            if (emphasis)
                            {
                                foreach (Point point in EmphasisPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, ecolor, etrans, flip);
                                }
                                foreach (Point point in BetterEmphasisPoints)
                                {
                                    RenderBaseText(X + point.X, Y + point.Y, drawme, font, ecolor, etrans, flip);
                                }
                            }
                            RenderBaseText(X, Y, drawme, font, color, trans, flip, pseudo, random, jello, obfu);
                            if (strike)
                            {
                                DrawRectangle(X, Y + (font.Height / 2), width, 1, font, ColorFor(scolor, strans));
                            }
                            X += width;
                        }
                        if (x < line.Length)
                        {
                            switch (line[x])
                            {
                            case '1': color = 1; break;

                            case '!': color = 11; break;

                            case '2': color = 2; break;

                            case '@': color = 12; break;

                            case '3': color = 3; break;

                            case '#': color = 13; break;

                            case '4': color = 4; break;

                            case '$': color = 14; break;

                            case '5': color = 5; break;

                            case '%': color = 15; break;

                            case '6': color = 6; break;

                            case '-': color = 16; break;

                            case '7': color = 7; break;

                            case '&': color = 17; break;

                            case '8': color = 8; break;

                            case '*': color = 18; break;

                            case '9': color = 9; break;

                            case '(': color = 19; break;

                            case '0': color = 0; break;

                            case ')': color = 20; break;

                            case 'a': color = 10; break;

                            case 'A': color = 21; break;

                            case 'i':
                            {
                                italic = true;
                                GLFont nfont = (super || sub) ? (bold ? font_bolditalichalf : font_italichalf) :
                                               (bold ? font_bolditalic : font_italic);
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                            }
                            break;

                            case 'b':
                            {
                                bold = true;
                                GLFont nfont = (super || sub) ? (italic ? font_bolditalichalf : font_boldhalf) :
                                               (italic ? font_bolditalic : font_bold);
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                            }
                            break;

                            case 'u': utrans = trans; underline = true; ucolor = color; break;

                            case 's': strans = trans; strike = true; scolor = color; break;

                            case 'h': htrans = trans; highlight = true; hcolor = color; break;

                            case 'e': etrans = trans; emphasis = true; ecolor = color; break;

                            case 'O': otrans = trans; overline = true; ocolor = color; break;

                            case 't': trans = (int)(128 * transmod); break;

                            case 'T': trans = (int)(64 * transmod); break;

                            case 'o': trans = (int)(255 * transmod); break;

                            case 'S':
                                if (!super)
                                {
                                    if (sub)
                                    {
                                        sub = false;
                                        Y  -= font.Height / 2;
                                    }
                                    GLFont nfont = bold && italic ? font_bolditalichalf : bold ? font_boldhalf :
                                                   italic ? font_italichalf : font_half;
                                    if (nfont != font)
                                    {
                                        font = nfont;
                                    }
                                }
                                super = true;
                                break;

                            case 'l':
                                if (!sub)
                                {
                                    if (super)
                                    {
                                        super = false;
                                    }
                                    Y += font_default.Height / 2;
                                    GLFont nfont = bold && italic ? font_bolditalichalf : bold ? font_boldhalf :
                                                   italic ? font_italichalf : font_half;
                                    if (nfont != font)
                                    {
                                        font = nfont;
                                    }
                                }
                                sub = true;
                                break;

                            case 'd': shadow = true; break;

                            case 'j': jello = true; break;

                            case 'k': obfu = true; break;

                            case 'R': random = true; break;

                            case 'p': pseudo = true; break;

                            case 'f': flip = true; break;

                            case 'n':
                                break;

                            case 'r':
                            {
                                GLFont nfont = font_default;
                                if (nfont != font)
                                {
                                    font = nfont;
                                }
                                if (sub)
                                {
                                    Y -= font_default.Height / 2;
                                }
                                sub       = false;
                                super     = false;
                                flip      = false;
                                random    = false;
                                pseudo    = false;
                                jello     = false;
                                obfu      = false;
                                shadow    = false;
                                bold      = false;
                                italic    = false;
                                underline = false;
                                strike    = false;
                                emphasis  = false;
                                highlight = false;
                                trans     = (int)(255 * transmod);
                                overline  = false;
                                break;
                            }

                            default:
                                break;
                            }
                        }
                    }
                }
                Y += font_default.Height;
                X  = (float)Position.X;
            }
            Engine.GLFonts.Shaders.TextCleanerShader.Bind();
            GL.UniformMatrix4(1, false, ref PrimaryEditor.ortho);
            Matrix4 ident = Matrix4.Identity;

            GL.UniformMatrix4(2, false, ref ident);
            Vector3 col = new Vector3(1, 1, 1);

            GL.Uniform3(3, ref col);
            VBO.Build();
            VBO.Render();
            VBO.Destroy();
            Engine.GLFonts.Shaders.ColorMultShader.Bind();
        }
示例#2
0
 public void DestroyVBO()
 {
     vbo.Destroy();
 }