mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 19:50:03 -06:00
Set the default window size to 66% of the primary window size (closes #1883)
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -67,6 +67,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
*global::configuration = configuration::loadConfigurationFromFile(
|
||||
configFile.string(),
|
||||
glm::ivec2(0),
|
||||
""
|
||||
);
|
||||
global::openSpaceEngine->registerPathTokens();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user