diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-05-09 21:16:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-05-09 21:17:31 +0300 |
commit | aab80ddc8f56d6a383182ce5c241e9d94ca27bab (patch) | |
tree | 9e81b97354b666820ab6e2bb9575dc1127a486a8 /src/joystick.cpp | |
parent | 0af9ff98876426c096d2b4b8a4f17172af92b8d0 (diff) | |
download | ManaVerse-aab80ddc8f56d6a383182ce5c241e9d94ca27bab.tar.gz ManaVerse-aab80ddc8f56d6a383182ce5c241e9d94ca27bab.tar.bz2 ManaVerse-aab80ddc8f56d6a383182ce5c241e9d94ca27bab.tar.xz ManaVerse-aab80ddc8f56d6a383182ce5c241e9d94ca27bab.zip |
Add ability to auto repeat some keys presses.
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r-- | src/joystick.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp index 694ac1526..09d5c6226 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -260,7 +260,8 @@ void Joystick::getNames(std::vector <std::string> &names) void Joystick::update() { - inputManager.updateKeyActionMap(mKeyToAction, mKeyToId, INPUT_JOYSTICK); + inputManager.updateKeyActionMap(mKeyToAction, mKeyToId, + mKeyTimeMap, INPUT_JOYSTICK); } KeysVector *Joystick::getActionVector(const SDL_Event &event) @@ -275,6 +276,16 @@ KeysVector *Joystick::getActionVector(const SDL_Event &event) return nullptr; } +KeysVector *Joystick::getActionVectorByKey(int i) +{ + if (i < 0 || i >= mButtonsNumber) + return nullptr; +// logger->log("button triggerAction: %d", i); + if (mKeyToAction.find(i) != mKeyToAction.end()) + return &mKeyToAction[i]; + return nullptr; +} + int Joystick::getButtonFromEvent(const SDL_Event &event) const { if (event.jbutton.which != mNumber) @@ -309,3 +320,31 @@ bool Joystick::validate() const return (mUseInactive || Client::getInputFocused()); } + +void Joystick::handleRepeat(int time) +{ + for (KeyTimeMapIter it = mKeyTimeMap.begin(), it_end = mKeyTimeMap.end(); + it != it_end; ++ it) + { + bool repeat(false); + const int key = (*it).first; + int &keyTime = (*it).second; + if (key >= 0 && key < mButtonsNumber) + { + if (mActiveButtons[key]) + repeat = true; + } + if (repeat && abs(keyTime - time) > 10) + { + keyTime = time; + inputManager.triggerAction(getActionVectorByKey(key)); + } + } +} + +void Joystick::resetRepeat(int key) +{ + KeyTimeMapIter it = mKeyTimeMap.find(key); + if (it != mKeyTimeMap.end()) + (*it).second = tick_time; +} |