diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-05-08 19:23:03 +0300 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2020-05-08 19:23:03 +0300 |
commit | d5592ae7ab7ee624f594098f99b2f9af964abab8 (patch) | |
tree | 910bde7df7cf267dcc9fb0c2c97d69b8ab387906 /src | |
parent | 040dd6f14eacad8abd903911c0f36ddbd0bf5846 (diff) | |
download | LibGui-d5592ae7ab7ee624f594098f99b2f9af964abab8.tar.gz LibGui-d5592ae7ab7ee624f594098f99b2f9af964abab8.tar.bz2 LibGui-d5592ae7ab7ee624f594098f99b2f9af964abab8.zip |
Painting changes
- paintBackground -> paint, removed paintForeground.
Closes #42.
- paint takes the MatrixStack as well.
Closes #52.
- Renamed WTextField.renderButton to renderTextField
and made it protected.
Diffstat (limited to 'src')
24 files changed, 153 insertions, 173 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java index 403b5c0..2721ff3 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonInventoryController.java @@ -374,7 +374,7 @@ public class CottonInventoryController extends ScreenHandler implements GuiDescr //extends ScreenHandler { @Override public boolean canUse(PlayerEntity entity) { - return (blockInventory!=null) ? blockInventory.canPlayerUseInv(entity) : true; + return (blockInventory!=null) ? blockInventory.canPlayerUse(entity) : true; } //} 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 05f3b68..968cbba 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 @@ -55,36 +55,33 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree } } - public void paint(int mouseX, int mouseY) { - super.renderBackground(ScreenDrawing.matrices); + public void paint(MatrixStack matrices, int mouseX, int mouseY) { + super.renderBackground(matrices); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { - root.paintBackground(left, top, mouseX-left, mouseY-top); + root.paint(matrices, left, top, mouseX-left, mouseY-top); } } if (getTitle() != null) { - textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), left, top, description.getTitleColor()); + textRenderer.method_27528(matrices, getTitle(), left, top, description.getTitleColor()); } } @SuppressWarnings("deprecation") @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { - ScreenDrawing.matrices = matrices; - paint(mouseX, mouseY); + paint(matrices, mouseX, mouseY); super.render(matrices, mouseX, mouseY, partialTicks); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { - root.paintForeground(left, top, mouseX, mouseY); - WWidget hitChild = root.hit(mouseX-left, mouseY-top); - if (hitChild!=null) hitChild.renderTooltip(left, top, mouseX-left, mouseY-top); + if (hitChild!=null) hitChild.renderTooltip(matrices, left, top, mouseX-left, mouseY-top); } } } @@ -223,7 +220,7 @@ public class CottonClientScreen extends Screen implements TextHoverRendererScree //} @Override - public void renderTextHover(Text text, int x, int y) { - renderTextHoverEffect(ScreenDrawing.matrices, text, x, y); + public void renderTextHover(MatrixStack matrices, Text text, int x, int y) { + renderTextHoverEffect(matrices, text, x, y); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java index 0e6fa4f..ae0f232 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/CottonHud.java @@ -106,7 +106,6 @@ public enum CottonHud implements HudRenderCallback { @Override public void onHudRender(MatrixStack matrices, float tickDelta) { - ScreenDrawing.matrices = matrices; Window window = MinecraftClient.getInstance().getWindow(); int hudWidth = window.getScaledWidth(); int hudHeight = window.getScaledHeight(); @@ -116,7 +115,7 @@ public enum CottonHud implements HudRenderCallback { positioner.reposition(widget, hudWidth, hudHeight); } - widget.paintBackground(widget.getX(), widget.getY(), -1, -1); + widget.paint(matrices, widget.getX(), widget.getY(), -1, -1); } } 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 c64ffa2..a018173 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 @@ -1,11 +1,11 @@ package io.github.cottonmc.cotton.gui.client; +import io.github.cottonmc.cotton.gui.CottonInventoryController; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.DiffuseLighting; import net.minecraft.client.util.math.MatrixStack; import org.lwjgl.glfw.GLFW; -import io.github.cottonmc.cotton.gui.CottonInventoryController; import io.github.cottonmc.cotton.gui.widget.WPanel; import io.github.cottonmc.cotton.gui.widget.WWidget; import net.minecraft.client.MinecraftClient; @@ -13,8 +13,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; -public class CottonInventoryScreen<T extends CottonCraftingController> extends HandledScreen<T> implements TextHoverRendererScreen { - protected CottonCraftingController description; +public class CottonInventoryScreen<T extends CottonInventoryController> extends HandledScreen<T> implements TextHoverRendererScreen { + protected CottonInventoryController description; public static final int PADDING = 8; protected WWidget lastResponder = null; protected WWidget focus = null; @@ -187,26 +187,25 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H @Override protected void drawBackground(MatrixStack matrices, float partialTicks, int mouseX, int mouseY) {} //This is just an AbstractContainerScreen thing; most Screens don't work this way. - public void paint(int mouseX, int mouseY) { - super.renderBackground(ScreenDrawing.matrices); + public void paint(MatrixStack matrices, int mouseX, int mouseY) { + super.renderBackground(matrices); if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { - root.paintBackground(x, y, mouseX-x, mouseY-y); + root.paint(matrices, x, y, mouseX-x, mouseY-y); } } if (getTitle() != null) { - textRenderer.method_27528(ScreenDrawing.matrices, getTitle(), x, y, description.getTitleColor()); + textRenderer.method_27528(matrices, getTitle(), x, y, description.getTitleColor()); } } @SuppressWarnings("deprecation") @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float partialTicks) { - ScreenDrawing.matrices = matrices; - paint(mouseX, mouseY); + paint(matrices, mouseX, mouseY); super.render(matrices, mouseX, mouseY, partialTicks); DiffuseLighting.disable(); //Needed because super.render leaves dirty state @@ -214,10 +213,8 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H if (description!=null) { WPanel root = description.getRootPanel(); if (root!=null) { - root.paintForeground(x, y, mouseX, mouseY); - WWidget hitChild = root.hit(mouseX-x, mouseY-y); - if (hitChild!=null) hitChild.renderTooltip(x, y, mouseX-x, mouseY-y); + if (hitChild!=null) hitChild.renderTooltip(matrices, x, y, mouseX-x, mouseY-y); } } @@ -236,7 +233,7 @@ public class CottonInventoryScreen<T extends CottonCraftingController> extends H } @Override - public void renderTextHover(Text text, int x, int y) { - renderTextHoverEffect(ScreenDrawing.matrices, text, x, y); + public void renderTextHover(MatrixStack matrices, Text text, int x, int y) { + renderTextHoverEffect(matrices, text, x, y); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java index 199909f..4588a51 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java @@ -19,23 +19,9 @@ import net.minecraft.util.Identifier; * {@code ScreenDrawing} contains utility methods for drawing contents on a screen. */ public class ScreenDrawing { - // Internal MatrixStack for rendering strings. - // TODO (2.0): Remove - static MatrixStack matrices; - private ScreenDrawing() {} /** - * Gets the currently bound matrix stack. - * - * @return the matrix stack - * @since 1.9.0 - */ - public static MatrixStack getMatrices() { - return matrices; - } - - /** * Draws a textured rectangle. * * @param x the x coordinate of the box on-screen @@ -301,14 +287,15 @@ public class ScreenDrawing { /** * Draws a string with a custom alignment. * - * @param s the string - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param matrices the rendering matrix stack + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color */ - public static void drawString(String s, Alignment align, int x, int y, int width, int color) { + public static void drawString(MatrixStack matrices, String s, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color); @@ -332,15 +319,16 @@ public class ScreenDrawing { /** * Draws a text component with a custom alignment. * - * @param text the text - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param matrices the rendering matrix stack + * @param text the text + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color * @since 1.9.0 */ - public static void drawString(Text text, Alignment align, int x, int y, int width, int color) { + public static void drawString(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color); @@ -364,14 +352,15 @@ public class ScreenDrawing { /** * Draws a shadowed string. * - * @param s the string - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param matrices the rendering matrix stack + * @param s the string + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color */ - public static void drawStringWithShadow(String s, Alignment align, int x, int y, int width, int color) { + public static void drawStringWithShadow(MatrixStack matrices, String s, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, s, x, y, color); @@ -395,14 +384,15 @@ public class ScreenDrawing { /** * Draws a shadowed text component. * - * @param text the text component - * @param align the alignment of the string - * @param x the X position - * @param y the Y position - * @param width the width of the string, used for aligning - * @param color the text color + * @param matrices the rendering matrix stack + * @param text the text component + * @param align the alignment of the string + * @param x the X position + * @param y the Y position + * @param width the width of the string, used for aligning + * @param color the text color */ - public static void drawStringWithShadow(Text text, Alignment align, int x, int y, int width, int color) { + public static void drawStringWithShadow(MatrixStack matrices, Text text, Alignment align, int x, int y, int width, int color) { switch(align) { case LEFT: { MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color); @@ -426,36 +416,29 @@ public class ScreenDrawing { /** * Draws a left-aligned string. * - * @param s the string - * @param x the X position - * @param y the Y position - * @param color the text color + * @param matrices the rendering matrix stack + * @param s the string + * @param x the X position + * @param y the Y position + * @param color the text color */ - public static void drawString(String s, int x, int y, int color) { + public static void drawString(MatrixStack matrices, String s, int x, int y, int color) { MinecraftClient.getInstance().textRenderer.draw(matrices, s, x, y, color); } /** * Draws a left-aligned text component. * - * @param text the text component - * @param x the X position - * @param y the Y position - * @param color the text color + * @param matrices the rendering matrix stack + * @param text the text component + * @param x the X position + * @param y the Y position + * @param color the text color */ - public static void drawString(Text text, int x, int y, int color) { + public static void drawString(MatrixStack matrices, Text text, int x, int y, int color) { MinecraftClient.getInstance().textRenderer.method_27528(matrices, text, x, y, color); } - /** - * @deprecated for removal; please use {@link #drawStringWithShadow(String, Alignment, int, int, int, int)} - */ - @Deprecated - public static void drawCenteredWithShadow(String s, int x, int y, int color) { - TextRenderer render = MinecraftClient.getInstance().textRenderer; - render.drawWithShadow(matrices, s, (float)(x - render.getStringWidth(s) / 2), (float)y, color); - } - public static int colorAtOpacity(int opaque, float opacity) { if (opacity<0.0f) opacity=0.0f; if (opacity>1.0f) opacity=1.0f; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java b/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java index d09df6f..7c46450 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/TextHoverRendererScreen.java @@ -1,10 +1,11 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; /** * Implemented by LibGui screens to access {@code Screen.renderTextHoverEffect()}. */ public interface TextHoverRendererScreen { - void renderTextHover(Text text, int x, int y); + void renderTextHover(MatrixStack matrices, Text text, int x, int y); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java index 52df46c..bc55760 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java @@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.WWidget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; public class WKirbSprite extends WWidget { @@ -52,7 +53,7 @@ public class WKirbSprite extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { long now = System.nanoTime() / 1_000_000L; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java index 168e540..1884243 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java @@ -6,6 +6,7 @@ import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.screen.PropertyDelegate; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; @@ -100,7 +101,7 @@ public class WBar extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (bg!=null) { ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); } else { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java index b3fc425..fc6eb72 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java @@ -7,6 +7,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; @@ -33,7 +34,7 @@ public class WButton extends WWidget { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { boolean hovered = (mouseX>=0 && mouseY>=0 && mouseX<getWidth() && mouseY<getHeight()); int state = 1; //1=regular. 2=hovered. 0=disabled. if (!enabled) state = 0; @@ -60,7 +61,7 @@ public class WButton extends WWidget { color = 0xFFFFA0; }*/ - ScreenDrawing.drawStringWithShadow(label, alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawStringWithShadow(matrices, label, alignment, x, y + ((20 - 8) / 2), width, color); //LibGuiClient.config.darkMode ? darkmodeColor : color); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java index ae8766e..cf72c5b 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java @@ -1,5 +1,6 @@ package io.github.cottonmc.cotton.gui.widget; +import net.minecraft.client.util.math.MatrixStack; import org.lwjgl.opengl.GL11; import net.minecraft.client.MinecraftClient; @@ -22,7 +23,7 @@ public class WClippedPanel extends WPanel { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(x, y, this); GL11.glEnable(GL11.GL_SCISSOR_TEST); @@ -36,7 +37,7 @@ public class WClippedPanel extends WPanel { GL11.glScissor((int) (x * scaleFactor), (int) (rawHeight - (y * scaleFactor) - scaledHeight), scaledWidth, scaledHeight); for(WWidget child : children) { - child.paintBackground(x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); + child.paint(matrices, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); } GL11.glDisable(GL11.GL_SCISSOR_TEST); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java index 91d062d..69332d6 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WDynamicLabel.java @@ -3,6 +3,7 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Alignment; +import net.minecraft.client.util.math.MatrixStack; import java.util.function.Supplier; @@ -33,9 +34,9 @@ public class WDynamicLabel extends WWidget { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { String tr = text.get(); - ScreenDrawing.drawString(tr, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(matrices, tr, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java index d3d91b0..c7e70ae 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItem.java @@ -6,6 +6,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; @@ -52,7 +53,7 @@ public class WItem extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { RenderSystem.pushMatrix(); RenderSystem.enableDepthTest(); RenderSystem.translatef(x, y, 0); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java index 7af7b29..96814aa 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java @@ -10,6 +10,7 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.inventory.Inventory; public class WItemSlot extends WWidget { @@ -127,7 +128,7 @@ public class WItemSlot extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter!=null) { backgroundPainter.paintBackground(x, y, this); } else { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java index 1ab42b1..3889ac2 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java @@ -7,8 +7,8 @@ import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.LiteralText; import net.minecraft.text.Text; @@ -75,14 +75,14 @@ public class WLabel extends WWidget { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { - ScreenDrawing.drawString(text, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { + ScreenDrawing.drawString(matrices, text, alignment, x, y, this.getWidth(), LibGuiClient.config.darkMode ? darkmodeColor : color); Text hoveredText = getTextAt(mouseX, mouseY); if (hoveredText != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen instanceof TextHoverRendererScreen) { - ((TextHoverRendererScreen) screen).renderTextHover(hoveredText, x + mouseX, y + mouseY); + ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredText, x + mouseX, y + mouseY); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index d9ab1b0..4b5617c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java @@ -7,6 +7,7 @@ import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.gui.widget.AbstractButtonWidget; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import javax.annotation.Nullable; @@ -156,7 +157,7 @@ public class WLabeledSlider extends WAbstractSlider { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { int aWidth = axis == Axis.HORIZONTAL ? width : height; int aHeight = axis == Axis.HORIZONTAL ? height : width; int rotMouseX = axis == Axis.HORIZONTAL ? mouseX : (height - mouseY); @@ -187,7 +188,7 @@ public class WLabeledSlider extends WAbstractSlider { if (label != null) { int color = isMouseInsideBounds(mouseX, mouseY) ? 0xFFFFA0 : 0xE0E0E0; - ScreenDrawing.drawStringWithShadow(label, labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); + ScreenDrawing.drawStringWithShadow(matrices, label, labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); } RenderSystem.popMatrix(); } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index ff2b897..a61371a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -7,6 +7,7 @@ import java.util.function.BiConsumer; import java.util.function.Supplier; import io.github.cottonmc.cotton.gui.widget.data.Axis; +import net.minecraft.client.util.math.MatrixStack; /** * Similar to the RecyclerView in Android, this widget represents a scrollable list of items. @@ -70,13 +71,13 @@ public class WListPanel<D, W extends WWidget> extends WClippedPanel { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (scrollBar.getValue()!=lastScroll) { layout(); lastScroll = scrollBar.getValue(); } - super.paintBackground(x, y, mouseX, mouseY); + super.paint(matrices, x, y, mouseX, mouseY); /* if (getBackgroundPainter()!=null) { getBackgroundPainter().paintBackground(x, y, this); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index e7bdeab..fe32718 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -8,6 +8,7 @@ import io.github.cottonmc.cotton.gui.GuiDescription; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; /** * Panels are widgets tthat contain other widgets. @@ -180,20 +181,11 @@ public abstract class WPanel extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter!=null) backgroundPainter.paintBackground(x, y, this); for(WWidget child : children) { - child.paintBackground(x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); - } - } - - @Environment(EnvType.CLIENT) - @Override - @Deprecated - public void paintForeground(int x, int y, int mouseX, int mouseY) { - for(WWidget child : children) { - child.paintForeground(x + child.getX(), y + child.getY(), mouseX, mouseY); + child.paint(matrices, x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 7f2dac3..02805f1 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java @@ -5,6 +5,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; public class WScrollBar extends WWidget { protected Axis axis = Axis.HORIZONTAL; @@ -32,7 +33,7 @@ public class WScrollBar extends WWidget { } @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (LibGuiClient.config.darkMode) { ScreenDrawing.drawBeveledPanel(x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); } else { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java index 2dd3a8e..11acfcd 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java @@ -6,6 +6,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import io.github.cottonmc.cotton.gui.widget.data.Axis; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import javax.annotation.Nullable; @@ -52,7 +53,7 @@ public class WSlider extends WAbstractSlider { @SuppressWarnings("SuspiciousNameCombination") @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter != null) { backgroundPainter.paintBackground(x, y, this); } else { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java index 0738875..1c78793 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java @@ -3,6 +3,7 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; public class WSprite extends WWidget { @@ -119,7 +120,7 @@ public class WSprite extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (singleImage) { ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), frames[0], u1, v1, u2, v2, tint); } else { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java index 2052379..094817c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WText.java @@ -9,7 +9,7 @@ import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.util.Texts; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Style; import net.minecraft.text.Text; @@ -73,7 +73,7 @@ public class WText extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y, int mouseX, int mouseY) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (wrappedLines == null || wrappingScheduled) { wrapLines(); wrappingScheduled = false; @@ -84,14 +84,14 @@ public class WText extends WWidget { Text line = wrappedLines.get(i); int c = LibGuiClient.config.darkMode ? darkmodeColor : color; - ScreenDrawing.drawString(line, alignment, x, y + i * font.fontHeight, width, c); + ScreenDrawing.drawString(matrices, line, alignment, x, y + i * font.fontHeight, width, c); } Text hoveredText = getTextAt(mouseX, mouseY); if (hoveredText != null) { Screen screen = MinecraftClient.getInstance().currentScreen; if (screen instanceof TextHoverRendererScreen) { - ((TextHoverRendererScreen) screen).renderTextHover(hoveredText, x + mouseX, y + mouseY); + ((TextHoverRendererScreen) screen).renderTextHover(matrices, hoveredText, x + mouseX, y + mouseY); } } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 75e7628..d6eadac 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java @@ -5,6 +5,7 @@ import java.util.function.Predicate; import javax.annotation.Nullable; +import net.minecraft.client.util.math.MatrixStack; import org.lwjgl.glfw.GLFW; import org.lwjgl.opengl.GL11; @@ -310,7 +311,7 @@ public class WTextField extends WWidget { }*/ @Environment(EnvType.CLIENT) - public void renderButton(int x, int y) { + protected void renderTextField(MatrixStack matrices, int x, int y) { if (this.font==null) this.font = MinecraftClient.getInstance().textRenderer; int borderColor = (this.isFocused()) ? 0xFF_FFFFA0 : 0xFF_A0A0A0; @@ -347,16 +348,16 @@ public class WTextField extends WWidget { int preCursorAdvance = textX; if (!trimText.isEmpty()) { String string_2 = trimText.substring(0,adjustedCursor); - preCursorAdvance = font.drawWithShadow(ScreenDrawing.getMatrices(), string_2, textX, textY, textColor); + preCursorAdvance = font.drawWithShadow(matrices, string_2, textX, textY, textColor); } if (adjustedCursor<trimText.length()) { - font.drawWithShadow(ScreenDrawing.getMatrices(), trimText.substring(adjustedCursor), preCursorAdvance-1, (float)textY, textColor); + font.drawWithShadow(matrices, trimText.substring(adjustedCursor), preCursorAdvance-1, (float)textY, textColor); } if (text.length()==0 && this.suggestion != null) { - font.drawWithShadow(ScreenDrawing.getMatrices(), this.suggestion, textX, textY, -8355712); + font.drawWithShadow(matrices, this.suggestion, textX, textY, 0xFF808080); } //int var10002; @@ -378,7 +379,7 @@ public class WTextField extends WWidget { // DrawableHelper.fill(int_9, var10001, var10002, var10003 + 9, -3092272); } else { - font.drawWithShadow(ScreenDrawing.getMatrices(), "_", preCursorAdvance, textY, textColor); + font.drawWithShadow(matrices, "_", preCursorAdvance, textY, textColor); } } @@ -510,7 +511,7 @@ public class WTextField extends WWidget { } @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { /* if (isFocused()) { @@ -527,7 +528,7 @@ public class WTextField extends WWidget { //int ofs = MinecraftClient.getInstance().textRenderer.getStringWidth(this.text); ScreenDrawing.rect(x+OFFSET_X_TEXT+getCaretOffset(this.text, cursor), y+OFFSET_Y_TEXT-2, 1, OFFSET_Y_TEXT*2, 0xFFE0E0E0);*/ - renderButton(x, y); + renderTextField(matrices, x, y); } @Environment(EnvType.CLIENT) diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java index d6aee69..b5d58ef 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java @@ -2,11 +2,11 @@ package io.github.cottonmc.cotton.gui.widget; import io.github.cottonmc.cotton.gui.client.LibGuiClient; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; -import io.github.cottonmc.cotton.gui.widget.data.Alignment; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -72,11 +72,11 @@ public class WToggleButton extends WWidget { @Environment(EnvType.CLIENT) @Override - public void paintBackground(int x, int y) { + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); if (label!=null) { - ScreenDrawing.drawString(label, x + 22, y+6, LibGuiClient.config.darkMode ? darkmodeColor : color); + ScreenDrawing.drawString(matrices, label, x + 22, y+6, LibGuiClient.config.darkMode ? darkmodeColor : color); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java index 91d4a98..cee18d5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WWidget.java @@ -9,6 +9,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import javax.annotation.Nullable; @@ -103,11 +104,11 @@ public class WWidget { return getY() + parent.getAbsoluteY(); } } - + public int getWidth() { return width; } - + public int getHeight() { return height; } @@ -129,7 +130,7 @@ public class WWidget { public void setParent(WPanel parent) { this.parent = parent; } - + /** * Notifies this widget that the mouse has been pressed while inside its bounds * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) @@ -140,7 +141,7 @@ public class WWidget { public WWidget onMouseDown(int x, int y, int button) { return this; } - + /** * Notifies this widget that the mouse has been moved while pressed and inside its bounds. * @@ -168,7 +169,7 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onMouseDrag(int x, int y, int button) { } - + /** * Notifies this widget that the mouse has been released while inside its bounds * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) @@ -179,7 +180,7 @@ public class WWidget { public WWidget onMouseUp(int x, int y, int button) { return this; } - + /** * Notifies this widget that the mouse has been pressed and released, both while inside its bounds. * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) @@ -189,7 +190,7 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onClick(int x, int y, int button) { } - + /** * Notifies this widget that the mouse has been scrolled inside its bounds. * @param x The X coordinate of the event, in widget-space (0 is the left edge of this widget) @@ -210,7 +211,7 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onMouseMove(int x, int y) { } - + /** * Notifies this widget that a character has been typed. This method is subject to key repeat, * and may be called for characters that do not directly have a corresponding keyboard key. @@ -219,7 +220,7 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onCharTyped(char ch) { } - + /** * Notifies this widget that a key has been pressed. * @param key the GLFW scancode of the key @@ -227,7 +228,7 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onKeyPressed(int ch, int key, int modifiers) { } - + /** * Notifies this widget that a key has been released * @param key the GLFW scancode of the key @@ -235,20 +236,20 @@ public class WWidget { @Environment(EnvType.CLIENT) public void onKeyReleased(int ch, int key, int modifiers) { } - + /** Notifies this widget that it has gained focus */ public void onFocusGained() { } - + /** Notifies this widget that it has lost focus */ public void onFocusLost() { } - + public boolean isFocused() { if (host==null) return false; return host.isFocused(this); } - + public void requestFocus() { if (host!=null) { host.requestFocus(this); @@ -256,15 +257,15 @@ public class WWidget { System.out.println("host is null"); } } - + public void releaseFocus() { if (host!=null) host.releaseFocus(this); } - + public boolean canFocus() { return false; } - + /** * Creates "heavyweight" component peers * @param c the top-level Container that will hold the peers @@ -272,22 +273,19 @@ public class WWidget { public void createPeers(GuiDescription c) { host=c; } - - @Environment(EnvType.CLIENT) - public void paintBackground(int x, int y, int mouseX, int mouseY) { - this.paintBackground(x, y); - } - - @Environment(EnvType.CLIENT) - public void paintBackground(int x, int y) { - } - - @Deprecated + + /** + * Paints this widget. + * + * @param matrices the rendering matrix stack + * @param x this widget's X coordinate on the screen + * @param y this widget's Y coordinate on the screen + * @param mouseX the X coordinate of the cursor + * @param mouseY the X coordinate of the cursor + * @since 2.0.0 + */ @Environment(EnvType.CLIENT) - public void paintForeground(int x, int y, int mouseX, int mouseY) { - //if (mouseX >= x && mouseX < x+getWidth() && mouseY >= y && mouseY < y+getHeight()) { - // renderTooltip(mouseX, mouseY); - //} + public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { } /** @@ -302,13 +300,13 @@ public class WWidget { public boolean isWithinBounds(int x, int y) { return x>=0 && y>=0 && x<this.width && y<this.height; } - + /** * Internal method to render tooltip data. This requires an overriden {@link #addTooltip(List) * addTooltip} method to insert data into the tooltip - without this, the method returns early, because no work */ @Environment(EnvType.CLIENT) - public void renderTooltip(int x, int y, int tX, int tY) { + public void renderTooltip(MatrixStack matrices, int x, int y, int tX, int tY) { List<Text> info = new ArrayList<>(); addTooltip(info); @@ -316,9 +314,9 @@ public class WWidget { return; Screen screen = MinecraftClient.getInstance().currentScreen; - screen.renderTooltip(ScreenDrawing.getMatrices(), info, tX+x, tY+y); + screen.renderTooltip(matrices, info, tX+x, tY+y); } - + /** * Creates component peers, lays out children, and initializes animation data for this Widget and all its children. * The host container must clear any heavyweight peers from its records before this method is called. @@ -333,7 +331,7 @@ public class WWidget { */ public void addTooltip(List<Text> tooltip) { } - + /** * Find the most specific child node at this location. For non-panel widgets, returns this widget. */ |