1
0
mirror of https://github.com/blupi-games/planetblupi synced 2024-12-30 10:15:36 +01:00

Restart the game when the display mode has changed

This commit is contained in:
Mathieu Schroeter 2018-06-28 23:55:08 +02:00
parent 05dd698578
commit 6bf6b3de07
3 changed files with 39 additions and 1 deletions

View File

@ -76,6 +76,7 @@ int g_settingsOverload = 0;
bool g_bTermInit = false; // initialisation en cours
Uint32 g_lastPhase = 999;
RestartMode g_restart = RestartMode::NO;
static bool g_pause;
#ifdef USE_CURL
@ -1089,5 +1090,18 @@ main (int argc, char * argv[])
delete (g_updateThread);
}
/* Restart the game when the fullscreen mode (ratio) has changed. */
if (g_restart != RestartMode::NO)
{
std::vector<const char *> _argv;
_argv.push_back (argv[0]);
if (g_restart == RestartMode::LEGACY)
_argv.push_back ("--legacy");
_argv.push_back (nullptr);
execv (argv[0], const_cast<char **> (&_argv[0]));
}
return 0;
}

View File

@ -28,6 +28,8 @@
class CEvent;
enum RestartMode { NO = 0, LEGACY, DESKTOP };
extern SDL_Window * g_window;
extern SDL_Renderer * g_renderer;
extern bool g_bFullScreen;
@ -37,6 +39,7 @@ extern bool g_restoreMidi;
extern bool g_enableRecorder;
extern std::string g_playRecord;
extern CEvent * g_pEvent;
extern RestartMode g_restart;
enum Settings {
SETTING_FULLSCREEN = 1 << 0,

View File

@ -4250,7 +4250,7 @@ CEvent::ChangeButtons (Sint32 message)
case EV_BUTTON3:
{
auto zoom = g_zoom;
g_zoom = 1;
g_zoom = g_settingsOverload & SETTING_LEGACY ? g_zoom = 2 : 1;
SetFullScreen (true, zoom);
break;
}
@ -4267,6 +4267,16 @@ CEvent::ChangeButtons (Sint32 message)
auto scale = g_zoom;
if (g_zoom > 1)
--g_zoom;
if (g_bFullScreen && scale == 2)
{
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent (&ev);
g_restart = RestartMode::DESKTOP;
break;
}
SetWindowSize (scale, g_zoom);
if (g_bFullScreen)
SetFullScreen (g_bFullScreen);
@ -4277,6 +4287,17 @@ CEvent::ChangeButtons (Sint32 message)
auto scale = g_zoom;
if (g_zoom < 2)
++g_zoom;
if (
g_bFullScreen && g_zoom == 2)
{
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent (&ev);
g_restart = RestartMode::LEGACY;
break;
}
SetWindowSize (scale, g_zoom);
if (g_bFullScreen)
SetFullScreen (g_bFullScreen);