示例#1
0
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            if (initialized)
            {
                return;
            }

            // must init after window
            initialized = GLFWNativeCalls.init_input();
            GLFWNativeCalls.resetStreams();
        }
示例#2
0
        protected override void OnUpdate()
        {
            if (!initialized)
            {
                return;
            }

            base.OnUpdate(); // advances input state one frame
            unsafe
            {
                // key, scancode, action, mods
                int  keyStreamLen = 0;
                int *keyStream    = GLFWNativeCalls.getKeyStream(ref keyStreamLen);
                for (int i = 0; i < keyStreamLen; i += 4)
                {
                    int     key           = keyStream[i];
                    int     scancode      = keyStream[i + 1];
                    int     action        = keyStream[i + 2];
                    int     mods          = keyStream[i + 3];
                    KeyCode translatedKey = TranslateKey(key, scancode, mods);
                    if (translatedKey == KeyCode.None)
                    {
                        continue;
                    }
                    if (action == GLFW_RELEASE)
                    {
                        m_inputState.KeyUp(translatedKey);
                    }
                    else if (action == GLFW_PRESS)
                    {
                        m_inputState.KeyDown(translatedKey);
                    }
                }

                // button, action, mods
                int  mouseButtonStreamLen = 0;
                int *mouseButtonStream    = GLFWNativeCalls.getMouseButtonStream(ref mouseButtonStreamLen);
                for (int i = 0; i < mouseButtonStreamLen; i += 3)
                {
                    int button = mouseButtonStream[i];
                    int action = mouseButtonStream[i + 1];
                    int mods   = mouseButtonStream[i + 2];
                    if (action == GLFW_RELEASE)
                    {
                        m_inputState.MouseUp(button);
                    }
                    else if (action == GLFW_PRESS)
                    {
                        m_inputState.MouseDown(button);
                    }
                }

                // position
                int  mousePosStreamLen = 0;
                int *mousePosStream    = GLFWNativeCalls.getMousePosStream(ref mousePosStreamLen);
                for (int i = 0; i < mousePosStreamLen; i += 2)
                {
                    m_inputState.mouseX = mousePosStream[i];
                    m_inputState.mouseY = mousePosStream[i + 1];
                }

                if (mouseButtonStreamLen != 0 || mousePosStreamLen != 0)
                {
                    m_inputState.hasMouse = true;
                }
            }

            GLFWNativeCalls.resetStreams();
        }