From: <axl...@us...> - 2009-05-17 21:38:06
|
Revision: 269 http://hgengine.svn.sourceforge.net/hgengine/?rev=269&view=rev Author: axlecrusher Date: 2009-05-17 21:37:58 +0000 (Sun, 17 May 2009) Log Message: ----------- add in key repeat Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/MercuryInput.cpp 2009-05-17 21:37:58 UTC (rev 269) @@ -27,23 +27,21 @@ } } -void KeyboardInput::ProcessKeyInput(uint16_t key, bool isDown) +void KeyboardInput::ProcessKeyInput(uint16_t key, bool isDown, bool repeat) { KeyboardInput* ki = new KeyboardInput(); ki->isDown = isDown; ki->key = key; + ki->isRepeat = repeat; + + //if statements are for old people, bruit force it - if (isDown) - { - m_keyStates[key] |= (1 << 1); - printf("press %d\n", key); - } - else - { - m_keyStates[key] &= ~(1 << 1); - printf("release %d\n", key); - } + m_keyStates[key] &= ~(1 << 1); //disable + m_keyStates[key] |= (isDown << 1); //enable if true + m_keyStates[key] &= ~(1 << 2); //disable + m_keyStates[key] |= (repeat << 2); //enable if true + POST_MESSAGE( INPUTEVENT_KEYBOARD, ki, 0 ); } @@ -52,6 +50,12 @@ return (m_keyStates[key] & (1 << 1)) > 0; } +bool KeyboardInput::IsKeyRepeat(uint16_t key) +{ + return (m_keyStates[key] & (1 << 2)) > 0; +} + + uint8_t KeyboardInput::m_keyStates[512]; Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/MercuryInput.h 2009-05-17 21:37:58 UTC (rev 269) @@ -23,13 +23,15 @@ class KeyboardInput : public MessageData { public: - static void ProcessKeyInput(uint16_t key, bool isDown); + static void ProcessKeyInput(uint16_t key, bool isDown, bool repeat); static bool IsKeyDown(uint16_t key); + static bool IsKeyRepeat(uint16_t key); KeyboardInput(); int16_t key; bool isDown; + bool isRepeat; private: static uint8_t m_keyStates[512]; }; Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/X11Window.cpp 2009-05-17 21:37:58 UTC (rev 269) @@ -155,17 +155,17 @@ case KeyPress: { //ignore autorepeat -// if ( IsKeyRepeat(&event.xkey) ) break; + if ( IsKeyRepeat(&event.xkey) ) break; - KeyboardInput::ProcessKeyInput(event.xkey.keycode, true); + KeyboardInput::ProcessKeyInput(event.xkey.keycode, true, false); break; } case KeyRelease: { //ignore autorepeat -// if ( IsKeyRepeat(&event.xkey) ) break; + if ( IsKeyRepeat(&event.xkey) ) break; - KeyboardInput::ProcessKeyInput(event.xkey.keycode, false); + KeyboardInput::ProcessKeyInput(event.xkey.keycode, false, false); break; } case MotionNotify: @@ -200,6 +200,7 @@ nEvent.xkey.time == e->time) { XNextEvent(m_display, &nEvent); //forget next event + KeyboardInput::ProcessKeyInput(e->keycode, true, true); //set repeat flag return true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |