Exemple #1
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (focused)
            {
                Terraria.GameInput.PlayerInput.WritingText = true;
                Main.instance.HandleIME();
                string oldText = Text;
                Text = Main.GetInputText(Text);
                if (oldText != Text)
                {
                    KeyPressed?.Invoke(this, ' ');
                }
                if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Tab))
                {
                    OnTabPress?.Invoke(this, new EventArgs());
                }
                if (Main.keyState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Enter))
                {
                    OnEnterPress?.Invoke(this, new EventArgs());
                }
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Main.UIScaleMatrix);
                Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f);
            }

            spriteBatch.Draw(textboxBackground, DrawPosition, null, Color.White, 0f, Origin, 1f, SpriteEffects.None, 0f);
            int     fillWidth = (int)Width - 2 * textboxBackground.Width;
            Vector2 pos       = DrawPosition;

            pos.X += textboxBackground.Width;
            spriteBatch.Draw(TextboxFill, pos - Origin, null, Color.White, 0f, Vector2.Zero, new Vector2(fillWidth, 1f), SpriteEffects.None, 0f);
            pos.X += fillWidth;
            spriteBatch.Draw(textboxBackground, pos, null, Color.White, 0f, Origin, 1f, SpriteEffects.FlipHorizontally, 0f);
            string drawString = Text;

            if (PasswordBox)
            {
                drawString = passwordString;
            }
            if (drawCarrot && focused)
            {
                drawString += "|";
            }
            label.Text = drawString;

            pos = DrawPosition - Origin;

            if (pos.X <= Main.screenWidth && pos.Y <= Main.screenHeight && pos.X + Width >= 0 && pos.Y + Height >= 0)
            {
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, _rasterizerState, null, Main.UIScaleMatrix);

                Rectangle cutRect = new Rectangle((int)pos.X, (int)pos.Y, (int)Width, (int)Height);

                /*if (cutRect.X < 0)
                 * {
                 *      cutRect.Width += cutRect.X;
                 *      cutRect.X = 0;
                 * }
                 * if (cutRect.Y < 0)
                 * {
                 *      cutRect.Height += cutRect.Y;
                 *      cutRect.Y = 0;
                 * }
                 * if (cutRect.X + Width > Main.screenWidth) cutRect.Width = Main.screenWidth - cutRect.X;
                 * if (cutRect.Y + Height > Main.screenHeight) cutRect.Height = Main.screenHeight - cutRect.Y;*/
                cutRect = CheatSheet.GetClippingRectangle(spriteBatch, cutRect);
                Rectangle currentRect = spriteBatch.GraphicsDevice.ScissorRectangle;
                spriteBatch.GraphicsDevice.ScissorRectangle = cutRect;

                base.Draw(spriteBatch);

                spriteBatch.GraphicsDevice.ScissorRectangle = currentRect;
                spriteBatch.End();
                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null, Main.UIScaleMatrix);
            }
        }
Exemple #2
0
 private void TabPress()
 {
     OnTabPress?.Invoke(this, EventArgs.Empty);
 }