Beispiel #1
0
        public Size2 MeasureText(string text, string fontName, int height, FontDrawFlags align)
        {
            Font      font          = GetFont(fontName, height);
            Rectangle fontDimension = font.MeasureText(null, text, align);

            return(new Size2(fontDimension.Width, fontDimension.Height));
        }
Beispiel #2
0
 /// <summary>
 ///     Draws formatted text. This method supports ANSI and Unicode strings.
 /// </summary>
 /// <param name="font">
 ///     Font interface encapsulates the textures and resources needed to render a specific font on a
 ///     specific device.
 /// </param>
 /// <param name="sprite">
 ///     Sprite interface provides a set of methods that simplify the process of drawing sprites using
 ///     Microsoft Direct3D.
 /// </param>
 /// <param name="text">String to draw.</param>
 /// <param name="rect">
 ///     Rectangle structure that contains the rectangle, in logical coordinates, in which
 ///     the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its
 ///     left side. Likewise, the coordinate value of the bottom must be greater than that of the top.
 /// </param>
 /// <param name="drawFlags">Specifies the method of formatting the text.</param>
 /// <param name="color">Color of the text.</param>
 /// <returns>
 ///     If the function succeeds, the return value is the height of the text in logical units. If
 ///     FontDrawFlags.VerticalCenter or FontDrawFlags.Bottom is specified, the return value is the offset from pRect (top
 ///     to the bottom) of the drawn text. If the function fails, the return value is zero.
 /// </returns>
 public static int DrawText(Font font,
                            Sprite sprite,
                            string text,
                            Rectangle rect,
                            FontDrawFlags drawFlags,
                            Color color)
 {
     return(font.DrawText(sprite, text, rect, drawFlags, new ColorBGRA(color.R, color.G, color.B, color.A)));
 }
Beispiel #3
0
 public Size2 DrawText(string text, string fontName, int height, Vector2 position, Color color, FontDrawFlags align)
 {
     try
     {
         var font = GetFont(fontName, height);
         var rectangle = new Rectangle((int)position.X, (int)position.Y, 0, 0);
         Rectangle fontDimension = font.MeasureText(null, text, rectangle, align);
         if (!sprite.IsDisposed)
             font.DrawText(sprite, text, fontDimension, align, color);
         return new Size2(fontDimension.Width, fontDimension.Height);
     }
     catch (Exception)
     {
         //
     }
     return new Size2();
 }
Beispiel #4
0
        /// <summary>
        /// Mede e retorna o comprimento e altura de um texto.
        /// </summary>
        /// <param name="style">Estilo</param>
        /// <param name="text">Texto</param>
        /// <param name="textformat">Formato</param>
        /// <returns></returns>
        public static Rectangle MeasureString(EngineFontStyle style, string text, FontDrawFlags textformat)
        {
            if (style == EngineFontStyle.Regular)
            {
                return(regular.MeasureText(null, text, textformat));
            }

            if (style == EngineFontStyle.Bold)
            {
                return(bold.MeasureText(null, text, textformat));
            }

            if (style == EngineFontStyle.Italic)
            {
                return(italic.MeasureText(null, text, textformat));
            }

            return(new Rectangle());
        }
Beispiel #5
0
 public Size2 DrawText(string text, string fontName, int height, Vector2 position, Color color, FontDrawFlags align)
 {
     Font font;
     Rectangle fontDimension;
     try
     {
         font = GetFont(fontName, height);
         var rectangle = new Rectangle((int)position.X, (int)position.Y, 0, 0);
         fontDimension = font.MeasureText(null, text, rectangle, align);
         if (!sprite.IsDisposed)
             font.DrawText(sprite, text, fontDimension, align, color);
         return new Size2(fontDimension.Width, fontDimension.Height);
     }
     catch (Exception exception)
     {
         //Console.WriteLine("Exception! X: " + position.X + ", Y: " + position.Y + ", Text: " + text);
         //Console.WriteLine(exception.StackTrace);
     }
     return new Size2();
 }
Beispiel #6
0
 /// <summary>
 /// Measures the specified text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D10.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
 /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 /// <unmanaged>int ID3DX10Font::DrawTextW([In] ID3DX10Sprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] RECT* pRect,[In] unsigned int Format,[In] D3DXCOLOR Color)</unmanaged>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags)
 {
     // DT_CALCRECT
     DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, whiteColor);
     return(rect);
 }
