Пример #1
0
        void HandleMouseEvents()
        {
            TouchInfo touch = _touches[0];

            if (touch.x != _touchPosition.x || touch.y != _touchPosition.y)
            {
                touch.x = _touchPosition.x;
                touch.y = _touchPosition.y;
                touch.Move();
            }

            if (touch.lastRollOver != touch.target)
            {
                HandleRollOver(touch);
            }

            if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1) || Input.GetMouseButtonDown(2))
            {
                if (!touch.began)
                {
                    _touchCount = 1;
                    touch.Begin();
                    touch.button = Input.GetMouseButtonDown(2) ? 2 : (Input.GetMouseButtonDown(1) ? 1 : 0);
                    this.focus   = touch.target;

                    touch.UpdateEvent();
                    touch.target.BubbleEvent("onTouchBegin", touch.evt);
                }
            }
            if (Input.GetMouseButtonUp(0) || Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
            {
                if (touch.began)
                {
                    _touchCount = 0;
                    touch.End();

                    DisplayObject clickTarget = touch.ClickTest();
                    if (clickTarget != null)
                    {
                        touch.UpdateEvent();

                        if (Input.GetMouseButtonUp(1) || Input.GetMouseButtonUp(2))
                        {
                            clickTarget.BubbleEvent("onRightClick", touch.evt);
                        }
                        else
                        {
                            clickTarget.BubbleEvent("onClick", touch.evt);
                        }
                    }

                    touch.button = -1;
                }
            }
        }
Пример #2
0
        void HandleCustomInput()
        {
            Vector2 pos = _customInputPos;

            pos.y = stageHeight - pos.y;
            TouchInfo touch = _touches[0];

            if (touch.x != pos.x || touch.y != pos.y)
            {
                touch.x = pos.x;
                touch.y = pos.y;
                touch.Move();
            }

            if (touch.lastRollOver != touch.target)
            {
                HandleRollOver(touch);
            }

            if (_customInputButtonDown)
            {
                if (!touch.began)
                {
                    _touchCount = 1;
                    touch.Begin();
                    touch.button = 0;
                    this.focus   = touch.target;

                    touch.UpdateEvent();
                    touch.target.BubbleEvent("onTouchBegin", touch.evt);
                }
            }
            else if (touch.began)
            {
                _touchCount = 0;
                touch.End();

                DisplayObject clickTarget = touch.ClickTest();
                if (clickTarget != null)
                {
                    touch.UpdateEvent();
                    clickTarget.BubbleEvent("onClick", touch.evt);
                }

                touch.button = -1;
            }
        }
Пример #3
0
        internal void HandleMouseEvents()
        {
            MouseState mouseState = Mouse.GetState();

            _touchPosition    = new Vector2(mouseState.Position.X, mouseState.Position.Y);
            _touchTarget      = HitTest(_touchPosition, true);
            _touchInfo.target = _touchTarget;

            if (Math.Abs(_touchInfo.x - _touchPosition.X) > 0 || Math.Abs(_touchInfo.y - _touchPosition.Y) > 0)
            {
                _touchInfo.x = _touchPosition.X;
                _touchInfo.y = _touchPosition.Y;
                _touchInfo.Move();
            }

            if (_touchInfo.lastRollOver != _touchInfo.target)
            {
                HandleRollOver(_touchInfo);
            }

            if (mouseState.LeftButton == ButtonState.Pressed ||
                mouseState.RightButton == ButtonState.Pressed ||
                mouseState.MiddleButton == ButtonState.Pressed)
            {
                if (!_touchInfo.began)
                {
                    _touchInfo.Begin();
                    _touchInfo.button =
                        (mouseState.LeftButton == ButtonState.Pressed)
                                                        ? 0
                                                        : (mouseState.RightButton == ButtonState.Pressed ? 1 : 2);
                    this.focus = _touchInfo.target;

                    _touchInfo.UpdateEvent();
                    _touchInfo.target.BubbleEvent("onTouchBegin", _touchInfo.evt);
                }
            }
            else if (mouseState.LeftButton == ButtonState.Released ||
                     mouseState.RightButton == ButtonState.Released ||
                     mouseState.MiddleButton == ButtonState.Released)
            {
                if (_touchInfo.began)
                {
                    _touchInfo.End();

                    DisplayObject clickTarget = _touchInfo.ClickTest();
                    if (clickTarget != null)
                    {
                        _touchInfo.UpdateEvent();

                        if (_touchInfo.button == 1)
                        {
                            clickTarget.BubbleEvent("onRightClick", _touchInfo.evt);
                        }
                        else
                        {
                            clickTarget.BubbleEvent("onClick", _touchInfo.evt);
                        }
                    }

                    _touchInfo.button = -1;
                }
            }

            int deltaWheel = mouseState.ScrollWheelValue - _lastScrollWheelValue;

            if (deltaWheel != 0)
            {
                if (_touchTarget != null)
                {
                    _touchInfo.mouseWheelDelta = -deltaWheel;
                    _touchInfo.UpdateEvent();
                    _touchTarget.BubbleEvent("onMouseWheel", _touchInfo.evt);
                    _touchInfo.mouseWheelDelta = 0;
                }

                _lastScrollWheelValue = mouseState.ScrollWheelValue;
            }
        }
