Browse Source

Set window position/size from settings.json

tags/v0.5.0
Andrew Belt 7 years ago
parent
commit
b31d4fb5ed
3 changed files with 62 additions and 0 deletions
  1. +5
    -0
      include/gui.hpp
  2. +29
    -0
      src/gui.cpp
  3. +28
    -0
      src/settings.cpp

+ 5
- 0
include/gui.hpp View File

@@ -32,6 +32,11 @@ void guiCursorLock();
void guiCursorUnlock();
bool guiIsModPressed();
bool guiIsShiftPressed();
Vec guiGetWindowSize();
void guiSetWindowSize(Vec size);
Vec guiGetWindowPos();
void guiSetWindowPos(Vec pos);
bool guiIsMaximized();


} // namespace rack

+ 29
- 0
src/gui.cpp View File

@@ -404,6 +404,35 @@ bool guiIsShiftPressed() {
return glfwGetKey(gWindow, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS || glfwGetKey(gWindow, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;
}

Vec guiGetWindowSize() {
int width, height;
glfwGetWindowSize(gWindow, &width, &height);
return Vec(width, height);
}

void guiSetWindowSize(Vec size) {
int width = size.x;
int height = size.y;
glfwSetWindowSize(gWindow, width, height);
}

Vec guiGetWindowPos() {
int x, y;
glfwGetWindowPos(gWindow, &x, &y);
return Vec(x, y);
}

void guiSetWindowPos(Vec pos) {
int x = pos.x;
int y = pos.y;
glfwSetWindowPos(gWindow, x, y);
}

bool guiIsMaximized() {
return glfwGetWindowAttrib(gWindow, GLFW_MAXIMIZED);
}



////////////////////
// resources


+ 28
- 0
src/settings.cpp View File

@@ -17,6 +17,18 @@ static json_t *settingsToJson() {
json_t *tokenJ = json_string(gToken.c_str());
json_object_set_new(rootJ, "token", tokenJ);

if (!guiIsMaximized()) {
// windowSize
Vec windowSize = guiGetWindowSize();
json_t *windowSizeJ = json_pack("[f, f]", windowSize.x, windowSize.y);
json_object_set_new(rootJ, "windowSize", windowSizeJ);

// windowPos
Vec windowPos = guiGetWindowPos();
json_t *windowPosJ = json_pack("[f, f]", windowPos.x, windowPos.y);
json_object_set_new(rootJ, "windowPos", windowPosJ);
}

// opacity
float opacity = gToolbar->wireOpacitySlider->value;
json_t *opacityJ = json_real(opacity);
@@ -57,6 +69,22 @@ static void settingsFromJson(json_t *rootJ) {
if (tokenJ)
gToken = json_string_value(tokenJ);

// windowSize
json_t *windowSizeJ = json_object_get(rootJ, "windowSize");
if (windowSizeJ) {
double width, height;
json_unpack(windowSizeJ, "[F, F]", &width, &height);
guiSetWindowSize(Vec(width, height));
}

// windowPos
json_t *windowPosJ = json_object_get(rootJ, "windowPos");
if (windowPosJ) {
double x, y;
json_unpack(windowPosJ, "[F, F]", &x, &y);
guiSetWindowPos(Vec(x, y));
}

// opacity
json_t *opacityJ = json_object_get(rootJ, "wireOpacity");
if (opacityJ)


Loading…
Cancel
Save