예제 #1
0
        /// <summary>
        /// Handles the input provided by the ScreenManager's InputControl. You should not need to override this - use the specialized input methods instead!
        /// </summary>
        /// <param name="input">The InputControl object passed in from the ScreenManager.</param>
        public override void HandleInput(InputControl input)
        {
            base.HandleInput(input);

            //store mouse pos
            Point mousePos = input.CurrentMouse;

            //check for a  widget at mouse point
            Widget widgetAtPoint = baseWidget.ChildAtPoint(mousePos, HitFlags.Mouse);

            //handle mouse movement
            bool cascade = true;
            if (input.MouseMoved())
            {
                //check for mouse enter/leave events
                if (widgetAtPoint != mouseHoverWidget)
                {
                    if (mouseHoverWidget != null)
                        cascade = !mouseHoverWidget.MouseLeave(mousePos);

                    mouseHoverWidget = widgetAtPoint;

                    if (mouseHoverWidget != null)
                        cascade &= !mouseHoverWidget.MouseEnter(mousePos);
                }

                if (cascade)
                    MouseMove(mousePos,input.PreviousMouse);
            }

            //handle mouse clicks
            for (int i = 1; i <= 5; i++)
            {
                ButtonState current;
                if (input.MouseChanged(i,out current))
                {
                    cascade = true;
                    if (current == ButtonState.Pressed)
                    {
                        mouseDownWidgets[i-1] = widgetAtPoint;
                        if (widgetAtPoint != null)
                            cascade = !widgetAtPoint.MouseDown(mousePos, i);

                        if (cascade)
                            MouseDown(mousePos, i);
                    }
                    else
                    {
                        if (mouseDownWidgets[i-1] != null)
                            cascade = !mouseDownWidgets[i - 1].MouseUp(mousePos, i);
                        mouseDownWidgets[i-1] = null;

                        if (cascade)
                            MouseUp(mousePos, i);
                    }
                }
            }

            //check keyboard events
            for (int i = 0; i < watchedKeys.Length; i++)
            {
                if (input.KeyReleased(watchedKeys[i]))
                {
                    cascade = true;
                    if (selectedWidget != null)
                        cascade = !selectedWidget.KeyUp(watchedKeys[i]);
                    if (cascade)
                        KeyUp(watchedKeys[i]);
                }

                if (input.KeyPressed(watchedKeys[i]))
                {
                    cascade = true;
                    if (selectedWidget != null)
                        cascade = !selectedWidget.KeyDown(watchedKeys[i]);
                    if (cascade)
                        KeyDown(watchedKeys[i]);
                }
            }
        }