void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 {
     if (onHover == null)
     {
         return;
     }
     if (gameObject == eventData.pointerEnter ||
         IsGameObjectMatchInChildren(transform, eventData.pointerEnter))
     {
         onHover.Invoke();
     }
 }
    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
    {
        volumeControlsParent.SetActive(true);

        if (onHover == null)
        {
            return;
        }
        if (gameObject == eventData.pointerEnter ||
            IsGameObjectMatchInChildren(transform, eventData.pointerEnter))
        {
            onHover.Invoke();
        }
    }
Exemplo n.º 3
0
 public override void Hover()
 {
     if (OnHover != null)
     {
         OnHover.Invoke();
     }
 }
Exemplo n.º 4
0
 private void OnMouseEnter()
 {
     if (!MainCanvas.mainCanvas.isUIOverride && beingMoved == false)
     {
         OnHover?.Invoke(true, propName, this.transform);
     }
 }
Exemplo n.º 5
0
        public override void onUpdate()
        {
            //only handle the update if the button is enabled and the parent screen is visible
            if (screenVisible && render)
            {
                //hovering logic
                if (isMouseHovering() && selectable && enabled)
                {
                    Parent.FocusedComponent = this;

                    if (isHovered == false)
                    {
                        isHovered = true;
                        if (OnHover != null)
                        {
                            OnHover.Invoke(this, null);
                        }
                    }

                    if (InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == false)
                        {
                            isClicked = true;
                        }
                    }

                    if (InputManager.Released("gui.click"))
                    {
                        if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this)
                        {
                            isClicked = false;
                            if (OnClicked != null)
                            {
                                OnClicked.Invoke(this, null);
                            }
                        }
                    }
                }
                //unhover logic
                else
                {
                    if (isHovered)
                    {
                        isHovered = false;
                    }
                    if (!InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == true)
                        {
                            isClicked = false;
                            if (OnReleased != null)
                            {
                                OnReleased.Invoke(this, null);
                            }
                        }
                    }
                }
            }
        }
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            base.DrawSelf(spriteBatch);

            if (IsMouseHovering)
            {
                OnHover?.Invoke(spriteBatch);
            }
        }
Exemplo n.º 7
0
        internal void TriggerOnHover(bool value)
        {
            if (value == Hovering)
            {
                return;
            }

            Hovering = value;
            OnHover?.Invoke(Hovering);
        }
Exemplo n.º 8
0
 public override void Update(GameTime time)
 {
     if (Entity.AABB.Contains(InputManager.Instance.MousePosition))
     {
         _renderer.Color = OnHover?.Invoke() ?? _hoverColor;
     }
     else
     {
         _renderer.Color = RegularColorFunc?.Invoke() ?? _origColor;
     }
 }
