Set the default window size to 66% of the primary window size (closes #1883)

This commit is contained in:
Alexander Bock
2022-02-17 17:55:43 +01:00
parent 9e69300642
commit cbe2e6cdcf
6 changed files with 59 additions and 23 deletions

View File

@@ -1138,10 +1138,21 @@ int main(int argc, char* argv[]) {
std::filesystem::path base = configurationFilePath.parent_path();
FileSys.registerPathToken("${BASE}", base);
// For now, we just initialize glfw since we can't execute anything meaningfully
// after SGCT initializes glfw. There is a bit of startup delay because of this,
// but it shouldn't be too bad
glfwInit();
GLFWmonitor* m = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(m);
glm::ivec2 size = glm::ivec2(mode->width, mode->height);
glfwTerminate();
// Loading configuration from disk
LDEBUG("Loading configuration from disk");
*global::configuration = configuration::loadConfigurationFromFile(
configurationFilePath.string(),
size,
commandlineArguments.configurationOverride
);

View File

@@ -141,7 +141,7 @@ struct Configuration {
std::filesystem::path findConfiguration(const std::string& filename = "openspace.cfg");
Configuration loadConfigurationFromFile(const std::filesystem::path& filename,
const std::string& overrideScript);
const glm::ivec2& primaryMonitorResolution, const std::string& overrideScript);
} // namespace openspace::configuration

View File

@@ -357,21 +357,6 @@ end
function normalizeArg(arg)
arg = arg or {}
check("number", arg, 1)
check("number", arg, 2)
if type(arg[1]) == "number" and type(arg[2]) == "number" then
arg["size"] = { arg[1], arg[2] }
arg[1] = nil
arg[2] = nil
end
end
function sgct.makeConfig(config)
local configFile = os.tmpname() .. ".json"
local file = io.open(configFile, "w+")
@@ -383,7 +368,21 @@ end
function sgct.config.single(arg)
normalizeArg(arg)
arg = arg or {}
if type(arg[1]) == "number" and type(arg[2]) == "number" then
arg["size"] = { arg[1], arg[2] }
arg[1] = nil
arg[2] = nil
else
-- No numbers specified, therefore we want to use the screen resolution of the primary
-- monitor to derive the resolution
-- ScreenResolution is a variable that got injected into the openspace.cfg by the
-- OpenSpace code prior to loading this file
local scale_factor = 2.0/3.0;
arg["size"] = { ScreenResolution.x * scale_factor, ScreenResolution.y * scale_factor }
end
check("table", arg, "size", "number")
check("table", arg, "fov", "number")
@@ -429,7 +428,24 @@ end
function sgct.config.fisheye(arg)
normalizeArg(arg)
arg = arg or {}
check("number", arg, 1)
check("number", arg, 2)
if type(arg[1]) == "number" and type(arg[2]) == "number" then
arg["size"] = { arg[1], arg[2] }
arg[1] = nil
arg[2] = nil
else
-- No numbers specified, therefore we want to use the screen resolution of the primary
-- monitor to derive the resolution
-- ScreenResolution is a variable that got injected into the openspace.cfg by the
-- OpenSpace code prior to loading this file
local scale_factor = 2.0/3.0;
arg["size"] = { ScreenResolution.x * scale_factor, ScreenResolution.y * scale_factor }
end
check("number", arg, "fov")
check("number", arg, "tilt")

View File

@@ -452,12 +452,20 @@ std::filesystem::path findConfiguration(const std::string& filename) {
}
Configuration loadConfigurationFromFile(const std::filesystem::path& filename,
const glm::ivec2& primaryMonitorResolution,
const std::string& overrideScript)
{
ghoul_assert(std::filesystem::is_regular_file(filename), "File must exist");
Configuration result;
// Injecting the resolution of the primary screen into the Lua state
std::string script = fmt::format(
"ScreenResolution = {{ x = {}, y = {} }}",
primaryMonitorResolution.x, primaryMonitorResolution.y
);
ghoul::lua::runScript(result.state, script);
// If there is an initial config helper file, load it into the state
if (std::filesystem::is_regular_file(absPath(InitialConfigHelper))) {
ghoul::lua::runScriptFile(result.state, absPath(InitialConfigHelper).string());

View File

@@ -67,6 +67,7 @@ int main(int argc, char** argv) {
*global::configuration = configuration::loadConfigurationFromFile(
configFile.string(),
glm::ivec2(0),
""
);
global::openSpaceEngine->registerPathTokens();

View File

@@ -53,15 +53,15 @@ FontSize = {
Configuration loadConfiguration(const std::string& tag, const std::string& content) {
std::string filename = fmt::format("test_configuration_{}.cfg", tag);
std::filesystem::path path = std::filesystem::temp_directory_path();
std::string configFile = (path / filename).string();
writeConfig(configFile, content);
std::string file = (path / filename).string();
writeConfig(file, content);
try {
Configuration conf = loadConfigurationFromFile(configFile, content);
std::filesystem::remove(configFile);
Configuration conf = loadConfigurationFromFile(file, glm::ivec2(0), content);
std::filesystem::remove(file);
return conf;
}
catch (...) {
std::filesystem::remove(configFile);
std::filesystem::remove(file);
throw;
}
}