Beispiel #1
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase captureInput = base.HandleInput();

            if (captureInput == null)
            {
                if (!m_activateOnMouseRelease)
                {
                    if (IsMouseOver && MyInput.Static.IsNewPrimaryButtonPressed())
                    {
                        m_readyToClick = true;
                    }
                    if (!IsMouseOver && MyInput.Static.IsNewPrimaryButtonReleased())
                    {
                        m_readyToClick = false;
                    }
                }
                else
                {
                    m_readyToClick = true;
                }

                if ((IsMouseOver && (MyInput.Static.IsNewPrimaryButtonReleased()) && m_readyToClick ||
                     (HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Enter) ||
                                   MyInput.Static.IsNewKeyPressed(MyKeys.Space)))))
                {
                    if (Enabled)
                    {
                        MyGuiSoundManager.PlaySound(m_cueEnum);
                        if (ButtonClicked != null)
                        {
                            ButtonClicked(this);
                        }
                    }

                    captureInput   = this;
                    m_readyToClick = false;
                    return(captureInput);
                }
                if (IsMouseOver && MyInput.Static.IsPrimaryButtonPressed())
                {
                    captureInput = this;//to be first in queue when button is released
                }
                if (captureInput == null && Enabled && AllowBoundKey && BoundKey != MyKeys.None)
                {
                    if (MyInput.Static.IsNewKeyPressed(BoundKey))
                    {
                        MyGuiSoundManager.PlaySound(m_cueEnum);
                        if (ButtonClicked != null)
                        {
                            ButtonClicked(this);
                        }

                        captureInput   = this;
                        m_readyToClick = false;
                    }
                }
            }
            return(captureInput);
        }
        /// <summary>
        /// Method returns true if input was captured by control, so no other controls, nor screen can use input in this update.
        /// </summary>
        public virtual MyGuiControlBase HandleInput()
        {
            bool isMouseOverOld = IsMouseOver;

            IsMouseOver = CheckMouseOver();
            if (IsActiveControl)
            {
                m_mouseButtonPressed = IsMouseOver && MyInput.Static.IsPrimaryButtonPressed();

                if (IsMouseOver && !isMouseOverOld && Enabled)
                {
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
                }
            }

            // if mouseover this control longer than specified period, show tooltip for the control
            if (IsMouseOver && isMouseOverOld)
            {
                if (m_showToolTip == false)
                {
                    m_showToolTipDelay = MyGuiManager.TotalTimeInMilliseconds + MyGuiConstants.SHOW_CONTROL_TOOLTIP_DELAY;
                    m_showToolTip      = true;
                }
            }
            else
            {
                m_showToolTip = false;
            }

            return(null);
        }
Beispiel #3
0
        //  Moves keyboard index to the next item, or previous item, or first item in the combobox.
        //  forwardMovement -> set to TRUE when you want forward movement, set to FALSE when you wasnt backward
        void HandleItemMovement(bool forwardMovement, bool page = false, bool list = false)
        {
            m_preselectedKeyboardIndexPrevious = m_preselectedKeyboardIndex;

            int step = 0;
            if (list && forwardMovement) // first item
            {
                m_preselectedKeyboardIndex = 0;
            }
            else if (list && !forwardMovement) // last item
            {
                m_preselectedKeyboardIndex = m_items.Count - 1;
            }
            else if (page && forwardMovement) // step + 1 page
            {
                if (m_openAreaItemsCount > m_items.Count)
                    step = m_items.Count - 1;
                else
                    step = m_openAreaItemsCount - 1;
            }
            else if (page && !forwardMovement) // step - 1 page
            {
                if (m_openAreaItemsCount > m_items.Count)
                    step = -(m_items.Count - 1);
                else
                    step = -m_openAreaItemsCount + 1;
            }
            else if (!page && !list && forwardMovement) // step 1 item
            {
                step = 1;
            }
            else // step -1 item
            {
                step = -1;
            }


            if (m_preselectedKeyboardIndex.HasValue == false)
            {
                //  If this is first keypress in this combobox, we will set keyboard index to begining or end of the list
                m_preselectedKeyboardIndex = (forwardMovement == true) ? 0 : m_items.Count - 1;
            }
            else
            {
                //  Increase or decrease and than check ranges and do sort of overflow
                m_preselectedKeyboardIndex += step;// sign;
                if (m_preselectedKeyboardIndex > (m_items.Count - 1)) m_preselectedKeyboardIndex = (m_items.Count - 1);
                if (m_preselectedKeyboardIndex < 0) m_preselectedKeyboardIndex = 0;
            }

            if (m_preselectedKeyboardIndex != m_preselectedKeyboardIndexPrevious)
            {
                MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
            }

            SetScrollBarPositionByIndex(m_preselectedKeyboardIndex.Value);
        }
