Esempio n. 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;
            }

            int2 textSize = font.Measure(text);
            int2 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);
            }
        }
Esempio n. 2
0
        public override void Draw()
        {
            SpriteFont font = Game.Renderer.Fonts[Font];
            var        text = GetText();

            if (text == null)
            {
                return;
            }

            int2 textSize = font.Measure(text);
            int2 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);
            }
        }
Esempio n. 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 + 10, chatLogArea.Bottom - 6);

            if (DrawBackground)
            {
                WidgetUtils.DrawPanel("dialog3", chatLogArea);
            }

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

            Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);

            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 + 10;
                }

                var text      = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset, font);
                var textLines = text.Split(new[] { '\n' }).Count();
                chatpos.Y -= 20 * textLines;

                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();
        }
Esempio n. 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 - 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.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();
        }