public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            if (DraggedItem != null)
            {
                if (input.IsLeftMousePressed())
                {
                    float dragDistanceSquared = MyGuiManager.GetScreenSizeFromNormalizedSize(StartDragPosition - MyGuiManager.MouseCursorPosition).LengthSquared();
                    if (dragDistanceSquared > 16)   // Drag Detection Sensitivity - 4 pixels
                    {
                        Dragging = m_frameBackDragging = true;
                    }
                }
                else
                {
                    if (Drop != null && Dragging)
                    {
                        Drop(this, EventArgs.Empty);
                    }

                    Dragging    = false;
                    DraggedItem = null;
                }
            }

            return(base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate));
        }
Пример #2
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captured = false;

            if (!CanScroll())
            {
                return(false);
            }

            switch (m_state)
            {
            case State.READY:
                if (input.IsNewLeftMousePressed() && MyGUIHelper.Contains(m_position + GetCarretPosition(), m_caretSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
                {
                    captured    = true;
                    m_state     = State.DRAG;
                    m_dragClick = MyGuiManager.MouseCursorPosition;
                }
                break;

            case State.DRAG:
                if (!input.IsLeftMousePressed())
                {
                    m_state = State.READY;
                }
                else
                {
                    ChangeValue((MyGuiManager.MouseCursorPosition.X - m_dragClick.X) * (m_max - m_page) / (m_size.X - m_caretSize.X));
                    m_dragClick = MyGuiManager.MouseCursorPosition;
                }
                captured = true;
                break;
            }
            return(captured);
        }
Пример #3
0
        public virtual void HandleUnhandledInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            // by calling this we are soure that no control handled input already
            if (m_windowIsMovable)
            {
                if (input.IsNewLeftMousePressed() && IsMouseOver())
                {
                    m_draged = true;
                    m_mouseDragEntryPoint = new Vector2(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y);
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("drag");
                }

                if (input.IsLeftMousePressed() && m_draged)
                {
                    Vector2 newMousePoint = new Vector2(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y);
                    Vector2 deltaPos      = newMousePoint - m_mouseDragEntryPoint;
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall( deltaPos.ToString() );

                    m_mouseDragEntryPoint = newMousePoint;
                    m_position           += deltaPos;
                }

                if (input.IsNewLeftMouseReleased())
                {
                    m_draged = false;
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("undrag");
                }
            }
        }
Пример #4
0
        private bool HandleInput(MyGuiInput input)
        {
            bool captureInput = false;

            if (IsActive())
            {
                // handling left mouse pressed drag and drop
                if (m_currentDropHandleType.Value == MyDropHandleType.LeftMousePressed)
                {
                    // still dragging
                    if (input.IsLeftMousePressed())
                    {
                        captureInput = true;
                    }
                    // dropping
                    else
                    {
                        HandleDropingItem();
                    }
                }
                // handling left mouse click drag and drop
                else if (m_currentDropHandleType.Value == MyDropHandleType.LeftMouseClick)
                {
                    if (input.IsNewLeftMousePressed())
                    {
                        HandleDropingItem();
                        captureInput = true;
                    }
                }
            }
            return(captureInput);
        }
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            if (DraggedItem != null)
            {
                if (input.IsLeftMousePressed())
                {
                    float dragDistanceSquared = MyGuiManager.GetScreenSizeFromNormalizedSize(StartDragPosition - MyGuiManager.MouseCursorPosition).LengthSquared();
                    if (dragDistanceSquared > 16)   // Drag Detection Sensitivity - 4 pixels
                    {
                        Dragging = m_frameBackDragging = true;
                    }
                }
                else
                {
                    if (Drop != null && Dragging)
                    {
                        Drop(this, EventArgs.Empty);
                    }

                    Dragging = false;
                    DraggedItem = null;
                }
            }

            return base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);
        }
        /// <summary>
        /// Handling scrollbar's input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="hasKeyboardActiveControl"></param>
        /// <param name="hasKeyboardActiveControlPrevious"></param>
        /// <param name="receivedFocusInThisUpdate"></param>
        /// <returns></returns>
        public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = false;

            // still scrolling
            if (IsScrolling() && input.IsLeftMousePressed())
            {
                if (m_mouseLastPosition != null)
                {
                    Vector2 distance = new Vector2(0.0f, 0.0f);
                    Vector2 sliderDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value;
                    switch (m_scrollDirection)
                    {
                    case MyScrollDirection.Horizontal:
                        distance.X = sliderDistanceFromLastUpdate.X;
                        break;

                    case MyScrollDirection.Vertical:
                        distance.Y = sliderDistanceFromLastUpdate.Y;
                        break;
                    }
                    if (distance.Length() > 0.00001f)
                    {
                        Vector2 newScrollSliderPosition = m_scrollSliderPosition + distance;
                        FixScrollSliderPosition(ref newScrollSliderPosition);

                        if (newScrollSliderPosition != m_scrollSliderPosition)
                        {
                            SetScrollSliderPosition(newScrollSliderPosition);
                            m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                        }
                    }
                    captureInput = true;
                }
            }
            // start scrolling
            else if (!IsScrolling() && input.IsNewLeftMousePressed() && IsMouseOverScrollSlider())
            {
                m_isScrollSliderDragging = true;
                m_mouseLastPosition      = MyGuiManager.MouseCursorPosition;
                captureInput             = true;
            }
            // no scrolling
            else
            {
                m_mouseLastPosition      = null;
                m_isScrollSliderDragging = false;
            }

            return(captureInput);
        }