Beispiel #4
0
        bool UpdateTransition()
        {
            if (State == MyGuiScreenState.OPENING || State == MyGuiScreenState.UNHIDING)
            {
                int deltaTime = MyGuiManager.TotalTimeInMilliseconds - m_lastTransitionTime;

                // Play opening sound
                if ((State == MyGuiScreenState.OPENING) && (m_openingCueEnum != null))// && (m_openingCue == null))
                {
                    MyGuiSoundManager.PlaySound(m_openingCueEnum.Value);
                }

                if (deltaTime >= GetTransitionOpeningTime())
                {
                    //  Opening phase finished, we are now in active state
                    State             = MyGuiScreenState.OPENED;
                    m_transitionAlpha = MyGuiConstants.TRANSITION_ALPHA_MAX;
                    OnShow();
                }
                else
                {
                    m_transitionAlpha = MathHelper.Lerp(MyGuiConstants.TRANSITION_ALPHA_MIN, MyGuiConstants.TRANSITION_ALPHA_MAX, MathHelper.Clamp((float)deltaTime / (float)GetTransitionOpeningTime(), 0, 1));
                }
            }
            else if (State == MyGuiScreenState.CLOSING || State == MyGuiScreenState.HIDING)
            {
                int deltaTime = MyGuiManager.TotalTimeInMilliseconds - m_lastTransitionTime;

                if (deltaTime >= GetTransitionClosingTime())
                {
                    m_transitionAlpha = MyGuiConstants.TRANSITION_ALPHA_MIN;

                    //  Closing phase finished, we are now in close state
                    if (State == MyGuiScreenState.CLOSING)
                    {
                        CloseScreenNow();
                        return(false);
                    }
                    else if (State == MyGuiScreenState.HIDING)
                    {
                        State = MyGuiScreenState.HIDDEN;

                        OnHide();
                    }
                }
                else
                {
                    m_transitionAlpha = MathHelper.Lerp(MyGuiConstants.TRANSITION_ALPHA_MAX, MyGuiConstants.TRANSITION_ALPHA_MIN, MathHelper.Clamp((float)deltaTime / (float)GetTransitionClosingTime(), 0, 1));
                }
            }

            return(true);
        }
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase captureInput = base.HandleInput();

            if (captureInput == null)
            {
                if (!m_activateOnMouseRelease)
                {
                    if (IsMouseOver && MyInput.Static.IsNewPrimaryButtonPressed())
                    {
                        m_readyToClick = true;
                    }
                    if (!IsMouseOver && MyInput.Static.IsNewPrimaryButtonReleased())
                    {
                        m_readyToClick = false;
                    }
                }
                else
                {
                    m_readyToClick = true;
                }

                if ((IsMouseOver && (MyInput.Static.IsNewPrimaryButtonReleased()) && m_readyToClick ||
                     (HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Enter) ||
                                   MyInput.Static.IsNewKeyPressed(MyKeys.Space)))))
                {
                    if (m_implementedFeature == false)
                    {
                        //MyAudio.Static.PlayCue(m_cueEnum);
                        //MyGuiManager2.AddScreen(new MyGuiScreenMessageBox(
                        //    messageText: MyTextsWrapper.Get(MyStringId.FeatureNotYetImplemented),
                        //    messageCaption: MyTextsWrapper.Get(MyStringId.MessageBoxCaptionFeatureDisabled)));
                    }
                    else if (Enabled)
                    {
                        MyGuiSoundManager.PlaySound(m_cueEnum);
                        if (ButtonClicked != null)
                        {
                            ButtonClicked(this);
                        }
                    }

                    captureInput   = this;
                    m_readyToClick = false;
                    return(captureInput);
                }
                if (IsMouseOver && MyInput.Static.IsPrimaryButtonPressed())
                {
                    captureInput = this;//to be first in queue when button is released
                }
            }
            return(captureInput);
        }
