示例#1
0
        private void InternalHandleMouseInput()
        {
            // clip the mouse position
            Point clippedPosition = m_Input.MousePosition;

            ClipMouse(ref clippedPosition);

            // Get the topmost control that is under the mouse and handles mouse input.
            // If this control is different from the previously focused control,
            // send that previous control a MouseOut event.
            AControl focusedControl = InternalGetMouseOverControl(clippedPosition);

            if ((MouseOverControl != null) && (focusedControl != MouseOverControl))
            {
                MouseOverControl.MouseOut(clippedPosition);
                // Also let the parent control know we've been moused out (for gumps).
                if (MouseOverControl.RootParent != null)
                {
                    if (focusedControl == null || MouseOverControl.RootParent != focusedControl.RootParent)
                    {
                        MouseOverControl.RootParent.MouseOut(clippedPosition);
                    }
                }
            }

            if (focusedControl != null)
            {
                focusedControl.MouseOver(clippedPosition);
                if (m_MouseDownControl[0] == focusedControl)
                {
                    AttemptDragControl(focusedControl, clippedPosition);
                }
                if (IsDraggingControl)
                {
                    DoDragControl(clippedPosition);
                }
            }

            // Set the new MouseOverControl.
            m_MouseOverControl = focusedControl;

            // Send a MouseOver event to any control that was previously the target of a MouseDown event.
            for (int iButton = 0; iButton < 5; iButton++)
            {
                if ((m_MouseDownControl[iButton] != null) && (m_MouseDownControl[iButton] != focusedControl))
                {
                    m_MouseDownControl[iButton].MouseOver(clippedPosition);
                }
            }

            // The cursor and world input objects occasionally must block input events from reaching the UI:
            // e.g. when the cursor is carrying an object.
            if ((IsModalControlOpen == false) && (ObjectsBlockingInput == true))
            {
                return;
            }

            List <InputEventMouse> events = m_Input.GetMouseEvents();

            foreach (InputEventMouse e in events)
            {
                // MouseDown event: the currently focused control gets a MouseDown event, and if
                // it handles Keyboard input, gets Keyboard focus as well.
                if (e.EventType == MouseEvent.Down)
                {
                    if (focusedControl != null)
                    {
                        MakeTopMostGump(focusedControl);
                        focusedControl.MouseDown(clippedPosition, e.Button);
                        if (focusedControl.HandlesKeyboardFocus)
                        {
                            m_keyboardFocusControl = focusedControl;
                        }
                        m_MouseDownControl[(int)e.Button] = focusedControl;
                    }
                    else
                    {
                        // close modal controls if they can be closed with a mouse down outside their drawn area
                        if (IsModalControlOpen)
                        {
                            foreach (AControl c in m_Controls)
                            {
                                if (c.MetaData.IsModal && c.MetaData.ModalClickOutsideAreaClosesThisControl)
                                {
                                    c.Dispose();
                                }
                            }
                        }
                    }
                }

                // MouseUp and MouseClick events
                if (e.EventType == MouseEvent.Up)
                {
                    int btn = (int)e.Button;

                    // If there is a currently focused control:
                    // 1.   If the currently focused control is the same control that was MouseDowned on with this button,
                    //      then send that control a MouseClick event.
                    // 2.   Send the currently focused control a MouseUp event.
                    // 3.   If the currently focused control is NOT the same control that was MouseDowned on with this button,
                    //      send that MouseDowned control a MouseUp event (but it does not receive MouseClick).
                    // If there is NOT a currently focused control, then simply inform the control that was MouseDowned on
                    // with this button that the button has been released, by sending it a MouseUp event.

                    EndDragControl(e.Position);

                    if (focusedControl != null)
                    {
                        if (m_MouseDownControl[btn] != null && focusedControl == m_MouseDownControl[btn])
                        {
                            focusedControl.MouseClick(clippedPosition, e.Button);
                        }
                        focusedControl.MouseUp(clippedPosition, e.Button);
                        if (m_MouseDownControl[btn] != null && focusedControl != m_MouseDownControl[btn])
                        {
                            m_MouseDownControl[btn].MouseUp(clippedPosition, e.Button);
                        }
                    }
                    else
                    {
                        if (m_MouseDownControl[btn] != null)
                        {
                            m_MouseDownControl[btn].MouseUp(clippedPosition, e.Button);
                        }
                    }

                    m_MouseDownControl[btn] = null;
                }
            }
        }