Beispiel #7
0
        /// <summary>
        /// Draws formatted text.
        /// </summary>
        /// <param name="sprite"><para>Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</para></param>
        /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
        /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
        /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </item></list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
        /// <param name="color"><para>Color of the text. For more information, see <see cref="RawColor4"/>.</para></param>
        /// <returns>If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero.</returns>
        /// <remarks>
        /// The parameters of this method are very similar to those of the GDI DrawText function.This method supports both ANSI and Unicode strings.This method must be called inside a  BeginScene ... EndScene block. The only exception is when an application calls DrawText with DT_CALCRECT to calculate the size of a given block of text.Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified.If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font.This method supports only fonts whose escapement and orientation are both zero.
        /// </remarks>
        /// <unmanaged>int ID3DXFont::DrawTextW([In] ID3DXSprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] void* pRect,[In] unsigned int Format,[In] D3DCOLOR Color)</unmanaged>
        public unsafe int DrawText(SharpDX.Direct3D9.Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, RawColorBGRA color)
        {
            int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int)drawFlags, color);

            if (value == 0)
            {
                throw new SharpDXException("Draw failed");
            }
            return(value);
        }
Beispiel #8
0
        /// <summary>
        /// Measures the specified sprite.
        /// </summary>
        /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
        /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
        /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
        /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
        /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>
        /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
        public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, out int textHeight)
        {
            // DT_CALCRECT
            int whiteColor = -1;

            textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, *(RawColorBGRA *)&whiteColor);
            return(rect);
        }
Beispiel #9
0
        public Size2 DrawText(string text, string fontName, int height, Vector2 position, Color color, FontDrawFlags align)
        {
            Font      font;
            Rectangle fontDimension;

            try
            {
                font = GetFont(fontName, height);
                var rectangle = new Rectangle((int)position.X, (int)position.Y, 0, 0);
                fontDimension = font.MeasureText(null, text, rectangle, align);
                if (!sprite.IsDisposed)
                {
                    font.DrawText(sprite, text, fontDimension, align, color);
                }
                return(new Size2(fontDimension.Width, fontDimension.Height));
            }
            catch (Exception exception)
            {
                //Console.WriteLine("Exception! X: " + position.X + ", Y: " + position.Y + ", Text: " + text);
                //Console.WriteLine(exception.StackTrace);
            }
            return(new Size2());
        }
Beispiel #10
0
 public static void Draw(string text, Color color, FontDrawFlags flags, Rectangle rectangle)
 {
     Font.DrawText(null, text, rectangle, flags, color);
 }
Beispiel #11
0
 /// <summary>
 /// Measures the specified text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D10.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 /// <unmanaged>int ID3DX10Font::DrawTextW([In] ID3DX10Sprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] RECT* pRect,[In] unsigned int Format,[In] D3DXCOLOR Color)</unmanaged>
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, SharpDX.Rectangle rect, FontDrawFlags drawFlags, out int textHeight)
 {
     // DT_CALCRECT
     textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, Color.White);
     return(rect);
 }
Beispiel #12
0
 public static extern void al_draw_text(IntPtr font, Color color, float x, float y, FontDrawFlags flags, string text);
Beispiel #13
0
 public Size2 DrawText(string text, string fontName, int height, Vector2 position, Color color, FontDrawFlags align)
 {
     try
     {
         var       font          = GetFont(fontName, height);
         var       rectangle     = new Rectangle((int)position.X, (int)position.Y, 0, 0);
         Rectangle fontDimension = font.MeasureText(null, text, rectangle, align);
         if (!sprite.IsDisposed)
         {
             font.DrawText(sprite, text, fontDimension, align, color);
         }
         return(new Size2(fontDimension.Width, fontDimension.Height));
     }
     catch (Exception)
     {
         //ignore
     }
     return(new Size2());
 }
Beispiel #14
0
 /// <summary>
 /// Measures the specified text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D10.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 /// <unmanaged>int ID3DX10Font::DrawTextW([In] ID3DX10Sprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] RECT* pRect,[In] unsigned int Format,[In] D3DXCOLOR Color)</unmanaged>	
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags)
 {
     // DT_CALCRECT
     DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, whiteColor);
     return rect;
 }
