diff options
20 files changed, 219 insertions, 190 deletions
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java index 52b0e81..de8a06a 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java @@ -144,7 +144,7 @@ public class TestClientGui extends LightweightGuiDescription { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(x, y, this.getWidth(), this.getHeight(), color); + ScreenDrawing.coloredRect(matrices, x, y, this.getWidth(), this.getHeight(), color); } } } diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java index 2cc1e4b..41d566d 100644 --- a/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java +++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/WHudTest.java @@ -16,7 +16,7 @@ public class WHudTest extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.coloredRect(x, y, width, height, 0xFF_00FF00); + ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF_00FF00); } @Override diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java index c856761..3d84e7c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java @@ -1,5 +1,6 @@ package io.github.cottonmc.cotton.gui.client; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.widget.WItemSlot; @@ -13,11 +14,12 @@ import io.github.cottonmc.cotton.gui.widget.WWidget; public interface BackgroundPainter { /** * Paint the specified panel to the screen. + * @param matrices The rendering matrix stack * @param left The absolute position of the left of the panel, in gui-screen coordinates * @param top The absolute position of the top of the panel, in gui-screen coordinates * @param panel The panel being painted */ - public void paintBackground(int left, int top, WWidget panel); + public void paintBackground(MatrixStack matrices, int left, int top, WWidget panel); /** * The {@code VANILLA} background painter draws a vanilla-like gui panel using {@linkplain NinePatch nine-patch textures}. @@ -40,9 +42,9 @@ public interface BackgroundPainter { /** * The {@code SLOT} background painter draws item slots or slot-like widgets. */ - public static BackgroundPainter SLOT = (left, top, panel) -> { + public static BackgroundPainter SLOT = (matrices, left, top, panel) -> { if (!(panel instanceof WItemSlot)) { - ScreenDrawing.drawBeveledPanel(left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); + ScreenDrawing.drawBeveledPanel(matrices, left-1, top-1, panel.getWidth()+2, panel.getHeight()+2, 0xB8000000, 0x4C000000, 0xB8FFFFFF); } else { WItemSlot slot = (WItemSlot)panel; for(int x = 0; x < slot.getWidth()/18; ++x) { @@ -53,26 +55,26 @@ public interface BackgroundPainter { //this will cause a slightly discolored bottom border on vanilla backgrounds but it's necessary for color support, it shouldn't be *too* visible unless you're looking for it int hi = 0xB8FFFFFF; if (slot.isBigSlot()) { - ScreenDrawing.drawBeveledPanel((x * 18) + left - 4, (y * 18) + top - 4, 26, 26, + ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left - 4, (y * 18) + top - 4, 26, 26, lo, bg, hi); if (slot.getFocusedSlot() == index) { int sx = (x * 18) + left - 3; int sy = (y * 18) + top - 3; - ScreenDrawing.coloredRect(sx, sy, 26, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 26 - 1, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 1, sy + 26 - 1, 26 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy, 26, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 26 - 1, sy + 1, 1, 26 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 1, sy + 26 - 1, 26 - 1, 1, 0xFF_FFFFA0); } } else { - ScreenDrawing.drawBeveledPanel((x * 18) + left, (y * 18) + top, 16+2, 16+2, + ScreenDrawing.drawBeveledPanel(matrices, (x * 18) + left, (y * 18) + top, 16+2, 16+2, lo, bg, hi); if (slot.getFocusedSlot() == index) { int sx = (x * 18) + left; int sy = (y * 18) + top; - ScreenDrawing.coloredRect(sx, sy, 18, 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 18 - 1, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); - ScreenDrawing.coloredRect(sx + 1, sy + 18 - 1, 18 - 1, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy, 18, 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 18 - 1, sy + 1, 1, 18 - 1, 0xFF_FFFFA0); + ScreenDrawing.coloredRect(matrices, sx + 1, sy + 18 - 1, 18 - 1, 1, 0xFF_FFFFA0); } } } @@ -85,11 +87,11 @@ public interface BackgroundPainter { * * @param panelColor the panel background color * @return a colorful gui panel painter - * @see ScreenDrawing#drawGuiPanel(int, int, int, int, int) + * @see ScreenDrawing#drawGuiPanel(MatrixStack, int, int, int, int, int) */ public static BackgroundPainter createColorful(int panelColor) { - return (left, top, panel) -> { - ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); + return (matrices, left, top, panel) -> { + ScreenDrawing.drawGuiPanel(matrices, left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); }; } @@ -101,11 +103,11 @@ public interface BackgroundPainter { * @return a colorful gui panel painter */ public static BackgroundPainter createColorful(int panelColor, float contrast) { - return (left, top, panel) -> { + return (matrices, left, top, panel) -> { int shadowColor = ScreenDrawing.multiplyColor(panelColor, 1.0f - contrast); int hilightColor = ScreenDrawing.multiplyColor(panelColor, 1.0f + contrast); - ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, shadowColor, panelColor, hilightColor, 0xFF000000); + ScreenDrawing.drawGuiPanel(matrices, left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, shadowColor, panelColor, hilightColor, 0xFF000000); }; } @@ -146,9 +148,9 @@ public interface BackgroundPainter { * @since 1.5.0 */ public static BackgroundPainter createLightDarkVariants(BackgroundPainter light, BackgroundPainter dark) { - return (left, top, panel) -> { - if (LibGui.isDarkMode()) dark.paintBackground(left, top, panel); - else light.paintBackground(left, top, panel); + return (matrices, left, top, panel) -> { + if (LibGui.isDarkMode()) dark.paintBackground(matrices, left, top, panel); + else light.paintBackground(matrices, left, top, panel); }; } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java index 033f7cf..8059b35 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java @@ -2,6 +2,7 @@ package io.github.cottonmc.cotton.gui.client; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @@ -156,7 +157,7 @@ public class NinePatch implements BackgroundPainter { } @Override - public void paintBackground(int left, int top, WWidget panel) { + public void paintBackground(MatrixStack matrices, int left, int top, WWidget panel) { int width = panel.getWidth() + leftPadding + rightPadding; int height = panel.getHeight() + topPadding + bottomPadding; left = left - leftPadding; @@ -169,10 +170,10 @@ public class NinePatch implements BackgroundPainter { float uv2 = 1.0f - cornerUv; Mode mode = this.mode != null ? this.mode : NinePatchInternals.MetadataLoader.INSTANCE.getProperties(texture).getMode(); - ScreenDrawing.texturedRect(left, top, cornerSize, cornerSize, texture, 0, 0, uv1, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, top, cornerSize, cornerSize, texture, uv2, 0, 1, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(left, y2, cornerSize, cornerSize, texture, 0, uv2, uv1, 1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y2, cornerSize, cornerSize, texture, uv2, uv2, 1, 1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, left, top, cornerSize, cornerSize, texture, 0, 0, uv1, uv1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x2, top, cornerSize, cornerSize, texture, uv2, 0, 1, uv1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, left, y2, cornerSize, cornerSize, texture, 0, uv2, uv1, 1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x2, y2, cornerSize, cornerSize, texture, uv2, uv2, 1, 1, 0xFF_FFFFFF); if (mode == Mode.TILING) { int tileSize = (int) (cornerSize / cornerUv - 2 * cornerSize); @@ -185,8 +186,8 @@ public class NinePatch implements BackgroundPainter { int tileWidth = Math.min(widthLeft, tileSize); float uo = (tileSize - tileWidth) * px; // Used to remove unnecessary pixels on the X axis - ScreenDrawing.texturedRect(x1 + i * tileSize, top, tileWidth, cornerSize, texture, uv1, 0, uv2 - uo, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1 + i * tileSize, y2, tileWidth, cornerSize, texture, uv1, uv2, uv2 - uo, 1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1 + i * tileSize, top, tileWidth, cornerSize, texture, uv1, 0, uv2 - uo, uv1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1 + i * tileSize, y2, tileWidth, cornerSize, texture, uv1, uv2, uv2 - uo, 1, 0xFF_FFFFFF); // Reset the height left each time the Y is looped heightLeft = height - 2 * cornerSize; @@ -195,21 +196,21 @@ public class NinePatch implements BackgroundPainter { int tileHeight = Math.min(heightLeft, tileSize); float vo = (tileSize - tileHeight) * px; // Used to remove unnecessary pixels on the Y axis - ScreenDrawing.texturedRect(left, y1 + j * tileSize, cornerSize, tileHeight, texture, 0, uv1, uv1, uv2 - vo, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y1 + j * tileSize, cornerSize, tileHeight, texture, uv2, uv1, 1, uv2 - vo, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, left, y1 + j * tileSize, cornerSize, tileHeight, texture, 0, uv1, uv1, uv2 - vo, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x2, y1 + j * tileSize, cornerSize, tileHeight, texture, uv2, uv1, 1, uv2 - vo, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1 + i * tileSize, y1 + j * tileSize, tileWidth, tileHeight, texture, uv1, uv1, uv2 - uo, uv2 - vo, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1 + i * tileSize, y1 + j * tileSize, tileWidth, tileHeight, texture, uv1, uv1, uv2 - uo, uv2 - vo, 0xFF_FFFFFF); heightLeft -= tileSize; } widthLeft -= tileSize; } } else { - ScreenDrawing.texturedRect(x1, top, width - 2 * cornerSize, cornerSize, texture, uv1, 0, uv2, uv1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(left, y1, cornerSize, height - 2 * cornerSize, texture, 0, uv1, uv1, uv2, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1, y2, width - 2 * cornerSize, cornerSize, texture, uv1, uv2, uv2, 1, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x2, y1, cornerSize, height - 2 * cornerSize, texture, uv2, uv1, 1, uv2, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1, top, width - 2 * cornerSize, cornerSize, texture, uv1, 0, uv2, uv1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, left, y1, cornerSize, height - 2 * cornerSize, texture, 0, uv1, uv1, uv2, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1, y2, width - 2 * cornerSize, cornerSize, texture, uv1, uv2, uv2, 1, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x2, y1, cornerSize, height - 2 * cornerSize, texture, uv2, uv1, 1, uv2, 0xFF_FFFFFF); - ScreenDrawing.texturedRect(x1, y1, width - 2 * cornerSize, height - 2 * cornerSize, texture, uv1, uv1, uv2, uv2, 0xFF_FFFFFF); + ScreenDrawing.texturedRect(matrices, x1, y1, width - 2 * cornerSize, height - 2 * cornerSize, texture, uv1, uv1, uv2, uv2, 0xFF_FFFFFF); } } 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 0781769..6e571cb 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 @@ -10,6 +10,7 @@ import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.OrderedText; import net.minecraft.util.Identifier; +import net.minecraft.util.math.Matrix4f; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; import io.github.cottonmc.cotton.gui.widget.data.Texture; @@ -24,6 +25,7 @@ public class ScreenDrawing { /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -31,13 +33,14 @@ public class ScreenDrawing { * @param texture the Identifier for the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedRect(int x, int y, int width, int height, Identifier texture, int color) { - texturedRect(x, y, width, height, texture, 0, 0, 1, 1, color, 1.0f); + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int color) { + texturedRect(matrices, x, y, width, height, texture, 0, 0, 1, 1, color, 1.0f); } /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -47,13 +50,14 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 2.0.0 */ - public static void texturedRect(int x, int y, int width, int height, Identifier texture, int color, float opacity) { - texturedRect(x, y, width, height, texture, 0, 0, 1, 1, color, opacity); + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int color, float opacity) { + texturedRect(matrices, x, y, width, height, texture, 0, 0, 1, 1, color, opacity); } /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -65,13 +69,14 @@ public class ScreenDrawing { * @param v2 the bottom edge of the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { - texturedRect(x, y, width, height, texture, u1, v1, u2, v2, color, 1.0f); + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color) { + texturedRect(matrices, x, y, width, height, texture, u1, v1, u2, v2, color, 1.0f); } /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -80,13 +85,14 @@ public class ScreenDrawing { * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint * @since 3.0.0 */ - public static void texturedRect(int x, int y, int width, int height, Texture texture, int color) { - texturedRect(x, y, width, height, texture, color, 1.0f); + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Texture texture, int color) { + texturedRect(matrices, x, y, width, height, texture, color, 1.0f); } /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -96,13 +102,14 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 3.0.0 */ - public static void texturedRect(int x, int y, int width, int height, Texture texture, int color, float opacity) { - texturedRect(x, y, width, height, texture.image, texture.u1, texture.v1, texture.u2, texture.v2, color, opacity); + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Texture texture, int color, float opacity) { + texturedRect(matrices, x, y, width, height, texture.image, texture.u1, texture.v1, texture.u2, texture.v2, color, opacity); } /** * Draws a textured rectangle. * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -116,7 +123,7 @@ public class ScreenDrawing { * @param opacity opacity of the drawn texture. (0f is fully opaque and 1f is fully visible) * @since 2.0.0 */ - public static void texturedRect(int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) { + public static void texturedRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, float u1, float v1, float u2, float v2, int color, float opacity) { MinecraftClient.getInstance().getTextureManager().bindTexture(texture); //float scale = 0.00390625F; @@ -129,14 +136,15 @@ public class ScreenDrawing { float b = (color & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); + Matrix4f model = matrices.peek().getModel(); RenderSystem.enableBlend(); //GlStateManager.disableTexture2D(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE); //I thought GL_QUADS was deprecated but okay, sure. - buffer.vertex(x, y + height, 0).color(r, g, b, opacity).texture(u1, v2).next(); - buffer.vertex(x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next(); - buffer.vertex(x + width, y, 0).color(r, g, b, opacity).texture(u2, v1).next(); - buffer.vertex(x, y, 0).color(r, g, b, opacity).texture(u1, v1).next(); + buffer.vertex(model, x, y + height, 0).color(r, g, b, opacity).texture(u1, v2).next(); + buffer.vertex(model, x + width, y + height, 0).color(r, g, b, opacity).texture(u2, v2).next(); + buffer.vertex(model, x + width, y, 0).color(r, g, b, opacity).texture(u2, v1).next(); + buffer.vertex(model, x, y, 0).color(r, g, b, opacity).texture(u1, v1).next(); tessellator.draw(); //GlStateManager.enableTexture2D(); RenderSystem.disableBlend(); @@ -146,6 +154,8 @@ public class ScreenDrawing { * Draws a textured rectangle with UV values based on the width and height. * * <p>If the texture is 256x256, this draws the texture at one pixel per texel. + * + * @param matrices the rendering matrix stack * @param x the x coordinate of the box on-screen * @param y the y coordinate of the box on-screen * @param width the width of the box on-screen @@ -155,9 +165,9 @@ public class ScreenDrawing { * @param textureY the y offset into the texture * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedGuiRect(int x, int y, int width, int height, Identifier texture, int textureX, int textureY, int color) { + public static void texturedGuiRect(MatrixStack matrices, int x, int y, int width, int height, Identifier texture, int textureX, int textureY, int color) { float px = 1/256f; - texturedRect(x, y, width, height, texture, textureX*px, textureY*px, (textureX+width)*px, (textureY+height)*px, color); + texturedRect(matrices, x, y, width, height, texture, textureX*px, textureY*px, (textureX+width)*px, (textureY+height)*px, color); } /** @@ -165,21 +175,22 @@ public class ScreenDrawing { * * <p>If the texture is 256x256, this draws the texture at one pixel per texel. * - * @param left the x coordinate of the box on-screen - * @param top the y coordinate of the box on-screen - * @param width the width of the box on-screen - * @param height the height of the box on-screen - * @param texture the Identifier for the texture - * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint + * @param matrices the rendering matrix stack + * @param left the x coordinate of the box on-screen + * @param top the y coordinate of the box on-screen + * @param width the width of the box on-screen + * @param height the height of the box on-screen + * @param texture the Identifier for the texture + * @param color a color to tint the texture. This can be transparent! Use 0xFF_FFFFFF if you don't want a color tint */ - public static void texturedGuiRect(int left, int top, int width, int height, Identifier texture, int color) { - texturedGuiRect(left, top, width, height, texture, 0, 0, color); + public static void texturedGuiRect(MatrixStack matrices, int left, int top, int width, int height, Identifier texture, int color) { + texturedGuiRect(matrices, left, top, width, height, texture, 0, 0, color); } /** * Draws an untextured rectangle of the specified RGB color. */ - public static void coloredRect(int left, int top, int width, int height, int color) { + public static void coloredRect(MatrixStack matrices, int left, int top, int width, int height, int color) { if (width <= 0) width = 1; if (height <= 0) height = 1; @@ -189,28 +200,29 @@ public class ScreenDrawing { float b = (color & 255) / 255.0F; Tessellator tessellator = Tessellator.getInstance(); BufferBuilder buffer = tessellator.getBuffer(); + Matrix4f model = matrices.peek().getModel(); RenderSystem.enableBlend(); RenderSystem.disableTexture(); RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ZERO); buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); //I thought GL_QUADS was deprecated but okay, sure. - buffer.vertex(left, top + height, 0.0D).color(r, g, b, a).next(); - buffer.vertex(left + width, top + height, 0.0D).color(r, g, b, a).next(); - buffer.vertex(left + width, top, 0.0D).color(r, g, b, a).next(); - buffer.vertex(left, top, 0.0D).color(r, g, b, a).next(); + buffer.vertex(model, left, top + height, 0).color(r, g, b, a).next(); + buffer.vertex(model, left + width, top + height, 0).color(r, g, b, a).next(); + buffer.vertex(model, left + width, top, 0).color(r, g, b, a).next(); + buffer.vertex(model, left, top, 0).color(r, g, b, a).next(); tessellator.draw(); RenderSystem.enableTexture(); RenderSystem.disableBlend(); } - public static void maskedRect(Identifier mask, Identifier texture, int left, int top, int width, int height) { + public static void maskedRect(MatrixStack matrices, Identifier mask, Identifier texture, int left, int top, int width, int height) { - texturedRect(left, top, width, height, mask, 0, 0, 1, 1, 0xFFFFFFFF); //TODO: 7 Z + texturedRect(matrices, left, top, width, height, mask, 0, 0, 1, 1, 0xFFFFFFFF); //TODO: 7 Z RenderSystem.enableDepthTest(); RenderSystem.depthFunc(GL11.GL_EQUAL); - texturedRect(left, top, width, height, texture, 0, 0, 1, 1, 0xFFFFFFFF); //, 7); + texturedRect(matrices, left, top, width, height, texture, 0, 0, 1, 1, 0xFFFFFFFF); //, 7); RenderSystem.depthFunc(GL11.GL_LESS); RenderSystem.disableDepthTest(); @@ -257,82 +269,86 @@ public class ScreenDrawing { /** * Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels. * - * @param x the X position of the panel - * @param y the Y position of the panel - * @param width the width of the panel - * @param height the height of the panel + * @param matrices the rendering matrix stack + * @param x the X position of the panel + * @param y the Y position of the panel + * @param width the width of the panel + * @param height the height of the panel */ - public static void drawGuiPanel(int x, int y, int width, int height) { - if (LibGui.isDarkMode()) drawGuiPanel(x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); - else drawGuiPanel(x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); + public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height) { + if (LibGui.isDarkMode()) drawGuiPanel(matrices, x, y, width, height, 0xFF0B0B0B, 0xFF2F2F2F, 0xFF414141, 0xFF000000); + else drawGuiPanel(matrices, x, y, width, height, 0xFF555555, 0xFFC6C6C6, 0xFFFFFFFF, 0xFF000000); } /** * Draws a beveled, round, and colored rectangle that is substantially similar to default Minecraft UI panels. * + * @param matrices the rendering matrix stack * @param x the X position of the panel * @param y the Y position of the panel * @param width the width of the panel * @param height the height of the panel * @param panelColor the panel ARGB color */ - public static void drawGuiPanel(int x, int y, int width, int height, int panelColor) { + public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height, int panelColor) { int shadowColor = multiplyColor(panelColor, 0.50f); int hilightColor = multiplyColor(panelColor, 1.25f); - drawGuiPanel(x, y, width, height, shadowColor, panelColor, hilightColor, 0xFF000000); + drawGuiPanel(matrices, x, y, width, height, shadowColor, panelColor, hilightColor, 0xFF000000); } /** * Draws a beveled, round rectangle with custom edge colors that is substantially similar to default Minecraft UI panels. * - * @param x the X position of the panel - * @param y the Y position of the panel - * @param width the width of the panel - * @param height the height of the panel - * @param shadow the bottom/right shadow ARGB color - * @param panel the center ARGB color - * @param hilight the top/left hilight ARGB color - * @param outline the outline ARGB color + * @param matrices the rendering matrix stack + * @param x the X position of the panel + * @param y the Y position of the panel + * @param width the width of the panel + * @param height the height of the panel + * @param shadow the bottom/right shadow ARGB color + * @param panel the center ARGB color + * @param hilight the top/left hilight ARGB color + * @param outline the outline ARGB color */ - public static void drawGuiPanel(int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { - coloredRect(x + 3, y + 3, width - 6, height - 6, panel); //Main panel area - - coloredRect(x + 2, y + 1, width - 4, 2, hilight); //Top hilight - coloredRect(x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow - coloredRect(x + 1, y + 2, 2, height - 4, hilight); //Left hilight - coloredRect(x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow - coloredRect(x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel - coloredRect(x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel - coloredRect(x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel - coloredRect(x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel - - coloredRect(x + 2, y, width - 4, 1, outline); //Top outline - coloredRect(x, y + 2, 1, height - 4, outline); //Left outline - coloredRect(x + width - 1, y + 2, 1, height - 4, outline); //Right outline - coloredRect(x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline - coloredRect(x + 1, y + 1, 1, 1, outline); //Topleft round pixel - coloredRect(x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel - coloredRect(x + width - 2, y + 1, 1, 1, outline); //Topright round pixel - coloredRect(x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel + public static void drawGuiPanel(MatrixStack matrices, int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { + coloredRect(matrices, x + 3, y + 3, width - 6, height - 6, panel); //Main panel area + + coloredRect(matrices, x + 2, y + 1, width - 4, 2, hilight); //Top hilight + coloredRect(matrices, x + 2, y + height - 3, width - 4, 2, shadow); //Bottom shadow + coloredRect(matrices, x + 1, y + 2, 2, height - 4, hilight); //Left hilight + coloredRect(matrices, x + width - 3, y + 2, 2, height - 4, shadow); //Right shadow + coloredRect(matrices, x + width - 3, y + 2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel + coloredRect(matrices, x + 2, y + height - 3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel + coloredRect(matrices, x + 3, y + 3, 1, 1, hilight); //Topleft round hilight pixel + coloredRect(matrices, x + width - 4, y + height - 4, 1, 1, shadow); //Bottomright round shadow pixel + + coloredRect(matrices, x + 2, y, width - 4, 1, outline); //Top outline + coloredRect(matrices, x, y + 2, 1, height - 4, outline); //Left outline + coloredRect(matrices, x + width - 1, y + 2, 1, height - 4, outline); //Right outline + coloredRect(matrices, x + 2, y + height - 1, width - 4, 1, outline); //Bottom outline + coloredRect(matrices, x + 1, y + 1, 1, 1, outline); //Topleft round pixel + coloredRect(matrices, x + 1, y + height - 2, 1, 1, outline); //Bottomleft round pixel + coloredRect(matrices, x + width - 2, y + 1, 1, 1, outline); //Topright round pixel + coloredRect(matrices, x + width - 2, y + height - 2, 1, 1, outline); //Bottomright round pixel } /** * Draws a default-sized recessed itemslot panel */ - public static void drawBeveledPanel(int x, int y) { - drawBeveledPanel(x, y, 18, 18, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); + public static void drawBeveledPanel(MatrixStack matrices, int x, int y) { + drawBeveledPanel(matrices, x, y, 18, 18, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } /** * Draws a default-color recessed itemslot panel of variable size */ - public static void drawBeveledPanel(int x, int y, int width, int height) { - drawBeveledPanel(x, y, width, height, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); + public static void drawBeveledPanel(MatrixStack matrices, int x, int y, int width, int height) { + drawBeveledPanel(matrices, x, y, width, height, 0xFF373737, 0xFF8b8b8b, 0xFFFFFFFF); } /** * Draws a generalized-case beveled panel. Can be inset or outset depending on arguments. + * @param matrices the rendering matrix stack * @param x x coordinate of the topleft corner * @param y y coordinate of the topleft corner * @param width width of the panel @@ -341,12 +357,12 @@ public class ScreenDrawing { * @param panel color of the panel area * @param bottomright color of the bottom/right bevel */ - public static void drawBeveledPanel(int x, int y, int width, int height, int topleft, int panel, int bottomright) { - coloredRect(x, y, width, height, panel); //Center panel - coloredRect(x, y, width - 1, 1, topleft); //Top shadow - coloredRect(x, y + 1, 1, height - 2, topleft); //Left shadow - coloredRect(x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - coloredRect(x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight + public static void drawBeveledPanel(MatrixStack matrices, int x, int y, int width, int height, int topleft, int panel, int bottomright) { + coloredRect(matrices, x, y, width, height, panel); //Center panel + coloredRect(matrices, x, y, width - 1, 1, topleft); //Top shadow + coloredRect(matrices, x, y + 1, 1, height - 2, topleft); //Left shadow + coloredRect(matrices, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight + coloredRect(matrices, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } /** diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java index 140819a..74f0f1a 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java @@ -96,7 +96,7 @@ public class WKirbSprite extends WWidget { } float offset = KIRB_WIDTH * currentFrame; - ScreenDrawing.texturedRect(x, y+8, 32, 32, KIRB, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y+8, 32, 32, KIRB, offset, 0, offset+KIRB_WIDTH, 1, 0xFFFFFFFF); long elapsed = now - lastFrame; currentFrameTime += elapsed; 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 13cf16b..1aea8ec 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 @@ -113,9 +113,9 @@ public class WBar extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (bg!=null) { - ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, getWidth(), getHeight(), bg, 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); + ScreenDrawing.coloredRect(matrices, x, y, getWidth(), getHeight(), ScreenDrawing.colorAtOpacity(0x000000, 0.25f)); } float percent = properties.get(field) / (float) properties.get(max); @@ -135,25 +135,25 @@ public class WBar extends WWidget { int top = y + getHeight(); top -= barSize; if (bar!=null) { - ScreenDrawing.texturedRect(left, top, getWidth(), barSize, bar.image, bar.u1, MathHelper.lerp(percent, bar.v2, bar.v1), bar.u2, bar.v2, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, left, top, getWidth(), barSize, bar.image, bar.u1, MathHelper.lerp(percent, bar.v2, bar.v1), bar.u2, bar.v2, 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(matrices, left, top, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } case RIGHT: { if (bar!=null) { - ScreenDrawing.texturedRect(x, y, barSize, getHeight(), bar.image, bar.u1, bar.v1, MathHelper.lerp(percent, bar.u1, bar.u2), bar.v2, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, barSize, getHeight(), bar.image, bar.u1, bar.v1, MathHelper.lerp(percent, bar.u1, bar.u2), bar.v2, 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(matrices, x, y, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } case DOWN: { if (bar!=null) { - ScreenDrawing.texturedRect(x, y, getWidth(), barSize, bar.image, bar.u1, bar.v1, bar.u2, MathHelper.lerp(percent, bar.v1, bar.v2), 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, getWidth(), barSize, bar.image, bar.u1, bar.v1, bar.u2, MathHelper.lerp(percent, bar.v1, bar.v2), 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(matrices, x, y, getWidth(), barSize, ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } @@ -162,9 +162,9 @@ public class WBar extends WWidget { int top = y; left -= barSize; if (bar!=null) { - ScreenDrawing.texturedRect(left, top, barSize, getHeight(), bar.image, MathHelper.lerp(percent, bar.u2, bar.u1), bar.v1, bar.u2, bar.v2, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, left, top, barSize, getHeight(), bar.image, MathHelper.lerp(percent, bar.u2, bar.u1), bar.v1, bar.u2, bar.v2, 0xFFFFFFFF); } else { - ScreenDrawing.coloredRect(left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); + ScreenDrawing.coloredRect(matrices, left, top, barSize, getHeight(), ScreenDrawing.colorAtOpacity(0xFFFFFF, 0.5f)); } break; } 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 65dde6f..deee662 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 @@ -93,8 +93,8 @@ public class WButton extends WWidget { float buttonEndLeft = (200-(getWidth()/2)) * px; - ScreenDrawing.texturedRect(x, y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x+(getWidth()/2), y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft+buttonWidth, buttonTop+buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x+(getWidth()/2), y, getWidth()/2, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200*px, buttonTop+buttonHeight, 0xFFFFFFFF); if (icon != null) { icon.paint(matrices, x + 1, y + 1, 16); 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 6daf600..a594fc2 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 @@ -13,7 +13,7 @@ public class WClippedPanel extends WPanel { @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(x, y, this); + if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(matrices, x, y, this); Scissors.push(x, y, width, height); for(WWidget child : children) { 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 45fc896..1667bee 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 @@ -328,7 +328,7 @@ public class WItemSlot extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter != null) { - backgroundPainter.paintBackground(x, y, this); + backgroundPainter.paintBackground(matrices, x, y, this); } } 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 fa1b49e..ba5edd4 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 @@ -1,10 +1,10 @@ package io.github.cottonmc.cotton.gui.widget; -import com.mojang.blaze3d.systems.RenderSystem; 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.client.util.math.Vector3f; import net.minecraft.text.Text; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -155,7 +155,6 @@ public class WLabeledSlider extends WAbstractSlider { return x >= 0 && x <= width && y >= 0 && y <= height; } - @SuppressWarnings("deprecation") @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { @@ -166,14 +165,13 @@ public class WLabeledSlider extends WAbstractSlider { : (direction == Direction.UP ? height - mouseY : mouseY); int rotMouseY = axis == Axis.HORIZONTAL ? mouseY : mouseX; - RenderSystem.pushMatrix(); // TODO: Get rid of this eventually matrices.push(); matrices.translate(x, y, 0); if (axis == Axis.VERTICAL) { - RenderSystem.translatef(0, height, 0); - RenderSystem.rotatef(270, 0, 0, 1); + matrices.translate(0, height, 0); + matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(270)); } - drawButton(0, 0, 0, aWidth); + drawButton(matrices, 0, 0, 0, aWidth); // 1: regular, 2: hovered, 0: disabled/dragging int thumbX = Math.round(coordToValueRatio * (value - min)); @@ -183,11 +181,11 @@ public class WLabeledSlider extends WAbstractSlider { boolean hovering = rotMouseX >= thumbX && rotMouseX <= thumbX + thumbWidth && rotMouseY >= thumbY && rotMouseY <= thumbY + thumbHeight; int thumbState = dragging || hovering ? 2 : 1; - drawButton(thumbX, thumbY, thumbState, thumbWidth); + drawButton(matrices, thumbX, thumbY, thumbState, thumbWidth); if (thumbState == 1 && isFocused()) { float px = 1 / 32f; - ScreenDrawing.texturedRect(thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, thumbX, thumbY, thumbWidth, thumbHeight, WSlider.LIGHT_TEXTURE, 24*px, 0*px, 32*px, 20*px, 0xFFFFFFFF); } if (label != null) { @@ -195,12 +193,11 @@ public class WLabeledSlider extends WAbstractSlider { ScreenDrawing.drawStringWithShadow(matrices, label.asOrderedText(), labelAlignment, 2, aHeight / 2 - 4, aWidth - 4, color); } matrices.pop(); - RenderSystem.popMatrix(); } // state = 1: regular, 2: hovered, 0: disabled/dragging @Environment(EnvType.CLIENT) - private void drawButton(int x, int y, int state, int width) { + private void drawButton(MatrixStack matrices, int x, int y, int state, int width) { float px = 1 / 256f; float buttonLeft = 0 * px; float buttonTop = (46 + (state * 20)) * px; @@ -210,8 +207,8 @@ public class WLabeledSlider extends WAbstractSlider { float buttonHeight = 20 * px; float buttonEndLeft = (200 - halfWidth) * px; - ScreenDrawing.texturedRect(x, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonLeft, buttonTop, buttonLeft + buttonWidth, buttonTop + buttonHeight, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x + halfWidth, y, halfWidth, 20, AbstractButtonWidget.WIDGETS_LOCATION, buttonEndLeft, buttonTop, 200 * px, buttonTop + buttonHeight, 0xFFFFFFFF); } /** 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 2576d46..d4b5626 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 @@ -184,7 +184,7 @@ public abstract class WPanel extends WWidget { @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - if (backgroundPainter!=null) backgroundPainter.paintBackground(x, y, this); + if (backgroundPainter!=null) backgroundPainter.paintBackground(matrices, x, y, this); for(WWidget child : children) { 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 812b5fe..5f9a6d5 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 @@ -37,9 +37,9 @@ public class WScrollBar extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (LibGui.isDarkMode()) { - ScreenDrawing.drawBeveledPanel(x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); + ScreenDrawing.drawBeveledPanel(matrices, x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D); } else { - ScreenDrawing.drawBeveledPanel(x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); + ScreenDrawing.drawBeveledPanel(matrices, x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF); } if (maxValue<=0) return; @@ -79,16 +79,16 @@ public class WScrollBar extends WWidget { } if (axis==Axis.HORIZONTAL) { - ScreenDrawing.drawBeveledPanel(x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom); + ScreenDrawing.drawBeveledPanel(matrices, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom); if (isFocused()) { - drawBeveledOutline(x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39); + drawBeveledOutline(matrices, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39); } } else { - ScreenDrawing.drawBeveledPanel(x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom); + ScreenDrawing.drawBeveledPanel(matrices, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom); if (isFocused()) { - drawBeveledOutline(x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39); + drawBeveledOutline(matrices, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39); } } } @@ -103,11 +103,12 @@ public class WScrollBar extends WWidget { return true; } - private static void drawBeveledOutline(int x, int y, int width, int height, int topleft, int bottomright) { - ScreenDrawing.coloredRect(x, y, width, 1, topleft); //Top shadow - ScreenDrawing.coloredRect(x, y + 1, 1, height - 1, topleft); //Left shadow - ScreenDrawing.coloredRect(x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight - ScreenDrawing.coloredRect(x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight + @Environment(EnvType.CLIENT) + private static void drawBeveledOutline(MatrixStack matrices, int x, int y, int width, int height, int topleft, int bottomright) { + ScreenDrawing.coloredRect(matrices, x, y, width, 1, topleft); //Top shadow + ScreenDrawing.coloredRect(matrices, x, y + 1, 1, height - 1, topleft); //Left shadow + ScreenDrawing.coloredRect(matrices, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight + ScreenDrawing.coloredRect(matrices, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight } /** 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 6638fb7..a63c9cb 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 @@ -50,7 +50,7 @@ public class WSlider extends WAbstractSlider { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (backgroundPainter != null) { - backgroundPainter.paintBackground(x, y, this); + backgroundPainter.paintBackground(matrices, x, y, this); } else { float px = 1 / 32f; // thumbX/Y: thumb position in widget-space @@ -67,9 +67,9 @@ public class WSlider extends WAbstractSlider { : Math.round(coordToValueRatio * (value - min)); thumbXOffset = 0; - ScreenDrawing.texturedRect(trackX, y + 1, TRACK_WIDTH, 1, texture, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(trackX, y + 2, TRACK_WIDTH, height - 2, texture, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(trackX, y + height, TRACK_WIDTH, 1, texture, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, trackX, y + 1, TRACK_WIDTH, 1, texture, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, trackX, y + 2, TRACK_WIDTH, height - 2, texture, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, trackX, y + height, TRACK_WIDTH, 1, texture, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF); } else { int trackY = y + height / 2 - TRACK_WIDTH / 2; thumbX = direction == Direction.LEFT @@ -78,18 +78,18 @@ public class WSlider extends WAbstractSlider { thumbY = height / 2 - THUMB_SIZE / 2; thumbXOffset = 8; - ScreenDrawing.texturedRect(x, trackY, 1, TRACK_WIDTH, texture, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x + 1, trackY, width - 2, TRACK_WIDTH, texture, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); - ScreenDrawing.texturedRect(x + width - 1, trackY, 1, TRACK_WIDTH, texture, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, trackY, 1, TRACK_WIDTH, texture, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x + 1, trackY, width - 2, TRACK_WIDTH, texture, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x + width - 1, trackY, 1, TRACK_WIDTH, texture, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF); } // thumbState values: // 0: default, 1: dragging, 2: hovered int thumbState = dragging ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0); - ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF); if (thumbState == 0 && isFocused()) { - ScreenDrawing.texturedRect(x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x + thumbX, y + thumbY, THUMB_SIZE, THUMB_SIZE, texture, 0*px, 24*px, 8*px, 32*px, 0xFFFFFFFF); } } } 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 632ca6c..a17ed42 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 @@ -184,7 +184,7 @@ public class WSprite extends WWidget { @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { if (singleImage) { - paintFrame(x, y, frames[0]); + paintFrame(matrices, x, y, frames[0]); } else { //grab the system time at the very start of the frame. long now = System.nanoTime() / 1_000_000L; @@ -194,7 +194,7 @@ public class WSprite extends WWidget { if (!inBounds) currentFrame = 0; //assemble and draw the frame calculated last iteration. Texture currentFrameTex = frames[currentFrame]; - paintFrame(x, y, currentFrameTex); + paintFrame(matrices, x, y, currentFrameTex); //calculate how much time has elapsed since the last animation change, and change the frame if necessary. long elapsed = now - lastFrame; @@ -216,12 +216,13 @@ public class WSprite extends WWidget { /** * Paints a single frame for this sprite. * - * @param x the X coordinate to draw it at - * @param y the Y coordinate to draw it at - * @param texture the texture to draw + * @param matrices the rendering matrix stack + * @param x the X coordinate to draw it at + * @param y the Y coordinate to draw it at + * @param texture the texture to draw */ @Environment(EnvType.CLIENT) - protected void paintFrame(int x, int y, Texture texture) { - ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), texture, tint); + protected void paintFrame(MatrixStack matrices, int x, int y, Texture texture) { + ScreenDrawing.texturedRect(matrices, x, y, getWidth(), getHeight(), texture, tint); } } diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java index 647f88b..7e5d02f 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java @@ -149,9 +149,9 @@ public class WTabPanel extends WPanel { } } - (selected ? Painters.SELECTED_TAB : Painters.UNSELECTED_TAB).paintBackground(x, y, this); + (selected ? Painters.SELECTED_TAB : Painters.UNSELECTED_TAB).paintBackground(matrices, x, y, this); if (isFocused()) { - (selected ? Painters.SELECTED_TAB_FOCUS_BORDER : Painters.UNSELECTED_TAB_FOCUS_BORDER).paintBackground(x, y, this); + (selected ? Painters.SELECTED_TAB_FOCUS_BORDER : Painters.UNSELECTED_TAB_FOCUS_BORDER).paintBackground(matrices, x, y, this); } int iconX = 6; 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 0e1037b..d1b16ea 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 @@ -1,15 +1,24 @@ package io.github.cottonmc.cotton.gui.widget; +import com.mojang.blaze3d.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; 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.render.BufferBuilder; +import net.minecraft.client.render.Tessellator; +import net.minecraft.client.render.VertexFormat; +import net.minecraft.client.render.VertexFormats; import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.text.LiteralText; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Matrix4f; import io.github.cottonmc.cotton.gui.client.BackgroundPainter; +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -116,8 +125,8 @@ public class WTextField extends WWidget { if (this.font==null) this.font = MinecraftClient.getInstance().textRenderer; int borderColor = (this.isFocused()) ? 0xFF_FFFFA0 : 0xFF_A0A0A0; - ScreenDrawing.coloredRect(x-1, y-1, width+2, height+2, borderColor); - ScreenDrawing.coloredRect(x, y, width, height, 0xFF000000); + ScreenDrawing.coloredRect(matrices, x-1, y-1, width+2, height+2, borderColor); + ScreenDrawing.coloredRect(matrices, x, y, width, height, 0xFF000000); int textColor = this.editable ? this.enabledColor : this.uneditableColor; @@ -171,7 +180,7 @@ public class WTextField extends WWidget { //} else { // caretLoc = textX+caretLoc-1; //} - ScreenDrawing.coloredRect(preCursorAdvance-1, textY-2, 1, 12, 0xFFD0D0D0); + ScreenDrawing.coloredRect(matrices, preCursorAdvance-1, textY-2, 1, 12, 0xFFD0D0D0); //if (boolean_3) { // int var10001 = int_7 - 1; // var10002 = int_9 + 1; @@ -192,7 +201,7 @@ public class WTextField extends WWidget { b = a; a = tmp; } - invertedRect(textX+a-1, textY-1, Math.min(b-a, width - OFFSET_X_TEXT), 12); + invertedRect(matrices, textX+a-1, textY-1, Math.min(b-a, width - OFFSET_X_TEXT), 12); // int int_10 = int_6 + MinecraftClient.getInstance().textRenderer.getStringWidth(trimText.substring(0, adjustedCursor)); // var10002 = int_7 - 1; // var10003 = int_10 - 1; @@ -202,18 +211,18 @@ public class WTextField extends WWidget { } @Environment(EnvType.CLIENT) - private void invertedRect(int x, int y, int width, int height) { + private void invertedRect(MatrixStack matrices, int x, int y, int width, int height) { Tessellator tessellator_1 = Tessellator.getInstance(); BufferBuilder bufferBuilder_1 = tessellator_1.getBuffer(); - RenderSystem.color4f(0.0F, 0.0F, 255.0F, 255.0F); + Matrix4f model = matrices.peek().getModel(); RenderSystem.disableTexture(); RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); - bufferBuilder_1.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION); - bufferBuilder_1.vertex(x, y+height, 0.0D).next(); - bufferBuilder_1.vertex(x+width, y+height, 0.0D).next(); - bufferBuilder_1.vertex(x+width, y, 0.0D).next(); - bufferBuilder_1.vertex(x, y, 0.0D).next(); + bufferBuilder_1.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder_1.vertex(model, x, y+height, 0).color(0, 0, 255, 255).next(); + bufferBuilder_1.vertex(model, x+width, y+height, 0).color(0, 0, 255, 255).next(); + bufferBuilder_1.vertex(model, x+width, y, 0).color(0, 0, 255, 255).next(); + bufferBuilder_1.vertex(model, x, y, 0).color(0, 0, 255, 255).next(); tessellator_1.draw(); RenderSystem.disableColorLogicOp(); RenderSystem.enableTexture(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java index 5750636..0ab9d7c 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java @@ -2,6 +2,7 @@ package io.github.cottonmc.cotton.gui.widget; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.client.ScreenDrawing; @@ -129,13 +130,14 @@ public class WTiledSprite extends WSprite { @Environment(EnvType.CLIENT) @Override - public void paintFrame(int x, int y, Texture texture) { + public void paintFrame(MatrixStack matrices, int x, int y, Texture texture) { // Y Direction (down) for (int tileYOffset = 0; tileYOffset < height; tileYOffset += tileHeight) { // X Direction (right) for (int tileXOffset = 0; tileXOffset < width; tileXOffset += tileWidth) { // draw the texture ScreenDrawing.texturedRect( + matrices, // at the correct position using tileXOffset and tileYOffset x + tileXOffset, y + tileYOffset, // but using the set tileWidth and tileHeight instead of the full height and 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 1a88ece..2f3cfc7 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 @@ -101,9 +101,9 @@ public class WToggleButton extends WWidget { @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int mouseX, int mouseY) { - ScreenDrawing.texturedRect(x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, 18, 18, isOn ? onImage : offImage, 0xFFFFFFFF); if (isFocused()) { - ScreenDrawing.texturedRect(x, y, 18, 18, focusImage, 0xFFFFFFFF); + ScreenDrawing.texturedRect(matrices, x, y, 18, 18, focusImage, 0xFFFFFFFF); } if (label!=null) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java index 18cf4c3..acc3ce5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java @@ -80,6 +80,6 @@ public class TextureIcon implements Icon { @Environment(EnvType.CLIENT) @Override public void paint(MatrixStack matrices, int x, int y, int size) { - ScreenDrawing.texturedRect(x, y, size, size, texture, color, opacity); + ScreenDrawing.texturedRect(matrices, x, y, size, size, texture, color, opacity); } } |