示例#1
0
        public override void HandleInput(InputControl input, bool inFocus)
        {
            if (inFocus)
            {
                if (input.MousePressed(1))
                {
                    if (input.MouseX() > Position.X && input.MouseX() < (Position.X + width) && input.MouseY() > Position.Y && input.MouseY() < (Position.Y + height))
                    {
                        isSelected = true;

                    }
                    else
                    {
                        isSelected = false;
                    }
                }
                if (isSelected)
                {
                    foreach (Keys key in keysToCheck)
                    {
                        if (input.KeyPressed(key) && (OnKeyPressed == null || !OnKeyPressed(this, key)))
                        {
                            switch (key)
                            {
                                case (Keys.Back):
                                    if (textValue.Length > 0 && index > 0)
                                    {
                                        textValue = textValue.Remove(index - 1, 1);
                                        index--;
                                    }
                                    break;
                                case (Keys.Enter):
                                    if(Submitted != null)
                                        Submitted(this);
                                    index = 0;
                                    break;
                                case (Keys.Space):
                                    textValue += " ";
                                    break;
                                case (Keys.Left):
                                    if (index > 0)
                                        index--;
                                    break;
                                case (Keys.Right):
                                    if (index < textValue.Count())
                                        index++;
                                    break;
                                default:
                                    string charToAdd = key.ToString();
                                    if (!input.KeyDown(Keys.RightShift) && !input.KeyDown(Keys.LeftShift))
                                    {
                                        charToAdd = charToAdd.ToLower();

                                    }
                                    if (textValue.Length < this.max)
                                    {
                                        textValue += charToAdd;
                                        index++;
                                    }
                                    break;
                            }
                        }
                    }

                }
            }
        }