Beispiel #15
0
        /// <summary>
        /// Desenha o texto na coordenada com quebra de linha.
        /// </summary>
        /// <param name="text">Texto</param>
        /// <param name="rec">Retângulo</param>
        /// <param name="color">Cor</param>
        /// <param name="style">Estilo</param>
        /// <param name="textformat">Formato</param>
        /// <param name="preload">Pré Carregamento</param>
        public static void DrawText(string text, Rectangle rec, Color color, EngineFontStyle style, FontDrawFlags textformat, bool preload = false)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (style == EngineFontStyle.Regular)
            {
                if (preload)
                {
                    regular.PreloadText(text);
                }

                regular.DrawText(null, text, rec, textformat, color);
                return;
            }

            if (style == EngineFontStyle.Bold)
            {
                if (preload)
                {
                    bold.PreloadText(text);
                }

                bold.DrawText(null, text, rec, textformat, color);
                return;
            }

            if (style == EngineFontStyle.Italic)
            {
                if (preload)
                {
                    italic.PreloadText(text);
                }

                italic.DrawText(null, text, rec, textformat, color);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>
 /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return(MeasureText(sprite, text, Rectangle.Empty, drawFlags));
 }
Beispiel #17
0
 public Size2 MeasureText(string text, int height, FontDrawFlags align = FontDrawFlags.Left)
 {
     return fontRenderer.MeasureText(text, "Verdana", height, align);
 }
Beispiel #18
0
 public Size2 DrawText(string text, int height, Vector2 position, FontDrawFlags align = FontDrawFlags.Left)
 {
     return fontRenderer.DrawText(text, "Verdana", height, position, Color.White, align);
 }
Beispiel #19
0
 public Size2 MeasureText(string text, string fontName, int height, FontDrawFlags align)
 {
     Font font = GetFont(fontName, height);
     Rectangle fontDimension = font.MeasureText(null, text, align);
     return new Size2(fontDimension.Width, fontDimension.Height);
 }
Beispiel #20
0
        /// <summary>
        /// Desenha o texto centralizado.
        /// </summary>
        /// <param name="text">Texto</param>
        /// <param name="size">Tamanho</param>
        /// <param name="point">Posição</param>
        /// <param name="color">Cor</param>
        /// <param name="style">Estilo</param>
        /// <param name="textformat">Formato</param>
        /// <param name="preload">Pré Carregamento</param>
        public static void DrawText(string text, Size2 size, Point point, Color color, EngineFontStyle style, FontDrawFlags textformat, bool preload = false)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            if (style == EngineFontStyle.Regular)
            {
                rect = regular.MeasureText(null, text, textformat);
                if (preload)
                {
                    regular.PreloadText(text);
                }
                regular.DrawText(null, text, point.X + (size.Width - rect.Width) / 2, (point.Y - 5) + (size.Height - rect.Height) / 2, color);
                return;
            }

            if (style == EngineFontStyle.Bold)
            {
                rect = bold.MeasureText(null, text, textformat);
                if (preload)
                {
                    bold.PreloadText(text);
                }
                bold.DrawText(null, text, point.X + (size.Width - rect.Width) / 2, (point.Y - 5) + (size.Height - rect.Height) / 2, color);
                return;
            }

            if (style == EngineFontStyle.Italic)
            {
                rect = italic.MeasureText(null, text, textformat);
                if (preload)
                {
                    italic.PreloadText(text);
                }
                italic.DrawText(null, text, point.X + (size.Width - rect.Width) / 2, (point.Y - 5) + (size.Height - rect.Height) / 2, color);
            }
        }
Beispiel #21
0
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return MeasureText(sprite, text, Rectangle.Empty, drawFlags);
 }
Beispiel #22
0
 public void Render(Color color, Point position, FontDrawFlags flags, string text)
 {
     Font.Draw(color, position.X, position.Y, flags, text);
 }
Beispiel #23
0
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return(MeasureText(sprite, text, new RawRectangle(), drawFlags));
 }
Beispiel #24
0
        public void RenderLabel(DrawArgs drawArgs, int x, int y, int buttonHeight, bool selected, MenuAnchor anchor)
        {
            if (selected)
            {
                if (buttonHeight == this.curSize)
                {
                    this.alpha += alphaStep;
                    if (this.alpha > 255)
                    {
                        this.alpha = 255;
                    }
                }
            }
            else
            {
                this.alpha -= alphaStep;
                if (this.alpha < 0)
                {
                    this.alpha = 0;
                    return;
                }
            }

            int halfWidth = (int)(SelectedSize * 0.75);
            int label_x   = x - halfWidth + 1;
            int label_y   = (int)(y + SelectedSize) + 1;

            FontDrawFlags format = FontDrawFlags.NoClip | FontDrawFlags.Center | FontDrawFlags.WordBreak;

            if (anchor == MenuAnchor.Bottom)
            {
                format |= FontDrawFlags.Bottom;
                label_y = y - 202;
            }

            Rectangle rect = new Rectangle(
                label_x,
                label_y,
                (int)halfWidth * 2,
                200);

            if (rect.Right > drawArgs.screenWidth)
            {
                rect = Rectangle.FromLTRB(rect.Left, rect.Top, drawArgs.screenWidth, rect.Bottom);
            }

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(2, 0);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(0, 2);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(-2, 0);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                black & 0xffffff + (this.alpha << 24));

            rect.Offset(1, -1);

            drawArgs.toolbarFont.DrawText(
                null, this.Description,
                rect,
                format,
                white & 0xffffff + (this.alpha << 24));
        }
