summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-10-07 20:05:56 +0300
committerAndrei Karas <akaras@inbox.ru>2013-10-07 20:05:56 +0300
commit327312c8f5a4fb89b0d38ae179c76e9885bfb698 (patch)
tree0e9f1eb4fa3ccdcf20f30b2bfbcd678ed402371f /src
parentc89329623cbe5a2c3d5baf25fc58808f13af6069 (diff)
downloadmanaplus-327312c8f5a4fb89b0d38ae179c76e9885bfb698.tar.gz
manaplus-327312c8f5a4fb89b0d38ae179c76e9885bfb698.tar.bz2
manaplus-327312c8f5a4fb89b0d38ae179c76e9885bfb698.tar.xz
manaplus-327312c8f5a4fb89b0d38ae179c76e9885bfb698.zip
move window events handling into eventsmanager.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp59
-rw-r--r--src/client.h6
-rw-r--r--src/eventsmanager.cpp158
-rw-r--r--src/eventsmanager.h6
-rw-r--r--src/game.cpp103
-rw-r--r--src/game.h6
6 files changed, 134 insertions, 204 deletions
diff --git a/src/client.cpp b/src/client.cpp
index b5ae5ee09..ffd7336ef 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -2922,65 +2922,6 @@ bool Client::isKeyboardVisible() const
#endif
}
-#ifdef USE_SDL2
-void Client::handleSDL2WindowEvent(const SDL_Event &event)
-{
- switch (event.window.event)
- {
- case SDL_WINDOWEVENT_RESIZED:
- resizeVideo(event.window.data1, event.window.data2, false);
- break;
- case SDL_WINDOWEVENT_ENTER:
- setMouseFocused(true);
- break;
- case SDL_WINDOWEVENT_LEAVE:
- setMouseFocused(false);
- break;
- case SDL_WINDOWEVENT_FOCUS_GAINED:
- setInputFocused(true);
- break;
- case SDL_WINDOWEVENT_FOCUS_LOST:
- setInputFocused(false);
- break;
- case SDL_WINDOWEVENT_MINIMIZED:
- setIsMinimized(true);
- break;
- case SDL_WINDOWEVENT_RESTORED:
- case SDL_WINDOWEVENT_MAXIMIZED:
- setIsMinimized(false);
- break;
- default:
- break;
- }
-}
-#else
-void Client::handleActive(const SDL_Event &event)
-{
- if (event.active.state & SDL_APPACTIVE)
- {
- if (event.active.gain)
- { // window restore
- setIsMinimized(false);
- setPriority(true);
- }
- else
- { // window minimization
-#if defined(ANDROID) && !defined(USE_SDL2)
- setState(STATE_EXIT);
-#else
- setIsMinimized(true);
- setPriority(false);
-#endif
- }
- }
-
- if (event.active.state & SDL_APPINPUTFOCUS)
- setInputFocused(event.active.gain);
- if (event.active.state & SDL_APPMOUSEFOCUS)
- setMouseFocused(event.active.gain);
-}
-#endif
-
#ifdef ANDROID
#ifdef USE_SDL2
void Client::extractAssets()
diff --git a/src/client.h b/src/client.h
index d107632a5..65e02e006 100644
--- a/src/client.h
+++ b/src/client.h
@@ -312,12 +312,6 @@ public:
static void applyKeyRepeat();
-#ifdef USE_SDL2
- void handleSDL2WindowEvent(const SDL_Event &event);
-#else
- void handleActive(const SDL_Event &event);
-#endif
-
void optionChanged(const std::string &name) override;
void action(const gcn::ActionEvent &event) override;
diff --git a/src/eventsmanager.cpp b/src/eventsmanager.cpp
index 7e9c24970..09234ec3f 100644
--- a/src/eventsmanager.cpp
+++ b/src/eventsmanager.cpp
@@ -30,6 +30,8 @@
#include "input/inputmanager.h"
+#include "utils/process.h"
+
#include "debug.h"
EventsManager eventsManager;
@@ -56,10 +58,17 @@ bool EventsManager::handleCommonEvents(const SDL_Event &event)
client->setState(STATE_EXIT);
logger->log1("force exit");
return true;
-#ifndef USE_SDL2
+#ifdef USE_SDL2
+ case SDL_WINDOWEVENT:
+ handleSDL2WindowEvent(event);
+ return true;
+#else
case SDL_VIDEORESIZE:
client->resizeVideo(event.resize.w, event.resize.h);
return true;
+ case SDL_ACTIVEEVENT:
+ handleActive(event);
+ return true;
#ifdef ANDROID
case SDL_KEYBOARDSHOW:
client->updateScreenKeyboard(event.user.code);
@@ -112,20 +121,12 @@ bool EventsManager::handleEvents()
break;
#endif
-#endif
- default:
- break;
-#ifdef USE_SDL2
- case SDL_WINDOWEVENT:
- client->handleSDL2WindowEvent(event);
- break;
#else
-#ifndef ANDROID
- case SDL_ACTIVEEVENT:
- client->handleActive(event);
- break;
+#ifndef USE_SDL2
#endif
#endif
+ default:
+ break;
}
}
@@ -161,24 +162,6 @@ void EventsManager::handleGameEvents()
if (handleCommonEvents(event))
break;
-
- switch (event.type)
- {
-#ifdef USE_SDL2
- case SDL_WINDOWEVENT:
- {
- game->handleSDL2WindowEvent(event);
- break;
- }
-#else
- // Active event
- case SDL_ACTIVEEVENT:
- game->handleActive(event);
- break;
-#endif
- default:
- break;
- }
BLOCK_END("Game::handleInput 2")
} // End while
}
@@ -392,3 +375,118 @@ void EventsManager::logEvent(const SDL_Event &event)
break;
};
}
+
+#ifdef USE_SDL2
+void EventsManager::handleSDL2WindowEvent(const SDL_Event &event)
+{
+ int fpsLimit = 0;
+ const int eventType = event.window.event;
+ const bool inGame = (client->getState() == STATE_GAME);
+ switch (eventType)
+ {
+ case SDL_WINDOWEVENT_RESIZED:
+ client->resizeVideo(event.window.data1, event.window.data2, false);
+ break;
+ case SDL_WINDOWEVENT_ENTER:
+ client->setMouseFocused(true);
+ break;
+ case SDL_WINDOWEVENT_LEAVE:
+ client->setMouseFocused(false);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_GAINED:
+ client->setInputFocused(true);
+ break;
+ case SDL_WINDOWEVENT_FOCUS_LOST:
+ client->setInputFocused(false);
+ break;
+ case SDL_WINDOWEVENT_MINIMIZED:
+ client->setIsMinimized(true);
+ if (inGame)
+ {
+ if (player_node && !player_node->getAway())
+ {
+ fpsLimit = config.getIntValue("altfpslimit");
+ player_node->setHalfAway(true);
+ }
+ }
+ setPriority(false);
+ break;
+ case SDL_WINDOWEVENT_RESTORED:
+ case SDL_WINDOWEVENT_MAXIMIZED:
+ client->setIsMinimized(false);
+ if (inGame)
+ {
+ if (player_node)
+ {
+ if (!player_node->getAway())
+ fpsLimit = config.getIntValue("fpslimit");
+ player_node->setHalfAway(false);
+ }
+ }
+ setPriority(true);
+ break;
+ default:
+ break;
+ }
+
+ if (!inGame)
+ return;
+
+ if (eventType == SDL_WINDOWEVENT_MINIMIZED
+ || eventType == SDL_WINDOWEVENT_RESTORED
+ || eventType == SDL_WINDOWEVENT_MAXIMIZED)
+ {
+ if (player_node)
+ {
+ player_node->updateStatus();
+ player_node->updateName();
+ }
+ updateFrameRate(fpsLimit);
+ }
+}
+#else
+void EventsManager::handleActive(const SDL_Event &event)
+{
+ int fpsLimit = 0;
+ const bool inGame = (client->getState() == STATE_GAME);
+ if (event.active.state & SDL_APPACTIVE)
+ {
+ if (event.active.gain)
+ { // window restore
+ client->setIsMinimized(false);
+ if (inGame && player_node)
+ {
+ if (!player_node->getAway())
+ fpsLimit = config.getIntValue("fpslimit");
+ player_node->setHalfAway(false);
+ }
+ setPriority(true);
+ }
+ else
+ { // window minimization
+#ifdef ANDROID
+ client->setState(STATE_EXIT);
+#else
+ client->setIsMinimized(true);
+ if (inGame && player_node && !player_node->getAway())
+ {
+ fpsLimit = config.getIntValue("altfpslimit");
+ player_node->setHalfAway(true);
+ }
+ setPriority(false);
+#endif
+ }
+ if (inGame && player_node)
+ player_node->updateStatus();
+ }
+ if (inGame && player_node)
+ player_node->updateName();
+
+ if (event.active.state & SDL_APPINPUTFOCUS)
+ client->setInputFocused(event.active.gain);
+ if (event.active.state & SDL_APPMOUSEFOCUS)
+ client->setMouseFocused(event.active.gain);
+ if (inGame)
+ Game::instance()->updateFrameRate(fpsLimit);
+}
+#endif
diff --git a/src/eventsmanager.h b/src/eventsmanager.h
index fc977d3be..690745ad6 100644
--- a/src/eventsmanager.h
+++ b/src/eventsmanager.h
@@ -45,6 +45,12 @@ class EventsManager final : public ConfigListener
void handleGameEvents();
+#ifdef USE_SDL2
+ void handleSDL2WindowEvent(const SDL_Event &event);
+#else
+ void handleActive(const SDL_Event &event);
+#endif
+
void optionChanged(const std::string &name);
void logEvent(const SDL_Event &event);
diff --git a/src/game.cpp b/src/game.cpp
index 971352234..1e8d19398 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -877,109 +877,6 @@ void Game::moveInDirection(const unsigned char direction)
}
}
-#ifdef USE_SDL2
-void Game::handleSDL2WindowEvent(const SDL_Event &event)
-{
- int fpsLimit = 0;
- const int eventType = event.window.event;
- switch (eventType)
- {
- case SDL_WINDOWEVENT_RESIZED:
- client->resizeVideo(event.window.data1, event.window.data2, false);
- break;
- case SDL_WINDOWEVENT_ENTER:
- client->setMouseFocused(true);
- break;
- case SDL_WINDOWEVENT_LEAVE:
- client->setMouseFocused(false);
- break;
- case SDL_WINDOWEVENT_FOCUS_GAINED:
- client->setInputFocused(true);
- break;
- case SDL_WINDOWEVENT_FOCUS_LOST:
- client->setInputFocused(false);
- break;
- case SDL_WINDOWEVENT_MINIMIZED:
- client->setIsMinimized(true);
- if (player_node && !player_node->getAway())
- {
- fpsLimit = config.getIntValue("altfpslimit");
- player_node->setHalfAway(true);
- }
- setPriority(false);
- break;
- case SDL_WINDOWEVENT_RESTORED:
- case SDL_WINDOWEVENT_MAXIMIZED:
- client->setIsMinimized(false);
- if (player_node)
- {
- if (!player_node->getAway())
- fpsLimit = config.getIntValue("fpslimit");
- player_node->setHalfAway(false);
- }
- setPriority(true);
- break;
- default:
- break;
- }
-
- if (eventType == SDL_WINDOWEVENT_MINIMIZED
- || eventType == SDL_WINDOWEVENT_RESTORED
- || eventType == SDL_WINDOWEVENT_MAXIMIZED)
- {
- if (player_node)
- {
- player_node->updateStatus();
- player_node->updateName();
- }
- updateFrameRate(fpsLimit);
- }
-}
-#else
-void Game::handleActive(const SDL_Event &event)
-{
- int fpsLimit = 0;
- if (event.active.state & SDL_APPACTIVE)
- {
- if (event.active.gain)
- { // window restore
- client->setIsMinimized(false);
- if (player_node)
- {
- if (!player_node->getAway())
- fpsLimit = config.getIntValue("fpslimit");
- player_node->setHalfAway(false);
- }
- setPriority(true);
- }
- else
- { // window minimization
-#ifdef ANDROID
- client->setState(STATE_EXIT);
-#else
- client->setIsMinimized(true);
- if (player_node && !player_node->getAway())
- {
- fpsLimit = config.getIntValue("altfpslimit");
- player_node->setHalfAway(true);
- }
- setPriority(false);
-#endif
- }
- if (player_node)
- player_node->updateStatus();
- }
- if (player_node)
- player_node->updateName();
-
- if (event.active.state & SDL_APPINPUTFOCUS)
- client->setInputFocused(event.active.gain);
- if (event.active.state & SDL_APPMOUSEFOCUS)
- client->setMouseFocused(event.active.gain);
- updateFrameRate(fpsLimit);
-}
-#endif
-
void Game::updateFrameRate(int fpsLimit)
{
if (!fpsLimit)
diff --git a/src/game.h b/src/game.h
index 34d6d5107..77df0a15b 100644
--- a/src/game.h
+++ b/src/game.h
@@ -83,12 +83,6 @@ class Game final
void handleMove();
-#ifdef USE_SDL2
- void handleSDL2WindowEvent(const SDL_Event &event);
-#else
- void handleActive(const SDL_Event &event);
-#endif
-
void changeMap(const std::string &mapName);
void updateFrameRate(int fpsLimit);