mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +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())
|
while(nextFrame())
|
||||||
{
|
{
|
||||||
GH.input().fetchEvents();
|
if(stopOnKey)
|
||||||
|
{
|
||||||
if(stopOnKey && GH.input().ignoreEventsUntilInput())
|
GH.input().fetchEvents();
|
||||||
return false;
|
if(GH.input().ignoreEventsUntilInput())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Rect rect = CSDL_Ext::toSDL(pos);
|
SDL_Rect rect = CSDL_Ext::toSDL(pos);
|
||||||
|
|
||||||
|
@ -78,8 +78,6 @@ void InputHandler::processEvents()
|
|||||||
boost::unique_lock<boost::mutex> lock(eventsMutex);
|
boost::unique_lock<boost::mutex> lock(eventsMutex);
|
||||||
for (auto const & currentEvent : eventsQueue)
|
for (auto const & currentEvent : eventsQueue)
|
||||||
{
|
{
|
||||||
GH.events().allowEventHandling(true);
|
|
||||||
|
|
||||||
if (currentEvent.type == SDL_MOUSEMOTION)
|
if (currentEvent.type == SDL_MOUSEMOTION)
|
||||||
{
|
{
|
||||||
cursorPosition = Point(currentEvent.motion.x, currentEvent.motion.y);
|
cursorPosition = Point(currentEvent.motion.x, currentEvent.motion.y);
|
||||||
|
@ -180,11 +180,6 @@ bool CGuiHandler::isKeyboardShiftDown() const
|
|||||||
return inputHandlerInstance->isKeyboardShiftDown();
|
return inputHandlerInstance->isKeyboardShiftDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGuiHandler::breakEventHandling()
|
|
||||||
{
|
|
||||||
events().allowEventHandling(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
const Point & CGuiHandler::getCursorPosition() const
|
const Point & CGuiHandler::getCursorPosition() const
|
||||||
{
|
{
|
||||||
return inputHandlerInstance->getCursorPosition();
|
return inputHandlerInstance->getCursorPosition();
|
||||||
|
@ -107,7 +107,6 @@ public:
|
|||||||
|
|
||||||
void handleEvents(); //takes events from queue and calls interested objects
|
void handleEvents(); //takes events from queue and calls interested objects
|
||||||
void fakeMouseMove();
|
void fakeMouseMove();
|
||||||
void breakEventHandling(); //current event won't be propagated anymore
|
|
||||||
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
|
void drawFPSCounter(); // draws the FPS to the upper left corner of the screen
|
||||||
|
|
||||||
bool amIGuiThread();
|
bool amIGuiThread();
|
||||||
|
@ -17,11 +17,6 @@
|
|||||||
|
|
||||||
#include "../../lib/Point.h"
|
#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)
|
void EventDispatcher::processList(const ui16 mask, const ui16 flag, CIntObjectList *lst, std::function<void (CIntObjectList *)> cb)
|
||||||
{
|
{
|
||||||
if (mask & flag)
|
if (mask & flag)
|
||||||
@ -83,12 +78,13 @@ void EventDispatcher::dispatchShortcutPressed(const std::vector<EShortcut> & sho
|
|||||||
|
|
||||||
for(auto & i : miCopy)
|
for(auto & i : miCopy)
|
||||||
{
|
{
|
||||||
if (!eventHandlingAllowed)
|
|
||||||
break;
|
|
||||||
|
|
||||||
for(EShortcut shortcut : shortcutsVector)
|
for(EShortcut shortcut : shortcutsVector)
|
||||||
if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut)))
|
if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut)))
|
||||||
|
{
|
||||||
i->keyPressed(shortcut);
|
i->keyPressed(shortcut);
|
||||||
|
if (keysCaptured)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,12 +101,13 @@ void EventDispatcher::dispatchShortcutReleased(const std::vector<EShortcut> & sh
|
|||||||
|
|
||||||
for(auto & i : miCopy)
|
for(auto & i : miCopy)
|
||||||
{
|
{
|
||||||
if (!eventHandlingAllowed)
|
|
||||||
break;
|
|
||||||
|
|
||||||
for(EShortcut shortcut : shortcutsVector)
|
for(EShortcut shortcut : shortcutsVector)
|
||||||
if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut)))
|
if(vstd::contains(keyinterested, i) && (!keysCaptured || i->captureThisKey(shortcut)))
|
||||||
|
{
|
||||||
i->keyReleased(shortcut);
|
i->keyReleased(shortcut);
|
||||||
|
if (keysCaptured)
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +135,6 @@ void EventDispatcher::dispatchMouseDoubleClick(const Point & position)
|
|||||||
if(!vstd::contains(doubleClickInterested, i))
|
if(!vstd::contains(doubleClickInterested, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!eventHandlingAllowed)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if(i->isInside(position))
|
if(i->isInside(position))
|
||||||
{
|
{
|
||||||
i->onDoubleClick();
|
i->onDoubleClick();
|
||||||
@ -170,9 +164,6 @@ void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, Mo
|
|||||||
if(!vstd::contains(interestedObjs, i))
|
if(!vstd::contains(interestedObjs, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!eventHandlingAllowed)
|
|
||||||
break;
|
|
||||||
|
|
||||||
auto prev = i->isMouseButtonPressed(btn);
|
auto prev = i->isMouseButtonPressed(btn);
|
||||||
if(!isPressed)
|
if(!isPressed)
|
||||||
i->currentMouseState[btn] = isPressed;
|
i->currentMouseState[btn] = isPressed;
|
||||||
@ -190,11 +181,11 @@ void EventDispatcher::handleMouseButtonClick(CIntObjectList & interestedObjs, Mo
|
|||||||
void EventDispatcher::dispatchMouseScrolled(const Point & distance, const Point & position)
|
void EventDispatcher::dispatchMouseScrolled(const Point & distance, const Point & position)
|
||||||
{
|
{
|
||||||
CIntObjectList hlp = wheelInterested;
|
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;
|
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 doubleClickInterested;
|
||||||
CIntObjectList textInterested;
|
CIntObjectList textInterested;
|
||||||
|
|
||||||
std::atomic<bool> eventHandlingAllowed = true;
|
|
||||||
|
|
||||||
CIntObjectList & getListForMouseButton(MouseButton button);
|
CIntObjectList & getListForMouseButton(MouseButton button);
|
||||||
|
|
||||||
void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed);
|
void handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed);
|
||||||
@ -44,9 +42,6 @@ class EventDispatcher
|
|||||||
void processLists(ui16 activityFlag, std::function<void(CIntObjectList *)> cb);
|
void processLists(ui16 activityFlag, std::function<void(CIntObjectList *)> cb);
|
||||||
|
|
||||||
public:
|
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
|
/// add specified UI element as interested. Uses unnamed enum from AEventsReceiver for activity flags
|
||||||
void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag);
|
void handleElementActivate(AEventsReceiver * elem, ui16 activityFlag);
|
||||||
|
|
||||||
|
@ -574,7 +574,6 @@ void CTextInput::keyPressed(EShortcut key)
|
|||||||
if(key == EShortcut::GLOBAL_MOVE_FOCUS)
|
if(key == EShortcut::GLOBAL_MOVE_FOCUS)
|
||||||
{
|
{
|
||||||
moveFocus();
|
moveFocus();
|
||||||
GH.breakEventHandling();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,6 +621,9 @@ bool CTextInput::captureThisKey(EShortcut key)
|
|||||||
if(key == EShortcut::GLOBAL_RETURN)
|
if(key == EShortcut::GLOBAL_RETURN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!focus)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,7 +295,6 @@ void CSpellWindow::fLcornerb()
|
|||||||
setCurrentPage(currentPage - 1);
|
setCurrentPage(currentPage - 1);
|
||||||
}
|
}
|
||||||
computeSpellsPerArea();
|
computeSpellsPerArea();
|
||||||
GH.breakEventHandling();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpellWindow::fRcornerb()
|
void CSpellWindow::fRcornerb()
|
||||||
@ -306,7 +305,6 @@ void CSpellWindow::fRcornerb()
|
|||||||
setCurrentPage(currentPage + 1);
|
setCurrentPage(currentPage + 1);
|
||||||
}
|
}
|
||||||
computeSpellsPerArea();
|
computeSpellsPerArea();
|
||||||
GH.breakEventHandling();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSpellWindow::show(SDL_Surface * to)
|
void CSpellWindow::show(SDL_Surface * to)
|
||||||
|
Loading…
Reference in New Issue
Block a user