Exemplo n.º 9
0
        public override void Update(GameTime time)
        {
            IsHover = _input.IsOver(X, Y, Width, Height);

            if (_input.HasEnterArea(X, Y, Width, Height))
            {
                OnHover?.Invoke( );
            }

            if (IsHover && _input.IsLMBPressedOnce( ))
            {
                OnClick?.Invoke( );
            }
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Switches the current state to the given ClickableState, and calls OnDown/OnHover as needed
        /// </summary>
        protected virtual void SwitchState(ClickableState newState)
        {
            State = newState;
            switch (State)
            {
            case ClickableState.None:
                break;

            case ClickableState.Hover:
                OnHover?.Invoke(this);
                break;

            case ClickableState.Active:
                OnDown?.Invoke(this);
                break;
            }
        }
Exemplo n.º 11
0
    public virtual void OnInteract()
    {
        bool checkedCanvas = true;

        if (needsACanvasCheck)
        {
            if (MainCanvas.mainCanvas.isUIOverride)
            {
                checkedCanvas = false;
            }
        }
        if (checkedCanvas)
        {
            for (int i = 0; i < clickEvents.Length; i++)
            {
                clickEvents[i].Invoke();
            }
            OnHover?.Invoke(false);
        }
    }
Exemplo n.º 12
0
 public override void Update(Window sender, Event e)
 {
     if (Velocity != null)
     {
         Position = Position + Velocity;
         _destinationRectangle.x = (int)Position.X;
         _destinationRectangle.y = (int)Position.Y;
     }
     if (Acceleration != null)
     {
         Velocity = Velocity + Acceleration;
     }
     if (e == Event.MOUSEBUTTONDOWN && MouseOnMe(sender))
     {
         OnClicked?.Invoke(this);
     }
     if (MouseOnMe(sender))
     {
         OnHover?.Invoke(this);
     }
 }
Exemplo n.º 13
0
        public override void Update(GameTime gameTime)
        {
            var mouseState = Mouse.GetState();
            var wasHovered = Hovered;

            Hovered = Rectangle.Contains(new Vector2(mouseState.X / ScaleMatrix.Right.X, mouseState.Y / ScaleMatrix.Up.Y));
            if (!wasHovered && Hovered)
            {
                OnHoverBegins?.Invoke(this, EventArgs.Empty);
            }
            else if (wasHovered && !Hovered)
            {
                OnHoverEnds?.Invoke(this, EventArgs.Empty);
            }
            else if (Hovered)
            {
                OnHover?.Invoke(this, EventArgs.Empty);
                Cursor.IsActive = true;
            }

            base.Update(gameTime);
        }
        public void Update()
        {
            var mouseState = Mouse.GetState();
            var mousePoint = new Point(mouseState.X, mouseState.Y);
            var rect       = new Rectangle((int)Coords.X, (int)Coords.Y, (int)Size.X, (int)Size.Y);

            if (rect.Contains(mousePoint))
            {
                IsHovered = true;
                OnHover?.Invoke(this);
                if (IsClicked && mouseState.LeftButton == ButtonState.Released && OnMouseUp != null)
                {
                    OnMouseUp(this);
                }
                IsClicked = mouseState.LeftButton == ButtonState.Pressed;
            }
            else
            {
                IsHovered = false;
                IsClicked = false;
            }
        }
Exemplo n.º 15
0
        public void Update(float deltaTime)
        {
            // Residual clicking handling.
            if (isMouseDown && Parent.Manager.IsClickReleased)
            {
                _handle_up(Parent.Manager);
            }
            // Hover management.
            var IsHovered = Parent.Manager.GetHover() == Parent;

            if (IsHovered == false && WasHoveredLastFrame == true)
            {
                OnUnhover?.Invoke(Parent);
            }
            else if (IsHovered == true && WasHoveredLastFrame == false)
            {
                OnHover?.Invoke(Parent);
            }

            WasHoveredLastFrame = IsHovered;

            if (double_click_timer > 0f)
            {
                double_click_timer -= deltaTime;
                if (double_click_timer <= 0f)
                {
                    OnClick?.Invoke(Parent);
                    OnEndClicking?.Invoke(Parent);
                    has_clicked = false;
                }
            }

            // Clicking related input.
            if (Parent.Manager.GetHover() == Parent)
            {
                _update(Parent.Manager, deltaTime);
            }
        }
Exemplo n.º 16
0
        private void OnMouseMove(double x, double y, double deltaX, double deltaY)
        {
            vec2 mPos = new vec2((float)x, (float)y).ToUISpace();

            if (Transform.Orientation % Math.PI > float.Epsilon)
            {
                mPos = Transform.Translation + (quat.FromAxisAngle(-Transform.Orientation, vec3.UnitZ) * new vec3(mPos - Transform.Translation, 0)).xy;
            }

            var size = Transform.Scale * Quad.Size;

            var min = Transform.Translation - (size / 2);
            var max = Transform.Translation + (size / 2);

            bool hovered = mPos.x >= min.x - 1 && mPos.x <= max.x + 1 && mPos.y >= min.y - 1 && mPos.y <= max.y + 1;

            if (!Hovered && hovered)
            {
                OnHover?.Invoke(this, null);
            }

            Hovered = hovered;
        }
Exemplo n.º 17
0
 public override void Update(double deltaTime)
 {
     base.Update(deltaTime);
     if (Input.onHover(ActRectangle))
     {
         OnHover?.Invoke(this, new UiEventArgs(Input.getPosition()));
     }
     if (Input.onLeave(ActRectangle))
     {
         OnLeave?.Invoke(this, new UiEventArgs(Input.getPosition()));
     }
     if (Input.OnMouseDown(Input.LeftButton) && Input.IsHover(ActRectangle))
     {
         OnDown?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.LeftButton));
     }
     if (Input.OnMouseDown(Input.MiddleButton) && Input.IsHover(ActRectangle))
     {
         OnDown?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.MiddleButton));
     }
     if (Input.OnMouseDown(Input.RightButton) && Input.IsHover(ActRectangle))
     {
         OnDown?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.RightButton));
     }
     if (Input.OnMouseUp(Input.LeftButton) && Input.IsHover(ActRectangle))
     {
         OnUp?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.LeftButton));
     }
     if (Input.OnMouseUp(Input.MiddleButton) && Input.IsHover(ActRectangle))
     {
         OnUp?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.MiddleButton));
     }
     if (Input.OnMouseUp(Input.RightButton) && Input.IsHover(ActRectangle))
     {
         OnUp?.Invoke(this, new UiEventArgs(Input.getPosition(), Input.RightButton));
     }
 }
