예제 #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
        public void End()
        {
            began = false;

            UpdateEvent();

            if (touchMonitors.Count > 0)
            {
                int len = touchMonitors.Count;
                for (int i = 0; i < len; i++)
                {
                    EventDispatcher e = touchMonitors[i];
                    if (e != null)
                    {
                        e.GetChainBridges("onTouchEnd", sHelperChain, false);
                    }
                }
                target.BubbleEvent("onTouchEnd", evt, sHelperChain);

                touchMonitors.Clear();
                sHelperChain.Clear();
            }
            else
            {
                target.BubbleEvent("onTouchEnd", evt);
            }

            if (Timers.time - lastClickTime < 0.35f)
            {
                if (clickCount == 2)
                {
                    clickCount = 1;
                }
                else
                {
                    clickCount++;
                }
            }
            else
            {
                clickCount = 1;
            }
            lastClickTime = Timers.time;
        }
예제 #3
0
        internal void HandleGUIEvents(Event evt)
        {
            if (evt.rawType == EventType.KeyDown)
            {
                TouchInfo touch = _touches[0];
                touch.keyCode        = evt.keyCode;
                touch.modifiers      = evt.modifiers;
                touch.character      = evt.character;
                InputEvent.shiftDown = (evt.modifiers & EventModifiers.Shift) != 0;

                touch.UpdateEvent();
                DisplayObject f = this.focus;
                if (f != null)
                {
                    f.BubbleEvent("onKeyDown", touch.evt);
                }
                else
                {
                    DispatchEvent("onKeyDown", touch.evt);
                }
            }
            else if (evt.rawType == EventType.KeyUp)
            {
                TouchInfo touch = _touches[0];
                touch.keyCode        = evt.keyCode;
                touch.modifiers      = evt.modifiers;
                touch.character      = evt.character;
                InputEvent.shiftDown = (evt.modifiers & EventModifiers.Shift) != 0;

                touch.UpdateEvent();
                DisplayObject f = this.focus;
                if (f != null)
                {
                    f.BubbleEvent("onKeyUp", touch.evt);
                }
                else
                {
                    DispatchEvent("onKeyUp", touch.evt);
                }
            }
#if UNITY_2017_1_OR_NEWER
            else if (evt.type == EventType.ScrollWheel)
#else
            else if (evt.type == EventType.scrollWheel)
#endif
            {
                if (_touchTarget != null)
                {
                    TouchInfo touch = _touches[0];
                    touch.mouseWheelDelta = evt.delta.y;
                    touch.UpdateEvent();
                    _touchTarget.BubbleEvent("onMouseWheel", touch.evt);
                    touch.mouseWheelDelta = 0;
                }
            }
        }
예제 #4
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;
            }
        }
예제 #5
0
 public void CallTouchEnd()
 {
     if (touchEndMonitors.Count > 0)
     {
         int len = touchEndMonitors.Count;
         for (int i = 0; i < len; i++)
         {
             touchEndMonitors[i].GetChainBridges("onTouchEnd", sHelperChain, false);
         }
         target.BubbleEvent("onTouchEnd", evt, sHelperChain);
         touchEndMonitors.Clear();
         sHelperChain.Clear();
     }
     else
     {
         target.onTouchEnd.BubbleCall(evt);
     }
 }
예제 #6
0
파일: Stage.cs 프로젝트: blueberryWT/CatLib
        public void end()
        {
            began = false;

            if (target != null)
            {
                UpdateEvent();

                if (touchEndMonitors.Count > 0)
                {
                    int len = touchEndMonitors.Count;
                    for (int i = 0; i < len; i++)
                    {
                        touchEndMonitors[i].GetChainBridges("onTouchEnd", sHelperChain, false);
                    }
                    target.BubbleEvent("onTouchEnd", evt, sHelperChain);
                    sHelperChain.Clear();
                }
                else
                {
                    target.onTouchEnd.BubbleCall(evt);
                }
            }

            touchEndMonitors.Clear();

            if (Time.realtimeSinceStartup - lastClickTime < 0.35f)
            {
                if (clickCount == 2)
                {
                    clickCount = 1;
                }
                else
                {
                    clickCount++;
                }
            }
            else
            {
                clickCount = 1;
            }
            lastClickTime = Time.realtimeSinceStartup;
        }
