Beispiel #1
0
        public override void Draw()
        {
            SpriteFont font;

            if (!Game.Renderer.Fonts.TryGetValue(Font, out font))
            {
                throw new ArgumentException("Requested font '{0}' was not found.".F(Font));
            }

            var text = GetText();

            if (text == null)
            {
                return;
            }

            var textSize = font.Measure(text);
            var position = RenderOrigin;

            if (VAlign == TextVAlign.Middle)
            {
                position += new int2(0, (Bounds.Height - textSize.Y) / 2);
            }

            if (VAlign == TextVAlign.Bottom)
            {
                position += new int2(0, Bounds.Height - textSize.Y);
            }

            if (Align == TextAlign.Center)
            {
                position += new int2((Bounds.Width - textSize.X) / 2, 0);
            }

            if (Align == TextAlign.Right)
            {
                position += new int2(Bounds.Width - textSize.X, 0);
            }

            if (WordWrap)
            {
                text = WidgetUtils.WrapText(text, Bounds.Width, font);
            }

            var color    = GetColor();
            var contrast = GetContrastColor();

            if (Contrast)
            {
                font.DrawTextWithContrast(text, position, color, contrast, 2);
            }
            else
            {
                font.DrawText(text, position, color);
            }
        }
Beispiel #2
0
        public override void Draw()
        {
            SpriteFont font;

            if (!Game.Renderer.Fonts.TryGetValue(Font, out font))
            {
                throw new ArgumentException("Requested font '{0}' was not found.".F(Font));
            }

            var text = GetText();

            if (text == null)
            {
                return;
            }

            var textSize = font.Measure(text);
            var position = RenderOrigin;
            var offset   = font.TopOffset;

            if (VAlign == TextVAlign.Top)
            {
                position += new int2(0, -offset);
            }

            if (VAlign == TextVAlign.Middle)
            {
                position += new int2(0, (Bounds.Height - textSize.Y - offset) / 2);
            }

            if (VAlign == TextVAlign.Bottom)
            {
                position += new int2(0, Bounds.Height - textSize.Y);
            }

            if (Align == TextAlign.Center)
            {
                position += new int2((Bounds.Width - textSize.X) / 2, 0);
            }

            if (Align == TextAlign.Right)
            {
                position += new int2(Bounds.Width - textSize.X, 0);
            }

            if (WordWrap)
            {
                text = WidgetUtils.WrapText(text, Bounds.Width, font);
            }

            DrawInner(text, font, GetColor(), position);
        }
Beispiel #3
0
        public override void Draw()
        {
            var pos         = RenderOrigin;
            var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
            var chatpos     = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 5);

            var font = Game.Renderer.Fonts["Regular"];

            Game.Renderer.EnableScissor(chatLogArea);

            foreach (var line in recentLines.AsEnumerable().Reverse())
            {
                var    inset = 0;
                string owner = null;

                if (!string.IsNullOrEmpty(line.Owner))
                {
                    owner = line.Owner + ":";
                    inset = font.Measure(owner).X + 5;
                }

                var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
                chatpos = chatpos.WithY(chatpos.Y - (Math.Max(15, font.Measure(text).Y) + 5));

                if (chatpos.Y < pos.Y)
                {
                    break;
                }

                if (owner != null)
                {
                    font.DrawTextWithContrast(owner, chatpos,
                                              line.Color, Color.Black, UseContrast ? 1 : 0);
                }

                font.DrawTextWithContrast(text, chatpos + new int2(inset, 0),
                                          Color.White, Color.Black, UseContrast ? 1 : 0);
            }

            Game.Renderer.DisableScissor();
        }
Beispiel #4
0
        public override void Draw()
        {
            var pos         = RenderOrigin;
            var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
            var chatPos     = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 8);

            var font = Game.Renderer.Fonts["Regular"];

            Game.Renderer.EnableScissor(chatLogArea);

            foreach (var line in recentLines.AsEnumerable().Reverse())
            {
                var    lineHeight = TextLineBoxHeight;
                var    inset      = 0;
                string name       = null;

                if (!string.IsNullOrEmpty(line.Name))
                {
                    name  = line.Name + ":";
                    inset = font.Measure(name).X + 5;
                }

                var text     = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
                var textSize = font.Measure(text).Y;
                var offset   = font.TopOffset;

                if (chatPos.Y - font.TopOffset < pos.Y)
                {
                    break;
                }

                var textLineHeight = lineHeight;

                var dh = textSize - textLineHeight;
                if (dh > 0)
                {
                    textLineHeight += dh;
                }

                var textOffset = textLineHeight - (textLineHeight - textSize - offset) / 2;
                var textPos    = new int2(chatPos.X + inset, chatPos.Y - textOffset);

                if (name != null)
                {
                    var nameSize = font.Measure(name).Y;
                    var namePos  = chatPos.WithY(chatPos.Y - (textLineHeight - (lineHeight - nameSize - offset) / 2));

                    if (UseContrast)
                    {
                        font.DrawTextWithContrast(name, namePos,
                                                  line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
                    }
                    else if (UseShadow)
                    {
                        font.DrawTextWithShadow(name, namePos,
                                                line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
                    }
                    else
                    {
                        font.DrawText(name, namePos, line.NameColor);
                    }
                }

                if (UseContrast)
                {
                    font.DrawTextWithContrast(text, textPos,
                                              line.TextColor, Color.Black, 1);
                }
                else if (UseShadow)
                {
                    font.DrawTextWithShadow(text, textPos,
                                            line.TextColor, Color.Black, 1);
                }
                else
                {
                    font.DrawText(text, textPos, Color.White);
                }

                chatPos = chatPos.WithY(chatPos.Y - Space - textLineHeight);
            }

            Game.Renderer.DisableScissor();
        }
        public override void Draw()
        {
            var pos         = RenderOrigin;
            var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
            var chatpos     = new int2(chatLogArea.X + 5, chatLogArea.Bottom - 5);

            var font = Game.Renderer.Fonts["Regular"];

            Game.Renderer.EnableScissor(chatLogArea);

            foreach (var line in recentLines.AsEnumerable().Reverse())
            {
                var    inset = 0;
                string name  = null;

                if (!string.IsNullOrEmpty(line.Name))
                {
                    name  = line.Name + ":";
                    inset = font.Measure(name).X + 5;
                }

                var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font);
                chatpos = chatpos.WithY(chatpos.Y - (Math.Max(15, font.Measure(text).Y) + 5));

                if (chatpos.Y < pos.Y)
                {
                    break;
                }

                if (name != null)
                {
                    if (UseContrast)
                    {
                        font.DrawTextWithContrast(name, chatpos,
                                                  line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
                    }
                    else if (UseShadow)
                    {
                        font.DrawTextWithShadow(name, chatpos,
                                                line.NameColor, BackgroundColorDark, BackgroundColorLight, 1);
                    }
                    else
                    {
                        font.DrawText(name, chatpos, line.NameColor);
                    }
                }

                if (UseContrast)
                {
                    font.DrawTextWithContrast(text, chatpos + new int2(inset, 0),
                                              line.TextColor, Color.Black, 1);
                }
                else if (UseShadow)
                {
                    font.DrawTextWithShadow(text, chatpos + new int2(inset, 0),
                                            line.TextColor, Color.Black, 1);
                }
                else
                {
                    font.DrawText(text, chatpos + new int2(inset, 0), Color.White);
                }
            }

            Game.Renderer.DisableScissor();
        }