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

WIP: add support for cli option to change the window size

This commit is contained in:
Mathieu Schroeter 2017-09-19 20:06:13 +02:00
parent 02da57e5bd
commit 459759ffa5
3 changed files with 48 additions and 0 deletions

View File

@ -59,6 +59,7 @@ CDecor * g_pDecor = nullptr;
std::thread * g_updateThread = nullptr;
bool g_bFullScreen = false; // false si mode de test
Uint8 g_windowScale = 1;
Sint32 g_speedRate = 1;
Sint32 g_timerInterval = 50; // inverval = 50ms
int g_rendererType = 0;
@ -71,6 +72,7 @@ enum Settings {
SETTING_SPEEDRATE = 1 << 1,
SETTING_TIMERINTERVAL = 1 << 2,
SETTING_RENDERER = 1 << 3,
SETTING_ZOOM = 1 << 4,
};
static int g_settingsOverload = 0;
@ -152,6 +154,13 @@ ReadConfig ()
g_bFullScreen = 1;
}
if (!(g_settingsOverload & SETTING_ZOOM) && j.find ("scale") != j.end ())
{
g_windowScale = j["scale"].get<Uint8> ();
if (g_windowScale != 0)
g_windowScale = 1;
}
if (
!(g_settingsOverload & SETTING_RENDERER) && j.find ("renderer") != j.end ())
{
@ -526,6 +535,10 @@ parseArgs (int argc, char * argv[], bool & exit)
{"-f", "--fullscreen"},
"load in fullscreen [on;off] (default: on)",
1},
{"zoom",
{"-z", "--zoom"},
"change the window scale (only if fullscreen is off) [1;2] (default: 1)",
1},
{"renderer",
{"-r", "--renderer"},
"set a renderer [auto;software;accelerated] (default: auto)",
@ -587,6 +600,12 @@ parseArgs (int argc, char * argv[], bool & exit)
g_settingsOverload |= SETTING_FULLSCREEN;
}
if (args["zoom"])
{
g_windowScale = args["zoom"];
g_settingsOverload |= SETTING_ZOOM;
}
if (args["renderer"])
{
if (args["renderer"].as<std::string> () == "auto")
@ -905,6 +924,7 @@ DoInit (int argc, char * argv[], bool & exit)
g_pEvent->Create (g_pPixmap, g_pDecor, g_pSound, g_pMovie);
g_updateThread = new std::thread (CheckForUpdates);
g_pEvent->SetFullScreen (g_bFullScreen);
g_pEvent->SetWindowSize (g_windowScale);
g_pEvent->ChangePhase (EV_PHASE_INTRO1);
g_bTermInit = true;

View File

@ -1667,6 +1667,33 @@ CEvent::SetFullScreen (bool bFullScreen)
CEvent::PushUserEvent (EV_WARPMOUSE, coord);
}
/**
* \brief Change the size of the window.
*
* We use an integer scale to be sure that the pixels are always well formed.
*
* \param[in] newScale - The new scale.
*/
void
CEvent::SetWindowSize (Uint8 newScale)
{
if (newScale == m_WindowScale)
return;
auto scale = m_WindowScale;
m_WindowScale = scale;
switch (newScale)
{
case 1:
case 2:
SetWindowSize (scale, m_WindowScale);
break;
default:
return;
}
}
/**
* \brief Change the size of the window.
*

View File

@ -140,6 +140,7 @@ public:
void IntroStep ();
Uint8 GetWindowScale ();
void SetWindowSize (Uint8 newScale);
void SetUpdateVersion (const std::string & version);
static void PushUserEvent (Sint32 code, void * data = nullptr);