Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _KEYSTATE_H_
- #define _KEYSTATE_H_
- #include "PaulMath.h"
- #include "GL/glfw.h"
- static class KeyState
- {
- private:
- struct Keys
- {
- BitSet * m_keyVal;
- BitSet * m_keyState;
- };
- static Keys * s_inst;
- public:
- //constructs and destructs,
- KeyState(void)
- {
- s_inst = new Keys;
- s_inst->m_keyVal = new BitSet(GLFW_KEY_LAST);
- s_inst->m_keyState = new BitSet(GLFW_KEY_LAST);
- glfwSetKeyCallback(KeyState::UpdateSingle);
- }
- ~KeyState(void) { delete s_inst->m_keyVal; delete s_inst->m_keyState; glfwSetKeyCallback(NULL); }
- static void GLFWCALL UpdateSingle(int key, int val)
- {
- //update values
- if(!(*(s_inst->m_keyState))[key] && !(*(s_inst->m_keyVal))[key])
- {
- if(glfwGetKey(key))
- s_inst->m_keyVal->SetBit(key);
- }
- else
- s_inst->m_keyVal->ClearBit(key);
- //update states
- if(glfwGetKey(key))
- s_inst->m_keyState->SetBit(key);
- else
- s_inst->m_keyState->ClearBit(key);
- }
- //for getting a key
- bool GetKey(const int key) const { return (*(s_inst->m_keyVal))[key]; }
- };
- KeyState::Keys* KeyState::s_inst = NULL;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement