mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-29 21:56:54 +02:00
split massive handleCurrentEvent method into per-event parts
This commit is contained in:
parent
cb4cf224a9
commit
008a1ebec4
@ -295,13 +295,42 @@ void CGuiHandler::fakeMouseButtonEventRelativeMode(bool down, bool right)
|
||||
|
||||
void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
{
|
||||
if(current.type == SDL_KEYDOWN || current.type == SDL_KEYUP)
|
||||
switch (current.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
return handleEventKeyDown(current);
|
||||
case SDL_KEYUP:
|
||||
return handleEventKeyUp(current);
|
||||
case SDL_MOUSEMOTION:
|
||||
return handleEventMouseMotion(current);
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
return handleEventMouseButtonDown(current);
|
||||
case SDL_MOUSEWHEEL:
|
||||
return handleEventMouseWheel(current);
|
||||
case SDL_TEXTINPUT:
|
||||
return handleEventTextInput(current);
|
||||
case SDL_TEXTEDITING:
|
||||
return handleEventTextEditing(current);
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return handleEventMouseButtonUp(current);
|
||||
case SDL_FINGERMOTION:
|
||||
return handleEventFingerMotion(current);
|
||||
case SDL_FINGERDOWN:
|
||||
return handleEventFingerDown(current);
|
||||
case SDL_FINGERUP:
|
||||
return handleEventFingerUp(current);
|
||||
}
|
||||
}
|
||||
|
||||
void CGuiHandler::handleEventKeyDown(SDL_Event & current)
|
||||
{
|
||||
SDL_KeyboardEvent key = current.key;
|
||||
|
||||
if(key.repeat != 0)
|
||||
return; // ignore periodic event resends
|
||||
|
||||
assert(key.state == SDL_PRESSED);
|
||||
|
||||
if(current.type == SDL_KEYDOWN && key.keysym.sym >= SDLK_F1 && key.keysym.sym <= SDLK_F15 && settings["session"]["spectate"].Bool())
|
||||
{
|
||||
//TODO: we need some central place for all interface-independent hotkeys
|
||||
@ -328,15 +357,6 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
s["spectate-skip-battle-result"].Bool() = !settings["session"]["spectate-skip-battle-result"].Bool();
|
||||
break;
|
||||
|
||||
case SDLK_F9:
|
||||
//not working yet since CClient::run remain locked after BattleInterface removal
|
||||
// if(LOCPLINT->battleInt)
|
||||
// {
|
||||
// GH.windows().popInts(1);
|
||||
// vstd::clear_pointer(LOCPLINT->battleInt);
|
||||
// }
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -347,37 +367,50 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
|
||||
bool keysCaptured = false;
|
||||
for(auto i = keyinterested.begin(); i != keyinterested.end() && continueEventHandling; i++)
|
||||
{
|
||||
for(EShortcut shortcut : shortcutsVector)
|
||||
{
|
||||
if((*i)->captureThisKey(shortcut))
|
||||
{
|
||||
keysCaptured = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::list<CIntObject *> miCopy = keyinterested;
|
||||
|
||||
for(auto i = miCopy.begin(); i != miCopy.end() && continueEventHandling; i++)
|
||||
{
|
||||
for(EShortcut shortcut : shortcutsVector)
|
||||
{
|
||||
if(vstd::contains(keyinterested, *i) && (!keysCaptured || (*i)->captureThisKey(shortcut)))
|
||||
{
|
||||
if (key.state == SDL_PRESSED)
|
||||
(**i).keyPressed(shortcut);
|
||||
if (key.state == SDL_RELEASED)
|
||||
}
|
||||
|
||||
void CGuiHandler::handleEventKeyUp(SDL_Event & current)
|
||||
{
|
||||
SDL_KeyboardEvent key = current.key;
|
||||
|
||||
if(key.repeat != 0)
|
||||
return; // ignore periodic event resends
|
||||
|
||||
assert(key.state == SDL_RELEASED);
|
||||
|
||||
auto shortcutsVector = shortcutsHandler().translateKeycode(key.keysym.sym);
|
||||
|
||||
bool keysCaptured = false;
|
||||
|
||||
for(auto i = keyinterested.begin(); i != keyinterested.end() && continueEventHandling; i++)
|
||||
for(EShortcut shortcut : shortcutsVector)
|
||||
if((*i)->captureThisKey(shortcut))
|
||||
keysCaptured = true;
|
||||
|
||||
std::list<CIntObject *> miCopy = keyinterested;
|
||||
|
||||
for(auto i = miCopy.begin(); i != miCopy.end() && continueEventHandling; i++)
|
||||
for(EShortcut shortcut : shortcutsVector)
|
||||
if(vstd::contains(keyinterested, *i) && (!keysCaptured || (*i)->captureThisKey(shortcut)))
|
||||
(**i).keyReleased(shortcut);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_MOUSEMOTION)
|
||||
|
||||
void CGuiHandler::handleEventMouseMotion(SDL_Event & current)
|
||||
{
|
||||
handleMouseMotion(current);
|
||||
}
|
||||
else if(current.type == SDL_MOUSEBUTTONDOWN)
|
||||
|
||||
void CGuiHandler::handleEventMouseButtonDown(SDL_Event & current)
|
||||
{
|
||||
switch(current.button.button)
|
||||
{
|
||||
@ -416,7 +449,8 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_MOUSEWHEEL)
|
||||
|
||||
void CGuiHandler::handleEventMouseWheel(SDL_Event & current)
|
||||
{
|
||||
std::list<CIntObject*> hlp = wheelInterested;
|
||||
for(auto i = hlp.begin(); i != hlp.end() && continueEventHandling; i++)
|
||||
@ -428,21 +462,24 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
(*i)->wheelScrolled(current.wheel.y < 0, (*i)->pos.isInside(x, y));
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_TEXTINPUT)
|
||||
|
||||
void CGuiHandler::handleEventTextInput(SDL_Event & current)
|
||||
{
|
||||
for(auto it : textInterested)
|
||||
{
|
||||
it->textInputed(current.text.text);
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_TEXTEDITING)
|
||||
|
||||
void CGuiHandler::handleEventTextEditing(SDL_Event & current)
|
||||
{
|
||||
for(auto it : textInterested)
|
||||
{
|
||||
it->textEdited(current.edit.text);
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_MOUSEBUTTONUP)
|
||||
|
||||
void CGuiHandler::handleEventMouseButtonUp(SDL_Event & current)
|
||||
{
|
||||
if(!multifinger)
|
||||
{
|
||||
@ -460,14 +497,16 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_FINGERMOTION)
|
||||
|
||||
void CGuiHandler::handleEventFingerMotion(SDL_Event & current)
|
||||
{
|
||||
if(isPointerRelativeMode)
|
||||
{
|
||||
fakeMoveCursor(current.tfinger.dx, current.tfinger.dy);
|
||||
}
|
||||
}
|
||||
else if(current.type == SDL_FINGERDOWN)
|
||||
|
||||
void CGuiHandler::handleEventFingerDown(SDL_Event & current)
|
||||
{
|
||||
auto fingerCount = SDL_GetNumTouchFingers(current.tfinger.touchId);
|
||||
|
||||
@ -491,7 +530,8 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
}
|
||||
#endif //VCMI_IOS
|
||||
}
|
||||
else if(current.type == SDL_FINGERUP)
|
||||
|
||||
void CGuiHandler::handleEventFingerUp(SDL_Event & current)
|
||||
{
|
||||
#ifndef VCMI_IOS
|
||||
auto fingerCount = SDL_GetNumTouchFingers(current.tfinger.touchId);
|
||||
@ -516,7 +556,6 @@ void CGuiHandler::handleCurrentEvent( SDL_Event & current )
|
||||
}
|
||||
#endif //VCMI_IOS
|
||||
}
|
||||
} //event end
|
||||
|
||||
void CGuiHandler::handleMouseButtonClick(CIntObjectList & interestedObjs, MouseButton btn, bool isPressed)
|
||||
{
|
||||
|
@ -91,6 +91,18 @@ private:
|
||||
void fakeMoveCursor(float dx, float dy);
|
||||
void fakeMouseButtonEventRelativeMode(bool down, bool right);
|
||||
|
||||
void handleEventKeyDown(SDL_Event & current);
|
||||
void handleEventKeyUp(SDL_Event & current);
|
||||
void handleEventMouseMotion(SDL_Event & current);
|
||||
void handleEventMouseButtonDown(SDL_Event & current);
|
||||
void handleEventMouseWheel(SDL_Event & current);
|
||||
void handleEventTextInput(SDL_Event & current);
|
||||
void handleEventTextEditing(SDL_Event & current);
|
||||
void handleEventMouseButtonUp(SDL_Event & current);
|
||||
void handleEventFingerMotion(SDL_Event & current);
|
||||
void handleEventFingerDown(SDL_Event & current);
|
||||
void handleEventFingerUp(SDL_Event & current);
|
||||
|
||||
public:
|
||||
void handleElementActivate(CIntObject * elem, ui16 activityFlag);
|
||||
void handleElementDeActivate(CIntObject * elem, ui16 activityFlag);
|
||||
|
Loading…
x
Reference in New Issue
Block a user