/// <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 #2
0
        /// <summary>
        /// Sets the clipping region to the specified triangles.
        /// </summary>
        /// <param name="indices">The index buffer.</param>
        /// <param name="vertices">The vertex buffer.</param>
        /// <param name="reset">Optional. If set to true the old clipping region is discarded, otherweise the new region adds to the old one.</param>
        /// <remarks>The clipping region is reset automatically before every render cycle.</remarks>
        public void SetClip(int[] indices, Vector2[] vertices, bool reset = true)
        {
            SetBrushBuffer(ClipBrush);

            if (reset) ResetClip();
            deviceContext.OutputMerger.SetDepthStencilState(clipDepthStencilState, 1);

            var realVertices = new Vertex[vertices.Length];
            for (int i = 0; i < vertices.Length; i++)
                realVertices[i] = new Vertex(vertices[i]);
            DrawVertices(indices, realVertices);

            deviceContext.OutputMerger.SetDepthStencilState(clippingDepthStencilState, 1);
        }
Beispiel #3
0
 /// <summary>
 /// Draws layouted text.
 /// </summary>
 /// <param name="layout">The precalculated layout.</param>
 /// <param name="location">THe location the layout will be displayed at.</param>
 /// <param name="brush">The brush used to draw the layout.</param>
 public void DrawTextLayout(TextLayout layout, Vector2 location, Brush brush)
 {
     
 }
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>
 /// Draws a texture.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="location">The loction the texture will be displayed at.</param>
 /// <param name="opacity">The opacity of the drawn texture.</param>
 /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
 public void DrawTexture(Texture texture, Vector2 location, float opacity = 1, InterpolationMode interpolationMode = InterpolationMode.Default)
 {
     DrawTexture(texture, Color4.White, new Rectangle(location.X, location.Y, texture.Width, texture.Height), opacity, interpolationMode);
 }
 /// <summary>
 /// Draws layouted text.
 /// </summary>
 /// <param name="layout">The precalculated layout.</param>
 /// <param name="location">THe location the layout will be displayed at.</param>
 /// <param name="brush">The brush used to draw the layout.</param>
 public void DrawTextLayout(TextLayout layout, Vector2 location, Brush brush)
 {
 }
 /// <summary>
 /// Draws a texture.
 /// </summary>
 /// <param name="texture">The texture.</param>
 /// <param name="location">The loction the texture will be displayed at.</param>
 /// <param name="opacity">The opacity of the drawn texture.</param>
 /// <param name="interpolationMode">The interpolation mode used to stretch the texture.</param>
 public void DrawTexture(Texture texture, Vector2 location, float opacity = 1, InterpolationMode interpolationMode = InterpolationMode.Default)
 {
     DrawTexture(texture, Color4.White, new Rectangle(location.X, location.Y, texture.Width, texture.Height), opacity, interpolationMode);
 }