Example #1
0
        private void DrawTextfields(Screen screen, GameTime time)
        {
            //Draw field background
            int buttonW = (int)(_buttonWidth * 0.2f);
            Rectangle left = new Rectangle(_r[1, 0].X, _r[1, 0].Y, buttonW, _r[1, 0].Height);
            Rectangle center = new Rectangle(_r[1, 0].X + buttonW, _r[1, 0].Y, (_r[1, 0].Width * (_r.GetLength(1) + 1)) - (buttonW * 2), _r[1, 0].Height);
            Rectangle right = new Rectangle(_r[1, 0].X + center.Width + buttonW, _r[1, 0].Y, buttonW, _r[1, 0].Height);

            screen.AddSprite(true, _textureKeys[3], left, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[4], center, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[5], right, Vector2.Zero, 0, Color.White, 1, null, false);

            screen.AddText(_fontKey, _descriptionText, new Vector2(
                                                     _r[0, 0].X + buttonW,
                                                     (_r[0, 0].Y + (_textfield.Height / 2)) -
                                                     ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(_descriptionText).Y / 2),
                                                     Vector2.Zero, Vector2.One,
                                                     0, Color.White, 0);

            //this is the input string that is drawn
            //its the same as _inputText but with a few modifications
            string drawString = _inputText;
            //do the password thing
            if (_passwordMode)
            {
                int stars = drawString.Length - 0; if (stars < 0) stars = 0;
                string s = ""; for (int i = 0; i < stars; i++) s += "*";
            }
            //add the flashing indicator
            if (time.TotalGameTime.Milliseconds / 500 % 2 == 0) drawString += "|";
            //format the string so its not to long for the textfield
            while (((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).X > center.Width) drawString = drawString.Remove(0, 1);

            screen.AddText(_fontKey, drawString, new Vector2(
                                                     _r[1, 0].X + buttonW,
                                                     (_r[1, 0].Y + (_textfield.Height / 2)) -
                                                     ((SpriteFont)screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).MeasureString(drawString).Y / 2),
                                                     Vector2.Zero, Vector2.One,
                                                     0, Color.White, 0);
        }
Example #2
0
        private void DrawButton(int x, int y, Screen screen)
        {
            int buttonW = (int)(_buttonWidth * 0.2f);
            Rectangle left = new Rectangle(
                _r[y,x].X,
                _r[y, x].Y,
                buttonW,
                _r[y, x].Height);

            Rectangle center = new Rectangle(
                _r[y, x].X + buttonW,
                _r[y, x].Y,
                _r[y, x].Width - (buttonW * 2),
                _r[y, x].Height);

            Rectangle right = new Rectangle(
                _r[y, x].X + _r[y, x].Width - buttonW,
                _r[y, x].Y,
                buttonW,
                _r[y, x].Height);

            screen.AddSprite(true, _textureKeys[0], left, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[1], center, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddSprite(true, _textureKeys[2], right, Vector2.Zero, 0, Color.White, 1, null, false);
            screen.AddText(_fontKey, _c[y, x], new Vector2(
                                              (_r[y, x].X + (_r[y, x].Width / 2)) -
                                              ((SpriteFont)
                                               screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).
                                                  MeasureString(_c[y, x]).X / 2,
                                              (_r[y, x].Y + (_r[y, x].Height / 2)) -
                                              ((SpriteFont)
                                               screen.ScreenManager.AssetsManager.GetAsset(_fontKey)).
                                                  MeasureString(_c[y, x]).Y / 2),
                           Vector2.Zero, Vector2.One,
                           0, Color.White, 0);
        }