/// <summary>
        /// Fills a set of triangles with a brush.
        /// </summary>
        /// <param name="indices">The index buffer.</param>
        /// <param name="vertices">The vertex buffer.</param>
        /// <param name="brush">The brush used to fill the triangles.</param>
        public void FillTriangleList(int[] indices, Vector2[] vertices, Brush brush)
        {
            SetBrush(brush);

            var realVertices = new Vertex[vertices.Length];

            for (int i = 0; i < vertices.Length; i++)
            {
                realVertices[i] = new Vertex(vertices[i]);
            }
            brush.UpdateVertices(realVertices);

            DrawVertices(indices, realVertices);
        }
        /// <summary>
        /// Fills a rectangle with a brush.
        /// </summary>
        /// <param name="rectangle">The rectangle to fill.</param>
        /// <param name="brush">The brush used to fill the rectangle.</param>
        public void FillRectangle(Rectangle rectangle, Brush brush)
        {
            SetBrush(brush);

            Vertex[] vertices = new[]
            {
                new Vertex(rectangle.Left, rectangle.Top),
                new Vertex(rectangle.Right, rectangle.Top),
                new Vertex(rectangle.Left, rectangle.Bottom),
                new Vertex(rectangle.Right, rectangle.Bottom),
            };
            int[] indices = { 0, 1, 2, 1, 2, 3 };

            brush.UpdateVertices(vertices);
            DrawVertices(indices, vertices, 0);
        }
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="location">The location the text will be displayed at.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="size">The font size in points.</param>
        /// <param name="brush">The brush used to draw the text.</param>
        public void DrawText(string text, Vector2 location, Font font, float size, Brush brush)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            float scale = (size * Dpi) / (72 * font.UnitsPerEm);

            SetBrush(brush);

            int horizontalPosition = 0;
            int verticalPosition   = font.Ascend;

            for (int i = 0; i < text.Length; i++)
            {
                if (char.IsControl(text[i]))
                {
                    switch (text[i])
                    {
                    case '\n':
                        verticalPosition  += font.Ascend - font.Descend + font.LineGap;
                        horizontalPosition = 0;
                        break;
                    }
                }
                else
                {
                    Font.Glyph glyph = font.GetGlyph(text[i]);
                    if (glyph.Vertices.Length > 0)
                    {
                        textMatrix = Matrix.Transpose(Matrix.Translation(horizontalPosition + glyph.LeftSideBearing, -verticalPosition, 0)
                                                      * Matrix.Scaling(scale, -scale, 1)
                                                      * Matrix.Translation(location.X, location.Y, 0));
                        UpdateMatrixBuffer();

                        brush.UpdateVertices(glyph.Vertices);
                        DrawVertices(glyph.Indices, glyph.Vertices);
                    }

                    horizontalPosition += glyph.AdvanceWidth;
                }
            }

            textMatrix = Matrix.Identity;
            UpdateMatrixBuffer();
        }
Beispiel #4
0
        /// <summary>
        /// Draws text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="location">The location the text will be displayed at.</param>
        /// <param name="font">The font of the text.</param>
        /// <param name="size">The font size in points.</param>
        /// <param name="brush">The brush used to draw the text.</param>
        public void DrawText(string text, Vector2 location, Font font, float size, Brush brush)
        {
            if (string.IsNullOrWhiteSpace(text))
                return;

            float scale = (size * Dpi) / (72 * font.UnitsPerEm);
            SetBrush(brush);

            int horizontalPosition = 0;
            int verticalPosition = font.Ascend;
            for (int i = 0; i < text.Length; i++)
            {
                if (char.IsControl(text[i]))
                {
                    switch (text[i])
                    {
                        case '\n':
                            verticalPosition += font.Ascend - font.Descend + font.LineGap;
                            horizontalPosition = 0;
                            break;
                    }
                }
                else
                {
                    Font.Glyph glyph = font.GetGlyph(text[i]);
                    if (glyph.Vertices.Length > 0)
                    {
                        textMatrix = Matrix.Transpose(Matrix.Translation(horizontalPosition + glyph.LeftSideBearing, -verticalPosition, 0)
                            * Matrix.Scaling(scale, -scale, 1)
                            * Matrix.Translation(location.X, location.Y, 0));
                        UpdateMatrixBuffer();

                        brush.UpdateVertices(glyph.Vertices);
                        DrawVertices(glyph.Indices, glyph.Vertices);
                    }

                    horizontalPosition += glyph.AdvanceWidth;
                }
            }

            textMatrix = Matrix.Identity;
            UpdateMatrixBuffer();
        }
Beispiel #5
0
        /// <summary>
        /// Fills a set of triangles with a brush.
        /// </summary>
        /// <param name="indices">The index buffer.</param>
        /// <param name="vertices">The vertex buffer.</param>
        /// <param name="brush">The brush used to fill the triangles.</param>
        public void FillTriangleList(int[] indices, Vector2[] vertices, Brush brush)
        {
            SetBrush(brush);

            var realVertices = new Vertex[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
                realVertices[i] = new Vertex(vertices[i]);
            brush.UpdateVertices(realVertices);

            DrawVertices(indices, realVertices);
        }
Beispiel #6
0
        /// <summary>
        /// Fills a rectangle with a brush.
        /// </summary>
        /// <param name="rectangle">The rectangle to fill.</param>
        /// <param name="brush">The brush used to fill the rectangle.</param>
        public void FillRectangle(Rectangle rectangle, Brush brush)
        {
            SetBrush(brush);

            Vertex[] vertices = new[]
            {
                new Vertex(rectangle.Left, rectangle.Top),
                new Vertex(rectangle.Right, rectangle.Top),
                new Vertex(rectangle.Left, rectangle.Bottom),
                new Vertex(rectangle.Right, rectangle.Bottom),
            };
            int[] indices = { 0, 1, 2, 1, 2, 3 };

            brush.UpdateVertices(vertices);
            DrawVertices(indices, vertices, 0);
        }