public override void OnRenderFrame(Device device, float elapsedTime)
 {
     base.OnRenderFrame(device, elapsedTime);
     StringBlock b = new StringBlock("FPS:" + ((int)GM.AppWindow.FPS).ToString(), new RectangleF(10, 10, 120, 50), Align.Left, 22, ColorValue.FromColor(Color.Red), false);
     BitmapFont font = GM.FontManager.GetFamily("Arial").GetFont(22);
     font.Render(device, font.GetProcessedQuads(b));
 }
示例#2
0
 private void RenderLoadingInfo(Device device)
 {
     SizeF windowSize = GM.AppWindow.GraphicsParameters.WindowSize;
     StringBlock b = new StringBlock(reporter.Info,
         new System.Drawing.RectangleF(windowSize.Width / 2 - 200, windowSize.Height / 2 - 20, 400, 35),
         Align.Center, 35, ColorValue.FromColor(Color.Blue), true);
     List<Quad> quads = GM.FontManager.GetDefaultFamily().GetFont(35).GetProcessedQuads(b);
     GM.FontManager.GetDefaultFamily().GetFont(35).Render(device, quads);
 }
示例#3
0
        protected override void BuildTextQuads()
        {
            StringBlock b = new StringBlock(m_text, m_textRect, m_alignment, m_fontSize, ColorValue.FromColor(Color.Black), true);
            m_textQuads = GM.FontManager.GetFont(FontName, m_fontSize).GetProcessedQuads(b);

            foreach (Quad q in m_textQuads)
            {
                q.X += m_positionDelta.X;
                q.Y += m_positionDelta.Y;
            }
        }
示例#4
0
        private void BuildHeaderQuads()
        {
            headerQuads.Clear();
            BitmapFont font = GM.FontManager.GetFamily("Arial").GetFont(22);
            StringBlock b = new StringBlock("Zabójcy:" + gameController.AssassinsScore.ToString() + " Rycerze:" + gameController.KnightsScore.ToString(),
                new RectangleF(nameX, headerY, controlRect.Width, 40), Align.Center, 40,
                ColorValue.FromColor(Color.Yellow), true);
            headerQuads.AddRange(font.GetProcessedQuads(b));
            b = new StringBlock("PLAYER", new RectangleF(nameX, headerY + 40, 100, 22), Align.Left, 22,
                ColorValue.FromColor(Color.Yellow), true);
            headerQuads.AddRange(font.GetProcessedQuads(b));

            b = new StringBlock("FRAGS", new RectangleF(fragsX, headerY + 40, 80, 22), Align.Left, 22,
                ColorValue.FromColor(Color.Yellow), true);
            headerQuads.AddRange(font.GetProcessedQuads(b));

            b = new StringBlock("DEATHS", new RectangleF(deathsX, headerY + 40, 80, 22), Align.Left, 22,
                ColorValue.FromColor(Color.Yellow), true);
            headerQuads.AddRange(font.GetProcessedQuads(b));
        }
示例#5
0
 protected override void BuildTextQuads()
 {
     StringBlock b = new StringBlock(m_windowTitle,new RectangleF( m_titleRect.X + m_positionDelta.X, m_titleRect.Y + m_positionDelta.Y,
         m_titleRect.Width, m_titleRect.Height), Align.Left, m_titleRect.Height, ColorValue.FromColor(Color.Black), true);
     m_fontSize = m_titleRect.Height;
     m_titleQuads = GM.FontManager.GetFont(FontName, m_fontSize).GetProcessedQuads(b);
 }
示例#6
0
        private void BuildPlayerQuads()
        {
            playerQuads.Clear();
            BitmapFont font = GM.FontManager.GetFamily("Arial").GetFont(18);
            StringBlock b;
            int currentY = playerY;
            foreach (Player p in World.Instance.Players)
            {

                Color color;
                if (p.CharacterClass != null)
                {
                    if (p.CharacterClass.GameTeam == GameTeam.Assassins)
                        color = Color.Green;
                    else
                        color = Color.Gray;
                }
                else
                    color = Color.Yellow;
                b = new StringBlock(p.Name, new RectangleF(nameX, currentY, 100, 20), Align.Left, 18,
                ColorValue.FromColor(color), true);
                playerQuads.AddRange(font.GetProcessedQuads(b));

                //b = new StringBlock(p.ShipClass.Name, new RectangleF(shipX, currentY, 100, 20), Align.Left, 18,
                //ColorValue.FromColor(Color.Yellow), true);
                //playerQuads.AddRange(font.GetProcessedQuads(b));

                b = new StringBlock(p.Frags.ToString(), new RectangleF(fragsX, currentY, 80, 20), Align.Left, 18,
                    ColorValue.FromColor(color), true);
                playerQuads.AddRange(font.GetProcessedQuads(b));

                b = new StringBlock(p.Deaths.ToString(), new RectangleF(deathsX, currentY, 80, 20), Align.Left, 18,
                    ColorValue.FromColor(color), true);
                playerQuads.AddRange(font.GetProcessedQuads(b));

                currentY += 20;
            }
        }
