Browse Source

remember window size and position in settings and apply at startup

Signed-off-by: Vladimir Pantelic <vladimir@pantelic.net>
pull/329/head
Vladimir Pantelic 7 years ago
parent
commit
0f894f721e
2 changed files with 44 additions and 1 deletions
  1. +24
    -1
      src/gui.cpp
  2. +20
    -0
      src/settings.cpp

+ 24
- 1
src/gui.cpp View File

@@ -41,6 +41,10 @@ void windowSizeCallback(GLFWwindow* window, int width, int height) {
gScene->box.size = Vec(width, height);
}

void windowPosCallback(GLFWwindow* window, int width, int height) {
gScene->box.pos = Vec(width, height);
}

void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
#ifdef ARCH_MAC
// Ctrl-left click --> right click
@@ -250,7 +254,8 @@ void guiInit() {
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
glfwWindowHint(GLFW_MAXIMIZED, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
gWindow = glfwCreateWindow(640, 480, "", NULL, NULL);
if (!gWindow) {
@@ -263,6 +268,7 @@ void guiInit() {
glfwSwapInterval(1);

glfwSetWindowSizeCallback(gWindow, windowSizeCallback);
glfwSetWindowPosCallback(gWindow, windowPosCallback);
glfwSetMouseButtonCallback(gWindow, mouseButtonStickyCallback);
// glfwSetCursorPosCallback(gWindow, cursorPosCallback);
glfwSetCursorEnterCallback(gWindow, cursorEnterCallback);
@@ -308,6 +314,23 @@ void guiDestroy() {

void guiRun() {
assert(gWindow);
{
// check if we have a valid window size from settings and apply it
int width = (int)gScene->box.size.x;
int height = (int)gScene->box.size.y;
int x = (int)gScene->box.pos.x;
int y = (int)gScene->box.pos.y;
if( width > 0 && height > 0 && x >= 0 && y >= 0 ) {
glfwSetWindowSize(gWindow, width, height);
glfwSetWindowPos(gWindow, x, y);
} else {
glfwMaximizeWindow(gWindow);
// help me Obi Wan: if we do not do this, widgets are not correclty drawn
int width, height;
glfwGetWindowSize(gWindow, &width, &height);
glfwSetWindowSize(gWindow, width, height);
}
}
{
int width, height;
glfwGetWindowSize(gWindow, &width, &height);


+ 20
- 0
src/settings.cpp View File

@@ -48,6 +48,10 @@ static json_t *settingsToJson() {
json_t *lastPathJ = json_string(gRackWidget->lastPath.c_str());
json_object_set_new(rootJ, "lastPath", lastPathJ);

// window size and position
json_t *winJ = json_pack("[i, i, i, i]", (int)gScene->box.size.x, (int)gScene->box.size.y, (int)gScene->box.pos.x, (int)gScene->box.pos.y );
json_object_set_new(rootJ, "window", winJ);

return rootJ;
}

@@ -95,6 +99,22 @@ static void settingsFromJson(json_t *rootJ) {
json_t *lastPathJ = json_object_get(rootJ, "lastPath");
if (lastPathJ)
gRackWidget->lastPath = json_string_value(lastPathJ);

// window size and position
json_t *winJ = json_object_get(rootJ, "window");
int w = 0;
int h = 0;
int x = 0;
int y = 0;
json_unpack(winJ, "[i, i, i, i]", &w, &h, &x, &y);
if( x < 0 )
x = 0;
if( y < 0 )
y = 0;
if(w > 0 && h > 0) {
gScene->box.size = Vec(w, h);
gScene->box.pos = Vec(x, y);
}
}




Loading…
Cancel
Save