Beispiel #6
0
 /// <summary>
 /// Called when user presses ESC or clicks on CANCEL - hook to this method so you can do gui-screen-specific event
 /// </summary>
 protected virtual void Canceling()
 {
     Cancelled = true;
     if (m_closingCueEnum.HasValue)
     {
         MyGuiSoundManager.PlaySound(m_closingCueEnum.Value);
     }
     else
     {
         MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
     }
     CloseScreen();
 }
Beispiel #7
0
        public override MyGuiControlBase HandleInput()
        {
            int tab = GetMouseOverTab();

            if (tab != -1 && GetTabSubControl(tab).Enabled&& MyInput.Static.IsNewPrimaryButtonPressed())
            {
                MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                SelectedPage = tab;
                return(this);
            }

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

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

            if (!Enabled)
            {
                return(captureInput);
            }

            if (!IsMouseOver)
            {
                //User moved mouse from toolbar area. Try to trigger any pending clicks registered
                TryTriggerSingleClickEvent();
                return(captureInput);
            }

            var oldMouseOverIndex = MouseOverIndex;

            MouseOverIndex = IsMouseOver ? ComputeIndex(MyGuiManager.MouseCursorPosition) : INVALID_INDEX;
            if (oldMouseOverIndex != MouseOverIndex && Enabled && MouseOverIndex != INVALID_INDEX)
            {
                MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
            }

            HandleNewMousePress(ref captureInput);
            HandleMouseDrag(ref captureInput, MySharedButtonsEnum.Primary, ref m_isItemDraggingLeft);
            HandleMouseDrag(ref captureInput, MySharedButtonsEnum.Secondary, ref m_isItemDraggingRight);

            //Handle right mouse button instantly. It cannot be double clicked
            if (m_singleClickEvents != null && m_singleClickEvents.Value.Button == MySharedButtonsEnum.Secondary)
            {
                TryTriggerSingleClickEvent();
            }

            if (m_doubleClickStarted.HasValue && (MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) >= MyGuiConstants.DOUBLE_CLICK_DELAY)
            {
                m_doubleClickStarted = null;
                //No double click, but a click was registered
                TryTriggerSingleClickEvent();
            }

            return(captureInput);
        }
Beispiel #9
0
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase ret = base.HandleInput();

            if (ret == null && Enabled)
            {
                if ((IsMouseOver && MyInput.Static.IsNewPrimaryButtonReleased()) ||
                    (HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Enter) || MyInput.Static.IsNewKeyPressed(MyKeys.Space) || MyInput.Static.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J01))))
                {
                    if (!Selected)
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                        Selected = true;
                        ret      = this;
                    }
                }
            }

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

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

            bool isControl = MyInput.Static.IsNewLeftMouseReleased() || MyControllerHelper.IsControl(MyControllerHelper.CX_GUI, MyControlsGUI.ACCEPT, MyControlStateType.NEW_RELEASED);

            if (Enabled && IsMouseOver && isControl ||
                HasFocus && MyInput.Static.IsNewKeyPressed(MyKeys.Enter))
            {
                Value        = !Value;
                captureInput = this;
                MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
            }

            return(captureInput);
        }
Beispiel #11
0
        public override void HandleInput(bool receivedFocusInThisUpdate)
        {
            base.HandleInput(receivedFocusInThisUpdate);

            if (MyCubeBuilder.Static == null)
            {
                return;
            }

            if (MyCubeBuilder.Static.IsCubeSizeModesAvailable && MyInput.Static.IsGameControlReleased(MyControlsSpace.CUBE_BUILDER_CUBESIZE_MODE) &&
                !m_searchItemTextBox.HasFocus)
            {
                int   selectionIdx = MyCubeBuilder.Static.CubeBuilderState.CubeSizeMode == MyCubeSize.Large ? 0 : 1;
                int?  selIdx       = m_gridBlocks.SelectedIndex;
                float scrollValue  = m_gridBlocksPanel.ScrollbarVPosition;
                m_rbGroupGridSize.SelectedIndex = selectionIdx;
                OnGridMouseOverIndexChanged(m_gridBlocks, new MyGuiControlGrid.EventArgs());
                m_gridBlocks.SelectedIndex           = selIdx;
                m_gridBlocksPanel.ScrollbarVPosition = scrollValue;
                MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);

                return;
            }
        }
