diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-24 13:22:54 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-24 21:08:17 +0300 |
commit | c63a2a04e47c361a7254b0749298de84a6f331fa (patch) | |
tree | 3d7ccae75c1d8bfd6adb6937c269c17139e3e9e1 | |
parent | 9b727d191c9cea2324a8505296b08d0719a49207 (diff) | |
download | manaverse-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.gz manaverse-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.bz2 manaverse-c63a2a04e47c361a7254b0749298de84a6f331fa.tar.xz manaverse-c63a2a04e47c361a7254b0749298de84a6f331fa.zip |
add minimize/maximize event handling in game class for SDL2.
-rw-r--r-- | src/client.cpp | 1 | ||||
-rw-r--r-- | src/game.cpp | 74 | ||||
-rw-r--r-- | src/game.h | 6 |
3 files changed, 75 insertions, 6 deletions
diff --git a/src/client.cpp b/src/client.cpp index 9c3397f72..974e8d400 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -3108,7 +3108,6 @@ void Client::handleSDL2WindowEvent(const SDL_Event &event) { switch (event.window.event) { - // +++ need add other window events case SDL_WINDOWEVENT_RESIZED: resizeVideo(event.window.data1, event.window.data2, false); break; 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 diff --git a/src/game.h b/src/game.h index 6eb26f2dc..fcef8b161 100644 --- a/src/game.h +++ b/src/game.h @@ -84,10 +84,16 @@ 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); + /** * Returns the currently active map. */ |