예제 #1
0
        static void ProcessMouseEvent(MouseEvent me)
        {
            var view = FindDeepestView(Current, me.X, me.Y, out int rx, out int ry);

            if (view != null && view.WantContinuousButtonPressed)
            {
                wantContinuousButtonPressedView = view;
            }
            else
            {
                wantContinuousButtonPressedView = null;
            }

            RootMouseEvent?.Invoke(me);
            if (mouseGrabView != null)
            {
                var newxy = mouseGrabView.ScreenToView(me.X, me.Y);
                var nme   = new MouseEvent()
                {
                    X     = newxy.X,
                    Y     = newxy.Y,
                    Flags = me.Flags,
                    OfX   = me.X - newxy.X,
                    OfY   = me.Y - newxy.Y,
                    View  = view
                };
                if (OutsideFrame(new Point(nme.X, nme.Y), mouseGrabView.Frame))
                {
                    lastMouseOwnerView?.OnMouseLeave(me);
                }
                if (mouseGrabView != null)
                {
                    mouseGrabView.OnMouseEvent(nme);
                    return;
                }
            }

            if (view != null)
            {
                var nme = new MouseEvent()
                {
                    X     = rx,
                    Y     = ry,
                    Flags = me.Flags,
                    OfX   = 0,
                    OfY   = 0,
                    View  = view
                };

                if (lastMouseOwnerView == null)
                {
                    lastMouseOwnerView = view;
                    view.OnMouseEnter(nme);
                }
                else if (lastMouseOwnerView != view)
                {
                    lastMouseOwnerView.OnMouseLeave(nme);
                    view.OnMouseEnter(nme);
                    lastMouseOwnerView = view;
                }

                if (!view.WantMousePositionReports && me.Flags == MouseFlags.ReportMousePosition)
                {
                    return;
                }

                if (view.WantContinuousButtonPressed)
                {
                    wantContinuousButtonPressedView = view;
                }
                else
                {
                    wantContinuousButtonPressedView = null;
                }

                // Should we bubbled up the event, if it is not handled?
                view.OnMouseEvent(nme);
            }
        }
예제 #2
0
        MouseEvent ToDriverMouse(Curses.MouseEvent cev)
        {
            MouseFlags mouseFlag = MouseFlags.AllEvents;

            if (LastMouseButtonPressed != null && cev.ButtonState != Curses.Event.ReportMousePosition)
            {
                LastMouseButtonPressed = null;
                IsButtonPressed        = false;
            }


            if ((cev.ButtonState == Curses.Event.Button1Clicked || cev.ButtonState == Curses.Event.Button2Clicked ||
                 cev.ButtonState == Curses.Event.Button3Clicked) &&
                LastMouseButtonPressed == null)
            {
                IsButtonPressed = false;
                mouseFlag       = ProcessButtonClickedEvent(cev);
            }
            else if (((cev.ButtonState == Curses.Event.Button1Pressed || cev.ButtonState == Curses.Event.Button2Pressed ||
                       cev.ButtonState == Curses.Event.Button3Pressed) && LastMouseButtonPressed == null) ||
                     IsButtonPressed && cev.ButtonState == Curses.Event.ReportMousePosition)
            {
                mouseFlag = (MouseFlags)cev.ButtonState;
                if (cev.ButtonState != Curses.Event.ReportMousePosition)
                {
                    LastMouseButtonPressed = cev.ButtonState;
                }
                IsButtonPressed       = true;
                isReportMousePosition = false;

                if (cev.ButtonState == Curses.Event.ReportMousePosition)
                {
                    mouseFlag = (MouseFlags)LastMouseButtonPressed | MouseFlags.ReportMousePosition;
                    point     = new Point();
                    //cancelButtonClicked = true;
                }
                else
                {
                    point = new Point()
                    {
                        X = cev.X,
                        Y = cev.Y
                    };
                }

                if ((mouseFlag & MouseFlags.ReportMousePosition) == 0)
                {
                    Task.Run(async() =>
                    {
                        while (IsButtonPressed && LastMouseButtonPressed != null)
                        {
                            await Task.Delay(100);
                            var me = new MouseEvent()
                            {
                                X     = cev.X,
                                Y     = cev.Y,
                                Flags = mouseFlag
                            };

                            var view = Application.wantContinuousButtonPressedView;
                            if (view == null)
                            {
                                break;
                            }
                            if (IsButtonPressed && LastMouseButtonPressed != null && (mouseFlag & MouseFlags.ReportMousePosition) == 0)
                            {
                                mouseHandler(me);
                                //mainLoop.Driver.Wakeup ();
                            }
                        }
                    });
                }
            }
            else if ((cev.ButtonState == Curses.Event.Button1Released || cev.ButtonState == Curses.Event.Button2Released ||
                      cev.ButtonState == Curses.Event.Button3Released))
            {
                mouseFlag       = ProcessButtonReleasedEvent(cev);
                IsButtonPressed = false;
                canWheeledDown  = false;
            }
            else if (cev.ButtonState == Curses.Event.Button4Pressed)
            {
                mouseFlag = MouseFlags.WheeledUp;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition && cev.X == point.X && cev.Y == point.Y &&
                     canWheeledDown)
            {
                mouseFlag      = MouseFlags.WheeledDown;
                canWheeledDown = true;
            }
            else if (cev.ButtonState == Curses.Event.ReportMousePosition && !canWheeledDown)
            {
                mouseFlag             = MouseFlags.ReportMousePosition;
                canWheeledDown        = true;
                isReportMousePosition = true;
            }
            else
            {
                mouseFlag      = (MouseFlags)cev.ButtonState;
                canWheeledDown = false;
                if (cev.ButtonState == Curses.Event.ReportMousePosition)
                {
                    isReportMousePosition = true;
                }
            }

            point = new Point()
            {
                X = cev.X,
                Y = cev.Y
            };

            return(new MouseEvent()
            {
                X = cev.X,
                Y = cev.Y,
                //Flags = (MouseFlags)cev.ButtonState
                Flags = mouseFlag
            });
        }