Skip to content

Commit

Permalink
Added feature to be able to position the window instead of it only be…
Browse files Browse the repository at this point in the history
…ing centered. This way the positioning will can be saved and used in the future.
  • Loading branch information
bob0bob committed Nov 21, 2021
1 parent cb5173b commit 1d20834
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
60 changes: 60 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/AppSettings.java
Expand Up @@ -289,6 +289,7 @@ public final class AppSettings extends HashMap<String, Object> {
defaults.put("SwapBuffers", true);
defaults.put("OpenCL", false);
defaults.put("OpenCLPlatformChooser", DefaultPlatformChooser.class.getName());
defaults.put("CenterWindow", true);
// defaults.put("Icons", null);
}

Expand Down Expand Up @@ -1331,4 +1332,63 @@ public boolean isGraphicsTrace() {
public void setGraphicsTrace(boolean trace) {
putBoolean("GraphicsTrace", trace);
}

/**
* Get the Center Window state
*
* @return true for center the window in the middle of the screen
* @see #setCenterWindow(boolean)
*/
public boolean getCenterWindow() {
return getBoolean("CenterWindow");
}

/**
* True to enable center the window.
*
* @param center whether to center the window or not.
*/
public void setCenterWindow(boolean center) {
putBoolean("CenterWindow", center);
}


/**
* Get the position of the window's X Position
*
* @return int screen coordinates of the X Position of the window
* @see #setWindowXPosition(int)
*/
public int getWindowXPosition() {
return getInteger("windowXpos");
}

/**
* The position of the window's X Position.
*
* @param pos screen coordinates for the X position.
*/
public void setWindowXPosition(int pos) {
putInteger("windowXpos", pos);
}


/**
* Get the position of the window's Y Position
*
* @return int screen coordinates of the Y Position of the window
* @see #setWindowXPosition(int)
*/
public int getWindowYPosition() {
return getInteger("windowYpos");
}

/**
* The position of the window's Y Position.
*
* @param pos screen coordinates for the Y position.
*/
public void setWindowYPosition(int pos) {
putInteger("windowYpos", pos);
}
}
Expand Up @@ -274,11 +274,16 @@ public void invoke(final long window, final boolean focus) {
}
});

// Center the window
if (!settings.isFullscreen()) {
glfwSetWindowPos(window,
if (settings.getCenterWindow())
{
// Center the window
glfwSetWindowPos(window,
(videoMode.width() - settings.getWidth()) / 2,
(videoMode.height() - settings.getHeight()) / 2);
} else {
glfwSetWindowPos(window,settings.getWindowXPosition(), settings.getWindowYPosition());
}
}

// Make the OpenGL context current
Expand Down

0 comments on commit 1d20834

Please sign in to comment.