Пример #1
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            if (initialized)
            {
                return;
            }

            // must init after window
            InputHTMLNativeCalls.JSInitInput();
            MouseEmulateReset();
            initialized = true;
        }
Пример #2
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            if (initialized)
            {
                return;
            }

            // must init after window
            InputHTMLNativeCalls.JSInitInput();
            firstTouch  = -1;
            initialized = true;
        }
Пример #3
0
        public override PointerModeType GetMouseMode()
        {
            int mouseMode = InputHTMLNativeCalls.JSGetMouseMode();

            switch (mouseMode)
            {
            case 1:
                return(PointerModeType.Hidden);

            case 2:
                return(PointerModeType.Locked);
            }
            return(PointerModeType.Normal);
        }
Пример #4
0
        public override void SetMouseMode(PointerModeType type)
        {
            switch (type)
            {
            case PointerModeType.Normal:
                InputHTMLNativeCalls.JSSetMouseMode(0);
                break;

            case PointerModeType.Hidden:
                InputHTMLNativeCalls.JSSetMouseMode(1);
                break;

            case PointerModeType.Locked:
                InputHTMLNativeCalls.JSSetMouseMode(2);
                break;
            }
        }
Пример #5
0
        protected override void OnUpdate()
        {
            // handle lost/reset
            if (InputHTMLNativeCalls.JSGetCanvasLost())
            {
                m_inputState.Clear();
                InputHTMLNativeCalls.JSResetStreams();
                InputHTMLNativeCalls.JSInitInput();
                MouseEmulateReset();
                return;
            }

            if (InputHTMLNativeCalls.JSGetFocusLost())
            {
                m_inputState.Clear();
                InputHTMLNativeCalls.JSResetStreams();
                MouseEmulateReset();
                return;
            }

            // advance input state
            base.OnUpdate();

            // keys
            int keyStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    keyStreamLen = InputHTMLNativeCalls.JSGetKeyStream(streamBuf.Length, ptr);
                }
            }

            for (int i = 0; i < keyStreamLen; i += 3)
            {
                int action   = streamBuf[i];
                int key      = streamBuf[i + 1];
                int location = streamBuf[i + 2];
                int nkeys    = TranslateKey(key, location, translatedKeys);
                for (int j = 0; j < nkeys; j++)
                {
                    KeyCode translatedKey = translatedKeys[j];
                    if (translatedKey == KeyCode.None)
                    {
                        continue;
                    }
                    if (action == 0)
                    {
                        m_inputState.KeyUp(translatedKey);
                    }
                    else if (action == 1)
                    {
                        m_inputState.KeyDown(translatedKey);
                    }
                }
            }

            // mouse (move + up/down)
            int mouseStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    mouseStreamLen = InputHTMLNativeCalls.JSGetMouseStream(streamBuf.Length, ptr);
                }
            }

            m_inputState.mouseDeltaX = 0;
            m_inputState.mouseDeltaY = 0;

            for (int i = 0; i < mouseStreamLen; i += 6)
            {
                int ev     = streamBuf[i];
                int button = streamBuf[i + 1];
                int x      = streamBuf[i + 2];
                int y      = streamBuf[i + 3];
                int dx     = streamBuf[i + 4];
                int dy     = streamBuf[i + 5];
                if (ev == 0)
                {
                    m_inputState.MouseUp(button);
                }
                else if (ev == 1)
                {
                    m_inputState.MouseDown(button);
                }
                m_inputState.mouseX       = x;
                m_inputState.mouseY       = y;
                m_inputState.mouseDeltaX += dx;
                m_inputState.mouseDeltaY -= dy;
            }

            if (mouseStreamLen != 0)
            {
                m_inputState.hasMouse = true;
            }

            // scrollwheel
            int wheelStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    wheelStreamLen = InputHTMLNativeCalls.JSGetWheelStream(streamBuf.Length, ptr);
                }
            }

            m_inputState.scrollDeltaX = 0;
            m_inputState.scrollDeltaY = 0;
            for (int i = 0; i < wheelStreamLen; i += 2)
            {
                int x = streamBuf[i];
                int y = streamBuf[i + 1];
                m_inputState.scrollDeltaX = x;
                m_inputState.scrollDeltaY = y;
            }

            // touches
            int touchStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    touchStreamLen = InputHTMLNativeCalls.JSGetTouchStream(streamBuf.Length, ptr);
                }
            }
            for (int i = 0; i < touchStreamLen; i += 4)
            {
                int        ev = streamBuf[i];
                int        id = streamBuf[i + 1];
                int        x  = streamBuf[i + 2];
                int        y  = streamBuf[i + 3];
                TouchState phase;
                switch (ev)
                {
                case 0:
                    phase = TouchState.Ended;
                    break;

                case 1:
                    phase = TouchState.Began;
                    break;

                case 2:
                    phase = TouchState.Moved;
                    break;

                case 3:
                    phase = TouchState.Canceled;
                    break;

                default:
                    continue;
                }
                ProcessTouch(id, phase, x, y);
            }
            InputHTMLNativeCalls.JSResetStreams();
        }
