diff options
author | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 22:19:41 +0300 |
---|---|---|
committer | Juuz <6596629+Juuxel@users.noreply.github.com> | 2023-09-09 22:19:41 +0300 |
commit | 8d1d2442866b3bb3a4b1d098add0ccb65343cd60 (patch) | |
tree | 108321f7ade793c93f231eaba6761929942169e2 /src/main/java | |
parent | 510906753e5f0d94681ac23932926f82a94532a8 (diff) | |
download | LibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.tar.gz LibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.tar.bz2 LibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.zip |
Move scroll bar textures to GUI sprites
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java | 19 | ||||
-rw-r--r-- | src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java | 39 |
2 files changed, 30 insertions, 28 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java index 86a2630..fd5a806 100644 --- a/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java +++ b/src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java @@ -22,6 +22,18 @@ public final class WidgetTextures { id("widget/button_disabled_dark"), id("widget/button_highlighted_dark") ); + private static final ScrollBarTextures LIGHT_SCROLL_BAR = new ScrollBarTextures( + id("widget/scroll_bar/background_light"), + id("widget/scroll_bar/thumb_light"), + id("widget/scroll_bar/thumb_pressed_light"), + id("widget/scroll_bar/thumb_hovered_light") + ); + private static final ScrollBarTextures DARK_SCROLL_BAR = new ScrollBarTextures( + id("widget/scroll_bar/background_dark"), + id("widget/scroll_bar/thumb_dark"), + id("widget/scroll_bar/thumb_pressed_dark"), + id("widget/scroll_bar/thumb_hovered_dark") + ); public static ButtonTextures getButtonTextures(boolean dark) { return dark ? DARK_BUTTON : PressableWidgetAccessor.libgui$getTextures(); @@ -31,7 +43,14 @@ public final class WidgetTextures { return dark ? DARK_LABELED_SLIDER_HANDLE : LIGHT_LABELED_SLIDER_HANDLE; } + public static ScrollBarTextures getScrollBarTextures(boolean dark) { + return dark ? DARK_SCROLL_BAR : LIGHT_SCROLL_BAR; + } + private static Identifier id(String path) { return new Identifier(LibGuiCommon.MOD_ID, path); } + + public record ScrollBarTextures(Identifier background, Identifier thumb, Identifier thumbPressed, Identifier thumbHovered) { + } } 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 a0c04be..add8688 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 @@ -7,17 +7,14 @@ import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.screen.narration.NarrationPart; import net.minecraft.util.Identifier; -import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.impl.LibGuiCommon; import io.github.cottonmc.cotton.gui.impl.client.NarrationMessages; -import io.github.cottonmc.cotton.gui.impl.client.NinePatchTextureRendererImpl; +import io.github.cottonmc.cotton.gui.impl.client.WidgetTextures; import io.github.cottonmc.cotton.gui.widget.data.Axis; import io.github.cottonmc.cotton.gui.widget.data.InputResult; -import juuxel.libninepatch.NinePatch; - -import static io.github.cottonmc.cotton.gui.client.BackgroundPainter.createNinePatch; public class WScrollBar extends WWidget { + private static final Identifier FOCUS_TEXTURE = new Identifier(LibGuiCommon.MOD_ID, "widget/scroll_bar/focus"); private static final int SCROLLING_SPEED = 4; protected Axis axis = Axis.HORIZONTAL; @@ -49,34 +46,35 @@ public class WScrollBar extends WWidget { public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) { var matrices = context.getMatrices(); boolean darkMode = shouldRenderInDarkMode(); + var textures = WidgetTextures.getScrollBarTextures(darkMode); - Painters.BACKGROUND.paintBackground(context, x, y, this); + context.drawGuiTexture(textures.background(), x, y, getWidth(), getHeight()); - NinePatch<Identifier> painter = (darkMode ? Painters.SCROLL_BAR_DARK : Painters.SCROLL_BAR); + Identifier thumbTexture = textures.thumb(); if (maxValue <= 0) return; if (sliding) { - painter = (darkMode ? Painters.SCROLL_BAR_PRESSED_DARK : Painters.SCROLL_BAR_PRESSED); + thumbTexture = textures.thumbPressed(); } else if (isWithinBounds(mouseX, mouseY)) { - painter = (darkMode ? Painters.SCROLL_BAR_HOVERED_DARK : Painters.SCROLL_BAR_HOVERED); + thumbTexture = textures.thumbHovered(); } matrices.push(); if (axis == Axis.HORIZONTAL) { matrices.translate(x + 1 + getHandlePosition(), y + 1, 0); - painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2); + context.drawGuiTexture(thumbTexture, 0, 0, getHandleSize(), getHeight() - 2); if (isFocused()) { - Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2); + context.drawGuiTexture(FOCUS_TEXTURE, 0, 0, getHandleSize(), getHeight() - 2); } } else { matrices.translate(x + 1, y + 1 + getHandlePosition(), 0); - painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize()); + context.drawGuiTexture(thumbTexture, 0, 0, getWidth() - 2, getHandleSize()); if (isFocused()) { - Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize()); + context.drawGuiTexture(FOCUS_TEXTURE, 0, 0, getWidth() - 2, getHandleSize()); } } @@ -255,19 +253,4 @@ public class WScrollBar extends WWidget { builder.put(NarrationPart.TITLE, NarrationMessages.SCROLL_BAR_TITLE); builder.put(NarrationPart.USAGE, NarrationMessages.SLIDER_USAGE); } - - @Environment(EnvType.CLIENT) - static final class Painters { - static final NinePatch<Identifier> SCROLL_BAR = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_light.png")).cornerSize(4).cornerUv(0.25f).build(); - static final NinePatch<Identifier> SCROLL_BAR_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_dark.png")).cornerSize(4).cornerUv(0.25f).build(); - static final NinePatch<Identifier> SCROLL_BAR_PRESSED = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_pressed_light.png")).cornerSize(4).cornerUv(0.25f).build(); - static final NinePatch<Identifier> SCROLL_BAR_PRESSED_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_pressed_dark.png")).cornerSize(4).cornerUv(0.25f).build(); - static final NinePatch<Identifier> SCROLL_BAR_HOVERED = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_hovered_light.png")).cornerSize(4).cornerUv(0.25f).build(); - static final NinePatch<Identifier> SCROLL_BAR_HOVERED_DARK = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/scroll_bar_hovered_dark.png")).cornerSize(4).cornerUv(0.25f).build(); - static final BackgroundPainter BACKGROUND = BackgroundPainter.createLightDarkVariants( - createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/background_light.png")), - createNinePatch(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/background_dark.png")) - ); - static final NinePatch<Identifier> FOCUS = NinePatch.builder(new Identifier(LibGuiCommon.MOD_ID, "textures/widget/scroll_bar/focus.png")).cornerSize(4).cornerUv(0.25f).build(); - } } |