mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Replaced event handling break system with key capturing
This commit is contained in:
parent
f4d67fe675
commit
c77f8482e3
@ -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);
|
||||
|
||||
|
@ -78,8 +78,6 @@ void InputHandler::processEvents()
|
||||
boost::unique_lock<boost::mutex> lock(eventsMutex);
|
||||
for (auto const & currentEvent : eventsQueue)
|
||||
{
|
||||
GH.events().allowEventHandling(true);
|
||||
|
||||
if (currentEvent.type == SDL_MOUSEMOTION)
|
||||
{
|
||||
cursorPosition = Point(currentEvent.motion.x, currentEvent.motion.y);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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<void (CIntObjectList *)> cb)
|
||||
{
|
||||
if (mask & flag)
|
||||
@ -83,12 +78,13 @@ void EventDispatcher::dispatchShortcutPressed(const std::vector<EShortcut> & 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<EShortcut> & 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,6 @@ class EventDispatcher
|
||||
CIntObjectList doubleClickInterested;
|
||||
CIntObjectList textInterested;
|
||||
|
||||
std::atomic<bool> 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<void(CIntObjectList *)> 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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user