示例#1
0
        /// <summary>
        /// Called when drawing the HUD component.
        /// </summary>
        /// <param name="batch">The sprite batch instance.</param>
        /// <param name="position"></param>
        protected override void OnDraw(SpriteBatch batch, Vector2 position)
        {
            if (this.Visible)
            {
                // Background

                batch.Draw(this.texture, new Rectangle((int)position.X, (int)position.Y, (int)this.Size.X, (int)this.Size.Y), this.color);

                // Borders
                batch.DrawLine(position, position + new Vector2(this.Size.X, 0), Color.Black, 2);
                batch.DrawLine(position + new Vector2(this.Size.X, 0), position + new Vector2(this.Size.X, this.Size.Y), Color.Black, 2);
                batch.DrawLine(position + new Vector2(this.Size.X, this.Size.Y), position + new Vector2(0, this.Size.Y), Color.Black, 2);
                batch.DrawLine(position + new Vector2(0, this.Size.Y), position, Color.Black, 2);

                batch.EnableScissor(new Rectangle((int)position.X + 2, (int)position.Y + 2, (int)this.Size.X - 4, (int)this.Size.Y - 4));
                {
                    var text = this.Password ? (this.Text.Length > 0 ? Enumerable.Repeat("*", this.Text.Length).Aggregate((s, n) => s + n) : "") : this.Text;
                    var size = this.font.Content.MeasureString(this.Text);
                    var pos = position + new Vector2(5, (this.Size.Y - size.Y) / 2);
                    if (size.X > this.Size.X - 10)
                    {
                        pos.X = (pos.X + this.Size.X - 10) - size.X;
                    }
                    batch.DrawString(this.font.Content, text, pos, Color.Black);
                }
                batch.DisableScissor();
            }
        }
示例#2
0
        /// <summary>
        /// Draw
        /// </summary>
        /// <param name="batch"></param>
        /// <param name="position"></param>
        protected override void OnDraw(SpriteBatch batch, Vector2 position)
        {
            if (this.Visible)
            {
                // Background
                batch.Draw(this.texture, new Rectangle((int)position.X, (int)position.Y, (int)this.Size.X, (int)this.Size.Y), this.color);

                // Borders
                batch.DrawLine(position, position + new Vector2(this.Size.X, 0), Color.Black, 2);
                batch.DrawLine(position + new Vector2(this.Size.X, 0), position + new Vector2(this.Size.X, this.Size.Y), Color.Black, 2);
                batch.DrawLine(position + new Vector2(this.Size.X, this.Size.Y), position + new Vector2(0, this.Size.Y), Color.Black, 2);
                batch.DrawLine(position + new Vector2(0, this.Size.Y), position, Color.Black, 2);

                batch.EnableScissor(new Rectangle((int)position.X + 2, (int)position.Y + 2, (int)this.Size.X - 2, (int)this.Size.Y - 2));
                {
                    batch.Draw(this.texture, new Rectangle(0, 0, 1, 1), Color.White * 0.0f);

                    var lastPosition = position + new Vector2(2, this.Size.Y - 2);
                    for (int i = this.messages.Count - 1; i >= 0; i--)
                    {
                        var text = this.messages[i];
                        var size = this.font.Content.MeasureText(text);
                        lastPosition.Y -= size.Y;
                        batch.DrawString(this.font.Content, text, lastPosition, Color.Black);
                    }
                }
                batch.DisableScissor();
            }
        }