public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase res = base.HandleInput();

            var scrolledArea = m_scrolledArea;

            scrolledArea.Position += GetPositionAbsoluteTopLeft();
            res = base.HandleInputElements();

            if (m_scrollbarV != null)
            {
                bool capturedByScrollbar = m_scrollbarV.HandleInput();
                if (capturedByScrollbar)
                {
                    res = res ?? this;
                }
            }

            if (m_scrollbarH != null)
            {
                bool capturedByScrollbar = m_scrollbarH.HandleInput();
                if (capturedByScrollbar)
                {
                    res = res ?? this;
                }
            }

            return(res);
        }
示例#2
0
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase res = base.HandleInput();

            var scrolledArea = m_scrolledArea;

            scrolledArea.Position += GetPositionAbsoluteTopLeft();
            bool oldVal = ScrolledControl.HandleMouse;

            ScrolledControl.HandleMouse = scrolledArea.Contains(MyGuiManager.MouseCursorPosition);
            res = base.HandleInputElements();
            ScrolledControl.HandleMouse = oldVal;

            if (m_scrollbarV != null)
            {
                bool capturedByScrollbar = m_scrollbarV.HandleInput();
                if (capturedByScrollbar)
                {
                    res = res ?? this;
                }
            }

            if (m_scrollbarH != null)
            {
                bool capturedByScrollbar = m_scrollbarH.HandleInput();
                if (capturedByScrollbar)
                {
                    res = res ?? this;
                }
            }

            return(res);
        }
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase captureInput = base.HandleInput();

            if (captureInput != null)
            {
                return(captureInput);
            }

            if (!Enabled || !IsMouseOver)
            {
                return(null);
            }

            if (m_scrollBar != null &&
                m_scrollBar.HandleInput())
            {
                if (m_styleDef.PriorityCaptureInput)
                {
                    captureInput = this;
                }
            }

            // Handle mouse
            HandleNewMousePress(ref captureInput);
            var mousePos = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();

            if (m_itemsRectangle.Contains(mousePos))
            {
                var idx = ComputeIndexFromPosition(mousePos);
                m_mouseOverItem = IsValidIndex(idx) ? Items[idx] : null;

                if (ItemMouseOver != null)
                {
                    ItemMouseOver(this);
                }

                if (m_styleDef.PriorityCaptureInput)
                {
                    captureInput = this;
                }
            }
            else
            {
                m_mouseOverItem = null;
            }

            if (m_doubleClickStarted.HasValue && (MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) >= MyGuiConstants.DOUBLE_CLICK_DELAY)
            {
                m_doubleClickStarted = null;
            }

            return(captureInput);
        }
示例#4
0
        public bool HandleInput()
        {
            var oldHooveredItem = HooveredItem;

            HooveredItem = null;

            bool captured = m_body.HandleInput(m_control.HasFocus) ||
                            m_vScrollbar.HandleInput() ||
                            m_hScrollbar.HandleInput();

            if (m_control.HasFocus)
            {
                if (FocusedItem == null &&
                    m_body.GetItemCount() > 0 &&
                    (MyInput.Static.IsNewKeyPressed(MyKeys.Up) ||
                     MyInput.Static.IsNewKeyPressed(MyKeys.Down) ||
                     MyInput.Static.IsNewKeyPressed(MyKeys.Left) ||
                     MyInput.Static.IsNewKeyPressed(MyKeys.Right) ||
                     MyInput.Static.DeltaMouseScrollWheelValue() != 0))
                {
                    FocusItem(m_body[0]);
                }
                else if (FocusedItem != null)
                {
                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Down) || (MyInput.Static.DeltaMouseScrollWheelValue() < 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(NextVisible(m_body, FocusedItem));
                    }

                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Up) || (MyInput.Static.DeltaMouseScrollWheelValue() > 0 && Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y)))
                    {
                        FocusItem(PrevVisible(m_body, FocusedItem));
                    }

                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Right))
                    {
                        if (FocusedItem.GetItemCount() > 0)
                        {
                            if (!FocusedItem.IsExpanded)
                            {
                                FocusedItem.IsExpanded = true;
                            }
                            else
                            {
                                var next = NextVisible(FocusedItem, FocusedItem);
                                FocusItem(next);
                            }
                        }
                    }

                    if (MyInput.Static.IsNewKeyPressed(MyKeys.Left))
                    {
                        if (FocusedItem.GetItemCount() > 0 && FocusedItem.IsExpanded)
                        {
                            FocusedItem.IsExpanded = false;
                        }
                        else if (FocusedItem.Parent is MyTreeViewItem)
                        {
                            FocusItem(FocusedItem.Parent as MyTreeViewItem);
                        }
                    }

                    if (FocusedItem.GetItemCount() > 0)
                    {
                        if (MyInput.Static.IsNewKeyPressed(MyKeys.Add))
                        {
                            FocusedItem.IsExpanded = true;
                        }

                        if (MyInput.Static.IsNewKeyPressed(MyKeys.Subtract))
                        {
                            FocusedItem.IsExpanded = false;
                        }
                    }
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.PageDown))
                {
                    m_vScrollbar.PageDown();
                }

                if (MyInput.Static.IsNewKeyPressed(MyKeys.PageUp))
                {
                    m_vScrollbar.PageUp();
                }

                captured = captured ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.PageDown) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.PageUp) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Down) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Up) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Left) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Right) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Add) ||
                           MyInput.Static.IsNewKeyPressed(MyKeys.Subtract) ||
                           MyInput.Static.DeltaMouseScrollWheelValue() != 0;
            }

            // Hoovered item changed
            if (HooveredItem != oldHooveredItem)
            {
                m_control.ShowToolTip(HooveredItem == null ? null : HooveredItem.ToolTip);
                MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
            }

            return(captured);
        }