示例#2
0
        private void InternalHandleMouseInput()
        {
            // Get the topmost control that is under the mouse and handles mouse input.
            // If this control is different from the previously focused control,
            // send that previous control a MouseOut event.
            AControl focusedControl = InternalGetMouseOverControl();

            if ((MouseOverControl != null) && (focusedControl != MouseOverControl))
            {
                MouseOverControl.MouseOut(Engine.Input.MousePosition);
            }
            if (focusedControl != null)
            {
                focusedControl.MouseOver(Engine.Input.MousePosition);
            }

            // Set the new MouseOverControl.
            m_MouseOverControl = focusedControl;

            // Send a MouseOver event to any control that was previously the target of a MouseDown event.
            for (int iButton = 0; iButton < 5; iButton++)
            {
                if ((m_MouseDownControl[iButton] != null) && (m_MouseDownControl[iButton] != focusedControl))
                {
                    m_MouseDownControl[iButton].MouseOver(Engine.Input.MousePosition);
                }
            }

            // The cursor and world input objects occasionally must block input events from reaching the UI:
            // e.g. when the cursor is carrying an object.
            if (!IsModalControlOpen && ObjectsBlockingInput)
            {
                return;
            }

            List <InputEventMouse> events = Engine.Input.GetMouseEvents();

            foreach (InputEventMouse e in events)
            {
                // MouseDown event: the currently focused control gets a MouseDown event, and if
                // it handles Keyboard input, gets Keyboard focus as well.
                if (e.EventType == MouseEvent.Down)
                {
                    if (focusedControl != null)
                    {
                        focusedControl.MouseDown(Engine.Input.MousePosition, e.Button);
                        if (focusedControl.HandlesKeyboardFocus)
                        {
                            m_keyboardFocusControl = focusedControl;
                        }
                        m_MouseDownControl[(int)e.Button] = focusedControl;
                    }
                }

                // MouseUp and MouseClick events
                if (e.EventType == MouseEvent.Up)
                {
                    int btn = (int)e.Button;

                    // If there is a currently focused control:
                    // 1.   If the currently focused control is the same control that was MouseDowned on with this button,
                    //      then send that control a MouseClick event.
                    // 2.   Send the currently focused control a MouseUp event.
                    // 3.   If the currently focused control is NOT the same control that was MouseDowned on with this button,
                    //      send that MouseDowned control a MouseUp event (but it does not receive MouseClick).
                    // If there is NOT a currently focused control, then simply inform the control that was MouseDowned on
                    // with this button that the button has been released, by sending it a MouseUp event.

                    if (focusedControl != null)
                    {
                        if (m_MouseDownControl[btn] != null && focusedControl == m_MouseDownControl[btn])
                        {
                            focusedControl.MouseClick(Engine.Input.MousePosition, e.Button);
                        }
                        focusedControl.MouseUp(Engine.Input.MousePosition, e.Button);
                        if (m_MouseDownControl[btn] != null && focusedControl != m_MouseDownControl[btn])
                        {
                            m_MouseDownControl[btn].MouseUp(Engine.Input.MousePosition, e.Button);
                        }
                    }
                    else
                    {
                        if (m_MouseDownControl[btn] != null)
                        {
                            m_MouseDownControl[btn].MouseUp(Engine.Input.MousePosition, e.Button);
                        }
                    }

                    m_MouseDownControl[btn] = null;
                }
            }
        }