From 015010a85fe2b6b705f961faa82cf10796b9dcf2 Mon Sep 17 00:00:00 2001 From: Juuxel <6596629+Juuxel@users.noreply.github.com> Date: Thu, 23 Jan 2020 22:54:11 +0200 Subject: Add nine-patch painter for panels --- .../cotton/gui/CottonCraftingController.java | 2 +- .../cotton/gui/client/BackgroundPainter.java | 23 +++++++++++++++++++++ .../gui/client/LightweightGuiDescription.java | 2 +- .../assets/libgui/textures/widget/panel_dark.png | Bin 0 -> 1644 bytes .../assets/libgui/textures/widget/panel_light.png | Bin 0 -> 650 bytes 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/assets/libgui/textures/widget/panel_dark.png create mode 100644 src/main/resources/assets/libgui/textures/widget/panel_light.png 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 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 @@ -30,6 +30,24 @@ public interface BackgroundPainter { ScreenDrawing.drawGuiPanel(left-8, top-8, panel.getWidth()+16, panel.getHeight()+16); }; + /** + * The {@code VANILLA_9PATCH} background painter draws a vanilla-like gui panel using nine-patch textures. + * + *

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. + * + *

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. + * + *

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. */ @@ -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 { * {@link Mode#STRETCHING stretching} | {@link Mode#TILING tiling} * * + * + * @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 Binary files /dev/null and b/src/main/resources/assets/libgui/textures/widget/panel_dark.png 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 Binary files /dev/null and b/src/main/resources/assets/libgui/textures/widget/panel_light.png differ -- cgit