コード例 #1
0
        // Ties into the events in InputSystem. Top events are asynchronous and
        // used for state management. The rest of them are synchronous and used to
        // trigger user specified event handlers.
        internal InputManager(Root <Widget> dom)
        {
            _dom = dom;

            _mouseEvents    = new MouseEvents();
            _keyboardEvents = new KeyboardEvents();

            MouseLocation = Mouse.GetState().Position;

            /* ## Input Events to Manage Internal State ## */
            #region Manage Internal State
            MouseEvents.MouseMoved += delegate
            {
                if (FocusedWidget != null &&
                    FocusedWidget.AbsoluteInputArea.Contains(MouseLocation) &&
                    FocusedWidget.BlocksInput)
                {
                    return;
                }

                HoverWidget = FindHover();
                if (PressedWidget == null)
                {
                    return;
                }

                if (!PressedWidget.AbsoluteInputArea.Contains(MouseLocation))
                {
                    PressedWidget = null;
                }
            };

            MouseEvents.ButtonReleased += delegate(object sender, MouseEventArgs e)
            {
                if (e.Button != MouseButton.Left)
                {
                    return;
                }

                if (PressedWidget != null)
                {
                    PressedWidget.MouseClick(e);
                }

                PressedWidget = null;
            };

            MouseEvents.ButtonPressed += delegate(Object o, MouseEventArgs e)
            {
                if (e.Button != MouseButton.Left)
                {
                    return;
                }

                if (HoverWidget == null && FocusedWidget != null && !FocusedWidget.BlocksInput)
                {
                    return;
                }

                FocusedWidget = HoverWidget;
                PressedWidget = HoverWidget;
            };

            MouseEvents.ButtonDoubleClicked += delegate(Object o, MouseEventArgs e)
            {
                if (e.Button != MouseButton.Left)
                {
                    return;
                }

                if (HoverWidget == null)
                {
                    return;
                }

                FocusedWidget = HoverWidget;
                PressedWidget = HoverWidget;
            };
            #endregion

            /* ## Input Events to fire the focused widget's event handlers ## */
            #region Widget Triggers

            KeyboardEvents.KeyTyped += delegate(Object o, CharacterEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.CharEntered(e);
                }
            };

            KeyboardEvents.KeyPressed += delegate(Object o, KeyEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.KeyDown(e);
                }
            };

            KeyboardEvents.KeyReleased += delegate(Object o, KeyEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.KeyUp(e);
                }
            };

            MouseEvents.ButtonDoubleClicked += delegate(Object o, MouseEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.MouseDoubleClick(e);
                }
            };

            MouseEvents.ButtonPressed += delegate(Object o, MouseEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.MouseDown(e);
                }
            };

            MouseEvents.MouseMoved += delegate(Object o, MouseEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.MouseMove(e);
                }
            };

            MouseEvents.ButtonReleased += delegate(Object o, MouseEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.MouseUp(e);
                }
            };

            MouseEvents.MouseWheelMoved += delegate(Object o, MouseEventArgs e)
            {
                if (FocusedWidget != null)
                {
                    FocusedWidget.MouseWheel(e);
                }
            };
            #endregion
        }
コード例 #2
0
        public void Update()
        {
            List <InputEventMouse>    mouse_events = Library.Input.GetMouseEvents();
            List <InputEventKeyboard> kb_events    = Library.Input.GetKeyboardEvents();

            #region Mouse Events
            foreach (InputEventMouse e in mouse_events)
            {
                switch (e.EventType)
                {
                case MouseEvent.Move:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseMove(e);
                        if (PressedWidget.BlocksInput)
                        {
                            continue;
                        }
                    }
                    if (HoverWidget != null)
                    {
                        HoverWidget.MouseMove(e);
                    }
                    HoverWidget = FindHover();
                    break;

                case MouseEvent.Down:
                    if (HoverWidget != null)
                    {
                        PressedWidget       = HoverWidget;
                        KeyboardFocusWidget = HoverWidget;
                        PressedWidget.MouseDown(e);
                    }
                    break;

                case MouseEvent.Up:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseUp(e);
                        PressedWidget = null;
                    }
                    break;

                case MouseEvent.Click:
                    if (HoverWidget != null)
                    {
                        PressedWidget = HoverWidget;
                        PressedWidget.MouseClick(e);
                    }
                    break;

                case MouseEvent.DoubleClick:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseClick(e);
                        PressedWidget.MouseDoubleClick(e);
                    }
                    break;

                case MouseEvent.WheelScroll:
                    if (PressedWidget != null)
                    {
                        PressedWidget.MouseWheel(e);
                    }
                    else if (HoverWidget != null)
                    {
                        HoverWidget.MouseWheel(e);
                    }
                    break;
                }
            }
            #endregion

            #region Keyboard Events
            foreach (InputEventKeyboard e in kb_events)
            {
                switch (e.EventType)
                {
                case KeyboardEvent.Press:
                    if (m_KeyboardEvents != null)
                    {
                        m_KeyboardEvents(e);
                    }
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.CharEntered(e);
                    }
                    break;

                case KeyboardEvent.Down:
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.KeyDown(e);
                    }
                    break;

                case KeyboardEvent.Up:
                    if (KeyboardFocusWidget != null)
                    {
                        KeyboardFocusWidget.KeyUp(e);
                    }
                    break;
                }
            }

            #endregion
        }