예제 #7
0
        private void HandleKeyEvents()
        {
            Keys[] keys = Keyboard.GetState().GetPressedKeys();

            InputModifierFlags modifiers = 0;

            float currTime = Timers.time;
            int   cnt      = keys.Length;

            for (int i = 0; i < cnt; i++)
            {
                Keys key = keys[i];

                switch (key)
                {
                case Keys.LeftShift:
                    modifiers |= InputModifierFlags.LShift;
                    break;

                case Keys.RightShift:
                    modifiers |= InputModifierFlags.RShift;
                    break;

                case Keys.LeftAlt:
                    modifiers |= InputModifierFlags.LAlt;
                    break;

                case Keys.RightAlt:
                    modifiers |= InputModifierFlags.RAlt;
                    break;

                case Keys.LeftControl:
                    modifiers |= InputModifierFlags.LCtrl;
                    break;

                case Keys.RightControl:
                    modifiers |= InputModifierFlags.RCtrl;
                    break;

                case Keys.CapsLock:
                    modifiers |= InputModifierFlags.CapsLock;
                    break;

                case Keys.NumLock:
                    modifiers |= InputModifierFlags.NumLock;
                    break;
                }
            }

            if (_lastKeys != null)
            {
                cnt = _lastKeys.Length;
                for (int i = 0; i < cnt; i++)
                {
                    Keys key = _lastKeys[i];
                    if (Array.IndexOf(keys, key) == -1)
                    {
                        _lastKeyDownTime.Remove(key);
                    }
                }
            }

            _lastKeys = keys;

            cnt = keys.Length;
            for (int i = 0; i < cnt; i++)
            {
                Keys key = keys[i];

                float lastDownTime;
                if (_lastKeyDownTime.TryGetValue(key, out lastDownTime))
                {
                    if (currTime - lastDownTime < 0)
                    {
                        continue;
                    }

                    _lastKeyDownTime[key] = currTime + 0.05f;
                }
                else
                {
                    _lastKeyDownTime[key] = currTime + 0.5f;
                }

                _touchInfo.keyCode   = key;
                _touchInfo.keyName   = null;
                _touchInfo.modifiers = modifiers;

                //evt.keyName is not reliable, I parse it myself.
                if (key >= Keys.A && key <= Keys.Z)
                {
                    bool capsLock = (modifiers & InputModifierFlags.CapsLock) != 0;
                    if ((modifiers & InputModifierFlags.Shift) != 0)
                    {
                        capsLock = !capsLock;
                    }
                    if (capsLock)
                    {
                        _touchInfo.keyName = key.ToString();
                    }
                    else
                    {
                        _touchInfo.keyName = key.ToString().ToLower();
                    }
                }
                else
                {
                    if (_charByScanCode3.TryGetValue(key, out _touchInfo.keyName))
                    {
                        if (key == Keys.NumLock)
                        {
                            _touchInfo.keyName = null;
                        }
                    }
                    else if ((modifiers & InputModifierFlags.Shift) != 0)
                    {
                        if (!_charByScanCode2.TryGetValue(key, out _touchInfo.keyName))
                        {
                            _charByScanCode1.TryGetValue(key, out _touchInfo.keyName);
                        }
                    }
                    else
                    {
                        _charByScanCode1.TryGetValue(key, out _touchInfo.keyName);
                    }
                }

                _touchInfo.UpdateEvent();
                DisplayObject f = this.focus;
                if (f != null)
                {
                    f.BubbleEvent("onKeyDown", _touchInfo.evt);
                }
                else
                {
                    DispatchEvent("onKeyDown", _touchInfo.evt);
                }
            }
        }
예제 #8
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;
            }
        }
예제 #9
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;
                    }
                }
            }
        }
예제 #10
0
        void OnKeyEvents(CryEngine.InputEvent evt)
        {
            //这里主要处理连按的逻辑,第一次收到按下通知后立刻发出键盘事件,然后延迟一段时间,如果后续还有down通知,按照一定频率触发键盘事件。
            float currTime = Engine.Timer.GetCurrTime();

            if (evt.State == InputState.Down)
            {
                float lastDownTime;
                if (_lastKeyDownTime.TryGetValue(evt.KeyId, out lastDownTime))
                {
                    if (currTime - lastDownTime < 0)
                    {
                        return;
                    }
                }

                _lastKeyDownTime[evt.KeyId] = currTime + 0.05f;
            }
            else if (evt.State == InputState.Released)
            {
                _lastKeyDownTime.Remove(evt.KeyId);
                return;
            }
            else if (evt.State == InputState.Pressed)
            {
                _lastKeyDownTime[evt.KeyId] = currTime + 0.5f;
            }
            else
            {
                return;
            }

            _touchInfo.keyCode   = evt.KeyId;
            _touchInfo.keyName   = null;
            _touchInfo.modifiers = evt.InputModifiers;

            bool shift = (evt.InputModifiers & InputModifierFlags.Shift) != 0;

            //evt.keyName is not reliable, I parse it myself.
            if (evt.KeyId >= KeyId.Q && evt.KeyId <= KeyId.P ||
                evt.KeyId >= KeyId.A && evt.KeyId <= KeyId.L ||
                evt.KeyId >= KeyId.Z && evt.KeyId <= KeyId.M)
            {
                bool capsLock = (evt.InputModifiers & InputModifierFlags.CapsLock) != 0;
                if (shift)
                {
                    capsLock = !capsLock;
                }
                if (capsLock)
                {
                    _touchInfo.keyName = evt.KeyName.ToUpper();
                }
                else
                {
                    _touchInfo.keyName = evt.KeyName;
                }
            }
            else
            {
                if (_charByScanCode3.TryGetValue(evt.KeyId, out _touchInfo.keyName))
                {
                    if ((evt.InputModifiers & InputModifierFlags.NumLock) == 0)
                    {
                        _touchInfo.keyName = null;
                    }
                }
                else if (shift)
                {
                    if (!_charByScanCode2.TryGetValue(evt.KeyId, out _touchInfo.keyName))
                    {
                        _charByScanCode1.TryGetValue(evt.KeyId, out _touchInfo.keyName);
                    }
                }
                else
                {
                    _charByScanCode1.TryGetValue(evt.KeyId, out _touchInfo.keyName);
                }
            }

            _touchInfo.UpdateEvent();
            DisplayObject f = this.focus;

            if (f != null)
            {
                f.BubbleEvent("onKeyDown", _touchInfo.evt);
            }
            else
            {
                this.DispatchEvent("onKeyDown", _touchInfo.evt);
            }
        }
예제 #11
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;
                }
            }
        }