Пример #7
0
        private bool HandleControlMoving(MyGuiInput input)
        {
            bool dragging = false;

            if (input.IsLeftMousePressed())
            {
                // if we dragging control, then we set it new position by mouse
                if (m_draggingControl != null)
                {
                    m_draggingControl.SetPosition(MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - m_draggingControlOffset);
                    dragging = true;
                }
                // if we are not dragging control, then we try find it
                else
                {
                    MyGuiControlBase controlToDrag = null;
                    // first we try find control, which has mouse over
                    controlToDrag = GetMouseOverControl();
                    // if there is no control which has mouse over, then we try find control, which is under mouse cursor (because some controls has no mouse over all time)
                    if (controlToDrag == null)
                    {
                        controlToDrag = GetControlUnderMouseCursor();
                    }

                    // if we found any contorl to drag, then we set it to dragging control
                    if (controlToDrag != null)
                    {
                        m_draggingControl       = controlToDrag;
                        m_draggingControlOffset = MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - controlToDrag.GetPosition();
                        dragging = true;
                    }
                }
            }
            else
            {
                m_draggingControl = null;
                if (input.IsNewLeftMouseReleased())
                {
                    dragging = true;
                }
            }

            return(dragging);
        }
Пример #8
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public virtual bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            if (m_isActiveControl)
            {
                //m_hasKeyboardActiveControlInPrevious = m_hasKeyboardActiveControl;
                m_hasKeyboardActiveControl = hasKeyboardActiveControl;

                m_isMouseOverInPrevious = m_isMouseOver;
                m_isMouseOver           = CheckMouseOver();
                m_mouseButtonPressed    = IsMouseOver() && input.IsLeftMousePressed();

                if (((m_isMouseOver == true) && (m_isMouseOverInPrevious == false)) ||
                    ((m_hasKeyboardActiveControl == true) && (hasKeyboardActiveControlPrevious == false)))
                {
                    if (receivedFocusInThisUpdate == false)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
                    }
                }
            }

            // if mouseover this control longer than specified period, show tooltip for the control
            if ((m_isMouseOver == true) && (m_isMouseOverInPrevious == true))
            {
                if (m_showToolTip == false)
                {
                    m_showToolTipDelay = MyMinerGame.TotalGamePlayTimeInMilliseconds + MyGuiConstants.SHOW_CONTROL_TOOLTIP_DELAY;
                    m_showToolTip      = true;
                }
            }
            else
            {
                m_showToolTip = false;
            }

            return(false);
        }
 private bool HandleInput(MyGuiInput input)
 {
     bool captureInput = false;
     if (IsActive())
     {
         // handling left mouse pressed drag and drop
         if (m_currentDropHandleType.Value == MyDropHandleType.LeftMousePressed)
         {
             // still dragging
             if (input.IsLeftMousePressed())
             {
                 captureInput = true;
             }
             // dropping
             else
             {
                 HandleDropingItem();
             }
         }
         // handling left mouse click drag and drop
         else if (m_currentDropHandleType.Value == MyDropHandleType.LeftMouseClick)
         {
             if (input.IsNewLeftMousePressed())
             {
                 HandleDropingItem();
                 captureInput = true;
             }
         }
     }
     return captureInput;
 }