Beispiel #25
0
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, out int textHeight)
 {
     // DT_CALCRECT
     int whiteColor = -1;
     textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, *(RawColorBGRA*)&whiteColor);
     return rect;
 }
Beispiel #26
0
        public Size2 DrawText(string text, string fontName, int height, Vector2 position, Color color, FontDrawFlags align)
        {
            Font      font          = GetFont(fontName, height);
            var       rectangle     = new Rectangle((int)position.X, (int)position.Y, 0, 0);
            Rectangle fontDimension = font.MeasureText(null, text, rectangle, align);

            font.DrawText(sprite, text, fontDimension, align, color);
            return(new Size2(fontDimension.Width, fontDimension.Height));
        }
Beispiel #27
0
 /// <summary>
 /// Measures the specified sprite.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D9.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="drawFlags"><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term></item> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term></item> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term></item> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term></item> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term></item> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term></item> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term></item> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term></item> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term></item> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term></item> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term></item> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term></item> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 public unsafe RawRectangle MeasureText(Sprite sprite, string text, FontDrawFlags drawFlags)
 {
     return MeasureText(sprite, text, new RawRectangle(), drawFlags);
 }
Beispiel #28
0
 public Size2 MeasureText(string text, int height, FontDrawFlags align = FontDrawFlags.Left)
 {
     return(fontRenderer.MeasureText(text, "Verdana", height, align));
 }
Beispiel #29
0
 public Size2 DrawText(string text, int height, Vector2 position, FontDrawFlags align = FontDrawFlags.Left)
 {
     return(fontRenderer.DrawText(text, "Verdana", height, position, Color.White, align));
 }
Beispiel #30
0
 /// <summary>
 /// Measures the specified text.
 /// </summary>
 /// <param name="sprite">Pointer to an <see cref="SharpDX.Direct3D10.Sprite"/> object that contains the string. Can be <c>null</c>, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if DrawText is to be called more than once in a row.</param>
 /// <param name="text"><para>Pointer to a string to draw. If the Count parameter is -1, the string must be null-terminated.</para></param>	
 /// <param name="rect"><para>Pointer to a <see cref="SharpDX.Rectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. The coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top.</para></param>	
 /// <param name="drawFlags"><para> </para><para>Specifies the method of formatting the text. It can be any combination of the following values:</para>  ValueMeaning <list> <item><term>DT_BOTTOM</term> </list>  <para>Justifies the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.</para>  <list> <item><term>DT_CALCRECT</term> </list>  <para>Determines the width and height of the rectangle. If there are multiple lines of text, DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, DrawText returns the height of the formatted text but does not draw the text.</para>  <list> <item><term>DT_CENTER</term> </list>  <para>Centers text horizontally in the rectangle.</para>  <list> <item><term>DT_EXPANDTABS</term> </list>  <para>Expands tab characters. The default number of characters per tab is eight.</para>  <list> <item><term>DT_LEFT</term> </list>  <para>Aligns text to the left.</para>  <list> <item><term>DT_NOCLIP</term> </list>  <para>Draws without clipping. DrawText is somewhat faster when DT_NOCLIP is used.</para>  <list> <item><term>DT_RIGHT</term> </list>  <para>Aligns text to the right.</para>  <list> <item><term>DT_RTLREADING</term> </list>  <para>Displays text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.</para>  <list> <item><term>DT_SINGLELINE</term> </list>  <para>Displays text on a single line only. Carriage returns and line feeds do not break the line.</para>  <list> <item><term>DT_TOP</term> </list>  <para>Top-justifies text.</para>  <list> <item><term>DT_VCENTER</term> </list>  <para>Centers text vertically (single line only).</para>  <list> <item><term>DT_WORDBREAK</term> </list>  <para>Breaks words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.</para>   <para>?</para></param>
 /// <param name="textHeight">The height of the formatted text but does not draw the text.</param>	
 /// <returns>Determines the width and height of the rectangle. If there are multiple lines of text, this function uses the width of the rectangle pointed to by the rect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, this method modifies the right side of the rectangle so that it bounds the last character in the line. </returns>
 /// <unmanaged>int ID3DX10Font::DrawTextW([In] ID3DX10Sprite* pSprite,[In] const wchar_t* pString,[In] int Count,[In] RECT* pRect,[In] unsigned int Format,[In] D3DXCOLOR Color)</unmanaged>	
 public unsafe SharpDX.Rectangle MeasureText(Sprite sprite, string text, SharpDX.Rectangle rect, FontDrawFlags drawFlags, out int textHeight)
 {
     // DT_CALCRECT
     textHeight = DrawText(sprite, text, text.Length, new IntPtr(&rect), ((int)drawFlags) | 0x400, Color.White);
     return rect;
 }
