Browse Source

Merge 0f894f721e into 205c04d4fe

pull/329/merge
Vladimir Pantelic GitHub 7 years ago
parent
commit
9171076624
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

@@ -43,6 +43,10 @@ void windowSizeCallback(GLFWwindow* window, int width, int height) {
gScene->box.size = Vec(width, 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) { void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
#ifdef ARCH_MAC #ifdef ARCH_MAC
// Ctrl-left click --> right click // Ctrl-left click --> right click
@@ -317,7 +321,8 @@ void guiInit() {
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 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); glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
lastWindowTitle = ""; lastWindowTitle = "";
gWindow = glfwCreateWindow(640, 480, lastWindowTitle.c_str(), NULL, NULL); gWindow = glfwCreateWindow(640, 480, lastWindowTitle.c_str(), NULL, NULL);
@@ -331,6 +336,7 @@ void guiInit() {
glfwSwapInterval(1); glfwSwapInterval(1);


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


void guiRun() { void guiRun() {
assert(gWindow); 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; int width, height;
glfwGetWindowSize(gWindow, &width, &height); glfwGetWindowSize(gWindow, &width, &height);


+ 20
- 0
src/settings.cpp View File

@@ -60,6 +60,10 @@ static json_t *settingsToJson() {
json_t *lastPathJ = json_string(gRackWidget->lastPath.c_str()); json_t *lastPathJ = json_string(gRackWidget->lastPath.c_str());
json_object_set_new(rootJ, "lastPath", lastPathJ); 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; return rootJ;
} }


@@ -123,6 +127,22 @@ static void settingsFromJson(json_t *rootJ) {
json_t *lastPathJ = json_object_get(rootJ, "lastPath"); json_t *lastPathJ = json_object_get(rootJ, "lastPath");
if (lastPathJ) if (lastPathJ)
gRackWidget->lastPath = json_string_value(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