Пример #1
0
        internal override void OnUpdate()
        {
            m_caretBox.Bounds = new RectangleShape(Bounds.X + 10, Bounds.Y + 10, 0, 0);

            Vector2f mousePosition = TackInput.MousePosition();

            if (TackInput.MouseButtonUp(MouseButtonKey.Left))
            {
                if (mousePosition.X >= Bounds.X && mousePosition.X <= (Bounds.X + Bounds.Width))
                {
                    if (mousePosition.Y >= Bounds.Y && mousePosition.Y <= (Bounds.Y + Bounds.Height))
                    {
                        RequiringInput             = true;
                        TackInput.GUIInputRequired = true;
                    }
                    else
                    {
                        RequiringInput             = false;
                        TackInput.GUIInputRequired = false;
                    }
                }
                else
                {
                    RequiringInput             = false;
                    TackInput.GUIInputRequired = false;
                }
            }

            KeyboardKey[] bufferOperations = TackInput.GetInputBufferArray();

            for (int i = 0; i < bufferOperations.Length; i++)
            {
                if (bufferOperations[i] == KeyboardKey.Enter)
                {
                    if (OnSubmit != null)
                    {
                        if (OnSubmit.GetInvocationList().Length > 0)
                        {
                            OnSubmit.Invoke(this, Text);
                        }
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Left)
                {
                    if (SelectionStart > 0)
                    {
                        SelectionStart -= 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Right)
                {
                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.BackSpace)
                {
                    if (SelectionStart > 0)
                    {
                        Text = Text.Remove((int)SelectionStart - 1, 1);
                    }

                    if (SelectionStart > 0)
                    {
                        SelectionStart -= 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Delete)
                {
                    if (SelectionStart < Text.Length)
                    {
                        Text = Text.Remove((int)SelectionStart, 1);
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Space)
                {
                    Text = Text.Insert((int)SelectionStart, " ");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Period)
                {
                    Text = Text.Insert((int)SelectionStart, ".");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Quote)
                {
                    Text = Text.Insert((int)SelectionStart, "\"");

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] == KeyboardKey.Minus)
                {
                    if (TackInput.InputBufferShift)
                    {
                        Text = Text.Insert((int)SelectionStart, "_");
                    }
                    else
                    {
                        Text = Text.Insert((int)SelectionStart, "-");
                    }

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }

                else if (bufferOperations[i] >= KeyboardKey.Number0 && bufferOperations[i] <= KeyboardKey.Number9)
                {
                    Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] - 61)).ToString());

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
                else if (bufferOperations[i] >= KeyboardKey.A && bufferOperations[i] <= KeyboardKey.Z)
                {
                    if (TackInput.InputBufferCapsLock || TackInput.InputBufferShift)
                    {
                        Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] - 18)).ToString());
                    }
                    else
                    {
                        Text = Text.Insert((int)SelectionStart, ((char)((int)bufferOperations[i] + 14)).ToString());
                    }

                    if (SelectionStart < Text.Length)
                    {
                        SelectionStart += 1;
                    }
                }
            }

            TackInput.ClearInputBuffer();
        }