Пример #10
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            if (Enabled && !captureInput && m_rows.Count > 0)
            {
                #region handle scrollbar
                if (m_verticalScrollBar != null)
                {
                    if (m_verticalScrollBar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate))
                    {
                        captureInput = true;
                    }
                }
                if (m_horizontalScrollBar != null)
                {
                    if (m_horizontalScrollBar.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate))
                    {
                        captureInput = true;
                    }
                }
                #endregion

                // handle only if mouse is over the control
                if (IsMouseOver() && !captureInput)
                {
                    #region handle mouse
                    HandleCurrentMousePreselected();
                    m_doubleClickTimer += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;

                    // selection by mouse
                    var preselectedItem = GetMousePreselectedItem();
                    if (input.IsNewLeftMousePressed())
                    {
                        if (preselectedItem != null && preselectedItem.Enabled)
                        {
                            // double click handle                            
                            if (m_doubleClickTimer <= DOUBLE_CLICK_DELAY && m_mouseLastPosition != null && (m_mouseLastPosition.Value - MyGuiManager.MouseCursorPosition).Length() <= 0.005f)
                            {
                                if (ItemDoubleClick != null)
                                {
                                    ItemDoubleClick(this, new MyGuiControlListboxItemEventArgs(m_mousePreselectedRowIndex.Value, m_mousePreselectedItemIndex.Value, preselectedItem.Key));
                                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                }
                            }
                            // click handle
                            else
                            {
                                int? oldSelectedRowIndex = m_selectedRowIndex;
                                int? oldSelectedItemIndex = m_selectedItemIndex;

                                SetSelectedItem(m_mousePreselectedRowIndex, m_mousePreselectedItemIndex);
                                HandleMultiSelect(input.IsAnyCtrlKeyPressed(), input.IsAnyShiftKeyPressed(),
                                    oldSelectedRowIndex, oldSelectedItemIndex, m_selectedRowIndex, m_selectedItemIndex);

                                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                                ResetPreselected();
                            }

                            m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                            m_doubleClickTimer = 0;
                            m_isListboxItemDragging = true;
                            captureInput = true;
                        }
                    }
                    // listbox item dragging
                    else if (input.IsLeftMousePressed())
                    {
                        if (m_isListboxItemDragging)
                        {
                            if (m_mouseLastPosition != null &&
                                preselectedItem != null &&
                                preselectedItem.Enabled && 
                                m_mousePreselectedItemIndex == m_previousMousePreselectedItemIndex &&
                                m_mousePreselectedRowIndex == m_previousMousePreselectedRowIndex)
                            {
                                Vector2 mouseDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value;
                                if (mouseDistanceFromLastUpdate.Length() != 0.0f)
                                {
                                    if (ItemDrag != null)
                                    {
                                        ItemDrag(this, new MyGuiControlListboxItemEventArgs(m_mousePreselectedRowIndex.Value, m_previousMousePreselectedItemIndex.Value, preselectedItem.Key));
                                    }
                                    m_isListboxItemDragging = false;
                                }

                                captureInput = true;
                            }
                        }
                        m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                    }
                    else
                    {
                        m_isListboxItemDragging = false;
                    }
                    #endregion

                    #region handle keyboard
                    if (hasKeyboardActiveControl)
                    {
                        // handle selection move
                        if (HandleCurrentPreselected(input))
                        {
                            captureInput = true;
                            preselectedItem = GetPreselectedItem();
                        }

                        // selection by keyboard
                        if (input.IsNewKeyPress(Keys.Enter) || input.IsNewKeyPress(Keys.Space))
                        {                            
                            if (preselectedItem != null && preselectedItem.Enabled)
                            {
                                SetSelectedItem(m_preselectedRowIndex, m_preselectedItemIndex);
                                MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            }
                            captureInput = true;
                        }
                    }
                    else
                    {
                        HandleMouseWheelScroll(input, ref captureInput);
                    }
                    #endregion
                }
                else
                {
                    m_mousePreselectedItemIndex = null;
                    m_mousePreselectedRowIndex = null;
                }
            }

            return captureInput;
        }
