diff options
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; +} |