示例#7
0
 public List<Quad> GetProcessedQuads(StringBlock b)
 {
     BitmapFont font = GetFont(b.Size);
     if (font != null)
         return font.GetProcessedQuads(b);
     else
         return new List<Quad>();
 }
示例#8
0
        public List<Quad> GetProcessedQuads(StringBlock b)
        {
            List<Quad> quads = new List<Quad>();
            if (b.Text == null)
                return quads;   //empty list

            string text = b.Text;

            float max_y = Math.Min(b.TextRect.Bottom, b.ViewportRect.Bottom);
            float x = b.TextRect.X;
            float y = b.TextRect.Y;

            float maxWidth = b.TextRect.Width;
            Align alignment = b.Alignment;
            float lineWidth = 0f;
            float sizeScale = b.Size / (float)m_charSet.LineHeight;
            char lastChar = new char();
            int lineNumber = 1;
            int wordNumber = 1;
            //int numWords = 0;
            int quadsInWord = 0;
            int quadsInLine = 0;
            //float wordWidth = 0f;
            bool firstCharOfLine = true;

            float z = 0f;
            float rhw = 1f;

            for (int i = 0; i < text.Length; i++)
            {
                //if (text[i] < 0 || text[i] > 255)
                //    continue;
                BitmapCharacter c = (BitmapCharacter)m_charSet.Characters[text[i]];
                if (c == null)
                    continue;
                float xOffset = c.XOffset * sizeScale;
                float yOffset = c.YOffset * sizeScale;
                float xAdvance = c.XAdvance * sizeScale;
                float width = c.Width * sizeScale;
                float height = c.Height * sizeScale;

                // Check vertical bounds
                if (y > max_y)
                {
                    break;
                }
                //if(

                //check other bounds

                // Newline
                if (text[i] == '\n' || text[i] == '\r' || (lineWidth >= maxWidth))
                {
                    if (alignment == Align.Left)
                    {
                        // Start at left
                        x = b.TextRect.X;
                    }
                    if (alignment == Align.Center)
                    {
                        // Start in center
                        x = b.TextRect.X + (maxWidth / 2f);
                    }
                    else if (alignment == Align.Right)
                    {
                        // Start at right
                        x = b.TextRect.Right;
                    }

                    y += m_charSet.LineHeight * sizeScale;
                    // Check vertical bounds

                    float offset = 0f;

                    if ((lineWidth + xAdvance >= maxWidth) && (wordNumber != 1))
                    {
                        // Next character extends past text box width
                        // We have to move the last word down one line
                        lineWidth = 0f;
                        i -= quadsInWord;
                        for (int j = quads.Count - quadsInWord; j < quads.Count; j++, i++)
                        {
                            if (alignment == Align.Left)
                            {
                                // Move current word to the left side of the text box

                                //quads[j].LineNumber++;
                                //quads[j].WordNumber = 1;
                                quads[j].X = x + ((BitmapCharacter)m_charSet.Characters[text[i]]).XOffset * sizeScale;
                                quads[j].Y = y + ((BitmapCharacter)m_charSet.Characters[text[i]]).YOffset * sizeScale;
                                x += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                lineWidth += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                if (b.Kerning && j != quads.Count - 1)
                                {
                                    m_nextChar = text[i + 1];
                                    Kerning kern = ((BitmapCharacter)m_charSet.Characters[text[i]]).KerningList.Find(FindKerningNode);
                                    if (kern != null)
                                    {
                                        x += kern.Amount * sizeScale;
                                        lineWidth += kern.Amount * sizeScale;
                                    }
                                }

                            }
                            else if (alignment == Align.Center)
                            {

                                // First move word down to next line
                                //quads[j].LineNumber++;
                                //quads[j].WordNumber = 1;
                                quads[j].X = x + ((BitmapCharacter)m_charSet.Characters[text[i]]).XOffset * sizeScale;
                                quads[j].Y = y + ((BitmapCharacter)m_charSet.Characters[text[i]]).YOffset * sizeScale;
                                x += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                lineWidth += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                offset += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale / 2f;
                                float kerning = 0f;
                                if (b.Kerning && j != quads.Count - 1)
                                {
                                    m_nextChar = text[i + 1];
                                    Kerning kern = ((BitmapCharacter)m_charSet.Characters[text[i]]).KerningList.Find(FindKerningNode);
                                    if (kern != null)
                                    {
                                        kerning = kern.Amount * sizeScale;
                                        x += kerning;
                                        lineWidth += kerning;
                                        offset += kerning / 2f;
                                    }
                                }

                            }
                            else if (alignment == Align.Right)
                            {

                                // Move character down to next line
                                //quads[j].LineNumber++;
                                //quads[j].WordNumber = 1;
                                quads[j].X = x + ((BitmapCharacter)m_charSet.Characters[text[i]]).XOffset * sizeScale;
                                quads[j].Y = y + ((BitmapCharacter)m_charSet.Characters[text[i]]).YOffset * sizeScale;
                                lineWidth += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                x += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                offset += ((BitmapCharacter)m_charSet.Characters[text[i]]).XAdvance * sizeScale;
                                float kerning = 0f;
                                if (b.Kerning && j != quads.Count - 1)
                                {
                                    m_nextChar = text[i + 1];
                                    Kerning kern = ((BitmapCharacter)m_charSet.Characters[text[i]]).KerningList.Find(FindKerningNode);
                                    if (kern != null)
                                    {
                                        kerning = kern.Amount * sizeScale;
                                        x += kerning;
                                        lineWidth += kerning;
                                        offset += kerning;
                                    }
                                }

                            }
                            //newLineLastChar = quads[j].Character;
                        }

                        // Make post-newline justifications
                        if (alignment == Align.Center || alignment == Align.Right)
                        {
                            // Justify the new line
                            for (int k = quads.Count - quadsInWord; k < quads.Count; k++)
                            {
                                quads[k].X -= offset;
                            }
                            x -= offset;

                            // Rejustify the line it was moved from
                            for (int k = quads.Count - quadsInLine; k < quads.Count - quadsInWord; k++)
                            {
                                quads[k].X += offset;
                            }
                        }
                        quadsInLine = quadsInWord;
                    }
                    else
                    {
                        // New line without any "carry-down" word
                        firstCharOfLine = true;
                        lineWidth = 0f;
                        quadsInLine = 0;
                        quadsInWord = 0;
                    }

                    wordNumber = 1;
                    lineNumber++;

                } // End new line check

                // Don't print these
                if (text[i] == '\n' || text[i] == '\r' || text[i] == '\t')
                {
                    continue;
                }

                // Set starting cursor for alignment
                if (firstCharOfLine)
                {
                    if (alignment == Align.Left)
                    {
                        // Start at left
                        x = b.TextRect.Left;
                    }
                    if (alignment == Align.Center)
                    {
                        // Start in center
                        x = b.TextRect.Left + (maxWidth / 2f);
                    }
                    else if (alignment == Align.Right)
                    {
                        // Start at right
                        x = b.TextRect.Right;
                    }
                }

                // Adjust for kerning
                float kernAmount = 0f;
                if (b.Kerning && !firstCharOfLine)
                {
                    m_nextChar = (char)text[i];
                    Kerning kern = ((BitmapCharacter)m_charSet.Characters[lastChar]).KerningList.Find(FindKerningNode);
                    if (kern != null)
                    {
                        kernAmount = kern.Amount * sizeScale;
                        x += kernAmount;
                        lineWidth += kernAmount;
                        //wordWidth += kernAmount;
                    }
                }

                // Create the vertices
                CustomVertex.TransformedColoredTextured topLeft = new CustomVertex.TransformedColoredTextured(
                    x + xOffset, y + yOffset, z, rhw, b.Color.ToArgb(),
                    (float)c.X / (float)m_charSet.Width,
                    (float)c.Y / (float)m_charSet.Height);

                CustomVertex.TransformedColoredTextured topRight = new CustomVertex.TransformedColoredTextured(
                    topLeft.X + width, topLeft.Y, z, rhw, b.Color.ToArgb(),
                    (float)(c.X + c.Width) / (float)m_charSet.Width,
                    topLeft.Tv);
                CustomVertex.TransformedColoredTextured bottomRight = new CustomVertex.TransformedColoredTextured(
                    topRight.X, topLeft.Y + height, z, rhw, b.Color.ToArgb(),
                    topRight.Tu,
                    (float)(c.Y + c.Height) / (float)m_charSet.Height);
                CustomVertex.TransformedColoredTextured bottomLeft = new CustomVertex.TransformedColoredTextured(
                    topLeft.X, bottomRight.Y, z, rhw, b.Color.ToArgb(),
                    topLeft.Tu,
                    bottomRight.Tv);

                // Create the quad
                Quad q = new Quad(topLeft, topRight, bottomLeft, bottomRight);

                quads.Add(q);

                quadsInLine++;
                quadsInWord++;

                if (text[i] == ' ')
                {
                    wordNumber++;
                    //wordWidth = 0f;
                    //numWords++;
                    quadsInWord = 0;
                }

                x += xAdvance;
                lineWidth += xAdvance;
                lastChar = text[i];
                //wordWidth += xAdvance;

                // Rejustify text
                if (alignment == Align.Center)
                {
                    // We have to recenter all Quads since we addded a
                    // new character
                    float offset = xAdvance / 2f;
                    if (b.Kerning && !firstCharOfLine)
                    {
                        offset += kernAmount / 2f;
                    }
                    for (int j = quads.Count - quadsInLine; j < quads.Count; j++)
                    {
                        quads[j].X -= offset;
                    }
                    x -= offset;
                }
                else if (alignment == Align.Right)
                {
                    // We have to rejustify all Quads since we addded a
                    // new character
                    float offset = xAdvance;
                    if (b.Kerning && !firstCharOfLine)
                    {
                        offset += kernAmount;
                    }
                    for (int j = quads.Count - quadsInLine; j < quads.Count; j++)
                    {
                        quads[j].X -= offset;
                    }
                    x -= offset;
                }
                firstCharOfLine = false;
            }
            for (int j = 0; j < quads.Count; j++)
            {
                if (!ClampToViewport(quads[j], b.ViewportRect))
                {
                    quads.RemoveAt(j);
                    j--;
                }
            }
            return quads;
        }
