Example #1
0
        public TextBox(Rectangle area, int maxCharacters, string text, GraphicsDevice graphicsDevice,
                       SpriteFont spriteFont, bool upperCase, bool lettersOnly, bool canSelect,
                       Color barColor, Color activeBarColor, Color fontColor, Color cursorColor, Color selectionColor,
                       int textPaddingTop, int textPaddingLeft)
        {
            GraphicsDevice = graphicsDevice;
            area           = new Rectangle(area.X - (area.Width / 2), area.Y, area.Width, area.Height);
            _lettersOnly   = lettersOnly;
            _upperCase     = upperCase;
            _canSelect     = canSelect;

            Text = new Text(maxCharacters)
            {
                String = text
            };

            Renderer = new TextRenderer(this, textPaddingTop, textPaddingLeft)
            {
                Area  = area,
                Font  = spriteFont,
                Color = fontColor
            };

            Cursor = new Cursor(this, cursorColor, selectionColor, new Rectangle(0, 0, 1, 1),
                                textPaddingLeft);

            KeyboardInput.CharPressed += CharacterTyped;
            KeyboardInput.KeyPressed  += KeyPressed;

            _bar            = area;
            _barColor       = barColor;
            _activeBarColor = activeBarColor;

            MenuList.AddMenuItem(this);
        }