예제 #1
0
        /// <summary>
        /// Write all
        /// </summary>
        public void WriteAll()
        {
            if (remTexts.Count == 0)
            {
                return;
            }

            // Start rendering
            fontSprite.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            // Draw each character in the text
            //foreach (UIRenderer.FontToRender fontText in texts)
            for (int textNum = 0; textNum < remTexts.Count; textNum++)
            {
                FontToRender fontText = remTexts[textNum];

                int   x     = fontText.x;
                int   y     = fontText.y;
                Color color = fontText.color;
                //foreach (char c in fontText.text)
                char[] chars = fontText.text.ToCharArray();
                for (int num = 0; num < chars.Length; num++)
                {
                    int charNum = (int)chars[num];
                    if (charNum >= 32 &&
                        charNum - 32 < CharRects.Length)
                    {
                        // Draw this char
                        Rectangle rect = CharRects[charNum - 32];
                        // Reduce height to prevent overlapping pixels
                        rect.Y     += 1;
                        rect.Height = FontHeight;
                        Rectangle destRect = new Rectangle(x,
                                                           y - BaseGame.YToRes1050(SubRenderHeight),
                                                           rect.Width, rect.Height);

                        // Scale destRect (1600x1200 is the base size)
                        destRect.Width = BaseGame.XToRes1400(
                            (int)Math.Round(destRect.Width * fontText.scale));
                        destRect.Height = BaseGame.YToRes1050(
                            (int)Math.Round(destRect.Height * fontText.scale));

                        // Since we want upscaling, we use the modified destRect
                        fontSprite.Draw(fontTexture.XnaTexture, destRect, rect, color);

                        // Increase x pos by width we use for this character
                        int charWidth = CharRects[charNum - 32].Height;
                        x += BaseGame.XToRes1400(
                            (int)Math.Round(charWidth * fontText.scale));
                    }
                }
            }

            // End rendering
            fontSprite.End();

            remTexts.Clear();
        }
예제 #2
0
        }         // WriteText(x, y, text)

        /// <summary>
        /// Write all
        /// </summary>
        /// <param name="texts">Texts</param>
        public void WriteAll()
        {
            if (remTexts.Count == 0)
            {
                return;
            }

            fontSprite.Begin(SpriteSortMode.Texture, BlendState.AlphaBlend);

            for (int textNum = 0; textNum < remTexts.Count; textNum++)
            {
                FontToRender fontText = remTexts[textNum];

                int   x     = fontText.x;
                int   y     = fontText.y;
                Color color = fontText.color;
                //foreach (char c in fontText.text)
                char[] chars = fontText.text.ToCharArray();
                for (int num = 0; num < chars.Length; num++)
                {
                    int charNum = (int)chars[num];
                    if (charNum >= 32 && charNum - 32 < CharRects.Length)
                    {
                        // Draw this char
                        Rectangle rect = CharRects[charNum - 32];
                        // Reduce height to prevent overlapping pixels
                        rect.Y     += 1;
                        rect.Height = FontHeight;                        // Height;// - 1;
                        // Add 2 pixel for g, j, y
                        //if (c == 'g' || c == 'j' || c == 'y')
                        //	rect.Height+=2;
                        Rectangle destRect = new Rectangle(x, y - SubRenderHeight, rect.Width, rect.Height);
                        fontSprite.Draw(fontTexture, new Rectangle(destRect.X * BaseGame.Width / 1024, destRect.Y * BaseGame.Height / 768, destRect.Width * BaseGame.Width / 1024, destRect.Height * BaseGame.Height / 768), rect, color);

                        int charWidth = CharRects[charNum - 32].Height;
                        x += charWidth;
                    }     // if (charNum)
                }         // foreach
            }             // foreach (fontText)

            // End rendering
            fontSprite.End();

            remTexts.Clear();
        } // WriteAll(texts)
        }         // WriteTextCentered(x, y, text)

        /// <summary>
        /// Write all
        /// </summary>
        /// <param name="texts">Texts</param>
        public void WriteAll()
        {
            if (remTexts.Count == 0)
            {
                return;
            }

            // Start rendering
            fontSprite.Begin(SpriteBlendMode.AlphaBlend);

            // Draw each character in the text
            //foreach (UIRenderer.FontToRender fontText in texts)
            for (int textNum = 0; textNum < remTexts.Count; textNum++)
            {
                FontToRender fontText = remTexts[textNum];

                int   x     = fontText.x;
                int   y     = fontText.y;
                Color color = fontText.color;
                //foreach (char c in fontText.text)
                char[] chars = fontText.text.ToCharArray();
                for (int num = 0; num < chars.Length; num++)
                {
                    int charNum = (int)chars[num];
                    if (charNum >= 32 &&
                        charNum - 32 < CharRects.Length)
                    {
                        // Draw this char
                        Rectangle rect = CharRects[charNum - 32];
                        // Reduce height to prevent overlapping pixels
                        rect.Y     += 1;
                        rect.Height = FontHeight;                        // Height;// - 1;
                        // Add 2 pixel for g, j, y
                        //if (c == 'g' || c == 'j' || c == 'y')
                        //	rect.Height+=2;
                        Rectangle destRect = new Rectangle(x,
                                                           y - SubRenderHeight,
                                                           rect.Width, rect.Height);

                        // Scale destRect (1600x1200 is the base size)
                        //destRect.Width = destRect.Width;
                        //destRect.Height = destRect.Height;

                        //TODO: if we want upscaling, just use destRect
                        fontSprite.Draw(fontTexture.XnaTexture, //obs:destRect,
                                                                // Rescale to fit resolution
                                        destRect,
                                                                //new Rectangle(
                                                                //destRect.X * BaseGame.Width / 1024,
                                                                //destRect.Y * BaseGame.Height / 768,
                                                                //destRect.Width * BaseGame.Width / 1024,
                                                                //destRect.Height * BaseGame.Height / 768),
                                        rect, color);
                        //,
                        // Make sure fonts are always displayed at the front of everything
                        //0, Vector2.Zero, SpriteEffects.None, 1.1f);

                        // Increase x pos by width we use for this character
                        int charWidth = CharRects[charNum - 32].Height;
                        x += charWidth;
                    }     // if (charNum)
                }         // foreach
            }             // foreach (fontText)

            // End rendering
            fontSprite.End();

            remTexts.Clear();
        }         // WriteAll(texts)