Beispiel #12
0
 private void UserCheck()
 {
     MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
     IsChecked = !IsChecked;
 }
        private void HandleNewMousePress(ref MyGuiControlBase captureInput)
        {
            var  mousePos      = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();
            bool cursorInItems = m_itemsRectangle.Contains(mousePos);

            if (MyInput.Static.IsAnyNewMouseOrJoystickPressed() && cursorInItems)
            {
                int row = ComputeIndexFromPosition(mousePos);
                if (IsValidIndex(row) && Items[row].Visible)
                {
                    if (MultiSelect && MyInput.Static.IsAnyCtrlKeyPressed())
                    {
                        if (SelectedItems.Contains(Items[row]))
                        {
                            SelectedItems.Remove(Items[row]);
                        }
                        else
                        {
                            SelectedItems.Add(Items[row]);
                        }
                    }
                    else if (MultiSelect && MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        int index = 0;
                        if (SelectedItems.Count > 0)
                        {
                            index = Items.IndexOf(SelectedItems[SelectedItems.Count - 1]);
                        }

                        do
                        {
                            index += index > row ? -1 : 1;
                            if (!IsValidIndex(index))
                            {
                                break;
                            }
                            if (!Items[index].Visible)
                            {
                                continue;
                            }
                            if (SelectedItems.Contains(Items[index]))
                            {
                                SelectedItems.Remove(Items[index]);
                            }
                            else
                            {
                                SelectedItems.Add(Items[index]);
                            }
                        } while (index != row);
                    }
                    else
                    {
                        SelectedItems.Clear();
                        SelectedItems.Add(Items[row]);
                    }
                    if (ItemsSelected != null)
                    {
                        ItemsSelected(this);
                    }

                    captureInput = this;
                    if (ItemClicked != null)
                    {
                        ItemClicked(this);
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                    }
                }
            }

            if (MyInput.Static.IsNewPrimaryButtonPressed() && cursorInItems)
            {
                if (!m_doubleClickStarted.HasValue)
                {
                    int row = ComputeIndexFromPosition(mousePos);
                    if (IsValidIndex(row) && Items[row].Visible)
                    {
                        m_doubleClickStarted       = MyGuiManager.TotalTimeInMilliseconds;
                        m_doubleClickFirstPosition = MyGuiManager.MouseCursorPosition;
                    }
                }
                else if ((MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) <= MyGuiConstants.DOUBLE_CLICK_DELAY &&
                         (m_doubleClickFirstPosition - MyGuiManager.MouseCursorPosition).Length() <= 0.005f)
                {
                    if (ItemDoubleClicked != null)
                    {
                        ItemDoubleClicked(this);
                    }

                    m_doubleClickStarted = null;
                    captureInput         = this;
                }
            }
        }
        private void HandleNewMousePress(ref MyGuiControlBase captureInput)
        {
            bool cursorInItems = m_rowsArea.Contains(MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft());

            MyMouseButtonsEnum mouseButton = MyMouseButtonsEnum.None;

            if (MyInput.Static.IsNewPrimaryButtonPressed())
            {
                mouseButton = MyMouseButtonsEnum.Left;
            }
            else if (MyInput.Static.IsNewSecondaryButtonPressed())
            {
                mouseButton = MyMouseButtonsEnum.Right;
            }
            else if (MyInput.Static.IsNewMiddleMousePressed())
            {
                mouseButton = MyMouseButtonsEnum.Middle;
            }
            else if (MyInput.Static.IsNewXButton1MousePressed())
            {
                mouseButton = MyMouseButtonsEnum.XButton1;
            }
            else if (MyInput.Static.IsNewXButton2MousePressed())
            {
                mouseButton = MyMouseButtonsEnum.XButton2;
            }

            if (MyInput.Static.IsAnyNewMouseOrJoystickPressed() && cursorInItems)
            {
                SelectedRowIndex = ComputeRowIndexFromPosition(MyGuiManager.MouseCursorPosition);
                captureInput     = this;
                if (ItemSelected != null)
                {
                    ItemSelected(this, new EventArgs()
                    {
                        RowIndex = SelectedRowIndex.Value, MouseButton = mouseButton
                    });
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                }
            }

            if (MyInput.Static.IsNewPrimaryButtonPressed())
            {
                if (m_mouseOverHeader)
                {
                    Debug.Assert(m_mouseOverColumnIndex.HasValue);
                    SortByColumn(m_mouseOverColumnIndex.Value);
                    if (ColumnClicked != null)
                    {
                        ColumnClicked(this, m_mouseOverColumnIndex.Value);
                    }
                }
                else if (cursorInItems)
                {
                    if (!m_doubleClickStarted.HasValue)
                    {
                        m_doubleClickStarted       = MyGuiManager.TotalTimeInMilliseconds;
                        m_doubleClickFirstPosition = MyGuiManager.MouseCursorPosition;
                    }
                    else if ((MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) <= MyGuiConstants.DOUBLE_CLICK_DELAY &&
                             (m_doubleClickFirstPosition - MyGuiManager.MouseCursorPosition).Length() <= 0.005f)
                    {
                        if (ItemDoubleClicked != null && SelectedRowIndex.HasValue)
                        {
                            ItemDoubleClicked(this, new EventArgs()
                            {
                                RowIndex = SelectedRowIndex.Value, MouseButton = mouseButton
                            });
                        }

                        m_doubleClickStarted = null;
                        captureInput         = this;
                    }
                }
            }
        }
        private void HandleNewMousePress(ref MyGuiControlBase captureInput)
        {
            bool cursorInItems = m_itemsRectangle.Contains(MyGuiManager.MouseCursorPosition);

            if (MyInput.Static.IsNewPrimaryButtonReleased() || MyInput.Static.IsNewSecondaryButtonReleased())
            {
                if (cursorInItems)
                {
                    int?mouseOverIndex = ComputeIndex(MyGuiManager.MouseCursorPosition);
                    if (!IsValidIndex(mouseOverIndex.Value))
                    {
                        mouseOverIndex = null;
                    }

                    SelectMouseOverItem(mouseOverIndex);

                    if (SelectedIndex.HasValue && m_itemClicked.HasValue && m_lastClick.HasValue && mouseOverIndex.HasValue)
                    {
                        if (MyGuiManager.TotalTimeInMilliseconds - m_lastClick.Value < MyGuiConstants.CLICK_RELEASE_DELAY && m_itemClicked.Value.ItemIndex == mouseOverIndex.Value)
                        {
                            captureInput = this;
                            MySharedButtonsEnum button = MySharedButtonsEnum.None;
                            if (MyInput.Static.IsNewPrimaryButtonReleased())
                            {
                                button = MySharedButtonsEnum.Primary;
                            }
                            else if (MyInput.Static.IsNewSecondaryButtonReleased())
                            {
                                button = MySharedButtonsEnum.Secondary;
                            }

                            EventArgs args;
                            MakeEventArgs(out args, SelectedIndex.Value, button);

                            var handler = ItemReleased;
                            if (handler != null)
                            {
                                handler(this, args);
                            }
                        }
                    }
                }
                m_itemClicked = null;
                m_lastClick   = null;
            }

            if (MyInput.Static.IsAnyNewMouseOrJoystickPressed() && cursorInItems)
            {
                m_lastClick = MyGuiManager.TotalTimeInMilliseconds;

                int?mouseOverIndex = ComputeIndex(MyGuiManager.MouseCursorPosition);
                if (!IsValidIndex(mouseOverIndex.Value))
                {
                    mouseOverIndex = null;
                }
                SelectMouseOverItem(mouseOverIndex);

                captureInput = this;
                if (SelectedIndex.HasValue && (ItemClicked != null || ItemClickedWithoutDoubleClick != null))
                {
                    MySharedButtonsEnum button = MySharedButtonsEnum.None;
                    if (MyInput.Static.IsNewPrimaryButtonPressed())
                    {
                        button = MySharedButtonsEnum.Primary;
                    }
                    else if (MyInput.Static.IsNewSecondaryButtonPressed())
                    {
                        button = MySharedButtonsEnum.Secondary;
                    }

                    EventArgs args;
                    MakeEventArgs(out args, SelectedIndex.Value, button);
                    var handler = ItemClicked;
                    if (handler != null)
                    {
                        handler(this, args);
                    }

                    m_singleClickEvents = args;
                    m_itemClicked       = args;

                    if (MyInput.Static.IsAnyCtrlKeyPressed() || MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.Item);
                    }
                }
            }

            if (MyInput.Static.IsNewPrimaryButtonPressed() && cursorInItems)
            {
                if (!m_doubleClickStarted.HasValue)
                {
                    m_doubleClickStarted       = MyGuiManager.TotalTimeInMilliseconds;
                    m_doubleClickFirstPosition = MyGuiManager.MouseCursorPosition;
                }
                else if ((MyGuiManager.TotalTimeInMilliseconds - m_doubleClickStarted.Value) <= MyGuiConstants.DOUBLE_CLICK_DELAY &&
                         (m_doubleClickFirstPosition - MyGuiManager.MouseCursorPosition).Length() <= 0.005f)
                {
                    if (SelectedIndex.HasValue && TryGetItemAt(SelectedIndex.Value) != null && ItemDoubleClicked != null)
                    {
                        //Cancel click event when we double click
                        m_singleClickEvents = null;

                        EventArgs args;
                        MakeEventArgs(out args, SelectedIndex.Value, MySharedButtonsEnum.Primary);
                        Debug.Assert(GetItemAt(args.ItemIndex) != null, "Double click should not be reported when clicking on empty position.");
                        ItemDoubleClicked(this, args);
                        MyGuiSoundManager.PlaySound(GuiSounds.Item);
                    }

                    m_doubleClickStarted = null;
                    captureInput         = this;
                }
            }
        }
