diff options
Diffstat (limited to 'src')
7 files changed, 116 insertions, 9 deletions
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 ac6271d..fe2a743 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 @@ -13,11 +13,44 @@ import net.minecraft.util.Identifier; import javax.annotation.Nullable; +/** + * A bar that displays int values from a {@link PropertyDelegate}. + * + * <p>Bars can be used for all kinds of bars including + * progress bars (and progress arrows) and energy bars. + */ public class WBar extends WWidget { + /** + * The background texture. If not null, it will be + * drawn behind the bar contents. + */ protected final Identifier bg; + + /** + * The bar texture. If not null, it will be + * drawn to represent the current field. + */ protected final Identifier bar; + + /** + * The ID of the displayed property in the {@link #properties}. + */ protected final int field; + + /** + * The ID of the property representing the maximum value of the {@link #field}. + * + * <p>If {@code max} is 0, the {@link #maxValue} constant will be used instead. + */ protected final int max; + + /** + * The constant maximum value of the {@link #field}. + * + * <p>This constant will only be used if {@link #max} is 0. + * + * @see #withConstantMaximum(Identifier, Identifier, int, int, Direction) + */ protected int maxValue; protected PropertyDelegate properties; protected final Direction direction; @@ -40,10 +73,11 @@ public class WBar extends WWidget { /** * Adds a tooltip to the WBar. * - * Formatting Guide: The tooltip label is passed into String.Format and can recieve two integers + * Formatting Guide: The tooltip label is passed into {@code String.format} and can receive two integers * (%d) - the first is the current value of the bar's focused field, and the second is the * bar's focused maximum. - * @param label String to render on the tooltip. + * + * @param label Translation key of the string to render on the tooltip. * @return WBar with tooltip enabled and set. */ public WBar withTooltip(String label) { diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java index 191e7ef..ae8766e 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WClippedPanel.java @@ -5,6 +5,9 @@ import org.lwjgl.opengl.GL11; import net.minecraft.client.MinecraftClient; import net.minecraft.util.Identifier; +/** + * A panel that is clipped to only render widgets inside its bounds. + */ public class WClippedPanel extends WPanel { @Deprecated protected Identifier mask; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java index 61adddf..3082389 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WGridPanel.java @@ -1,11 +1,37 @@ package io.github.cottonmc.cotton.gui.widget; +/** + * A panel that positions children in a grid. + */ public class WGridPanel extends WPanel { + /** + * The grid size in pixels. + * Defaults to 18, which is the size of one item slot. + */ protected int grid = 18; - + + /** + * Constructs a grid panel with the default grid size. + */ public WGridPanel() {} + + /** + * Constructs a grid panel with a custom grid size. + * + * @param gridSize the grid size in pixels + */ public WGridPanel(int gridSize) { this.grid = gridSize; } - + + /** + * Adds a widget to this panel. + * + * <p>If the widget {@linkplain WWidget#canResize() can be resized}, + * it will be resized to ({@link #grid}, {@link #grid}). + * + * @param w the widget + * @param x the X position in grid cells + * @param y the Y position in grid cells + */ public void add(WWidget w, int x, int y) { children.add(w); w.parent = this; @@ -16,7 +42,16 @@ public class WGridPanel extends WPanel { expandToFit(w); } - + + /** + * Adds a widget to this panel and resizes it to a custom size. + * + * @param w the widget + * @param x the X position in grid cells + * @param y the Y position in grid cells + * @param width the new width in grid cells + * @param height the new height in grid cells + */ public void add(WWidget w, int x, int y, int width, int height) { children.add(w); w.parent = this; diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java index 7e227f7..1233d7d 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPanel.java @@ -51,7 +51,12 @@ public abstract class WPanel extends WWidget { expandToFit(child); } } - + + /** + * Expands this panel be at least as large as the widget. + * + * @param w the widget + */ protected void expandToFit(WWidget w) { int pushRight = w.getX()+w.getWidth(); int pushDown = w.getY()+w.getHeight(); diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java index 310ae69..aba2da5 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WPlainPanel.java @@ -1,6 +1,19 @@ package io.github.cottonmc.cotton.gui.widget; +/** + * A panel that positions children by pixel-perfect positions. + */ public class WPlainPanel extends WPanel { + /** + * Adds a new widget to this panel. + * + * <p>If the widget {@linkplain WWidget#canResize() can be resized}, + * it will be resized to (18, 18). + * + * @param w the widget + * @param x the X position + * @param y the Y position + */ public void add(WWidget w, int x, int y) { children.add(w); w.parent = this; @@ -13,6 +26,15 @@ public class WPlainPanel extends WPanel { //valid = false; } + /** + * Adds a new widget to this panel and resizes it to a custom size. + * + * @param w the widget + * @param x the X position + * @param y the Y position + * @param width the new width + * @param height the new height + */ public void add(WWidget w, int x, int y, int width, int height) { children.add(w); w.parent = this; 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 7f7dc84..0d67d00 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 @@ -13,10 +13,18 @@ public class WScrollBar extends WWidget { protected int anchor = -1; protected int anchorValue = -1; protected boolean sliding = false; - + + /** + * Constructs a horizontal scroll bar. + */ public WScrollBar() { } - + + /** + * Constructs a scroll bar with a custom axis. + * + * @param axis the axis + */ public WScrollBar(Axis axis) { this.axis = axis; } 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 364761d..d666fc2 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 @@ -116,7 +116,7 @@ public class WSprite extends WWidget { @Override public void paintBackground(int x, int y) { if (singleImage) { - ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), frames[0], tint); + ScreenDrawing.texturedRect(x, y, getWidth(), getHeight(), frames[0], u1, v1, u2, v2, tint); } else { //grab the system time at the very start of the frame. long now = System.nanoTime() / 1_000_000L; |