Fixed window position config storage and command line parsing

This commit is contained in:
Bart Trzynadlowski 2023-03-04 11:59:49 -08:00 committed by trzy
parent 83144f80b7
commit ae5af4c036

View file

@ -177,7 +177,7 @@ static void GLAPIENTRY DebugCallback(GLenum source, GLenum type, GLuint id, GLen
} }
// In windows with an nvidia card (sorry not tested anything else) you can customise the resolution. // In windows with an nvidia card (sorry not tested anything else) you can customise the resolution.
// This also allows you to set a totally custom refresh rate. Apparently you can drive most monitors at // This also allows you to set a totally custom refresh rate. Apparently you can drive most monitors at
// 57.5fps with no issues. Anyway this code will automatically pick up your custom refresh rate, and set it if it exists // 57.5fps with no issues. Anyway this code will automatically pick up your custom refresh rate, and set it if it exists
// It it doesn't exist, then it'll probably just default to 60 or whatever your refresh rate is. // It it doesn't exist, then it'll probably just default to 60 or whatever your refresh rate is.
static void SetFullScreenRefreshRate() static void SetFullScreenRefreshRate()
@ -828,7 +828,7 @@ private:
const char* vertexShader = R"glsl( const char* vertexShader = R"glsl(
#version 410 core #version 410 core
uniform mat4 mvp; uniform mat4 mvp;
layout(location = 0) in vec3 inVertices; layout(location = 0) in vec3 inVertices;
@ -841,7 +841,7 @@ private:
const char* fragmentShader = R"glsl( const char* fragmentShader = R"glsl(
#version 410 core #version 410 core
uniform vec4 colour; uniform vec4 colour;
out vec4 fragColour; out vec4 fragColour;
@ -1087,15 +1087,10 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
SDL_SetWindowTitle(s_window, baseTitleStr); SDL_SetWindowTitle(s_window, baseTitleStr);
SDL_SetWindowSize(s_window, totalXRes, totalYRes); SDL_SetWindowSize(s_window, totalXRes, totalYRes);
if (!s_runtime_config["WindowXPosition"].Empty() && !s_runtime_config["WindowYPosition"].Empty()) int xpos = s_runtime_config["WindowXPosition"].Exists() ? s_runtime_config["WindowXPosition"].ValueAs<int>() : SDL_WINDOWPOS_CENTERED;
{ int ypos = s_runtime_config["WindowYPosition"].Exists() ? s_runtime_config["WindowYPosition"].ValueAs<int>() : SDL_WINDOWPOS_CENTERED;
SDL_SetWindowPosition(s_window, s_runtime_config["WindowXPosition"].ValueAs<unsigned>(), s_runtime_config["WindowYPosition"].ValueAs<unsigned>()); SDL_SetWindowPosition(s_window, xpos, ypos);
}
else
{
SDL_SetWindowPosition(s_window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
}
if (s_runtime_config["BorderlessWindow"].ValueAs<bool>()) if (s_runtime_config["BorderlessWindow"].ValueAs<bool>())
{ {
SDL_SetWindowBordered(s_window, SDL_FALSE); SDL_SetWindowBordered(s_window, SDL_FALSE);
@ -1642,8 +1637,8 @@ static Util::Config::Node DefaultConfig()
config.Set("QuadRendering", false); config.Set("QuadRendering", false);
config.Set("XResolution", "496"); config.Set("XResolution", "496");
config.Set("YResolution", "384"); config.Set("YResolution", "384");
config.Set("WindowXPosition", "NA"); config.SetEmpty("WindowXPosition");
config.Set("WindowYPosition", "NA"); config.SetEmpty("WindowYPosition");
config.Set("FullScreen", false); config.Set("FullScreen", false);
config.Set("BorderlessWindow", false); config.Set("BorderlessWindow", false);
@ -1725,7 +1720,7 @@ static void Help(void)
puts(""); puts("");
puts("Video Options:"); puts("Video Options:");
puts(" -res=<x>,<y> Resolution [Default: 496,384]"); puts(" -res=<x>,<y> Resolution [Default: 496,384]");
puts(" -window-pos=<x>,<y> Window position [Default: centered]"); puts(" -window-pos=<x>,<y> Window position [Default: centered]");
puts(" -window Windowed mode [Default]"); puts(" -window Windowed mode [Default]");
puts(" -borderless Windowed mode with no border"); puts(" -borderless Windowed mode with no border");
puts(" -fullscreen Full screen mode"); puts(" -fullscreen Full screen mode");
@ -1966,13 +1961,11 @@ static ParsedCommandLine ParseCommandLine(int argc, char **argv)
} }
else else
{ {
unsigned x, y; int xpos, ypos;
if (2 == sscanf(&argv[i][4], "=%u,%u", &x, &y)) if (2 == sscanf(&argv[i][11], "=%d,%d", &xpos, &ypos))
{ {
std::string xres = Util::Format() << x; cmd_line.config.Set("WindowXPosition", xpos);
std::string yres = Util::Format() << y; cmd_line.config.Set("WindowYPosition", ypos);
cmd_line.config.Set("WindowXPosition", xres);
cmd_line.config.Set("WindowYPosition", yres);
} }
else else
{ {