diff options
author | Falkreon <falkreon@gmail.com> | 2019-08-30 13:36:57 -0500 |
---|---|---|
committer | Falkreon <falkreon@gmail.com> | 2019-08-30 13:36:57 -0500 |
commit | a018db6c699488aa9b9e392cd4515c97fade095a (patch) | |
tree | c0381c0b56bad5df79865b6d94f05227b74736d2 | |
parent | f31ed14fa9bcd45f1509c709ca51ce3c2aa4b6cf (diff) | |
download | LibGui-a018db6c699488aa9b9e392cd4515c97fade095a.tar.gz LibGui-a018db6c699488aa9b9e392cd4515c97fade095a.tar.bz2 LibGui-a018db6c699488aa9b9e392cd4515c97fade095a.zip |
Implement panel clipping
3 files changed, 58 insertions, 10 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 d1b8bca..4c16b81 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 @@ -23,7 +23,7 @@ public class TestClientGui extends LightweightGuiDescription { @Environment(EnvType.CLIENT) public static final BackgroundPainter PANEL = (x, y, panel)->{ - ScreenDrawing.drawBeveledPanel(x, y, panel.getWidth(), panel.getHeight()); + ScreenDrawing.drawBeveledPanel(x-1, y-1, panel.getWidth()+2, panel.getHeight()+2); }; private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png"); @@ -69,6 +69,7 @@ public class TestClientGui extends LightweightGuiDescription { }; WListPanel<String, PortalDestination> list = new WListPanel<String, PortalDestination>(data, PortalDestination.class, PortalDestination::new, configurator); list.setListItemHeight(2*18); + list.setBackgroundPainter(PANEL); root.add(list, 0, 2, 7, 6); root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1); 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! * <p> W is the WWidget class that will represent a single D of data. */ -public class WListPanel<D, W extends WWidget> extends WPanel { +public class WListPanel<D, W extends WWidget> extends WClippedPanel { protected List<D> data; protected Class<W> listItemClass; protected Supplier<W> supplier; @@ -41,20 +41,24 @@ public class WListPanel<D, W extends WWidget> 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<D, W extends WWidget> 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<D, W extends WWidget> extends WPanel { int presentCells = Math.min(data.size()-scrollOffset, cellsHigh); if (presentCells>0) { - for(int i=0; i<presentCells; i++) { + for(int i=0; i<presentCells+1; i++) { int index = i+scrollOffset; if (index>=data.size()) break; if (index<0) continue; //THIS IS A THING THAT IS HAPPENING >:( @@ -131,7 +134,7 @@ public class WListPanel<D, W extends WWidget> 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); } } |