Exemplo n.º 18
0
 public virtual void Hover()
 {
     OnHover?.Invoke();
 }
Exemplo n.º 19
0
 protected override void OnMouseEnter(UIMouseEventParameter p)
 {
     base.OnMouseEnter(p);
     OnHover?.Invoke(this, p);
 }
Exemplo n.º 20
0
 public void OnMouseOver()
 {
     OnHover?.Invoke(this, new EventArgs());
 }
Exemplo n.º 21
0
 //Not sure if this is really needed?
 public virtual void Hovering()
 {
     Transparency = 0.5f;
     OnHover?.Invoke(this, new EventArgs());
 }
Exemplo n.º 22
0
 public void OnPointerEnter(PointerEventData eventData)
 {
     OnHover?.Invoke(this);
 }
Exemplo n.º 23
0
 public void Hover()
 {
     OnHover.Invoke();
 }
Exemplo n.º 24
0
 private void OnMouseExit()
 {
     OnHover?.Invoke(false);
 }
Exemplo n.º 25
0
        public override void onUpdate()
        {
            //only handle the update if the button is enabled and the parent screen is visible
            if (screenVisible && render)
            {
                //hovering logic (checks if the slider is hovered)
                if (isMouseHovering() && selectable && enabled)
                {
                    Parent.FocusedComponent = this;

                    if (isMouseHovering(new Point(FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y), new Point(HandleWidth * GameSettings.UIScale, size.Y)))
                    {
                        if (isHovered == false)
                        {
                            isHovered = true;
                            if (OnHover != null)
                            {
                                OnHover.Invoke(null, null);
                            }
                        }
                    }

                    if (InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == false)
                        {
                            isClicked = true;
                            if (OnClicked != null)
                            {
                                OnClicked.Invoke(null, null);
                            }
                        }
                    }

                    if (InputManager.Released("gui.click"))
                    {
                        if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this)
                        {
                            isClicked = false;
                            if (OnReleased != null)
                            {
                                OnReleased.Invoke(null, null);
                            }
                        }
                    }

                    if (isClicked)
                    {
                        if (isSliding == false)
                        {
                            //If we are hovering on the handle then:
                            if (isMouseHovering(new Point(FastMath.FastClamp(location.X + (_value * size.X / (_maxValue - _minValue)), location.X, location.X + size.X - HandleWidth * GameSettings.UIScale), location.Y), new Point(HandleWidth * GameSettings.UIScale, size.Y)))
                            {
                                MouseOffset = new Point(handleX - InputManager.MouseX, location.Y - InputManager.MouseY);
                            }
                            //We are not hovering on the handle, so assume its half the width
                            else
                            {
                                MouseOffset = new Point(-HandleWidth * GameSettings.UIScale / 2, location.Y - InputManager.MouseY);
                            }
                            isSliding = true;
                        }
                    }
                }
                //unhover logic
                else
                {
                    if (isHovered)
                    {
                        isHovered = false;
                    }
                    if (!InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == true)
                        {
                            isClicked = false;
                            if (OnClicked != null)
                            {
                                OnClicked.Invoke(null, null);
                            }
                            if (OnReleased != null)
                            {
                                OnReleased.Invoke(null, null);
                            }
                        }
                    }
                }

                if (isClicked == false || Parent.FocusedComponent != this)
                {
                    isSliding = false;
                }

                //Handle the slider position
                if (isSliding)
                {
                    //Get the mouse relative to the component
                    int localPosition = InputManager.MouseX - location.X;

                    float coef  = (float)(_maxValue) / (float)(size.X - 3);
                    int   value = (int)(localPosition * coef);
                    value = FastMath.FastClamp(value, 0, _maxValue);

                    if (value != _value)
                    {
                        _value = value;

                        if (OnValueChanged != null)
                        {
                            OnValueChanged.Invoke(null, null);
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
 public void TriggerOnHover(Widget widget, bool isHovering, PointerEventData eventData)
 {
     OnHover?.Invoke(widget, isHovering, eventData);
 }
Exemplo n.º 27
0
 public virtual void Hovering()
 {
     OnHover?.Invoke(this, new EventArgs());
 }
Exemplo n.º 28
0
 // Calling these methods invokes the corresponding event
 public void Hover(RaycastHit hit)
 {
     OnHover.Invoke(hit);
 }
Exemplo n.º 29
0
        public override void onUpdate()
        {
            //only handle the update if the button is enabled and the parent screen is visible
            if (screenVisible && render)
            {
                #region Mouse Logic
                //hovering logic (checks if the slider is hovered)
                if (isMouseHovering() && selectable && enabled)
                {
                    var prevPosition = caretPosition;
                    Mouse.SetCursor(MouseCursor.IBeam);

                    Parent.FocusedComponent = this;

                    if (isHovered == false)
                    {
                        isHovered = true;
                        if (OnHover != null)
                        {
                            OnHover.Invoke(null, null);
                        }
                    }

                    #region Focusing Logic
                    if (InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == false)
                        {
                            isClicked = true;
                            if (OnClicked != null)
                            {
                                OnClicked.Invoke(null, null);
                            }
                            isEditing = true;
                        }

                        #region Mouse Highlighting Logic
                        if (isEditing)
                        {
                            GetCaretUnderMouse();

                            if (selectedCaretPositionTMP == -1)
                            {
                                selectedCaretPositionTMP = caretPosition;
                            }
                            if (selectedCaretPositionTMP != caretPosition)
                            {
                                //is holding
                                selectedPosition = selectedCaretPositionTMP;
                            }
                        }
                        #endregion
                    }
                    #endregion

                    #region Double Click Logic
                    if (InputManager.Released("gui.click"))
                    {
                        if (isClicked && Parent.FocusedComponent != null && Parent.FocusedComponent == this)
                        {
                            isClicked = false;
                            if (OnReleased != null)
                            {
                                OnReleased.Invoke(null, null);
                            }

                            selectedCaretPositionTMP = -1;
                            caretTimer = 0f;

                            //empty text boxes shouldnt crash
                            if (text.Length > 0)
                            {
                                //Double click logic
                                if (previousClickTime - timingMachine > 0f && previousClickTime - timingMachine <= 0.5f)                                 //Check the time frame
                                {
                                    if (selectedPosition == -1)
                                    {
                                        //If we moved more than 5 pixels from the last click in any direction then it doesnt count as a double click
                                        if (prevMouseLocation.X - 5 <= InputManager.MouseX && prevMouseLocation.X + 5 >= InputManager.MouseX &&
                                            prevMouseLocation.Y - 5 <= InputManager.MouseY && prevMouseLocation.Y + 5 >= InputManager.MouseY)
                                        {
                                            GetCaretUnderMouse();

                                            //Get the bounds of the current word
                                            int end = IndexOfNextCharAfterWhitespace();
                                            caretPosition = end;

                                            int start = IndexOfLastCharBeforeWhitespace();
                                            selectedPosition = start;

                                            timingMachine     = 0f;
                                            previousClickTime = 0f;
                                        }
                                    }
                                    else
                                    {
                                        selectedPosition = -1;
                                    }
                                }

                                timingMachine = previousClickTime;
                            }

                            prevMouseLocation = new Point(InputManager.MouseX, InputManager.MouseY);
                        }
                    }
                    #endregion

                    if (InputManager.PressedStart("gui.click"))
                    {
                        selectedPosition = -1;
                    }
                }

                #region Unhover Logic
                else
                {
                    if (!isMouseHovering() && Parent.FocusedComponent == this)
                    {
                        Mouse.SetCursor(MouseCursor.Arrow);
                    }

                    if (isHovered)
                    {
                        isHovered = false;
                    }
                    if (!InputManager.IsPressed("gui.click"))
                    {
                        if (isClicked == true)
                        {
                            isClicked = false;
                            if (OnClicked != null)
                            {
                                OnClicked.Invoke(null, null);
                            }
                            if (OnReleased != null)
                            {
                                OnReleased.Invoke(null, null);
                            }
                            caretTimer = 0f;
                            isEditing  = false;
                        }
                    }
                }
                #endregion
                #endregion

                caretTimer += Time.DeltaTime;

                #region Losing Focus to Another Component
                if (isEditing)
                {
                    previousClickTime += Time.DeltaTime;
                }

                if (Parent.FocusedComponent != this)
                {
                    if (Parent.FocusedComponent != null)
                    {
                        previousComponent = Parent.FocusedComponent;
                    }
                    else
                    {
                        isEditing = false;
                    }
                }

                //Focusing logic (on click on unfocused = unfocused)
                if (InputManager.Released("gui.click"))
                {
                    if (!isMouseHovering())
                    {
                        isEditing   = false;
                        timingChars = 0f;
                    }
                }
                #endregion

                #region Keyboard Handling
                //Get Textbox input
                if (isEditing)
                {
                    bool isShiftPressed = InputManager.IsPressed("misc.shift") || InputManager.IsPressed("misc.shift.alt");
                    bool isControlHeld  = InputManager.IsPressed("misc.control") || InputManager.IsPressed("misc.control.alt");
                    bool isAltHeld      = InputManager.IsPressed("misc.alternate") || InputManager.IsPressed("misc.alternate.alt");

                    #region Misc Input Handling

                    #region Caret Movement
                    timingChars += Time.DeltaTime;
                    if (InputManager.Released("misc.left") || InputManager.Released("misc.right"))
                    {
                        timingChars = 0f;
                    }

                    //Arrow hold timings
                    if ((timingChars < 1f && timingChars % 0.5f < 0.1f) ||                  //First second delay
                        (timingChars > 1f && timingChars < 2f && timingChars % 0.25f < 0.1f) ||                          //Second second delay
                        (timingChars > 2f && timingChars < 3f && timingChars % 0.1f < 0.05f))                             //Hold delay
                    {
                        //Movement
                        if (InputManager.IsPressed("misc.left") && !isAltHeld)                         //Left Arrow
                        {
                            if (isShiftPressed)
                            {
                                if (selectedPosition == -1)
                                {
                                    selectedPosition = FastMath.FastClamp(caretPosition, 0, text.Length);
                                }
                            }
                            else
                            {
                                if (selectedPosition != -1)
                                {
                                    caretPosition    = Math.Min(caretPosition, selectedPosition);
                                    selectedPosition = -1;
                                    caretPosition++;
                                }
                            }
                            if (isControlHeld)
                            {
                                caretPosition = IndexOfLastCharBeforeWhitespace() + 1;
                            }

                            caretPosition = FastMath.FastClamp(caretPosition - 1, 0, text.Length);                             //Minimum position = 0
                        }

                        if (InputManager.IsPressed("misc.right") && !isAltHeld)                         //Right Arrow
                        {
                            if (isShiftPressed)
                            {
                                if (selectedPosition == -1)
                                {
                                    selectedPosition = FastMath.FastClamp(caretPosition, 0, text.Length);
                                }
                            }
                            else
                            {
                                if (selectedPosition != -1)
                                {
                                    caretPosition    = Math.Max(caretPosition, selectedPosition);
                                    selectedPosition = -1;
                                    caretPosition--;
                                }
                            }
                            if (isControlHeld)
                            {
                                caretPosition = IndexOfNextCharAfterWhitespace() - 1;
                            }

                            caretPosition = FastMath.FastClamp(caretPosition + 1, 0, text.Length);                              //Maximum position = text.Length
                        }
                    }

                    //Home key
                    if (InputManager.Released("misc.home"))
                    {
                        caretPosition = 0;
                    }

                    //End key
                    if (InputManager.Released("misc.end"))
                    {
                        caretPosition = text.Length;
                    }

                    #endregion

                    #region Clipboard (Copy / Cut / Paste)
                    //Control things
                    if (isControlHeld)
                    {
                        //CTRL + A
                        if (InputManager.Released("misc.A"))
                        {
                            selectedPosition = 0;
                            caretPosition    = text.Length;
                        }

                        //Clipboard
                        if (InputManager.Released("misc.X"))
                        {
                            if (text.Length > 0)
                            {
                                if (selectedPosition != -1)
                                {
                                    //Get the selected text
                                    string toCopy = text.Substring(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition));

                                    Clipboard.SetText(toCopy);

                                    //Same logic as backspace / delete
                                    Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty);
                                    if (selectedPosition < caretPosition)
                                    {
                                        caretPosition -= caretPosition - selectedPosition;
                                    }
                                    selectedPosition = -1;
                                }
                            }
                        }
                        if (InputManager.Released("misc.C"))
                        {
                            if (text.Length > 0)
                            {
                                if (selectedPosition != -1)
                                {
                                    int min = Math.Min(selectedPosition, caretPosition);
                                    int max = Math.Max(selectedPosition, caretPosition);

                                    //Get the selected text
                                    string toCopy = text.Substring(min, max - min);
                                    Clipboard.SetText(toCopy);
                                }
                            }
                        }
                        if (InputManager.Released("misc.V"))
                        {
                            string toAdd = Clipboard.GetText();

                            //remove newlines
                            toAdd = toAdd.Replace("\n", string.Empty);
                            toAdd = toAdd.Replace("\r", string.Empty);
                            toAdd = toAdd.Replace("\t", string.Empty);

                            //Append the clipboard text
                            if (text.Length > 0)
                            {
                                if (selectedPosition == -1)
                                {
                                    text = text.Substring(0, caretPosition) + toAdd + text.Substring(caretPosition);
                                    //caretPosition += toAdd.Length;
                                }
                                else
                                {
                                    Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), toAdd.ToString());
                                    if (selectedPosition < caretPosition)
                                    {
                                        caretPosition -= caretPosition - selectedPosition;
                                    }
                                    selectedPosition = -1;
                                }
                            }
                            else
                            {
                                text += toAdd;
                            }

                            caretPosition += toAdd.Length;
                        }
                    }
                    #endregion

                    //Escape means lose focus
                    if (InputManager.Released("misc.pause"))
                    {
                        //lose focus
                        isEditing = false;

                        //reset the cursor
                        Mouse.SetCursor(MouseCursor.Arrow);

                        //reset
                        GameClient.CurrentCharacter = (char)0;
                        GameClient.CurrentKey       = Keys.None;
                        return;
                    }

                    #region Text Removal

                    if (GameClient.CurrentKey == Keys.Back)                     //Backspace
                    {
                        //If no highlighted text
                        if (selectedPosition == -1 || text.Length == 0)
                        {
                            text          = text.Substring(0, Math.Max(0, caretPosition - 1)) + text.Substring(Math.Min(caretPosition, text.Length));
                            caretPosition = FastMath.FastClamp(caretPosition, 0, text.Length);
                        }
                        else
                        {
                            Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty);
                            if (selectedPosition < caretPosition)
                            {
                                caretPosition -= caretPosition - selectedPosition;
                            }
                            selectedPosition = -1;
                        }
                    }

                    if (GameClient.CurrentKey == Keys.Delete)                     //Delete?
                    {
                        //If no highlighted text
                        if (selectedPosition == -1)
                        {
                            text          = text.Substring(0, caretPosition) + text.Substring(Math.Min(caretPosition + 1, text.Length));
                            caretPosition = FastMath.FastClamp(caretPosition, 0, text.Length);
                        }
                        else
                        {
                            Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), string.Empty);
                            if (selectedPosition < caretPosition)
                            {
                                caretPosition -= caretPosition - selectedPosition;
                            }
                            selectedPosition = -1;
                        }
                    }
                    #endregion
                    #endregion

                    #region Input Handling
                    //Appending text
                    if (!(GameClient.CurrentKey == Keys.Back ||
                          GameClient.CurrentKey == Keys.Delete ||
                          GameClient.CurrentKey == Keys.Escape ||
                          GameClient.CurrentKey == Keys.Tab))                          //If the current key isn't a printable character
                    {
                        #region Regular Text Input
                        if (GameClient.CurrentKey != Keys.None)
                        {
                            //Append the character
                            if (text.Length > 0)
                            {
                                if (selectedPosition == -1)
                                {
                                    text = text.Substring(0, caretPosition) + GameClient.CurrentCharacter + text.Substring(caretPosition);
                                }
                                else
                                {
                                    Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), GameClient.CurrentCharacter.ToString());
                                    if (selectedPosition < caretPosition)
                                    {
                                        caretPosition -= caretPosition - selectedPosition;
                                    }
                                    selectedPosition = -1;
                                }
                            }
                            else
                            {
                                text += GameClient.CurrentCharacter;
                            }

                            caretPosition++;
                        }
                        #endregion
                        #region Modifier Characters
                        else if (GameClient.CurrentCharacter != '\0')
                        {
                            char toAdd = GameClient.CurrentCharacter;

                            //if uppercase
                            if (isShiftPressed)
                            {
                                toAdd = char.ToUpper(toAdd);
                            }

                            //Caps Lock
#if DESKTOP
                            if (InputManager.IsPressed("misc.capslock"))
                            {
                                toAdd = char.ToUpper(toAdd);
                            }
#endif

                            //Append the character
                            if (text.Length > 0)
                            {
                                if (selectedPosition == -1)
                                {
                                    text = text.Substring(0, caretPosition) + toAdd + text.Substring(caretPosition);
                                }
                                else
                                {
                                    Replace(Math.Min(selectedPosition, caretPosition), Math.Max(selectedPosition, caretPosition), toAdd.ToString());
                                    if (selectedPosition < caretPosition)
                                    {
                                        caretPosition -= caretPosition - selectedPosition;
                                    }
                                    selectedPosition = -1;
                                }
                            }
                            else
                            {
                                text += toAdd;
                            }

                            caretPosition++;
                        }
                        #endregion
                    }
                    #endregion

                    //Reset
                    GameClient.CurrentCharacter = (char)0;
                    GameClient.CurrentKey       = Keys.None;
                }
                #endregion
                else
                {
                    //Reset highlighting
                    selectedPosition = -1;
                }
            }
        }