Beispiel #1
0
 public Text(IContext context, string content, Font font, Vector2I size, Color color, HorizontalAlignment horizontalAligment, VerticalAlignment verticalAlignment, Padding padding)
 {
     Font = font;
     _size = size;
     Padding = padding;
     VerticalAlignment = verticalAlignment;
     HorizontalAlignment = horizontalAligment;
     BaseColor = color;
     _shader = context.Shaders.Get<FontShader>();
     _device = context.DirectX.Device;
     Content = content;
 }
Beispiel #2
0
        public SimpleText(IContext context, Font font, int maxLength, Color color)
        {
            Device device = context.DirectX.Device;
            Font = font;
            MaxLength = maxLength;
            Color = color;
            _shader = context.Shaders.Get<FontShader>();
            _icons = new List<TexturedRectangle>();
            // The index buffer is static and do not change when the text changes
            uint[] indices = new uint[maxLength * 6]; // 6 indices per character

            for (uint i = 0; i < maxLength; i++)
            {
                indices[i * 6] = i * 4;
                indices[i * 6 + 1] = i * 4 + 1;
                indices[i * 6 + 2] = i * 4 + 2;
                indices[i * 6 + 3] = i * 4;
                indices[i * 6 + 4] = i * 4 + 3;
                indices[i * 6 + 5] = i * 4 + 1;
            }

            _indexBuffer = Buffer.Create(device, BindFlags.IndexBuffer, indices);

            // The vertex buffer is initialized empty
            _vertices = new VertexDefinition.PositionTextureColor[maxLength * 4]; // 4 vertices per character

            var vertexBufferDesc = new BufferDescription
            {
                Usage = ResourceUsage.Dynamic,
                SizeInBytes = Utilities.SizeOf<VertexDefinition.PositionTextureColor>() * maxLength * 4,
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.Write,
                OptionFlags = ResourceOptionFlags.None,
                StructureByteStride = 0
            };

            // Create the vertex buffer.
            _vertexBuffer = Buffer.Create(device, _vertices, vertexBufferDesc);
        }