public static void OnRender()
        {
            if (Offset != 0)
            {
                int consoleHeight = AllodsWindow.Height / 2;

                QMesh.SetVertex(0, 0f, 0f, 0f, 0f, 0f, 64, 64, 64, 192);
                QMesh.SetVertex(1, (float)AllodsWindow.Width, 0f, 0f, 0f, 0f, 64, 64, 64, 192);
                QMesh.SetVertex(2, (float)AllodsWindow.Width, (float)consoleHeight, 0f, 0f, 0f, 16, 16, 16, 192);
                QMesh.SetVertex(3, 0f, (float)consoleHeight, 0f, 0f, 0f, 16, 16, 16, 192);

                QMesh.SetVertex(4, 0f, (float)consoleHeight, 0f, 0f, 0f, 255, 120, 0, 255);
                QMesh.SetVertex(5, (float)AllodsWindow.Width, (float)consoleHeight, 0f, 0f, 0f, 150, 72, 0, 255);
                QMesh.SetVertex(6, (float)AllodsWindow.Width, (float)(consoleHeight + 2), 0f, 0f, 0f, 73, 33, 0, 255);
                QMesh.SetVertex(7, 0f, (float)(consoleHeight + 2), 0f, 0f, 0f, 73, 33, 0, 255);

                QMesh.SetVertex(8, 0f, (float)(consoleHeight + 2), 0f, 0f, 0f, 0, 0, 0, 255);
                QMesh.SetVertex(9, (float)AllodsWindow.Width, (float)(consoleHeight + 2), 0f, 0f, 0f, 0, 0, 0, 255);
                QMesh.SetVertex(10, (float)AllodsWindow.Width, (float)(consoleHeight + 8), 0f, 0f, 0f, 0, 0, 0, 0);
                QMesh.SetVertex(11, 0f, (float)(consoleHeight + 8), 0f, 0f, 0f, 0, 0, 0, 0);

                AllodsWindow.SetTranslation(0f, (float)(Offset - consoleHeight), 0f);
                QMesh.Render("notex");

                // now draw last messages. starts with consoleHeight-Fonts.Font2.LineHeight*2
                int textY = Offset - Fonts.Font2.LineHeight * 2;
                int textX = 3;

                // draw text field
                if (LineEditLeft == null)
                {
                    LineEditLeft = Fonts.Font2.Render(">", Font.Align.Left, 0, 0, false);
                }
                LineEditLeft.Render(textX, textY + 6, 1, 255, 255, 255, 255);
                LineEdit.Resize(12, textY + 4, AllodsWindow.Width - 16, Fonts.Font2.LineHeight + 4);
                LineEdit.SetFont(Fonts.Font2);
                LineEdit.TreeRender();

                for (int i = Messages.Count - 1; i >= 0; i--)
                {
                    ClientConsoleMessage msg = Messages[i];
                    if (msg.Text.Length > 0)
                    {
                        msg.UpdateMesh();
                        if (textY + msg.Mesh.MeshHeight < 0)
                        {
                            break;
                        }

                        textY -= msg.Mesh.MeshHeight;
                        msg.Mesh.Render(textX, textY, 1, 255, 255, 255, 255);
                    }
                }
            }
        }
        public int LastWidth; // if null, mesh should be regenerated

        public void UpdateMesh()
        {
            if (LastWidth != AllodsWindow.Width - 6 || Mesh == null)
            {
                if (Mesh != null)
                {
                    Mesh.Dispose();
                }
                Mesh      = Fonts.Font2.Render(Text, Font.Align.Left, AllodsWindow.Width - 6, 0, true);
                LastWidth = AllodsWindow.Width - 6;
            }
        }
Exemple #3
0
        public FontMesh Render(string text, Align align, int width, int height, bool wrapping)
        {
            FontMesh nm = new FontMesh();
            Mesh     m  = new Mesh(PrimitiveType.Quads);

            // todo: wrap text / output
            string text2 = "";

            for (int i = 0; i < text.Length; i++)
            {
                text2 += MapChar(text[i]);
            }

            string[] wrapped = Wrap(text2, width, wrapping);

            int vx = 0;

            nm.MeshWidth  = 0;
            nm.MeshHeight = 0;

            float y = 0f;

            for (int i = 0; i < wrapped.Length; i++)
            {
                if (wrapped[i].Length > 0)
                {
                    float x = 0f;

                    int line_wd2    = 0;
                    int line_wd     = 0;
                    int line_spccnt = 0;

                    float spc_width = (float)(Widths[0]);

                    if (wrapped[i][wrapped[i].Length - 1] == 0)
                    {
                        wrapped[i] = wrapped[i].Substring(0, wrapped[i].Length - 1); // remove last space if any
                    }
                    for (int j = 0; j < wrapped[i].Length; j++)
                    {
                        char c  = wrapped[i][j];
                        int  wd = (c != 0) ? Width(c) : (int)spc_width;
                        line_wd += wd;
                        if (c == 0) // space
                        {
                            line_spccnt++;
                        }
                        else if (c != 0)
                        {
                            line_wd2 += wd;
                        }
                    }

                    if (align == Align.LeftRight && line_spccnt > 0 && i != wrapped.Length - 1)
                    {
                        spc_width = (float)(width - line_wd2) / line_spccnt;
                    }

                    if (align == Align.Right)
                    {
                        x = (float)(width - line_wd);
                    }
                    else if (align == Align.Center)
                    {
                        x = (float)(width / 2 - line_wd / 2);
                    }

                    int rw = 0;
                    for (int j = 0; j < wrapped[i].Length; j++)
                    {
                        char  c   = wrapped[i][j];
                        float sx1 = (float)((c % 16) * CellX);
                        float sx2 = (float)((c % 16) * CellX + CellX);
                        float sy1 = (float)((c / 16) * CellY);
                        float sy2 = (float)((c / 16) * CellY + CellY);

                        m.SetVertex(vx++, x, y, 0f, sx1, sy1, 255, 255, 255, 255);
                        m.SetVertex(vx++, x + CellX, y, 0f, sx2, sy1, 255, 255, 255, 255);
                        m.SetVertex(vx++, x + CellX, y + CellY, 0f, sx2, sy2, 255, 255, 255, 255);
                        m.SetVertex(vx++, x, y + CellY, 0f, sx1, sy2, 255, 255, 255, 255);

                        rw = (int)(x + Width(c));
                        x += (c != 0) ? (float)Width(c) : spc_width;
                    }

                    if (rw > nm.MeshWidth)
                    {
                        nm.MeshWidth = rw;
                    }
                }

                y             += (float)LineHeight;
                nm.MeshHeight += LineHeight;
            }

            nm.MeshObject  = m;
            nm.MeshTexture = CombinedTexture;

            return(nm);
        }