Fixed a GUI reassembly issue and added cursor disabling suppression

- Buttons no longer reassemble every frame
- Label.setFont() no longer requests reassembly
- Component.reassembleAt now actually works
- Using a very long flag, cursor capturing can be disabled to facilitate
GUI debugging
This commit is contained in:
OLEGSHA 2021-08-26 12:09:22 +03:00
parent 1727a2a4a1
commit dd80df2cf2
Signed by: OLEGSHA
GPG Key ID: E57A4B08D64AFF7A
3 changed files with 21 additions and 2 deletions

View File

@ -19,6 +19,7 @@
package ru.windcorp.progressia.client.graphics.backend;
import glm.vec._2.i.Vec2i;
import org.lwjgl.glfw.GLFWVidMode;
import static org.lwjgl.glfw.GLFW.*;
@ -43,6 +44,13 @@ public class GraphicsBackend {
private static boolean isGLFWInitialized = false;
private static boolean isOpenGLInitialized = false;
private static boolean allowDisablingCursor;
static {
String key = GraphicsBackend.class.getName() + ".allowDisablingCursor";
allowDisablingCursor = Boolean.parseBoolean(System.getProperty(key, "false"));
}
private static boolean forceCursorToCenter = false;
private GraphicsBackend() {
}
@ -114,6 +122,10 @@ public class GraphicsBackend {
frameLength = now - frameStart;
frameStart = now;
}
if (forceCursorToCenter) {
glfwSetCursorPos(windowHandle, FRAME_SIZE.x / 2.0, FRAME_SIZE.y / 2.0);
}
}
static void endFrame() {
@ -194,10 +206,18 @@ public class GraphicsBackend {
}
public static boolean isMouseCaptured() {
if (!allowDisablingCursor) {
return forceCursorToCenter;
}
return glfwGetInputMode(windowHandle, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
}
public static void setMouseCaptured(boolean capture) {
if (!allowDisablingCursor) {
forceCursorToCenter = capture;
return;
}
int mode = capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL;
glfwSetInputMode(windowHandle, GLFW_CURSOR, mode);

View File

@ -807,7 +807,7 @@ public class Component extends Named {
for (ARTrigger trigger : triggers) {
if (!autoReassemblyTriggerObjects.containsKey(trigger)) {
Object triggerObject = createTriggerObject(trigger);
addListener(trigger);
addListener(triggerObject);
autoReassemblyTriggerObjects.put(trigger, triggerObject);
}
}

View File

@ -85,7 +85,6 @@ public class Label extends Component {
public void setFont(Font font) {
this.font = font;
requestReassembly();
}
public String getCurrentText() {