diff --git a/jme3-core/src/main/java/com/jme3/system/AppSettings.java b/jme3-core/src/main/java/com/jme3/system/AppSettings.java index 7617b1d38b..4400baf376 100644 --- a/jme3-core/src/main/java/com/jme3/system/AppSettings.java +++ b/jme3-core/src/main/java/com/jme3/system/AppSettings.java @@ -266,6 +266,7 @@ public final class AppSettings extends HashMap { public static final String JOAL = "JOAL"; static { + defaults.put("CenterWindow", true); defaults.put("Width", 640); defaults.put("Height", 480); defaults.put("BitsPerPixel", 24); @@ -290,6 +291,8 @@ public final class AppSettings extends HashMap { 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); } @@ -1350,4 +1353,91 @@ public boolean isUseRetinaFrameBuffer() { public void setUseRetinaFrameBuffer(boolean useRetinaFrameBuffer) { putBoolean("UseRetinaFrameBuffer", useRetinaFrameBuffer); } + + /** + * Tests the state of the Center Window flag. + * + *

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. + * + *

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. + * + *

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. + * + *

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. + * + *

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. + * + *

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); + } } diff --git a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java index abf13eb1c5..e47c9e3a69 100644 --- a/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java +++ b/jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java @@ -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