示例#9
0
 protected override void BuildTextQuads()
 {
     StringBlock b = new StringBlock(m_buttonText, new RectangleF(m_textRect.X + PositionDelta.X, m_textRect.Y + PositionDelta.Y, m_textRect.Width, m_textRect.Height), Align.Center, m_fontSize, ColorValue.FromColor(Color.Black), true);
     m_textQuads = GM.FontManager.GetFont(FontName, m_fontSize).GetProcessedQuads(b);
 }
示例#10
0
 ///// <summary>
 ///// Constructor
 ///// </summary>
 ///// <param name="name">Control's unique name</param>
 ///// <param name="rect">Control's size and position</param>
 ///// <param name="text">Control's text</param>
 ///// <param name="fontSize">Font size in pixels(max line height). 0 for default</param>
 ///// <param name="font">Font</param>
 ///// <param name="alignment">Text alignment</param>
 ///// <param name="color">Text color</param>
 //public GuiTextLabel(string name, string text, Rectangle rect, float fontSize,
 //    string fontName, Align alignment, Color color)
 //    : base(rect, name)
 //{
 //    m_text = text;
 //    m_fontSize = (fontSize == 0) ? DefaultValues.TextSize : fontSize;
 //    FontName = fontName;
 //    m_alignment = alignment;
 //    m_color = color;
 //    BuildTextQuads();
 //}
 protected override void BuildTextQuads()
 {
     StringBlock b = new StringBlock(m_text, new RectangleF(m_position.X+PositionDelta.X,m_position.Y+PositionDelta.Y, m_size.Width,m_size.Height),
         m_alignment, m_fontSize, ColorValue.FromColor(m_color), true);
     m_textQuads = GM.FontManager.GetFont(FontName, m_fontSize).GetProcessedQuads(b);
 }