aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLopyMine <127966446+LopyMine@users.noreply.github.com>2023-09-09 18:52:08 +0500
committerGitHub <noreply@github.com>2023-09-09 16:52:08 +0300
commitcc01e089d361f56382eb43560aee952674211dd2 (patch)
treed19318599d6467395bd576e0df0f4946e23e56c0 /src/main
parent54ad50bc3499a4b489801c15a540917f74878e74 (diff)
downloadLibGui-cc01e089d361f56382eb43560aee952674211dd2.tar.gz
LibGui-cc01e089d361f56382eb43560aee952674211dd2.tar.bz2
LibGui-cc01e089d361f56382eb43560aee952674211dd2.zip
Paint WScrollBar using textures (#212)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WScrollBar.java89
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.pngbin0 -> 165 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.pngbin0 -> 159 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.pngbin0 -> 156 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.pngbin0 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.pngbin0 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.pngbin0 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.pngbin0 -> 162 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.pngbin0 -> 164 bytes
-rw-r--r--src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.pngbin0 -> 161 bytes
10 files changed, 40 insertions, 49 deletions
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 0846d68..2b7bb0c 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
@@ -5,11 +5,17 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.gui.DrawContext;
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.ScreenDrawing;
+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.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 int SCROLLING_SPEED = 4;
@@ -41,63 +47,40 @@ public class WScrollBar extends WWidget {
@Environment(EnvType.CLIENT)
@Override
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
+ var matrices = context.getMatrices();
boolean darkMode = shouldRenderInDarkMode();
- if (darkMode) {
- ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_212121, 0xFF_2F2F2F, 0xFF_5D5D5D);
- } else {
- ScreenDrawing.drawBeveledPanel(context, x, y, width, height, 0xFF_373737, 0xFF_8B8B8B, 0xFF_FFFFFF);
- }
- if (maxValue<=0) return;
+ Painters.BACKGROUND.paintBackground(context, x, y, this);
+
+ NinePatch<Identifier> painter = (darkMode ? Painters.SCROLL_BAR_DARK : Painters.SCROLL_BAR);
- // Handle colors
- int top, middle, bottom;
+ if (maxValue <= 0) return;
if (sliding) {
- if (darkMode) {
- top = 0xFF_6C6C6C;
- middle = 0xFF_2F2F2F;
- bottom = 0xFF_212121;
- } else {
- top = 0xFF_FFFFFF;
- middle = 0xFF_8B8B8B;
- bottom = 0xFF_555555;
- }
+ painter = (darkMode ? Painters.SCROLL_BAR_PRESSED_DARK : Painters.SCROLL_BAR_PRESSED);
} else if (isWithinBounds(mouseX, mouseY)) {
- if (darkMode) {
- top = 0xFF_5F6A9D;
- middle = 0xFF_323F6E;
- bottom = 0xFF_0B204A;
- } else {
- top = 0xFF_CFD0F7;
- middle = 0xFF_8791C7;
- bottom = 0xFF_343E75;
- }
- } else {
- if (darkMode) {
- top = 0xFF_6C6C6C;
- middle = 0xFF_414141;
- bottom = 0xFF_212121;
- } else {
- top = 0xFF_FFFFFF;
- middle = 0xFF_C6C6C6;
- bottom = 0xFF_555555;
- }
+ painter = (darkMode ? Painters.SCROLL_BAR_HOVERED_DARK : Painters.SCROLL_BAR_HOVERED);
}
- if (axis==Axis.HORIZONTAL) {
- ScreenDrawing.drawBeveledPanel(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, top, middle, bottom);
+ matrices.push();
+
+ if (axis == Axis.HORIZONTAL) {
+ matrices.translate(x + 1 + getHandlePosition(), y + 1, 0);
+ painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2);
if (isFocused()) {
- drawBeveledOutline(context, x+1+getHandlePosition(), y+1, getHandleSize(), height-2, 0xFF_FFFFA7, 0xFF_8C8F39);
+ Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, getHandleSize(), height - 2);
}
} else {
- ScreenDrawing.drawBeveledPanel(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), top, middle, bottom);
+ matrices.translate(x + 1, y + 1 + getHandlePosition(), 0);
+ painter.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize());
if (isFocused()) {
- drawBeveledOutline(context, x+1, y+1+getHandlePosition(), width-2, getHandleSize(), 0xFF_FFFFA7, 0xFF_8C8F39);
+ Painters.FOCUS.draw(NinePatchTextureRendererImpl.INSTANCE, context, width - 2, getHandleSize());
}
}
+
+ matrices.pop();
}
@Override
@@ -110,13 +93,6 @@ public class WScrollBar extends WWidget {
return true;
}
- private static void drawBeveledOutline(DrawContext context, int x, int y, int width, int height, int topleft, int bottomright) {
- ScreenDrawing.coloredRect(context, x, y, width, 1, topleft); //Top shadow
- ScreenDrawing.coloredRect(context, x, y + 1, 1, height - 1, topleft); //Left shadow
- ScreenDrawing.coloredRect(context, x + width - 1, y + 1, 1, height - 1, bottomright); //Right hilight
- ScreenDrawing.coloredRect(context, x + 1, y + height - 1, width - 1, 1, bottomright); //Bottom hilight
- }
-
/**
* Gets the on-axis size of the scrollbar handle in gui pixels
*/
@@ -279,4 +255,19 @@ 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/widget/scroll_bar/background_dark.png
new file mode 100644
index 0000000..3df12e3
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png
new file mode 100644
index 0000000..38c6ef8
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/background_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png
new file mode 100644
index 0000000..955aa7e
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/focus.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png
new file mode 100644
index 0000000..4c2aab0
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png
new file mode 100644
index 0000000..472db90
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png
new file mode 100644
index 0000000..b0695ed
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_hovered_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png
new file mode 100644
index 0000000..6d802e7
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_light.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png
new file mode 100644
index 0000000..8835712
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_dark.png
Binary files differ
diff --git a/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png
new file mode 100644
index 0000000..9df19b0
--- /dev/null
+++ b/src/main/resources/assets/libgui/textures/widget/scroll_bar/scroll_bar_pressed_light.png
Binary files differ