Beispiel #31
-1
 /// <summary>	
 /// Draw formatted text.
 /// </summary>	
 /// <remarks>	
 /// The parameters of this method are very similar to those of the {{GDI DrawText}} function. This method supports both ANSI and Unicode strings. Unless the DT_NOCLIP format is used, this method clips the text so that it does not appear outside the specified rectangle. All formatting is assumed to have multiple lines unless the DT_SINGLELINE format is specified. If the selected font is too large for the rectangle, this method does not attempt to substitute a smaller font. This method supports only fonts whose escapement and orientation are both zero. 	
 /// </remarks>	
 /// <param name="sprite">Reference to an ID3DX10Sprite object that contains the string you wish to draw. Can be NULL, in which case Direct3D will render the string with its own sprite object. To improve efficiency, a sprite object should be specified if ID3DX10Font::DrawText is to be called more than once in a row. </param>
 /// <param name="text">Pointer to a string to draw. If UNICODE is defined, this parameter type resolves to an LPCWSTR, otherwise, the type resolves to an LPCSTR. If the Count parameter is -1, the string must be NULL terminated. </param>
 /// <param name="rect">Pointer to a <see cref="RawRectangle"/> structure that contains the rectangle, in logical coordinates, in which the text is to be formatted. As with any RECT object, the coordinate value of the rectangle's right side must be greater than that of its left side. Likewise, the coordinate value of the bottom must be greater than that of the top. </param>
 /// <param name="drawFlags">Specify the method of formatting the text. It can be any combination of the following values:    ItemDescription  DT_BOTTOM  Justify the text to the bottom of the rectangle. This value must be combined with DT_SINGLELINE.   DT_CALCRECT  Tell DrawText to automatically calculate the width and height of the rectangle based on the length of the string you tell it to draw. If there are multiple lines of text, ID3DX10Font::DrawText uses the width of the rectangle pointed to by the pRect parameter and extends the base of the rectangle to bound the last line of text. If there is only one line of text, ID3DX10Font::DrawText modifies the right side of the rectangle so that it bounds the last character in the line. In either case, ID3DX10Font::DrawText returns the height of the formatted text but does not draw the text.   DT_CENTER  Center text horizontally in the rectangle.   DT_EXPANDTABS  Expand tab characters. The default number of characters per tab is eight.   DT_LEFT  Align text to the left.   DT_NOCLIP  Draw without clipping. ID3DX10Font::DrawText is somewhat faster when DT_NOCLIP is used.   DT_RIGHT  Align text to the right.   DT_RTLREADING  Display text in right-to-left reading order for bidirectional text when a Hebrew or Arabic font is selected. The default reading order for all text is left-to-right.   DT_SINGLELINE  Display text on a single line only. Carriage returns and line feeds do not break the line.   DT_TOP  Top-justify text.   DT_VCENTER  Center text vertically (single line only).   DT_WORDBREAK  Break words. Lines are automatically broken between words if a word would extend past the edge of the rectangle specified by the pRect parameter. A carriage return/line feed sequence also breaks the line.   ? </param>
 /// <param name="color">Color of the text. See <see cref="RawColor4"/>. </param>
 /// <returns>If the function succeeds, the return value is the height of the text in logical units. If DT_VCENTER or DT_BOTTOM is specified, the return value is the offset from pRect (top to the bottom) of the drawn text. If the function fails, the return value is zero. </returns>
 /// <unmanaged>int ID3DX10Font::DrawTextW([None] LPD3DX10SPRITE pSprite,[None] const wchar_t* pString,[None] int Count,[None] RECT* pRect,[None] int Format,[None] D3DXCOLOR Color)</unmanaged>
 public unsafe int DrawText(SharpDX.Direct3D10.Sprite sprite, string text, RawRectangle rect, FontDrawFlags drawFlags, RawColor4 color)
 {
     int value = DrawText(sprite, text, text.Length, new IntPtr(&rect), (int) drawFlags, color);
     if (value == 0)
         throw new SharpDXException("Draw failed");
     return value;
 }