Пример #11
0
        public virtual void HandleUnhandledInput(MyGuiInput input, bool receivedFocusInThisUpdate)
        {
            // by calling this we are soure that no control handled input already 
            if (m_windowIsMovable)
            {
                if (input.IsNewLeftMousePressed() && IsMouseOver())
                {
                    m_draged = true;
                    m_mouseDragEntryPoint = new Vector2(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y);
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("drag");
                }

                if (input.IsLeftMousePressed() && m_draged)
                {

                    Vector2 newMousePoint = new Vector2(MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y);
                    Vector2 deltaPos = newMousePoint - m_mouseDragEntryPoint;
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall( deltaPos.ToString() );

                    m_mouseDragEntryPoint = newMousePoint;
                    m_position += deltaPos;
                    
                }

                if (input.IsNewLeftMouseReleased())
                {
                    m_draged = false;
                    //KeenSoftwareHouse.Library.Trace.Trace.SendMsgLastCall("undrag");
                }
            }        
        }
Пример #12
0
        private bool HandleControlMoving(MyGuiInput input)
        {
            bool dragging = false;
            
            if (input.IsLeftMousePressed())
            {
                // if we dragging control, then we set it new position by mouse
                if (m_draggingControl != null)
                {
                    m_draggingControl.SetPosition(MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - m_draggingControlOffset);
                    dragging = true;
                }
                // if we are not dragging control, then we try find it
                else
                {
                    MyGuiControlBase controlToDrag = null;
                    // first we try find control, which has mouse over
                    controlToDrag = GetMouseOverControl();                    
                    // if there is no control which has mouse over, then we try find control, which is under mouse cursor (because some controls has no mouse over all time)
                    if (controlToDrag == null)
                    {
                        controlToDrag = GetControlUnderMouseCursor();
                    }

                    // if we found any contorl to drag, then we set it to dragging control
                    if(controlToDrag != null)
                    {
                        m_draggingControl = controlToDrag;
                        m_draggingControlOffset = MyGuiManager.MouseCursorPosition - m_draggingControl.GetParent().GetPositionAbsolute() - controlToDrag.GetPosition();
                        dragging = true;
                    }
                }
            }
            else
            {
                m_draggingControl = null;
                if (input.IsNewLeftMouseReleased())
                {
                    dragging = true;
                }
            }            

            return dragging;
        }