Beispiel #16
0
        public bool HandleInputEx(bool hasKeyboardActiveControl)
        {
            if (!Visible)
            {
                return(false);
            }

            bool captured = false;

            // Hoover item if mouse cursor is inside its area
            if (TreeView.Contains(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y) &&
                MyGUIHelper.Contains(m_currentOrigin, m_currentSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
            {
                TreeView.HooveredItem = this;
            }

            if (Enabled && DragDrop != null)
            {
                captured = DragDrop.HandleInput(this);
            }

            // Single click - expand or focus item
            if (MyInput.Static.IsNewLeftMouseReleased())
            {
                if (GetItemCount() > 0 && MyGUIHelper.Contains(m_currentOrigin + GetExpandIconPosition(), m_expandIconSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
                {
                    IsExpanded = !IsExpanded;
                    captured   = true;
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                }
                else if (TreeView.HooveredItem == this)
                {
                    TreeView.FocusItem(this);
                    captured = true;
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                }
            }

            // Double click - launch Action event
            if (Enabled && /*!captured && MyInput.Static.IsNewLeftMouseDoubleClick() && */ TreeView.HooveredItem == this)
            {
                if (Action != null)
                {
                    DoAction();
                }
                else if (GetItemCount() > 0)
                {
                    IsExpanded = !IsExpanded;
                }
                captured = true;
            }

            // Right click - launch RightClick event
            if (/*!captured && */ MyInput.Static.IsNewRightMousePressed() && TreeView.HooveredItem == this)
            {
                if (RightClick != null)
                {
                    RightClick(this, EventArgs.Empty);
                }
                captured = true;
                MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
            }

            return(captured);
        }
Beispiel #17
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);
        }
Beispiel #18
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override MyGuiControlBase HandleInput()
        {
            MyGuiControlBase captureInput = base.HandleInput();

            if (captureInput == null && Enabled)
            {
                if (IsMouseOver && MyInput.Static.IsNewPrimaryButtonPressed() && !m_isOpen && !m_scrollBarDragging)
                    return this;

                if (MyInput.Static.IsNewPrimaryButtonReleased() && !m_scrollBarDragging) 
                {
                    if (IsMouseOver && !m_isOpen || IsMouseOverSelectedItem() && m_isOpen) 
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                        SwitchComboboxMode();
                        captureInput = this;
                    }
                }

                if (HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Enter) ||
                                 MyInput.Static.IsNewKeyPressed(MyKeys.Space)))
                {
                    MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                    if ((m_preselectedKeyboardIndex.HasValue) && (m_preselectedKeyboardIndex.Value < m_items.Count))
                    {
                        if (m_isOpen == false)
                        {
                            SetScrollBarPositionByIndex(m_selected.Key);
                        }
                        else
                        {
                            SelectItemByKey(m_items[m_preselectedKeyboardIndex.Value].Key);
                        }
                    }

                    //  Close but capture focus for this update so parent screen don't receive this ENTER
                    SwitchComboboxMode();
                    captureInput = this;
                }

                //  In listbox mode, the list is always in opened state
                if (m_isOpen == true)
                {
                    #region Handle mouse and scrollbar interaction
                    if (m_showScrollBar == true && MyInput.Static.IsPrimaryButtonPressed() == true)
                    {
                        //  Handles mouse input of dragging the scrollbar up or down
                        Vector2 position = GetPositionAbsoluteCenterLeft();
                        MyRectangle2D openedArea = GetOpenedArea();
                        openedArea.LeftTop += GetPositionAbsoluteTopLeft();
                        float minX = position.X + Size.X - m_scrollBarWidth;
                        float maxX = position.X + Size.X;
                        float minY = position.Y + Size.Y / 2.0f;
                        float maxY = minY + openedArea.Size.Y;

                        // if we are already scrolling, the area used for scrollbar moving will be extended to whole screen
                        if (m_scrollBarDragging)
                        {
                            minX = float.NegativeInfinity;
                            maxX = float.PositiveInfinity;
                            minY = float.NegativeInfinity;
                            maxY = float.PositiveInfinity;
                        }

                        // In case mouse cursor is intersecting scrollbar area, start scroll bar dragging mode
                        if ((MyGuiManager.MouseCursorPosition.X >= minX) && (MyGuiManager.MouseCursorPosition.X <= maxX)
                            && (MyGuiManager.MouseCursorPosition.Y >= minY) && (MyGuiManager.MouseCursorPosition.Y <= maxY))
                        {                           
                            // Are we over thee scroll bar handle?
                            float P0 = m_scrollBarCurrentPosition + (openedArea.LeftTop.Y);
                            if (MyGuiManager.MouseCursorPosition.Y > P0 && MyGuiManager.MouseCursorPosition.Y < P0 + m_scrollBarHeight)
                            {
                                if (m_mousePositionReinit)
                                {
                                    m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                                    m_mousePositionReinit = false;
                                }

                                float mdeff = MyGuiManager.MouseCursorPosition.Y - m_mouseOldPosition;
                                if (mdeff > float.Epsilon || mdeff < float.Epsilon)
                                {
                                    SetScrollBarPosition(m_scrollBarCurrentNonadjustedPosition + mdeff);
                                }

                                m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                            }
                            else
                            {
                                // If we are not over the scrollbar handle -> jump:
                                float scrollPositionY = MyGuiManager.MouseCursorPosition.Y - (openedArea.LeftTop.Y) - m_scrollBarHeight / 2.0f;
                                SetScrollBarPosition(scrollPositionY);
                            }

                            m_scrollBarDragging = true;
                        }
                    }
                    #endregion

                    // Reset mouse parameters after it was released now
                    if (MyInput.Static.IsNewPrimaryButtonReleased())
                    {
                        m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                        m_mousePositionReinit = true;
                    }

                    //  If ESC was pressed while combobox has keyboard focus and combobox was opened, then close combobox but don't send this ESC to parent screen
                    //  Or if user clicked outside of the combobox's area
                    if ((HasFocus && (MyInput.Static.IsNewKeyPressed(MyKeys.Escape) || MyInput.Static.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))) ||
                        (!IsMouseOverOnOpenedArea() && !IsMouseOver && MyInput.Static.IsNewPrimaryButtonReleased())
                        )
                    {
                        MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                        m_isOpen = false;
                    }

                    //  Still capture focus, don't allow parent screen to receive this ESCAPE
                    captureInput = this;

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //  Mouse controling items in the combobox
                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    if (m_scrollBarDragging == false)
                    {
                        #region Handle item that is under mouse cursor
                        //  Search for item that is under the mouse cursor
                        m_preselectedMouseOverPrevious = m_preselectedMouseOver;
                        m_preselectedMouseOver = null;

                        //  The following are used for controlling scroll window range
                        int startIndex = 0;
                        int endIndex = m_items.Count;
                        float widthOffSet = 0f;
                        if (m_showScrollBar == true)
                        {
                            startIndex = m_displayItemsStartIndex;
                            endIndex = m_displayItemsEndIndex;
                            widthOffSet = 0.025f;
                        }

                        for (int i = startIndex; i < endIndex; i++)
                        {
                            Vector2 position = GetOpenItemPosition(i - m_displayItemsStartIndex);
                            MyRectangle2D openedArea = GetOpenedArea();

                            Vector2 min = new Vector2(position.X, Math.Max(openedArea.LeftTop.Y, position.Y));
                            Vector2 max = min + new Vector2(Size.X - widthOffSet, m_comboboxItemDeltaHeight);
                            var mousePos = MyGuiManager.MouseCursorPosition - GetPositionAbsoluteTopLeft();
                            if ((mousePos.X >= min.X) &&
                                (mousePos.X <= max.X) &&
                                (mousePos.Y >= min.Y) &&
                                (mousePos.Y <= max.Y))
                            {
                                m_preselectedMouseOver = m_items[i];
                            }
                        }

                        if (m_preselectedMouseOver != null && m_preselectedMouseOver != m_preselectedMouseOverPrevious)
                        {
                            MyGuiSoundManager.PlaySound(GuiSounds.MouseOver);
                        }

                        #endregion

                        #region Selecting item in opened combobox area
                        //  Select item when user clicks on it
                        if (MyInput.Static.IsNewPrimaryButtonReleased() == true && m_preselectedMouseOver != null)
                        {
                            SelectItemByKey(m_preselectedMouseOver.Key);

                            MyGuiSoundManager.PlaySound(GuiSounds.MouseClick);
                            m_isOpen = false;

                            //  Still capture focus, don't allow parent screen to receive this CLICK
                            captureInput = this;
                        }
                        #endregion

                        #region Keyboard and scrollwheel controlling items in combobox

                        if (HasFocus || IsMouseOverOnOpenedArea())
                        {
                            if (m_mouseWheelValueLast == null) m_mouseWheelValueLast = MyInput.Static.MouseScrollWheelValue();

                            if (MyInput.Static.MouseScrollWheelValue() < m_mouseWheelValueLast)
                            {
                                HandleItemMovement(true);
                                captureInput = this;
                            }
                            else if (MyInput.Static.MouseScrollWheelValue() > m_mouseWheelValueLast)
                            {
                                HandleItemMovement(false);
                                captureInput = this;
                            }

                            //  Keyboard and mouse movement
                            if (MyInput.Static.IsNewKeyPressed(MyKeys.Down) || MyInput.Static.IsNewGamepadKeyDownPressed())
                            {
                                HandleItemMovement(true);
                                captureInput = this;
                                if (MyInput.Static.IsNewGamepadKeyDownPressed())
                                    SnapCursorToControl(m_preselectedKeyboardIndex.Value);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Up) || MyInput.Static.IsNewGamepadKeyUpPressed())
                            {
                                HandleItemMovement(false);
                                captureInput = this;
                                if (MyInput.Static.IsNewGamepadKeyUpPressed())
                                    SnapCursorToControl(m_preselectedKeyboardIndex.Value);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.PageDown))
                            {
                                HandleItemMovement(true, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.PageUp))
                            {
                                HandleItemMovement(false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Home))
                            {
                                HandleItemMovement(true, false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.End))
                            {
                                HandleItemMovement(false, false, true);
                            }
                            else if (MyInput.Static.IsNewKeyPressed(MyKeys.Tab))
                            {
                                //  We want to close the combobox without selecting any item and forward TAB or SHIF+TAB to parent screen so it can navigate to next control
                                if (m_isOpen) SwitchComboboxMode();
                                captureInput = null;
                            }

                            m_mouseWheelValueLast = MyInput.Static.MouseScrollWheelValue();
                        }
                        #endregion
                    }
                    else
                    {
                        // When finished scrollbar dragging, set it to false and enable input capturing again
                        if (MyInput.Static.IsNewPrimaryButtonReleased()) 
                            m_scrollBarDragging = false;
                        captureInput = this;
                    }
                }
            }

            return captureInput;
        }