aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuz <6596629+Juuxel@users.noreply.github.com>2023-09-09 22:19:41 +0300
committerJuuz <6596629+Juuxel@users.noreply.github.com>2023-09-09 22:19:41 +0300
commit8d1d2442866b3bb3a4b1d098add0ccb65343cd60 (patch)
tree108321f7ade793c93f231eaba6761929942169e2
parent510906753e5f0d94681ac23932926f82a94532a8 (diff)
downloadLibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.tar.gz
LibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.tar.bz2
LibGui-8d1d2442866b3bb3a4b1d098add0ccb65343cd60.zip
Move scroll bar textures to GUI sprites
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/impl/client/WidgetTextures.java19
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java39
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png)bin165 -> 165 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png)bin159 -> 159 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png)bin156 -> 156 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png)bin164 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png)bin164 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png)bin164 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png)bin162 -> 162 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png)bin164 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png.mcmeta10
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png (renamed from src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png)bin161 -> 161 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png.mcmeta10
20 files changed, 120 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();
- }
}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png
index 3df12e3..3df12e3 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_dark.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png
index 38c6ef8..38c6ef8 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/background_light.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png
index 955aa7e..955aa7e 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/focus.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png
index 4c2aab0..4c2aab0 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_dark.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png
index 472db90..472db90 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_dark.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png
index b0695ed..b0695ed 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_hovered_light.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png
index 6d802e7..6d802e7 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_light.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png
index 8835712..8835712 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_dark.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png
index 9df19b0..9df19b0 100644
--- a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png.mcmeta b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png.mcmeta
new file mode 100644
index 0000000..731ee64
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/gui/sprites/widget/scroll_bar/thumb_pressed_light.png.mcmeta
@@ -0,0 +1,10 @@
+{
+ "gui": {
+ "scaling": {
+ "type": "nine_slice",
+ "width": 16,
+ "height": 16,
+ "border": 1
+ }
+ }
+}