diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/defaultsettings.cpp | 1 | ||||
-rw-r--r-- | src/game.cpp | 16 | ||||
-rw-r--r-- | src/guiEngine.cpp | 20 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index d45e386cf..434c887e8 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -121,6 +121,7 @@ void set_default_settings(Settings *settings) settings->setDefault("viewing_range", "100"); settings->setDefault("screenW", "800"); settings->setDefault("screenH", "600"); + settings->setDefault("autosave_screensize", "true"); settings->setDefault("fullscreen", "false"); settings->setDefault("fullscreen_bpp", "24"); settings->setDefault("vsync", "false"); diff --git a/src/game.cpp b/src/game.cpp index be0cc8fd5..ace647456 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1629,10 +1629,26 @@ void Game::run() && client->checkPrivilege("fast"); #endif + irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screenW"), + g_settings->getU16("screenH")); + while (device->run() && !(*kill || g_gamecallback->shutdown_requested || (server && server->getShutdownRequested()))) { + const irr::core::dimension2d<u32> ¤t_screen_size = + device->getVideoDriver()->getScreenSize(); + // Verify if window size has changed and save it if it's the case + // Ensure evaluating settings->getBool after verifying screensize + // First condition is cheaper + if (previous_screen_size != current_screen_size && + current_screen_size != irr::core::dimension2d<u32>(0,0) && + g_settings->getBool("autosave_screensize")) { + g_settings->setU16("screenW", current_screen_size.Width); + g_settings->setU16("screenH", current_screen_size.Height); + previous_screen_size = current_screen_size; + } + /* Must be called immediately after a device->run() call because it * uses device->getTimer()->getTime() */ diff --git a/src/guiEngine.cpp b/src/guiEngine.cpp index ebc4aac44..2d1bd6d44 100644 --- a/src/guiEngine.cpp +++ b/src/guiEngine.cpp @@ -262,8 +262,24 @@ void GUIEngine::run() unsigned int text_height = g_fontengine->getTextHeight(); - while(m_device->run() && (!m_startgame) && (!m_kill)) - { + irr::core::dimension2d<u32> previous_screen_size(g_settings->getU16("screenW"), + g_settings->getU16("screenH")); + + while (m_device->run() && (!m_startgame) && (!m_kill)) { + + const irr::core::dimension2d<u32> ¤t_screen_size = + m_device->getVideoDriver()->getScreenSize(); + // Verify if window size has changed and save it if it's the case + // Ensure evaluating settings->getBool after verifying screensize + // First condition is cheaper + if (previous_screen_size != current_screen_size && + current_screen_size != irr::core::dimension2d<u32>(0,0) && + g_settings->getBool("autosave_screensize")) { + g_settings->setU16("screenW", current_screen_size.Width); + g_settings->setU16("screenH", current_screen_size.Height); + previous_screen_size = current_screen_size; + } + //check if we need to update the "upper left corner"-text if (text_height != g_fontengine->getTextHeight()) { updateTopLeftTextSize(); |