From a018db6c699488aa9b9e392cd4515c97fade095a Mon Sep 17 00:00:00 2001 From: Falkreon Date: Fri, 30 Aug 2019 13:36:57 -0500 Subject: Implement panel clipping --- .../cottonmc/cotton/gui/widget/WClippedPanel.java | 44 ++++++++++++++++++++++ .../cottonmc/cotton/gui/widget/WListPanel.java | 21 ++++++----- 2 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java (limited to 'src/main/java/io') 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 new file mode 100644 index 0000000..342ba33 --- /dev/null +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java @@ -0,0 +1,44 @@ +package io.github.cottonmc.cotton.gui.widget; + +import org.lwjgl.opengl.GL11; + +import com.mojang.blaze3d.systems.RenderSystem; + +import io.github.cottonmc.cotton.gui.client.ScreenDrawing; +import net.minecraft.util.Identifier; + +public class WClippedPanel extends WPanel { + protected Identifier mask; + + public WClippedPanel setClippingMask(Identifier mask) { + this.mask = mask; + return this; + } + + @Override + public void paintBackground(int x, int y, int mouseX, int mouseY) { + if (getBackgroundPainter()!=null) getBackgroundPainter().paintBackground(x, y, this); + + RenderSystem.translatef(0, 0, 10); + //RenderSystem.depthFunc(GL11.GL_LEQUAL); + //RenderSystem.disableDepthTest(); + + + RenderSystem.colorMask(false, false, false, true); + if (mask!=null) { + ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), mask, 0xFFFFFFFF); + } else { + ScreenDrawing.coloredRect(x, y, getWidth(), getHeight(), 0xFFFFFFFF); + } + RenderSystem.colorMask(true, true, true, true); + + for(WWidget child : children) { + RenderSystem.enableDepthTest(); + RenderSystem.depthFunc(GL11.GL_GEQUAL); + child.paintBackground(x + child.getX(), y + child.getY(), mouseX-child.getX(), mouseY-child.getY()); + } + RenderSystem.translated(0, 0, -10); + RenderSystem.depthFunc(GL11.GL_LEQUAL); + RenderSystem.disableDepthTest(); + } +} diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java index 155f979..75e337d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WListPanel.java @@ -15,7 +15,7 @@ import io.github.cottonmc.cotton.gui.client.ScreenDrawing; * D's *must* have working equals and hashCode methods to distinguish them from each other! *

W is the WWidget class that will represent a single D of data. */ -public class WListPanel extends WPanel { +public class WListPanel extends WClippedPanel { protected List data; protected Class listItemClass; protected Supplier supplier; @@ -41,20 +41,24 @@ public class WListPanel extends WPanel { @Override public void paintBackground(int x, int y, int mouseX, int mouseY) { + if (scrollBar.getValue()!=lastScroll) { + layout(); + lastScroll = scrollBar.getValue(); + } + + super.paintBackground(x, y, mouseX, mouseY); + /* if (getBackgroundPainter()!=null) { getBackgroundPainter().paintBackground(x, y, this); } else { ScreenDrawing.drawBeveledPanel(x, y, width, height); } - if (scrollBar.getValue()!=lastScroll) { - layout(); - lastScroll = scrollBar.getValue(); - } + for(WWidget child : children) { child.paintBackground(x + child.getX(), y + child.getY(), mouseX - child.getX(), mouseY - child.getY()); - } + }*/ } @Override @@ -87,7 +91,6 @@ public class WListPanel extends WPanel { if (!exemplar.canResize()) cellHeight = exemplar.getHeight(); } } - System.out.println("CellHeight: "+cellHeight); if (cellHeight<4) cellHeight=4; int layoutHeight = this.getHeight()-(margin*2); @@ -110,7 +113,7 @@ public class WListPanel extends WPanel { int presentCells = Math.min(data.size()-scrollOffset, cellsHigh); if (presentCells>0) { - for(int i=0; i=data.size()) break; if (index<0) continue; //THIS IS A THING THAT IS HAPPENING >:( @@ -131,7 +134,7 @@ public class WListPanel extends WPanel { w.setSize(this.width-(margin*2) - scrollBar.getWidth(), cellHeight); } w.x = margin; - w.y = margin + (cellHeight * i); + w.y = margin + ((cellHeight+margin) * i); this.children.add(w); } } -- cgit