示例#1
0
        protected override void DrawControl(IGraphicsBatch graphics)
        {
            int srcX = 0;

            if (this.IsMouseOver)
            {
                if (this.IsLeftMouseDown)
                {
                    srcX = 48;
                }
                else
                {
                    srcX = 24;
                }
            }

            Rectangle srcTopLeft = new Rectangle(srcX, 0, 8, 8);
            Rectangle srcTopCenter = new Rectangle(srcX + 8, 0, 8, 8);
            Rectangle srcTopRight = new Rectangle(srcX + 16, 0, 8, 8);

            Rectangle srcMiddleLeft = new Rectangle(srcX + 0, 8, 8, 8);
            Rectangle srcMiddleCenter = new Rectangle(srcX + 8, 8, 8, 8);
            Rectangle srcMiddleRight = new Rectangle(srcX + 16, 8, 8, 8);

            Rectangle srcBottomLeft = new Rectangle(srcX + 0, 16, 8, 8);
            Rectangle srcBottomCenter = new Rectangle(srcX + 8, 16, 8, 8);
            Rectangle srcBottomRight = new Rectangle(srcX + 16, 16, 8, 8);

            int x = (int)this.X;
            int y = (int)this.Y;

            int midWidth = this.Width - 16;
            int midHeight = this.Height - 16;

            Rectangle destTopLeft = new Rectangle(x, y, 8, 8);
            Rectangle destTopCenter = new Rectangle(x + 8, y, midWidth, 8);
            Rectangle destTopRight = new Rectangle(x + 8 + midWidth, y, 8, 8);

            Rectangle destMiddleLeft = new Rectangle(x, y + 8, 8, midHeight);
            Rectangle destMiddleCenter = new Rectangle(x + 8, y + 8, midWidth, midHeight);
            Rectangle destMiddleRight = new Rectangle(x + 8 + midWidth, y + 8, 8, midHeight);

            Rectangle destBottomLeft = new Rectangle(x, y + 8 + midHeight, 8, 8);
            Rectangle destBottomCenter = new Rectangle(x + 8, y + 8 + midHeight, midWidth, 8);
            Rectangle destBottomRight = new Rectangle(x + 8 + midWidth, y + 8 + midHeight, 8, 8);

            graphics.DrawTexture(this.Texture, destTopLeft, srcTopLeft, Color.White);
            graphics.DrawTexture(this.Texture, destTopCenter, srcTopCenter, Color.White);
            graphics.DrawTexture(this.Texture, destTopRight, srcTopRight, Color.White);

            graphics.DrawTexture(this.Texture, destMiddleLeft, srcMiddleLeft, Color.White);
            graphics.DrawTexture(this.Texture, destMiddleCenter, srcMiddleCenter, Color.White);
            graphics.DrawTexture(this.Texture, destMiddleRight, srcMiddleRight, Color.White);

            graphics.DrawTexture(this.Texture, destBottomLeft, srcBottomLeft, Color.White);
            graphics.DrawTexture(this.Texture, destBottomCenter, srcBottomCenter, Color.White);
            graphics.DrawTexture(this.Texture, destBottomRight, srcBottomRight, Color.White);

            if (!string.IsNullOrEmpty(this.Text))
                graphics.DrawString(this.Font, this.Text, this.ScreenRectangle, TextAlignment.MiddleCenter, Color.Gray);
        }
示例#2
0
        public void Draw(IGraphicsBatch graphics)
        {
            if (graphics == null)
                throw new ArgumentNullException("graphics");

            this.EnsureFont();

            if (this.IsVisible)
            {
                float top = 0.0f;

                if (this.State == GameConsoleState.SlideDown || this.State == GameConsoleState.SlideUp)
                    top = this.Height - (this.Height * (float)(this.AnimationTime.TotalSeconds / this.animationElapsedTime.TotalSeconds));

                Rectangle rectangle = new Rectangle(0, (int)top, this.Window.DisplayWidth, this.Height);

                if (this.BackgroundTexture != null)
                    graphics.DrawTexture(this.BackgroundTexture, rectangle, this.BackgroundColor);
                else
                    graphics.DrawFilledRectangle(rectangle, this.BackgroundColor);

                float y = top + this.Height - this.Padding;

                if (this.InputEnabled)
                {
                    y -= this.Font.LineHeight + this.Font.LineSpacing;

                    graphics.DrawString(this.Font, this.InputPrompt, new Vector2(this.Padding, y), this.InputColor);

                    Size promptSize = this.Font.MeasureString(this.InputPrompt);
                    graphics.DrawString(this.Font, this.input.ToString(), new Vector2(this.Padding + promptSize.Width, y), this.InputColor);

                    Size cursorLocation = Size.Zero;
                    if (this.cursorPosition > 0 && this.input.Length > 0)
                        cursorLocation = this.Font.MeasureString(this.input.ToString(), 0, this.cursorPosition);

                    graphics.DrawString(this.Font, "_", new Vector2(this.Padding + promptSize.Width + cursorLocation.Width, y), this.InputColor);
                }

                for (int i = 0; i < this.lineCount; i++)
                {
                    int index = this.firstLine - i;

                    if (index < 0)
                        index += this.lines.Length;

                    y -= this.Font.LineHeight + this.Font.LineSpacing;
                    graphics.DrawString(this.Font, this.lines[index].Text, new Vector2(this.Padding, y), this.lines[index].Color);
                }
            }
        }