diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index db7b04a90..51ea64e0f 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -441,10 +441,12 @@ bool CVideoPlayer::playVideo(int x, int y, bool stopOnKey) while(nextFrame()) { - GH.input().fetchEvents(); - - if(stopOnKey && GH.input().ignoreEventsUntilInput()) - return false; + if(stopOnKey) + { + GH.input().fetchEvents(); + if(GH.input().ignoreEventsUntilInput()) + return false; + } SDL_Rect rect = CSDL_Ext::toSDL(pos); diff --git a/client/eventsSDL/InputHandler.cpp b/client/eventsSDL/InputHandler.cpp index d66d05d5e..1705b9ecc 100644 --- a/client/eventsSDL/InputHandler.cpp +++ b/client/eventsSDL/InputHandler.cpp @@ -78,8 +78,6 @@ void InputHandler::processEvents() boost::unique_lock lock(eventsMutex); for (auto const & currentEvent : eventsQueue) { - GH.events().allowEventHandling(true); - if (currentEvent.type == SDL_MOUSEMOTION) { cursorPosition = Point(currentEvent.motion.x, currentEvent.motion.y); diff --git a/client/gui/CGuiHandler.cpp b/client/gui/CGuiHandler.cpp index 4e8a1a501..cab19664e 100644 --- a/client/gui/CGuiHandler.cpp +++ b/client/gui/CGuiHandler.cpp @@ -180,11 +180,6 @@ bool CGuiHandler::isKeyboardShiftDown() const return inputHandlerInstance->isKeyboardShiftDown(); } -void CGuiHandler::breakEventHandling() -{ - events().allowEventHandling(false); -} - const Point & CGuiHandler::getCursorPosition() const { return inputHandlerInstance->getCursorPosition(); diff --git a/client/gui/CGuiHandler.h b/client/gui/CGuiHandler.h index c4d995618..024489d02 100644 --- a/client/gui/CGuiHandler.h +++ b/client/gui/CGuiHandler.h @@ -107,7 +107,6 @@ public: void handleEvents(); //takes events from queue and calls interested objects void fakeMouseMove(); - void breakEventHandling(); //current event won't be propagated anymore void drawFPSCounter(); // draws the FPS to the upper left corner of the screen bool amIGuiThread(); diff --git a/client/gui/EventDispatcher.cpp b/client/gui/EventDispatcher.cpp index 4a199daf9..995f66c13 100644 --- a/client/gui/EventDispatcher.cpp +++ b/client/gui/EventDispatcher.cpp @@ -17,11 +17,6 @@ #include "../../lib/Point.h" -void EventDispatcher::allowEventHandling(bool enable) -{ - eventHandlingAllowed = enable; -} - void EventDispatcher::processList(const ui16 mask, const ui16 flag, CIntObjectList *lst, std::function cb) { if (mask & flag) @@ -83,12 +78,13 @@ void EventDispatcher::dispatchShortcutPressed(const std::vector & sho for(auto & i : miCopy) { - if (!eventHandlingAllowed) - break; - for(EShortcut shortcut : shortcutsVector) if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut))) + { i->keyPressed(shortcut); + if (keysCaptured) + return; + } } } @@ -105,12 +101,13 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector & sh for(auto & i : miCopy) { - if (!eventHandlingAllowed) - break; - for(EShortcut shortcut : shortcutsVector) if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut))) + { i->keyReleased(shortcut); + if (keysCaptured) + return; + } } } @@ -138,9 +135,6 @@ void EventDispatcher::dispatchMouseDoubleClick(const Point & position) if(!vstd::contains(doubleClickInterested, i)) continue; - if (!eventHandlingAllowed) - break; - if(i->isInside(position)) { i->onDoubleClick(); @@ -170,9 +164,6 @@ void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, Mo if(!vstd::contains(interestedObjs, i)) continue; - if (!eventHandlingAllowed) - break; - auto prev = i->isMouseButtonPressed(btn); if(!isPressed) i->currentMouseState[btn] = isPressed; @@ -190,11 +181,11 @@ void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, Mo void EventDispatcher::dispatchMouseScrolled(const Point & distance, const Point & position) { CIntObjectList hlp = wheelInterested; - for(auto i = hlp.begin(); i != hlp.end() && eventHandlingAllowed; i++) + for(auto & i : hlp) { - if(!vstd::contains(wheelInterested,*i)) + if(!vstd::contains(wheelInterested,i)) continue; - (*i)->wheelScrolled(distance.y < 0, (*i)->isInside(position)); + i->wheelScrolled(distance.y < 0, i->isInside(position)); } } diff --git a/client/gui/EventDispatcher.h b/client/gui/EventDispatcher.h index 8ec01c446..a9fd59f34 100644 --- a/client/gui/EventDispatcher.h +++ b/client/gui/EventDispatcher.h @@ -34,8 +34,6 @@ class EventDispatcher CIntObjectList doubleClickInterested; CIntObjectList textInterested; - std::atomic eventHandlingAllowed = true; - CIntObjectList & getListForMouseButton(MouseButton button); void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed); @@ -44,9 +42,6 @@ class EventDispatcher void processLists(ui16 activityFlag, std::function cb); public: - /// allows to interrupt event handling and abort any subsequent event processing - void allowEventHandling(bool enable); - /// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag); diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index ed1c7445b..76d8987df 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -574,7 +574,6 @@ void CTextInput::keyPressed(EShortcut key) if(key == EShortcut::GLOBAL_MOVE_FOCUS) { moveFocus(); - GH.breakEventHandling(); return; } @@ -622,6 +621,9 @@ bool CTextInput::captureThisKey(EShortcut key) if(key == EShortcut::GLOBAL_RETURN) return false; + if (!focus) + return false; + return true; } diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index f220b24e7..83245bdda 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -295,7 +295,6 @@ void CSpellWindow::fLcornerb() setCurrentPage(currentPage - 1); } computeSpellsPerArea(); - GH.breakEventHandling(); } void CSpellWindow::fRcornerb() @@ -306,7 +305,6 @@ void CSpellWindow::fRcornerb() setCurrentPage(currentPage + 1); } computeSpellsPerArea(); - GH.breakEventHandling(); } void CSpellWindow::show(SDL_Surface * to)