diff options
author | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 16:10:07 +0200 |
---|---|---|
committer | Juuxel <6596629+Juuxel@users.noreply.github.com> | 2021-02-27 16:10:07 +0200 |
commit | 5ae6164d6bcfe0c2af93afc2015443a1a7d236a0 (patch) | |
tree | 68275b5a9eb8ef2ecd6e738d509ebd0ca4551538 /src/main/java | |
parent | e9c1a13abd8d73267d4846dafb93964646684818 (diff) | |
download | LibGui-5ae6164d6bcfe0c2af93afc2015443a1a7d236a0.tar.gz LibGui-5ae6164d6bcfe0c2af93afc2015443a1a7d236a0.tar.bz2 LibGui-5ae6164d6bcfe0c2af93afc2015443a1a7d236a0.zip |
Migrate all rectangle rendering to use MatrixStacks
Diffstat (limited to 'src/main/java')
14 files changed, 179 insertions, 171 deletions
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 a847629..e3e25f0 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 @@ -43,7 +43,7 @@ public interface BackgroundPainter { */ 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) { @@ -54,26 +54,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 - 4; int sy = (y * 18) + top - 4; - 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); } } } @@ -86,11 +86,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 (matrices, left, top, panel) -> { - ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); + ScreenDrawing.drawGuiPanel(matrices, left-8, top-8, panel.getWidth()+16, panel.getHeight()+16, panelColor); }; } @@ -106,7 +106,7 @@ public interface BackgroundPainter { 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); }; } 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 cdc657e..0375d8d 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 @@ -181,10 +181,10 @@ public class NinePatch implements BackgroundPainter { float uv2 = 1.0f - cornerUv; Mode mode = this.mode != null ? this.mode : 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); @@ -197,8 +197,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; @@ -207,21 +207,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 410840d..0d6aca0 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 @@ -12,6 +12,9 @@ import net.minecraft.util.Identifier; import io.github.cottonmc.cotton.gui.widget.data.HorizontalAlignment; import io.github.cottonmc.cotton.gui.widget.data.Texture; + +import net.minecraft.util.math.Matrix4f; + import org.lwjgl.opengl.GL11; /** @@ -23,6 +26,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 @@ -30,13 +34,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 @@ -46,13 +51,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 @@ -64,13 +70,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 @@ -79,13 +86,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 @@ -95,13 +103,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 @@ -115,7 +124,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; @@ -128,14 +137,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(GL11.GL_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(); @@ -145,6 +155,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 @@ -154,9 +166,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); } /** @@ -164,21 +176,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; @@ -188,33 +201,20 @@ 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(GL11.GL_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) { - - - texturedRect(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); - - RenderSystem.depthFunc(GL11.GL_LESS); - RenderSystem.disableDepthTest(); - } - /** * Draws a rectangle for a Fluid, because fluids are tough. */ @@ -256,82 +256,87 @@ 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 @@ -340,12 +345,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/client/modmenu/WKirbSprite.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/WKirbSprite.java index f0300b1..2f7832d 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 @@ -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/WLabeledSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java index 0c1a510..ef5391e 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 @@ -172,7 +172,7 @@ public class WLabeledSlider extends WAbstractSlider { RenderSystem.translatef(0, height, 0); RenderSystem.rotatef(270, 0, 0, 1); } - 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)); @@ -182,11 +182,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) { @@ -198,7 +198,7 @@ public class WLabeledSlider extends WAbstractSlider { // 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; @@ -208,8 +208,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/WScrollBar.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java index 812b5fe..1f97f48 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,11 @@ 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 + 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 96f5fa5..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 @@ -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/WTextField.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java index 8ff03cf..e4f36de 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 @@ -314,8 +314,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; @@ -369,7 +369,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; 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); } } |