Пример #4
0
        void HandleTouchEvents()
        {
            int tc = Input.touchCount;

            for (int i = 0; i < tc; ++i)
            {
                Touch uTouch = Input.GetTouch(i);

                if (uTouch.phase == TouchPhase.Stationary)
                {
                    continue;
                }

                Vector2 pos = uTouch.position;
                pos.y = stageHeight - pos.y;

                TouchInfo touch = null;
                for (int j = 0; j < 5; j++)
                {
                    if (_touches[j].touchId == uTouch.fingerId)
                    {
                        touch = _touches[j];
                        break;
                    }
                }
                if (touch == null)
                {
                    continue;
                }

                if (touch.x != pos.x || touch.y != pos.y)
                {
                    touch.x = pos.x;
                    touch.y = pos.y;
                    if (touch.began)
                    {
                        touch.Move();
                    }
                }

                if (touch.lastRollOver != touch.target)
                {
                    HandleRollOver(touch);
                }

                if (uTouch.phase == TouchPhase.Began)
                {
                    if (!touch.began)
                    {
                        _touchCount++;
                        touch.Begin();
                        touch.button = 0;
                        this.focus   = touch.target;

                        touch.UpdateEvent();
                        touch.target.BubbleEvent("onTouchBegin", touch.evt);
                    }
                }
                else if (uTouch.phase == TouchPhase.Canceled || uTouch.phase == TouchPhase.Ended)
                {
                    if (touch.began)
                    {
                        _touchCount--;
                        touch.End();

                        if (uTouch.phase != TouchPhase.Canceled)
                        {
                            DisplayObject clickTarget = touch.ClickTest();
                            if (clickTarget != null)
                            {
                                touch.clickCount = uTouch.tapCount;
                                touch.UpdateEvent();
                                clickTarget.BubbleEvent("onClick", touch.evt);
                            }
                        }

                        touch.target = null;
                        HandleRollOver(touch);

                        touch.touchId = -1;
                    }
                }
            }
        }
Пример #5
0
        internal void HandleMouseEvents(int iX, int iY, EHARDWAREMOUSEEVENT eHardwareMouseEvent, int wheelDelta)
        {
            if (wheelDelta != 0)
            {
                if (_touchTarget != null)
                {
                    _touchInfo.mouseWheelDelta = -wheelDelta;
                    _touchInfo.UpdateEvent();
                    _touchTarget.onMouseWheel.BubbleCall(_touchInfo.evt);
                    _touchInfo.mouseWheelDelta = 0;
                }
                return;
            }

            _touchPosition    = new Vector2(iX, iY);
            _touchTarget      = HitTest(_touchPosition, true);
            _touchInfo.target = _touchTarget;

            if (_touchInfo.x != _touchPosition.x || _touchInfo.y != _touchPosition.y)
            {
                _touchInfo.x = _touchPosition.x;
                _touchInfo.y = _touchPosition.y;
                _touchInfo.Move();
            }

            if (_touchInfo.lastRollOver != _touchInfo.target)
            {
                HandleRollOver(_touchInfo);
            }

            if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOWN ||
                eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOWN ||
                eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONDOWN ||
                eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOUBLECLICK)
            {
                if (!_touchInfo.began)
                {
                    _touchInfo.Begin();
                    _touchInfo.button = (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOWN || eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONDOUBLECLICK) ? 0 : (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONDOWN ? 1 : 2);
                    this.focus        = _touchInfo.target;

                    _touchInfo.UpdateEvent();
                    _touchInfo.target.BubbleEvent("onTouchBegin", _touchInfo.evt);
                }
            }
            if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONUP ||
                eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP ||
                eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_MBUTTONUP)
            {
                if (_touchInfo.began)
                {
                    _touchInfo.button = eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_LBUTTONUP ? 0 : (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP ? 1 : 2);
                    _touchInfo.End();

                    DisplayObject clickTarget = _touchInfo.ClickTest();
                    if (clickTarget != null)
                    {
                        _touchInfo.UpdateEvent();

                        if (eHardwareMouseEvent == EHARDWAREMOUSEEVENT.HARDWAREMOUSEEVENT_RBUTTONUP)
                        {
                            clickTarget.BubbleEvent("onRightClick", _touchInfo.evt);
                        }
                        else
                        {
                            clickTarget.BubbleEvent("onClick", _touchInfo.evt);
                        }
                    }

                    _touchInfo.button = -1;
                }
            }
        }