Пример #6
0
        protected override void OnUpdate()
        {
            // handle lost/reset
            if (InputHTMLNativeCalls.JSGetCanvasLost())
            {
                m_inputState.Clear();
                InputHTMLNativeCalls.JSResetStreams();
                InputHTMLNativeCalls.JSInitInput();
                firstTouch = -1;
                return;
            }

            if (InputHTMLNativeCalls.JSGetFocusLost())
            {
                m_inputState.Clear();
                InputHTMLNativeCalls.JSResetStreams();
                firstTouch = -1;
                return;
            }

            // advance input state
            base.OnUpdate();

            // keys
            int keyStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    keyStreamLen = InputHTMLNativeCalls.JSGetKeyStream(streamBuf.Length, ptr);
                }
            }

            for (int i = 0; i < keyStreamLen; i += 2)
            {
                int     action        = streamBuf[i];
                int     key           = streamBuf[i + 1];
                KeyCode translatedKey = TranslateKey(key);
                if (translatedKey == KeyCode.None)
                {
                    continue;
                }
                if (action == 0)
                {
                    m_inputState.KeyUp(translatedKey);
                }
                else if (action == 1)
                {
                    m_inputState.KeyDown(translatedKey);
                }
            }

            // mouse (move + up/down)
            int mouseStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    mouseStreamLen = InputHTMLNativeCalls.JSGetMouseStream(streamBuf.Length, ptr);
                }
            }

            for (int i = 0; i < mouseStreamLen; i += 4)
            {
                int ev     = streamBuf[i];
                int button = streamBuf[i + 1];
                int x      = streamBuf[i + 2];
                int y      = streamBuf[i + 3];
                if (ev == 0)
                {
                    m_inputState.MouseUp(button);
                }
                else if (ev == 1)
                {
                    m_inputState.MouseDown(button);
                }
                m_inputState.mouseX = x;
                m_inputState.mouseY = y;
            }

            if (mouseStreamLen != 0)
            {
                m_inputState.hasMouse = true;
            }

            // touches
            int touchStreamLen;

            unsafe
            {
                fixed(int *ptr = streamBuf)
                {
                    touchStreamLen = InputHTMLNativeCalls.JSGetTouchStream(streamBuf.Length, ptr);
                }
            }
            for (int i = 0; i < touchStreamLen; i += 4)
            {
                int        ev = streamBuf[i];
                int        id = streamBuf[i + 1];
                int        x  = streamBuf[i + 2];
                int        y  = streamBuf[i + 3];
                TouchState phase;
                switch (ev)
                {
                case 0:
                    phase = TouchState.Ended;
                    break;

                case 1:
                    phase = TouchState.Began;
                    break;

                case 2:
                    phase = TouchState.Moved;
                    break;

                case 3:
                    phase = TouchState.Canceled;
                    break;

                default:
                    continue;
                }
                m_inputState.TouchEvent(id, phase, x, y);

                // simulate mouse from touch as well
                if (!m_inputState.hasMouse)
                {
                    if (ev == 0 || ev == 3)
                    {
                        if (firstTouch == id)
                        {
                            m_inputState.MouseUp(0);
                            firstTouch = -1;
                        }
                    }
                    else if (ev == 1)
                    {
                        if (firstTouch == -1)
                        {
                            firstTouch = id;
                            m_inputState.MouseDown(0);
                        }
                    }

                    if (firstTouch == id)
                    {
                        m_inputState.mouseX = x;
                        m_inputState.mouseY = y;
                    }
                }
            }
            InputHTMLNativeCalls.JSResetStreams();
        }