Пример #13
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = base.HandleInput(input, hasKeyboardActiveControl, hasKeyboardActiveControlPrevious, receivedFocusInThisUpdate);

            //Assert();

            if (captureInput == false)
            {
                if ((IsMouseOver() == true) && (input.IsNewLeftMousePressed() == true) && (m_supportListBoxMode == false && !m_isOpen) && m_scrollBarDragging == false)
                    return true;
                // Make sure here, that whenever not in listbox mode, switch opened/closed state when clicked on combobobox
                //if ((IsMouseOver() == true) && (input.IsNewLeftMouseReleased() == true) && (m_supportListBoxMode == false) && m_scrollBarDragging == false)
                if (input.IsNewLeftMouseReleased() && !m_supportListBoxMode && !m_scrollBarDragging) 
                {
                    if (IsMouseOver() && !m_isOpen || IsMouseOverSelectedItem() && m_isOpen) 
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                        SwitchComboboxMode();
                        captureInput = true;
                    }
                }

                if ((hasKeyboardActiveControl == true) && ((input.IsNewKeyPress(Keys.Enter)) || (input.IsNewKeyPress(Keys.Space) || (input.IsNewGameControlPressed(MyGameControlEnums.FIRE_PRIMARY) && !input.IsNewLeftMousePressed()))))
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);

                    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 = true;
                }

                //  In listbox mode, the list is always in opened state
                if (m_isOpen == true)
                {                   
                    #region Handle mouse and scrollbar interaction
                    if (m_showScrollBar == true && input.IsLeftMousePressed() == true)
                    {
                        //  Handles mouse input of dragging the scrollbar up or down
                        Vector2 position = GetDrawPosition();
                        MyRectangle2D openedArea = GetOpenedArea();
                        float minX = position.X + m_size.Value.X - m_scrollBarWidth;
                        float maxX = position.X + m_size.Value.X;
                        float minY = m_supportListBoxMode == false ? position.Y + m_size.Value.Y / 2.0f : position.Y - m_size.Value.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 = 0;
                            maxX = 1;
                            minY = 0;
                            maxY = 1;
                        }

                        // 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.Value + (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 (input.IsNewLeftMouseReleased())
                    {
                        m_mouseOldPosition = MyGuiManager.MouseCursorPosition.Y;
                        m_mousePositionReinit = true;
                    }

                    //  Don't try close combobox if listbox mode is suported.
                    if (m_supportListBoxMode == false)
                    {
                        //  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 (((hasKeyboardActiveControl == true) && (input.IsNewKeyPress(Keys.Escape) || input.IsJoystickButtonNewPressed(MyJoystickButtonsEnum.J02))) ||
                            ((IsMouseOverOnOpenedArea() != true) && (IsMouseOver() != true) && (input.IsNewLeftMouseReleased() == true)))
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            m_isOpen = false;
                        }

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

                    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    //  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)
                        {
                            if (m_supportSmoothScroll == true)
                            {
                                //  Extend the display items range by 1(top and bottom) in smooth scrolling mode because of the scenario of partial rendering
                                startIndex = Math.Max(0, m_displayItemsStartIndex - 1);
                                endIndex = Math.Min(m_items.Count, endIndex + 1);
                            }
                            else
                            {
                                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(m_size.Value.X - widthOffSet, m_comboboxItemDeltaHeight);

                            if ((MyGuiManager.MouseCursorPosition.X >= min.X) && (MyGuiManager.MouseCursorPosition.X <= max.X) && (MyGuiManager.MouseCursorPosition.Y >= min.Y) && (MyGuiManager.MouseCursorPosition.Y <= max.Y))
                            {
                                m_preselectedMouseOver = m_items[i];

                                //  Auto snap(scroll) current pre-selected/selected item to be fully visible 
                                if (m_supportSmoothScroll == true)
                                {
                                    if (position.Y + 0.001f < openedArea.LeftTop.Y)
                                    {
                                        float scrollUpBy = m_scrollBarCurrentPosition.Value;
                                        scrollUpBy -= 0.001f;
                                        SetScrollBarPosition(scrollUpBy);
                                    }
                                    else if (position.Y + m_comboboxItemDeltaHeight - 0.001f > openedArea.LeftTop.Y + openedArea.Size.Y)
                                    {
                                        float scrollDownBy = m_scrollBarCurrentPosition.Value;
                                        scrollDownBy += 0.001f;
                                        SetScrollBarPosition(scrollDownBy);
                                    }
                                }
                            }
                        }

                        if (m_preselectedMouseOver != null && m_preselectedMouseOver != m_preselectedMouseOverPrevious)
                        {
                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
                        }

                        //  To be used to check for mouse double click action
                        m_doubleClickTimer += MyConstants.PHYSICS_STEP_SIZE_IN_MILLISECONDS;

                        #endregion

                        #region Selecting item in opened combobox area
                        //  Select item when user clicks on it
                        if (input.IsNewLeftMouseReleased() == true && m_preselectedMouseOver != null)
                        {                            
                            //  Checks for double click, only listbox mode supports this type of input
                            if (m_supportListBoxMode == true && m_preselectedMouseOver.Key.Equals(m_selected.Key) == true && m_doubleClickTimer < DOUBLE_CLICK_DELAY)
                            {
                                if (OnSelectItemDoubleClick != null)
                                    OnSelectItemDoubleClick();
                            }
                            m_doubleClickTimer = 0;

                            //m_selected = m_preselectedMouseOver;
                            SelectItemByKey(m_preselectedMouseOver.Key);

                            MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseClick);
                            if (m_supportListBoxMode == false) m_isOpen = false;

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

                        #region Keyboard and scrollwheel controlling items in combobox

                        if (hasKeyboardActiveControl == true || IsMouseOverOnOpenedArea())
                        {
                            if (m_mouseWheelValueLast == null) m_mouseWheelValueLast = input.MouseScrollWheelValue();

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

                            //  Keyboard and mouse movement
                            if (input.IsNewKeyPress(Keys.Down) || input.IsNewGamepadKeyDownPressed())
                            {
                                HandleItemMovement(true);
                                captureInput = true;
                            }
                            else if (input.IsNewKeyPress(Keys.Up) || input.IsNewGamepadKeyUpPressed())
                            {
                                HandleItemMovement(false);
                                captureInput = true;
                            }
                            else if (input.IsNewKeyPress(Keys.PageDown))
                            {
                                HandleItemMovement(true, true);
                            }
                            else if (input.IsNewKeyPress(Keys.PageUp))
                            {
                                HandleItemMovement(false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.Home))
                            {
                                HandleItemMovement(true, false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.End))
                            {
                                HandleItemMovement(false, false, true);
                            }
                            else if (input.IsNewKeyPress(Keys.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_supportListBoxMode == false && m_isOpen) SwitchComboboxMode();
                                captureInput = false;
                            }

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

            return captureInput;
        }
        /// <summary>
        /// Handling scrollbar's input
        /// </summary>
        /// <param name="input"></param>
        /// <param name="hasKeyboardActiveControl"></param>
        /// <param name="hasKeyboardActiveControlPrevious"></param>
        /// <param name="receivedFocusInThisUpdate"></param>
        /// <returns></returns>
        public bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captureInput = false;
            // still scrolling
            if (IsScrolling() && input.IsLeftMousePressed())
            {
                if (m_mouseLastPosition != null)
                {
                    Vector2 distance = new Vector2(0.0f, 0.0f);
                    Vector2 sliderDistanceFromLastUpdate = MyGuiManager.MouseCursorPosition - m_mouseLastPosition.Value;
                    switch (m_scrollDirection)
                    {
                        case MyScrollDirection.Horizontal:
                            distance.X = sliderDistanceFromLastUpdate.X;
                            break;
                        case MyScrollDirection.Vertical:
                            distance.Y = sliderDistanceFromLastUpdate.Y;
                            break;
                    }
                    if (distance.Length() > 0.00001f)
                    {
                        Vector2 newScrollSliderPosition = m_scrollSliderPosition + distance;
                        FixScrollSliderPosition(ref newScrollSliderPosition);

                        if (newScrollSliderPosition != m_scrollSliderPosition)
                        {                            
                            SetScrollSliderPosition(newScrollSliderPosition);
                            m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                        }

                    }
                    captureInput = true;
                }
            }
            // start scrolling
            else if (!IsScrolling() && input.IsNewLeftMousePressed() && IsMouseOverScrollSlider())
            {
                m_isScrollSliderDragging = true;
                m_mouseLastPosition = MyGuiManager.MouseCursorPosition;
                captureInput = true;
            }
            // no scrolling
            else
            {
                m_mouseLastPosition = null;
                m_isScrollSliderDragging = false;
            }

            return captureInput;
        }
