summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-24 13:22:54 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-24 21:08:17 +0300
commitc63a2a04e47c361a7254b0749298de84a6f331fa (patch)
tree3d7ccae75c1d8bfd6adb6937c269c17139e3e9e1 /src/game.cpp
parent9b727d191c9cea2324a8505296b08d0719a49207 (diff)
downloadmv-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.gz
mv-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.bz2
mv-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.xz
mv-c63a2a04e47c361a7254b0749298de84a6f331fa.zip
add minimize/maximize event handling in game class for SDL2.
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp74
1 files changed, 69 insertions, 5 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 41a036c0f..9a18e9da7 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -874,9 +874,71 @@ 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:
+#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
+ 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)
{
-#ifndef USE_SDL2
int fpsLimit = 0;
if (event.active.state & SDL_APPACTIVE)
{
@@ -915,7 +977,12 @@ void Game::handleActive(const SDL_Event &event)
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)
{
if (player_node && player_node->getAway())
@@ -932,7 +999,6 @@ void Game::handleActive(const SDL_Event &event)
}
client->setFramerate(fpsLimit);
mNextAdjustTime = cur_time + adjustDelay;
-#endif
}
/**
@@ -967,13 +1033,11 @@ void Game::handleInput()
#ifdef USE_SDL2
case SDL_WINDOWEVENT:
{
- client->handleSDL2WindowEvent(event);
+ handleSDL2WindowEvent(event);
break;
}
#else
case SDL_VIDEORESIZE:
- // Let the client deal with this one (it'll
- // pass down from there)
client->resizeVideo(event.resize.w, event.resize.h);
break;
// Active event