From 83eaa11f607c202b66bb866b8dc76cccf3252ace Mon Sep 17 00:00:00 2001 From: Darren Keese Date: Tue, 10 May 2016 22:22:40 -0400 Subject: Add window size limits to LWJGL 3 app and window configurations. Update CHANGES --- CHANGES | 1 + .../badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java | 12 +++++++++++- .../backends/lwjgl3/Lwjgl3ApplicationConfiguration.java | 16 ++++++++++++++++ .../gdx/backends/lwjgl3/Lwjgl3WindowConfiguration.java | 14 +++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 13c70f973..31bdaba00 100755 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,7 @@ - Fixed Gdx.input.getCurrentEventTime() not being set on LWJGL3, fixes GestureDetector and flick scroll not working - Fixed not being able to select non-latin characters in TextFields - Bullet: added CustomActionInterface, see https://github.com/libgdx/libgdx/pull/4025 +- Add window size limits option to LWJGL3 app and window configurations [1.9.2] - Added TextureArray wrapper see https://github.com/libgdx/libgdx/pull/3807 diff --git a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java index fca89db05..94f0c7617 100644 --- a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java +++ b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3Application.java @@ -315,6 +315,7 @@ public class Lwjgl3Application implements Application { Lwjgl3ApplicationConfiguration appConfig = Lwjgl3ApplicationConfiguration.copy(this.config); appConfig.setWindowedMode(config.windowWidth, config.windowHeight); appConfig.setWindowPosition(config.windowX, config.windowY); + appConfig.setWindowSizeLimits(config.windowMinWidth, config.windowMinHeight, config.windowMaxWidth, config.windowMaxHeight); appConfig.setResizable(config.windowResizable); appConfig.setDecorated(config.windowDecorated); appConfig.setWindowListener(config.windowListener); @@ -372,10 +373,19 @@ public class Lwjgl3Application implements Application { if (windowHandle == 0) { throw new GdxRuntimeException("Couldn't create window"); } + GLFW.glfwSetWindowSizeLimits(windowHandle, + config.windowMinWidth > -1 ? config.windowMinWidth : GLFW.GLFW_DONT_CARE, + config.windowMinHeight > -1 ? config.windowMinHeight : GLFW.GLFW_DONT_CARE, + config.windowMaxWidth > -1 ? config.windowMaxWidth : GLFW.GLFW_DONT_CARE, + config.windowMaxHeight> -1 ? config.windowMaxHeight : GLFW.GLFW_DONT_CARE); if (config.fullscreenMode == null) { if (config.windowX == -1 && config.windowY == -1) { + int windowWidth = Math.max(config.windowWidth, config.windowMinWidth); + int windowHeight = Math.max(config.windowHeight, config.windowMinHeight); + if (config.windowMaxWidth > -1) windowWidth = Math.min(windowWidth, config.windowMaxWidth); + if (config.windowMaxHeight > -1) windowHeight = Math.min(windowHeight, config.windowMaxHeight); GLFWVidMode vidMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor()); - GLFW.glfwSetWindowPos(windowHandle, vidMode.width() / 2 - config.windowWidth / 2, vidMode.height() / 2 - config.windowHeight / 2); + GLFW.glfwSetWindowPos(windowHandle, vidMode.width() / 2 - windowWidth / 2, vidMode.height() / 2 - windowHeight / 2); } else { GLFW.glfwSetWindowPos(windowHandle, config.windowX, config.windowY); } diff --git a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3ApplicationConfiguration.java b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3ApplicationConfiguration.java index fcb979f46..08ae39898 100644 --- a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3ApplicationConfiguration.java +++ b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3ApplicationConfiguration.java @@ -57,6 +57,7 @@ public class Lwjgl3ApplicationConfiguration { int windowY = -1; int windowWidth = 640; int windowHeight = 480; + int windowMinWidth = -1, windowMinHeight = -1, windowMaxWidth = -1, windowMaxHeight = -1; boolean windowResizable = true; boolean windowDecorated = true; Lwjgl3WindowListener windowListener; @@ -91,6 +92,10 @@ public class Lwjgl3ApplicationConfiguration { copy.windowY = config.windowY; copy.windowWidth = config.windowWidth; copy.windowHeight = config.windowHeight; + copy.windowMinWidth = config.windowMinWidth; + copy.windowMinHeight = config.windowMinHeight; + copy.windowMaxWidth = config.windowMaxWidth; + copy.windowMaxHeight = config.windowMaxHeight; copy.windowResizable = config.windowResizable; copy.windowDecorated = config.windowDecorated; copy.windowListener = config.windowListener; @@ -221,6 +226,17 @@ public class Lwjgl3ApplicationConfiguration { windowY = y; } + /** + * Sets minimum and maximum size limits for the window. If the window is full screen or not resizable, these + * limits are ignored. The default for all four parameters is -1, which means unrestricted. + */ + public void setWindowSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) { + windowMinWidth = minWidth; + windowMinHeight = minHeight; + windowMaxWidth = maxWidth; + windowMaxHeight = maxHeight; + } + /** * Sets the {@link Lwjgl3WindowListener} which will be informed about * iconficiation, focus loss and window close events. diff --git a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3WindowConfiguration.java b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3WindowConfiguration.java index edbac858c..16eaecfbe 100644 --- a/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3WindowConfiguration.java +++ b/backends/gdx-backend-lwjgl3/src/com/badlogic/gdx/backends/lwjgl3/Lwjgl3WindowConfiguration.java @@ -25,6 +25,7 @@ public class Lwjgl3WindowConfiguration { int windowY = -1; int windowWidth = 640; int windowHeight = 480; + int windowMinWidth = -1, windowMinHeight = -1, windowMaxWidth = -1, windowMaxHeight = -1; boolean windowResizable = true; boolean windowDecorated = true; Lwjgl3WindowListener windowListener; @@ -61,13 +62,24 @@ public class Lwjgl3WindowConfiguration { /** * Sets the position of the window in windowed mode on the - * primary monitor. Default -1 for booth coordinates for centered. + * primary monitor. Default -1 for both coordinates for centered. */ public void setWindowPosition(int x, int y) { windowX = x; windowY = y; } + /** + * Sets minimum and maximum size limits for the window. If the window is full screen or not resizable, these + * limits are ignored. The default for all four parameters is -1, which means unrestricted. + */ + public void setWindowSizeLimits(int minWidth, int minHeight, int maxWidth, int maxHeight) { + windowMinWidth = minWidth; + windowMinHeight = minHeight; + windowMaxWidth = maxWidth; + windowMaxHeight = maxHeight; + } + /** * Sets the {@link Lwjgl3WindowListener} which will be informed about * iconficiation, focus loss and window close events. -- cgit v1.2.3