aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJuuxel <6596629+Juuxel@users.noreply.github.com>2020-01-23 22:54:11 +0200
committerJuuxel <6596629+Juuxel@users.noreply.github.com>2020-01-23 22:54:11 +0200
commit015010a85fe2b6b705f961faa82cf10796b9dcf2 (patch)
treed7ba395f7f1ac72602074a245e6460d901998e16 /src/main
parent72790c3bb6094a99d1258ccf1fec6f1c5581550d (diff)
downloadLibGui-015010a85fe2b6b705f961faa82cf10796b9dcf2.tar.gz
LibGui-015010a85fe2b6b705f961faa82cf10796b9dcf2.tar.bz2
LibGui-015010a85fe2b6b705f961faa82cf10796b9dcf2.zip
Add nine-patch painter for panels
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/BackgroundPainter.java23
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java2
-rw-r--r--src/main/resources/assets/libgui/textures/widget/panel_dark.pngbin0 -> 1644 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/panel_light.pngbin0 -> 650 bytes
5 files changed, 25 insertions, 2 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java
index 54038ec..8524afb 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/CottonCraftingController.java
@@ -83,7 +83,7 @@ public class CottonCraftingController extends CraftingContainer<Inventory> imple
@Environment(EnvType.CLIENT)
public void addPainters() {
if (this.rootPanel!=null) {
- this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA);
+ this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA_9PATCH);
}
}
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 24cf6ab..48b9834 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
@@ -31,6 +31,24 @@ public interface BackgroundPainter {
};
/**
+ * The {@code VANILLA_9PATCH} background painter draws a vanilla-like gui panel using nine-patch textures.
+ *
+ * <p>This background painter uses {@code libgui:textures/widget/panel_light.png} as the light texture and
+ * {@code libgui:textures/widget/panel_dark.png} as the dark texture.
+ *
+ * <p>This background painter is the default painter for root panels.
+ * You can override {@link io.github.cottonmc.cotton.gui.GuiDescription#addPainters()} to customize the painter yourself.
+ *
+ * <p>This background painter applies a padding of 8 pixels to all sides around the widget.
+ *
+ * @since 1.5.0
+ */
+ public static BackgroundPainter VANILLA_9PATCH = createLightDarkVariants(
+ createNinePatch(new Identifier("libgui", "textures/widget/panel_light.png"), 8),
+ createNinePatch(new Identifier("libgui", "textures/widget/panel_dark.png"), 8)
+ );
+
+ /**
* The {@code SLOT} background painter draws item slots or slot-like widgets.
*/
public static BackgroundPainter SLOT = (left, top, panel) -> {
@@ -92,6 +110,7 @@ public interface BackgroundPainter {
*
* @param texture the background painter texture
* @return a new nine-patch background painter
+ * @since 1.5.0
*/
public static BackgroundPainter.NinePatch createNinePatch(Identifier texture) {
return new NinePatch(texture);
@@ -105,6 +124,7 @@ public interface BackgroundPainter {
* @param texture the background painter texture
* @param padding the padding of the painter
* @return a new nine-patch background painter
+ * @since 1.5.0
*/
public static BackgroundPainter.NinePatch createNinePatch(Identifier texture, int padding) {
return new NinePatch(texture).setPadding(padding);
@@ -117,6 +137,7 @@ public interface BackgroundPainter {
* @param light the light mode background painter
* @param dark the dark mode background painter
* @return a new background painter that chooses between the two inputs
+ * @since 1.5.0
*/
public static BackgroundPainter createLightDarkVariants(BackgroundPainter light, BackgroundPainter dark) {
return (left, top, panel) -> {
@@ -154,6 +175,8 @@ public interface BackgroundPainter {
* <td>{@link Mode#STRETCHING stretching} | {@link Mode#TILING tiling}</td>
* </tr>
* </table>
+ *
+ * @since 1.5.0
*/
public static class NinePatch implements BackgroundPainter {
private final Identifier texture;
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java
index 6284c2f..078b390 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/LightweightGuiDescription.java
@@ -45,7 +45,7 @@ public class LightweightGuiDescription implements GuiDescription {
@Override
public void addPainters() {
if (this.rootPanel!=null) {
- this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA);
+ this.rootPanel.setBackgroundPainter(BackgroundPainter.VANILLA_9PATCH);
}
}
diff --git a/src/main/resources/assets/libgui/textures/widget/panel_dark.png b/src/main/resources/assets/libgui/textures/widget/panel_dark.png
new file mode 100644
index 0000000..c4e643f
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/panel_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/panel_light.png b/src/main/resources/assets/libgui/textures/widget/panel_light.png
new file mode 100644
index 0000000..8bb50a8
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/panel_light.png
Binary files differ