Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window position to SettingsManager (JSON + CLI) #136

Merged
merged 2 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/ViewTypesSample/assets/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"fullscreen": true,
"borderless": false,
"size": {"x": 1280, "y": 720},
//"pos": {"x": -1, "y": -1}, //Window draws at center if un-declared
"cameraOffset": {"x": 0, "y": 0},
"clearColor": {"r": 0, "g": 0, "b": 0, "a": 1.0}
},
Expand Down
15 changes: 11 additions & 4 deletions src/bluecadet/core/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ void SettingsManager::setup(ci::app::App::Settings * appSettings, ci::fs::path j
mWindowSize = ivec2(stoi(wStr), stoi(hStr));
}
});
addCommandLineParser("pos", [&](const string &value) {
int commaIndex = (int)value.find(",");
if (commaIndex != string::npos) {
string wStr = value.substr(0, commaIndex);
string hStr = value.substr(commaIndex + 1, value.size() - commaIndex - 1);
mWindowPos = ivec2(stoi(wStr), stoi(hStr));
}
});
addCommandLineParser("bezel", [&](const string &value) {
int commaIndex = (int)value.find(",");
if (commaIndex != string::npos) {
Expand Down Expand Up @@ -114,8 +122,8 @@ void SettingsManager::parseJson(ci::JsonTree & json) {
setFieldFromJsonIfExists(&mBorderless, "settings.window.borderless");
setFieldFromJsonIfExists(&mWindowSize.x, "settings.window.size.x");
setFieldFromJsonIfExists(&mWindowSize.y, "settings.window.size.y");
setFieldFromJsonIfExists(&mWindowPos.x, "settings.window.position.x");
benjaminbojko marked this conversation as resolved.
Show resolved Hide resolved
setFieldFromJsonIfExists(&mWindowPos.y, "settings.window.position.y");
setFieldFromJsonIfExists(&mWindowPos.x, "settings.window.pos.x");
setFieldFromJsonIfExists(&mWindowPos.y, "settings.window.pos.y");
setFieldFromJsonIfExists(&mCameraOffset.x, "settings.window.cameraOffset.x");
setFieldFromJsonIfExists(&mCameraOffset.y, "settings.window.cameraOffset.y");
setFieldFromJsonIfExists(&mClearColor.r, "settings.window.clearColor.r");
Expand Down Expand Up @@ -173,12 +181,11 @@ void SettingsManager::applyToAppSettings(ci::app::App::Settings * settings) {
}

// Default window position to centered in display if no custom pos has been set
if (mWindowPos == ivec2(-1)) {
if (mWindowPos == ivec2(INT_MIN)) {
ivec2 windowSizeInPx = vec2(settings->getWindowSize()) * pixelScale;
ivec2 windowPos = (Display::getMainDisplay()->getSize() - windowSizeInPx) / 2;
windowPos = glm::max(windowPos, ivec2(0));
settings->setWindowPos(windowPos);

} else {
settings->setWindowPos(vec2(mWindowPos) * pixelScale);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bluecadet/core/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SettingsManager {

// Window
ci::ivec2 mWindowSize; //! The window size on launch
ci::ivec2 mWindowPos = ci::ivec2(-1, -1); //! The window position on launch
ci::ivec2 mWindowPos = ci::ivec2(INT_MIN); //! The window position on launch
benjaminbojko marked this conversation as resolved.
Show resolved Hide resolved
ci::vec2 mCameraOffset; //! The offset of the camera on launch
ci::ColorA mClearColor = ci::ColorA::black(); //! The color used when clearing the screen before draw(). Defaults to opaque black.

Expand Down