aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-11-28 13:27:08 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-11-28 13:27:08 +0200
commitb9265894f3dddc0e7df8c420c867e82078e78f99 (patch)
tree7a371923b527b2566edb0726754dee2b13132bad /src/main/java
parent850a94c6ba322b445a536a29fb78cf047cfb8275 (diff)
downloadLibGui-b9265894f3dddc0e7df8c420c867e82078e78f99.tar.gz
LibGui-b9265894f3dddc0e7df8c420c867e82078e78f99.tar.bz2
LibGui-b9265894f3dddc0e7df8c420c867e82078e78f99.zip
Migrate all rectangle rendering to use MatrixStacks
Still need testing.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java44
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/NinePatch.java31
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/ScreenDrawing.java176
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/modmenu/WKirbSprite.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WBar.java20
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WButton.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WItemSlot.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WLabeledSlider.java21
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java23
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java18
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WSprite.java15
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTabPanel.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTextField.java31
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WTiledSprite.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WToggleButton.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/icon/TextureIcon.java2
18 files changed, 217 insertions, 188 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 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,