示例#5
0
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase baseResult = base.HandleInput();

            if (HasFocus && Selectable)
            {
                //  Move left
                if ((MyInput.Static.IsKeyPress(MyKeys.Left)))
                {
                    if ((IsEnoughDelay(MyMultilineTextKeys.LEFT, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (MyInput.Static.IsAnyCtrlKeyPressed())
                        {
                            CarriagePositionIndex = GetPreviousSpace();
                        }
                        else
                        {
                            CarriagePositionIndex--;
                        }

                        UpdateLastKeyPressTimes(MyMultilineTextKeys.LEFT);
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                    }
                    return(this);
                }

                //  Move right
                if ((MyInput.Static.IsKeyPress(MyKeys.Right)))
                {
                    if ((IsEnoughDelay(MyMultilineTextKeys.RIGHT, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        if (MyInput.Static.IsAnyCtrlKeyPressed())
                        {
                            CarriagePositionIndex = GetNextSpace();
                        }
                        else
                        {
                            ++CarriagePositionIndex;
                        }
                        UpdateLastKeyPressTimes(MyMultilineTextKeys.RIGHT);
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                    }
                    return(this);
                }

                //  Move Down
                if ((MyInput.Static.IsKeyPress(MyKeys.Down)))
                {
                    if ((IsEnoughDelay(MyMultilineTextKeys.DOWN, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        CarriagePositionIndex = GetIndexUnderCarriage(CarriagePositionIndex);
                        UpdateLastKeyPressTimes(MyMultilineTextKeys.DOWN);
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                    }
                    return(this);
                }

                //  Move Up
                if ((MyInput.Static.IsKeyPress(MyKeys.Up)))
                {
                    if ((IsEnoughDelay(MyMultilineTextKeys.UP, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY)))
                    {
                        CarriagePositionIndex = GetIndexOverCarriage(CarriagePositionIndex);
                        UpdateLastKeyPressTimes(MyMultilineTextKeys.UP);
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                    }
                    return(this);
                }

                //Copy
                if (MyInput.Static.IsNewKeyPressed(MyKeys.C) && IsEnoughDelay(MyMultilineTextKeys.C, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    UpdateLastKeyPressTimes(MyMultilineTextKeys.C);
                    m_selection.CopyText(this);
                }

                //Select All
                if (MyInput.Static.IsNewKeyPressed(MyKeys.A) && IsEnoughDelay(MyMultilineTextKeys.A, MyGuiConstants.TEXTBOX_MOVEMENT_DELAY) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    m_selection.SelectAll(this);
                    return(this);
                }
            }

            //scroll
            bool captured   = false;
            var  deltaWheel = MyInput.Static.DeltaMouseScrollWheelValue();

            if (IsMouseOver && deltaWheel != 0)
            {
                m_scrollbar.ChangeValue(-0.0005f * deltaWheel);
                captured = true;
            }


            if (m_drawScrollbar)
            {
                bool capturedScrollbar = m_scrollbar.HandleInput();

                if (capturedScrollbar || captured)
                {
                    return(this);
                }
            }
            if (IsMouseOver && m_label.HandleInput(GetPositionAbsoluteTopLeft(), m_scrollbar.Value))
            {
                return(this);
            }

            if (Selectable)
            {
                if (MyInput.Static.IsNewLeftMousePressed())
                {
                    if (IsMouseOver)
                    {
                        m_selection.Dragging  = true;
                        CarriagePositionIndex = GetCarriagePositionFromMouseCursor();
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                        return(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                }

                else if (MyInput.Static.IsNewLeftMouseReleased())
                {
                    m_selection.Dragging = false;
                }

                //user holding the mouse button
                else if (m_selection.Dragging)
                {
                    //If inside, we update selection and move the carriage (dragging what you want to select)
                    if (IsMouseOver)
                    {
                        CarriagePositionIndex = GetCarriagePositionFromMouseCursor();
                        m_selection.SetEnd(this);
                    }

                    //Otherwise, do the "scroll along with selection" effect
                    else if (HasFocus)
                    {
                        Vector2 mousePos        = MyGuiManager.MouseCursorPosition;
                        Vector2 positionTopLeft = GetPositionAbsoluteTopLeft();
                        if (mousePos.Y < positionTopLeft.Y)
                        {
                            m_scrollbar.ChangeValue(Position.Y - mousePos.Y);
                        }
                        else if (mousePos.Y > positionTopLeft.Y + Size.Y)
                        {
                            m_scrollbar.ChangeValue(mousePos.Y - positionTopLeft.Y - Size.Y);
                        }
                    }
                }
            }

            return(baseResult);
        }
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase baseResult = base.HandleInput();

            if (HasFocus && Selectable)
            {
                //  Move left
                switch (m_keyThrottler.GetKeyStatus(MyKeys.Left))
                {
                case ThrottledKeyStatus.PRESSED_AND_WAITING:
                    return(this);

                case ThrottledKeyStatus.PRESSED_AND_READY:
                    if (MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        CarriagePositionIndex = GetPreviousSpace();
                    }
                    else
                    {
                        CarriagePositionIndex--;
                    }

                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        m_selection.SetEnd(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                    return(this);
                }

                //  Move right
                switch (m_keyThrottler.GetKeyStatus(MyKeys.Right))
                {
                case ThrottledKeyStatus.PRESSED_AND_WAITING:
                    return(this);

                case ThrottledKeyStatus.PRESSED_AND_READY:
                    if (MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        CarriagePositionIndex = GetNextSpace();
                    }
                    else
                    {
                        ++CarriagePositionIndex;
                    }
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        m_selection.SetEnd(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                    return(this);
                }

                //  Move Down
                switch (m_keyThrottler.GetKeyStatus(MyKeys.Down))
                {
                case ThrottledKeyStatus.PRESSED_AND_WAITING:
                    return(this);

                case ThrottledKeyStatus.PRESSED_AND_READY:
                    CarriagePositionIndex = GetIndexUnderCarriage(CarriagePositionIndex);
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        m_selection.SetEnd(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                    return(this);
                }

                //  Move Up
                switch (m_keyThrottler.GetKeyStatus(MyKeys.Up))
                {
                case ThrottledKeyStatus.PRESSED_AND_WAITING:
                    return(this);

                case ThrottledKeyStatus.PRESSED_AND_READY:
                    CarriagePositionIndex = GetIndexOverCarriage(CarriagePositionIndex);
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        m_selection.SetEnd(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                    return(this);
                }

                //Copy
                if (m_keyThrottler.IsNewPressAndThrottled(MyKeys.C) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    m_selection.CopyText(this);
                }

                //Select All
                if (m_keyThrottler.IsNewPressAndThrottled(MyKeys.A) && MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    m_selection.SelectAll(this);
                    return(this);
                }
            }

            //scroll
            bool captured   = false;
            var  deltaWheel = MyInput.Static.DeltaMouseScrollWheelValue();

            if (IsMouseOver && deltaWheel != 0)
            {
                m_scrollbar.ChangeValue(-0.0005f * deltaWheel);
                captured = true;
            }

            if (m_drawScrollbar)
            {
                bool capturedScrollbar = m_scrollbar.HandleInput();

                if (capturedScrollbar || captured)
                {
                    return(this);
                }
            }

            if (IsMouseOver && m_label.HandleInput(GetPositionAbsoluteTopLeft(), m_scrollbar.Value))
            {
                return(this);
            }

            if (Selectable)
            {
                if (MyInput.Static.IsNewLeftMousePressed())
                {
                    if (IsMouseOver)
                    {
                        m_selection.Dragging  = true;
                        CarriagePositionIndex = GetCarriagePositionFromMouseCursor();
                        if (MyInput.Static.IsAnyShiftKeyPressed())
                        {
                            m_selection.SetEnd(this);
                        }
                        else
                        {
                            m_selection.Reset(this);
                        }
                        return(this);
                    }
                    else
                    {
                        m_selection.Reset(this);
                    }
                }

                else if (MyInput.Static.IsNewLeftMouseReleased())
                {
                    m_selection.Dragging = false;
                }

                //user holding the mouse button
                else if (m_selection.Dragging)
                {
                    //If inside, we update selection and move the carriage (dragging what you want to select)
                    if (IsMouseOver)
                    {
                        CarriagePositionIndex = GetCarriagePositionFromMouseCursor();
                        m_selection.SetEnd(this);
                    }

                    //Otherwise, do the "scroll along with selection" effect
                    else if (HasFocus)
                    {
                        Vector2 mousePos        = MyGuiManager.MouseCursorPosition;
                        Vector2 positionTopLeft = GetPositionAbsoluteTopLeft();
                        if (mousePos.Y < positionTopLeft.Y)
                        {
                            m_scrollbar.ChangeValue(Position.Y - mousePos.Y);
                        }
                        else if (mousePos.Y > positionTopLeft.Y + Size.Y)
                        {
                            m_scrollbar.ChangeValue(mousePos.Y - positionTopLeft.Y - Size.Y);
                        }
                    }
                }
            }

            return(baseResult);
        }