예제 #1
0
        /// <summary>
        /// Process mouse events.
        /// </summary>
        /// <param name="Event"></param>
        /// <param name="Args"></param>
        public void HandleInput(InputEvents Event, InputEventArgs Args)
        {
            switch (Event)
            {
            case InputEvents.MouseMove:
            {
                // Destroy tooltips when the mouse moves.
                MouseMotionTime = DateTime.Now;

                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs {
                    X = MousePosition.X, Y = MousePosition.Y
                };
                // Detect hover item and fire mouse enter/leave events as appropriate.
                var newHoverItem = RootItem.FindWidgetAt(MousePosition.X, MousePosition.Y);
                if (!Object.ReferenceEquals(newHoverItem, HoverItem))
                {
                    if (HoverItem != null)
                    {
                        SafeCall(HoverItem.OnMouseLeave, HoverItem, newArgs);
                    }
                    if (newHoverItem != null)
                    {
                        SafeCall(newHoverItem.OnMouseEnter, newHoverItem, newArgs);
                    }
                    if (TooltipItem != null)
                    {
                        DestroyWidget(TooltipItem);
                    }
                    HoverItem = newHoverItem;
                }

                if (MouseDownItem != null)
                {
                    SafeCall(MouseDownItem.OnMouseMove, MouseDownItem,
                             new InputEventArgs {
                            X = MousePosition.X, Y = MousePosition.Y
                        });
                }

                if (HoverItem != null && !Object.ReferenceEquals(HoverItem, MouseDownItem))
                {
                    SafeCall(HoverItem.OnMouseMove, HoverItem,
                             new InputEventArgs {
                            X = MousePosition.X, Y = MousePosition.Y
                        });
                }
            }
            break;

            case InputEvents.MouseDown:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                MouseDownItem = null;
                if (PopupStack.Count != 0)
                {
                    if (IsHoverPartOfPopup())
                    {
                        MouseDownItem = HoverItem;
                    }
                }
                else
                {
                    MouseDownItem = HoverItem;
                }

                if (MouseDownItem != null)
                {
                    CallOnMouseDown(MouseDownItem, newArgs);
                }
            }
            break;

            case InputEvents.MouseUp:
            {
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                if (MouseDownItem != null)
                {
                    CallOnMouseUp(MouseDownItem, newArgs);
                }
                //MouseDownItem = null;
            }
            break;

            case InputEvents.MouseClick:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));

                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    X           = MousePosition.X,
                    Y           = MousePosition.Y,
                    MouseButton = Args.MouseButton
                };

                if (PopupStack.Count != 0)
                {
                    if (HoverItem == null || !IsHoverPartOfPopup())
                    {
                        if (PopupStack[PopupStack.Count - 1].PopupDestructionType == PopupDestructionType.DestroyOnOffClick)
                        {
                            DestroyWidget(PopupStack[PopupStack.Count - 1]);
                        }

                        MouseDownItem = null;
                        return;
                    }

                    if (IsHoverPartOfPopup())
                    {
                        Args.Handled = true;
                        if (Object.ReferenceEquals(HoverItem, MouseDownItem))
                        {
                            CallOnClick(HoverItem, newArgs);
                        }
                        MouseDownItem = null;
                        return;
                    }

                    MouseDownItem = null;
                    return;
                }

                if (HoverItem != null && Object.ReferenceEquals(HoverItem, MouseDownItem))
                {
                    Args.Handled = true;
                    CallOnClick(HoverItem, newArgs);
                }
                else
                {
                    SetFocus(null);
                }
                MouseDownItem = null;
            }
            break;

            case InputEvents.MouseWheel:
            {
                var newArgs = new InputEventArgs
                {
                    Alt         = Args.Alt,
                    Control     = Args.Control,
                    Shift       = Args.Shift,
                    ScrollValue = Args.ScrollValue
                };

                if (HoverItem != null)
                {
                    Args.Handled = true;
                    CallOnScroll(HoverItem, newArgs);
                }
            }
            break;

            case InputEvents.KeyPress:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyPress, FocusItem, Args);
                }
                break;

            case InputEvents.KeyDown:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyDown, FocusItem, Args);
                }
                break;

            case InputEvents.KeyUp:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyUp, FocusItem, Args);
                }
                break;
            }
        }
