Skip to content
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
90 changes: 90 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ public final class AppSettings extends HashMap<String, Object> {
public static final String JOAL = "JOAL";

static {
defaults.put("CenterWindow", true);
defaults.put("Width", 640);
defaults.put("Height", 480);
defaults.put("BitsPerPixel", 24);
Expand All @@ -290,6 +291,8 @@ public final class AppSettings extends HashMap<String, Object> {
defaults.put("OpenCL", false);
defaults.put("OpenCLPlatformChooser", DefaultPlatformChooser.class.getName());
defaults.put("UseRetinaFrameBuffer", true);// MacOS spec
defaults.put("WindowYPosition", 0);
defaults.put("WindowXPosition", 0);
// defaults.put("Icons", null);
}

Expand Down Expand Up @@ -1350,4 +1353,91 @@ public boolean isUseRetinaFrameBuffer() {
public void setUseRetinaFrameBuffer(boolean useRetinaFrameBuffer) {
putBoolean("UseRetinaFrameBuffer", useRetinaFrameBuffer);
}

/**
* Tests the state of the Center Window flag.
*
* <p>The Center Window flag is used only with LWJGL3 and has no effect on
* fullscreen windows.
*
* @return true to center the window on the desktop, false to position the
* window at (WindowXPosition, WindowYPosition)
* @see #setCenterWindow(boolean)
*/
public boolean getCenterWindow() {
return getBoolean("CenterWindow");
}

/**
* Enables or disables the Center Window flag.
*
* <p>The Center Window flag is used only with LWJGL3 and has no effect on
* fullscreen windows. It defaults to true.
*
* @param center true to center the window on the desktop, false to position
* the window at (WindowXPosition, WindowYPosition)
*/
public void setCenterWindow(boolean center) {
putBoolean("CenterWindow", center);
}

/**
* Gets the window's initial X position on the desktop.
*
* <p>This setting is used only with LWJGL3, has no effect on fullscreen
* windows, and is ignored if the Center Window flag is true.
*
* @return the initial position of the window's left edge relative to the
* left edge of the desktop
* @see #setCenterWindow(boolean)
* @see #setWindowXPosition(int)
*/
public int getWindowXPosition() {
return getInteger("WindowXPosition");
}

/**
* Sets the window's initial X position on the desktop.
*
* <p>This setting is used only with LWJGL3, has no effect on fullscreen
* windows, and is ignored if the Center Window flag is true. Its default
* value is 0.
*
* @param pos the desired initial position of the window's left edge
* relative to the left edge of the desktop
* @see #setCenterWindow(boolean)
*/
public void setWindowXPosition(int pos) {
putInteger("WindowXPosition", pos);
}

/**
* Gets the window's initial Y position on the desktop.
*
* <p>This setting is used only with LWJGL3, has no effect on fullscreen
* windows, and is ignored if the Center Window flag is true.
*
* @return the initial position of the window's upper edge relative to the
* upper edge of the desktop
* @see #setCenterWindow(boolean)
* @see #setWindowYPosition(int)
*/
public int getWindowYPosition() {
return getInteger("WindowYPosition");
}

/**
* Sets the window's initial Y position on the desktop.
*
* <p>This setting is used only with LWJGL3, has no effect on fullscreen
* windows, and is ignored if the Center Window flag is true. Its default
* value is 0.
*
* @param pos the desired initial position of the window's upper edge
* relative to the upper edge of the desktop
* @see #setCenterWindow(boolean)
*/
public void setWindowYPosition(int pos) {
putInteger("WindowYPosition", pos);
}
}
14 changes: 10 additions & 4 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,17 @@ public void invoke(final long window, final boolean focus) {
}
});

// Center the window
if (!settings.isFullscreen()) {
glfwSetWindowPos(window,
(videoMode.width() - settings.getWidth()) / 2,
(videoMode.height() - settings.getHeight()) / 2);
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