示例#1
0
 public TextBox() : base(typeof(TextBox))
 {
     textRenderer = CoreEngine.gEngine.TextRender;
     textCanvas   = textRenderer.CreateCanvas();
     textCanvas.alignHorizontal = TextAlignHorizontal.Left;
     textCanvas.alignVertical   = TextAlignVertical.Center;
 }
示例#2
0
        private Matrix4 CalculatePosition(TextCanvas textCanvas, RectTransform transform)
        {
            Vector3 location = Vector3.Zero;

            switch (textCanvas.alignVertical)
            {
            case TextAlignVertical.Bottom:
                location.Y = transform.Min.Y;
                break;

            case TextAlignVertical.Top:
                location.Y = (transform.Max.Y - textCanvas.Heigth * textCanvas.Scale);
                break;

            case TextAlignVertical.Center:
                location.Y = (transform.Min.Y + transform.Max.Y - textCanvas.Heigth * textCanvas.Scale) * 0.5f;
                break;
            }

            switch (textCanvas.alignHorizontal)
            {
            case TextAlignHorizontal.Left:
                location.X = transform.Min.X;
                break;

            case TextAlignHorizontal.Right:
                location.X = (transform.Max.X - textCanvas.Width * textCanvas.Scale);
                break;

            case TextAlignHorizontal.Center:
                location.X = (transform.Min.X + transform.Max.X - textCanvas.Width * textCanvas.Scale) * 0.5f;
                break;
            }
            return(Matrix4.CreateTranslation(location));
        }
示例#3
0
 public void CloneTo(TextCanvas obj)
 {
     obj.alignHorizontal = alignHorizontal;
     obj.alignVertical   = alignVertical;
     obj.Text            = Text;
     obj.StringLength    = StringLength;
     obj.Position        = Position;
     obj.Scale           = Scale;
     obj.colour          = colour;
     obj.Length          = Length;
     obj.Width           = Width;
     obj.Heigth          = Heigth;
 }
示例#4
0
        internal TextCanvas CreateCanvas()
        {
            int VAO = GL.GenVertexArray();
            int VBO = GL.GenBuffer();

            GL.BindVertexArray(VAO);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 5 * 4, 0);
            GL.EnableVertexAttribArray(1);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 5 * 4, 3 * 4);
            GL.BindVertexArray(0);

            var canvas = new TextCanvas(VAO, VBO);

            texts.Add(canvas);

            GL.BindBuffer(BufferTarget.ArrayBuffer, VBO);
            GL.BufferData(BufferTarget.ArrayBuffer, 1000 * 4, IntPtr.Zero, BufferUsageHint.DynamicDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            return(canvas);
        }
示例#5
0
 internal void UnloadText(TextCanvas canvas)
 {
     texts.Remove(canvas);
     GL.DeleteVertexArray(canvas.VAO);
     GL.DeleteBuffer(canvas.VBO);
 }
示例#6
0
        public void UpdateText(TextCanvas canvas)
        {
            GL.ActiveTexture(TextureUnit.Texture0);
            charmap.BindTexture();

            float[] vertices = new float[6 * 5 * canvas.Text.Length];
            int     x        = 0;
            int     y        = 0;
            int     i        = 0;

            canvas.Width  = 0;
            canvas.Heigth = 0;
            float rowHeigth = 0;


            foreach (var c in canvas.Text)
            {
                if (c == 8381)
                {
                    continue;
                }

                //move to new line
                if (c == '\n' || c == '\r')
                {
                    x  = 0;
                    y -= size;
                    continue;
                }

                var   chr  = GetCharacter(c);
                float xpos = x + chr.Bearing.X;
                float ypos = y - (chr.Size.Y - chr.Bearing.Y);
                float w    = chr.Size.X;
                float h    = chr.Size.Y;

                //update text size
                if (y == 0 && rowHeigth < chr.Size.Y - y)
                {
                    rowHeigth = chr.Size.Y - y;
                }
                if (canvas.Width < xpos + w)
                {
                    canvas.Width = xpos + w;
                }

                float[] verts =
                {
                    xpos,     ypos + h, 0, chr.Position.X,                        chr.Position.Y,
                    xpos,     ypos,     0, chr.Position.X,                        chr.Position.Y + chr.Size.Y / mapSize,
                    xpos + w, ypos,     0, chr.Position.X + chr.Size.X / mapSize, chr.Position.Y + chr.Size.Y / mapSize,
                    xpos,     ypos + h, 0, chr.Position.X,                        chr.Position.Y,
                    xpos + w, ypos,     0, chr.Position.X + chr.Size.X / mapSize, chr.Position.Y + chr.Size.Y / mapSize,
                    xpos + w, ypos + h, 0, chr.Position.X + chr.Size.X / mapSize, chr.Position.Y
                };
                Array.Copy(verts, 0, vertices, i, verts.Length);
                x += (chr.Advance >> 6);

                i += 30;
            }
            canvas.Heigth = rowHeigth - y;

            for (int n = 1; n < vertices.Length; n += 5)
            {
                vertices[n] -= y;
            }

            GL.BindBuffer(BufferTarget.ArrayBuffer, canvas.VBO);
            GL.BufferSubData(BufferTarget.ArrayBuffer, IntPtr.Zero, vertices.Length * 4, vertices);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            canvas.StringLength = canvas.Text.Length;
        }