فهرست منبع

Added Window Position for LJWGL3 libraries (#1670)

* This is a very simple addition. It allows a person to set 3 variables in AppSettings. ‘CenterWindow’, ‘WindowXPosition’ and ‘WindowYPosition’ variables. This way these variable will be saved in the profile when the profile is saved, and be reloaded. I added ‘CenterWindow’ to be added with a ‘true’ value for the default value so it will run just like it did before.

But if you set ‘CenterWindow’ to ‘false’ then inside LwjglWindow.java (lwjgl3 code) it will look at these new values, it will determine to center the window or use the position values to place the window back at the location the user last moved it to.

Of course, these values are only updated if the “program” updates this value. So if you want to save screen position, you can save them on closing to and on restart put the window back into the same location.

* formatting and comments changes.

* jme3test.app.TestApplication hangs with LWJGL3 #1193
LWJGL3-JME library would block the current thread when executing LWJGL3.    Instead of calling run() that is blocking,  made it work like LWJGL2-JME library when they start it as a thread so run gets called. I commented out the run() function and replaced it with Thread.start().

* removing unwanted changes, since you can't do multiple pull requests at once.

* formatting issues.

* changed parameter naming to be more consistency with other items.

* jme3test.app.TestApplication hangs with LWJGL3 #1193

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* jme3test.app.TestApplication hangs with LWJGL3 #1193 (#3)

LWJGL3-JME projects was doing a call that is blocking the current thread.  I changed it to match how LWJGL2-JME project launches the Context Window.

* removing unwanted changes.

* AppSettings:  enhance the new javadoc

* AppSettings:  capitalize Window{X/Y}Position consistent w/other settings

* LwjglWindow:  convert tabs to spaces

* AppSettings:  re-arrange @see tags in javadoc

Co-authored-by: Stephen Gold <[email protected]>
bob0bob 3 سال پیش
والد
کامیت
255d6fc1ff

+ 90 - 0
jme3-core/src/main/java/com/jme3/system/AppSettings.java

@@ -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);
@@ -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);
     }
 
@@ -1350,4 +1353,91 @@ public final class AppSettings extends HashMap<String, Object> {
     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);
+    }
 }

+ 10 - 4
jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java

@@ -276,11 +276,17 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
             }
         });
 
-        // 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