aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2020-06-18 12:26:11 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2020-06-18 12:26:11 +0300
commit8be018af0916f464ef31daa1c93aae751e36bdd9 (patch)
tree280cb5625303b1539792ae9177015130e1c2a2b4 /src
parent722c3cb442c7b5e751132f0a812d2fc771d304d5 (diff)
downloadLibGui-8be018af0916f464ef31daa1c93aae751e36bdd9.tar.gz
LibGui-8be018af0916f464ef31daa1c93aae751e36bdd9.tar.bz2
LibGui-8be018af0916f464ef31daa1c93aae751e36bdd9.zip
Fix the screen title being drawn at an incorrect position, add title coordinate support to CottonClientScreen
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java33
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java16
2 files changed, 44 insertions, 5 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
index 7c7d7d9..e10bd4c 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonClientScreen.java
@@ -17,6 +17,20 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
protected int left = 0;
protected int top = 0;
+ /**
+ * The X coordinate of the screen title.
+ *
+ * @since 2.0.0
+ */
+ protected int titleX;
+
+ /**
+ * The Y coordinate of the screen title.
+ *
+ * @since 2.0.0
+ */
+ protected int titleY;
+
protected WWidget lastResponder = null;
public CottonClientScreen(GuiDescription description) {
@@ -41,17 +55,30 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
description.addPainters();
reposition(screenWidth, screenHeight);
}
-
- private void reposition(int screenWidth, int screenHeight) {
+
+ /**
+ * Repositions the root panel.
+ *
+ * @param screenWidth the width of the screen
+ * @param screenHeight the height of the screen
+ */
+ protected void reposition(int screenWidth, int screenHeight) {
if (description!=null) {
WPanel root = description.getRootPanel();
if (root!=null) {
if (!description.isFullscreen()) {
this.left = (screenWidth - root.getWidth()) / 2;
this.top = (screenHeight - root.getHeight()) / 2;
+ this.titleX = this.left;
+ this.titleY = this.top;
} else {
this.left = 0;
this.top = 0;
+
+ // Offset the title coordinates a little from the edge
+ this.titleX = 10;
+ this.titleY = 10;
+
root.setSize(screenWidth, screenHeight);
}
}
@@ -73,7 +100,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree
}
if (getTitle() != null) {
- textRenderer.draw(matrices, getTitle(), left, top, description.getTitleColor());
+ textRenderer.draw(matrices, getTitle(), titleX, titleY, description.getTitleColor());
}
}
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
index 7ada7bd..dbc7404 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonInventoryScreen.java
@@ -68,8 +68,14 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
reposition(screenWidth, screenHeight);
}
-
- private void reposition(int screenWidth, int screenHeight) {
+
+ /**
+ * Repositions the root panel.
+ *
+ * @param screenWidth the width of the screen
+ * @param screenHeight the height of the screen
+ */
+ protected void reposition(int screenWidth, int screenHeight) {
WPanel basePanel = description.getRootPanel();
if (basePanel!=null) {
basePanel.validate(description);
@@ -85,10 +91,16 @@ public class CottonInventoryScreen<T extends SyncedGuiDescription> extends Handl
if (!description.isFullscreen()) {
x = (width / 2) - (backgroundWidth / 2);
y = (height / 2) - (backgroundHeight / 2);
+ titleX = x;
+ titleY = y;
} else {
x = 0;
y = 0;
+ // Offset the title coordinates a little from the edge
+ titleX = 10;
+ titleY = 10;
+
if (basePanel != null) {
basePanel.setSize(screenWidth, screenHeight);
}