Пример #15
0
        //  Method returns true if input was captured by control, so no other controls, nor screen can use input in this update
        public virtual bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {            
            if (m_isActiveControl)
            {
                //m_hasKeyboardActiveControlInPrevious = m_hasKeyboardActiveControl;
                m_hasKeyboardActiveControl = hasKeyboardActiveControl;

                m_isMouseOverInPrevious = m_isMouseOver;
                m_isMouseOver = CheckMouseOver();
                m_mouseButtonPressed = IsMouseOver() && input.IsLeftMousePressed();

                if (((m_isMouseOver == true) && (m_isMouseOverInPrevious == false)) ||
                    ((m_hasKeyboardActiveControl == true) && (hasKeyboardActiveControlPrevious == false)))
                {
                    if (receivedFocusInThisUpdate == false)
                    {
                        MyAudio.AddCue2D(MySoundCuesEnum.GuiMouseOver);
                    }
                }
            }

            // if mouseover this control longer than specified period, show tooltip for the control
            if ((m_isMouseOver == true) && (m_isMouseOverInPrevious == true))
            {
                if (m_showToolTip == false)
                {
                    m_showToolTipDelay = MyMinerGame.TotalGamePlayTimeInMilliseconds + MyGuiConstants.SHOW_CONTROL_TOOLTIP_DELAY;
                    m_showToolTip = true;
                }
            }
            else
            {
                m_showToolTip = false;
            }

            return false;
        }
Пример #16
0
        public override bool HandleInput(MyGuiInput input, bool hasKeyboardActiveControl, bool hasKeyboardActiveControlPrevious, bool receivedFocusInThisUpdate)
        {
            bool captured = false;
            if (!CanScroll())
            {
                return false;
            }

            switch (m_state)
            {
                case State.READY:
                    if (input.IsNewLeftMousePressed() && MyGUIHelper.Contains(m_position + GetCarretPosition(), m_caretSize, MyGuiManager.MouseCursorPosition.X, MyGuiManager.MouseCursorPosition.Y))
                    {
                        captured = true;
                        m_state = State.DRAG;
                        m_dragClick = MyGuiManager.MouseCursorPosition;
                    }
                    break;
                case State.DRAG:
                    if (!input.IsLeftMousePressed())
                    {
                        m_state = State.READY;
                    }
                    else
                    {
                        ChangeValue((MyGuiManager.MouseCursorPosition.X - m_dragClick.X) * (m_max - m_page) / (m_size.X - m_caretSize.X));
                        m_dragClick = MyGuiManager.MouseCursorPosition;
                    }
                    captured = true;
                    break;
            }
            return captured;
        }