예제 #2
0
파일: Root.cs 프로젝트: Blecki/GemGui
        /// <summary>
        /// Process mouse events.
        /// </summary>
        /// <param name="State"></param>
        public void HandleInput(InputEvents Event, InputEventArgs Args)
        {
            switch (Event)
            {
            case InputEvents.MouseMove:
            {
                // Destroy tooltips when the mouse moves.
                MouseMotionTime = DateTime.Now;
                if (TooltipItem != null)
                {
                    DestroyWidget(TooltipItem);
                }

                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs {
                    X = MousePosition.X, Y = MousePosition.Y
                };
                // Detect hover item and fire mouse enter/leave events as appropriate.
                var newHoverItem = RootItem.FindWidgetAt(MousePosition.X, MousePosition.Y);
                if (!Object.ReferenceEquals(newHoverItem, HoverItem))
                {
                    if (HoverItem != null)
                    {
                        SafeCall(HoverItem.OnMouseLeave, HoverItem, newArgs);
                    }
                    if (newHoverItem != null)
                    {
                        SafeCall(newHoverItem.OnMouseEnter, newHoverItem, newArgs);
                    }
                    HoverItem = newHoverItem;
                }

                if (MouseDownItem != null)
                {
                    SafeCall(MouseDownItem.OnMouseMove, MouseDownItem,
                             new InputEventArgs {
                            X = MousePosition.X, Y = MousePosition.Y
                        });
                }
            }
            break;

            case InputEvents.MouseDown:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs {
                    X = MousePosition.X, Y = MousePosition.Y
                };

                MouseDownItem = null;
                if (PopupItem != null)
                {
                    if (IsHoverPartOfPopup())
                    {
                        MouseDownItem = HoverItem;
                    }
                }
                else
                {
                    MouseDownItem = HoverItem;
                }
            }
            break;

            case InputEvents.MouseUp:
                //MouseDownItem = null;
                break;

            case InputEvents.MouseClick:
            {
                MousePosition = ScreenPointToGuiPoint(new Point(Args.X, Args.Y));
                var newArgs = new InputEventArgs {
                    X = MousePosition.X, Y = MousePosition.Y
                };

                if (PopupItem != null)
                {
                    if (HoverItem == null || (!Object.ReferenceEquals(HoverItem, PopupItem) &&
                                              !HoverItem.IsChildOf(PopupItem)))
                    {
                        if (DestroyPopupOnOffClick)
                        {
                            SafeCall(PopupItem.OnPopupClose, PopupItem);
                            DestroyWidget(PopupItem);
                            PopupItem = null;
                        }

                        MouseDownItem = null;
                        return;
                    }

                    if (HoverItem != null && (Object.ReferenceEquals(HoverItem, PopupItem) ||
                                              HoverItem.IsChildOf(PopupItem)))
                    {
                        Args.Handled = true;
                        if (Object.ReferenceEquals(HoverItem, MouseDownItem))
                        {
                            CallOnClick(HoverItem, newArgs);
                        }
                        MouseDownItem = null;
                        return;
                    }

                    MouseDownItem = null;
                    return;
                }

                if (HoverItem != null && Object.ReferenceEquals(HoverItem, MouseDownItem))
                {
                    Args.Handled = true;
                    CallOnClick(HoverItem, newArgs);
                }
                MouseDownItem = null;
            }
            break;

            case InputEvents.KeyPress:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyPress, FocusItem, Args);
                }
                break;

            case InputEvents.KeyDown:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyDown, FocusItem, Args);
                }
                break;

            case InputEvents.KeyUp:
                if (FocusItem != null)
                {
                    SafeCall(FocusItem.OnKeyUp, FocusItem, Args);
                }
                break;
            }
        }