Skip to content

Commit a3ab7aa

Browse files
committed
Begin work on Scrollbar functionality
1 parent 12259ff commit a3ab7aa

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

src/main/java/btw/lowercase/optiboxes/screen/DebugScreen.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import btw.lowercase.optiboxes.screen.widget.Gidget;
44
import net.minecraft.client.gui.GuiGraphics;
55
import net.minecraft.client.gui.screens.Screen;
6+
import net.minecraft.client.input.KeyEvent;
67
import net.minecraft.client.input.MouseButtonEvent;
78
import net.minecraft.network.chat.Component;
89
import org.jetbrains.annotations.NotNull;
@@ -53,6 +54,21 @@ public void mouseMoved(double mouseX, double mouseY) {
5354
super.mouseMoved(mouseX, mouseY);
5455
}
5556

57+
@Override
58+
public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, double scrollY) {
59+
return super.mouseScrolled(mouseX, mouseY, scrollX, scrollY);
60+
}
61+
62+
@Override
63+
public boolean keyPressed(@NotNull KeyEvent event) {
64+
return super.keyPressed(event);
65+
}
66+
67+
@Override
68+
public boolean keyReleased(@NotNull KeyEvent event) {
69+
return super.keyReleased(event);
70+
}
71+
5672
@Override
5773
public void onClose() {
5874
this.minecraft.setScreen(this.parent);

src/main/java/btw/lowercase/optiboxes/screen/widget/Gidget.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public void onMouseMove(double mouseX, double mouseY) {
3131
public void onMouseClicked(double mouseX, double mouseY) {
3232
}
3333

34+
public void onMouseScrolled(double amount) {
35+
}
36+
37+
public void onKeyDown(int scancode, int keycode) {
38+
}
39+
40+
public void onKeyUp(int scancode, int keycode) {
41+
}
42+
3443
public boolean isInside(double x, double y) {
3544
return (x >= this.x && x <= this.x + this.width) && (y >= this.y && y <= this.y + this.height);
3645
}

src/main/java/btw/lowercase/optiboxes/screen/widget/ScrollableList.java

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
public class ScrollableList extends Gidget {
99
private final List<Gidget> gidgets;
10-
private double scrollY;
10+
private final Scrollbar scrollbar;
1111

1212
public ScrollableList(List<Gidget> gidgets, int x, int y, int width, int height) {
1313
super(x, y, width, height);
1414
this.gidgets = gidgets;
15-
this.scrollY = 0.0F;
15+
this.scrollbar = new Scrollbar(width - Scrollbar.DEFAULT_WIDTH - 8, y, height);
1616
for (Gidget gidget : this.gidgets) {
1717
gidget.reposition(this.x() + gidget.x(), this.y() + gidget.y() + 4);
1818
}
@@ -21,6 +21,7 @@ public ScrollableList(List<Gidget> gidgets, int x, int y, int width, int height)
2121
@Override
2222
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
2323
this.renderBackground(guiGraphics);
24+
this.scrollbar.render(guiGraphics, mouseX, mouseY);
2425
guiGraphics.enableScissor(this.x(), this.y(), this.x() + this.width(), this.y() + this.height());
2526
for (Gidget gidget : this.gidgets) {
2627
gidget.render(guiGraphics, mouseX, mouseY);
@@ -43,6 +44,10 @@ public void onMouseMove(double mouseX, double mouseY) {
4344
gidget.onMouseMove(mouseX, mouseY);
4445
}
4546
}
47+
48+
if (this.scrollbar.isInside(mouseX, mouseY)) {
49+
this.scrollbar.onMouseMove(mouseX, mouseY);
50+
}
4651
}
4752

4853
@Override
@@ -53,5 +58,64 @@ public void onMouseClicked(double mouseX, double mouseY) {
5358
gidget.onMouseClicked(mouseX, mouseY);
5459
}
5560
}
61+
62+
if (this.scrollbar.isInside(mouseX, mouseY)) {
63+
this.scrollbar.onMouseClicked(mouseX, mouseY);
64+
}
65+
}
66+
67+
private static class Scrollbar extends Gidget {
68+
public static final int DEFAULT_WIDTH = 10;
69+
private final Knob knob;
70+
private double scrollY;
71+
72+
protected Scrollbar(int x, int y, int height) {
73+
super(x, y, DEFAULT_WIDTH, height);
74+
this.knob = new Knob(x, y, Knob.DEFAULT_HEIGHT);
75+
this.scrollY = 0.0;
76+
}
77+
78+
@Override
79+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
80+
this.renderBackground(guiGraphics);
81+
this.knob.render(guiGraphics, mouseX, mouseY);
82+
}
83+
84+
@Override
85+
public void renderBackground(GuiGraphics guiGraphics) {
86+
guiGraphics.fill(this.x(), this.y(), this.x() + this.width(), this.y() + this.height(), ARGB.color(0.5F, 0x00FF95));
87+
}
88+
89+
@Override
90+
public void onMouseClicked(double mouseX, double mouseY) {
91+
super.onMouseClicked(mouseX, mouseY);
92+
}
93+
94+
@Override
95+
public void onMouseMove(double mouseX, double mouseY) {
96+
super.onMouseMove(mouseX, mouseY);
97+
}
98+
99+
public double getScrollY() {
100+
return this.scrollY;
101+
}
102+
103+
private class Knob extends Gidget {
104+
public static final int DEFAULT_HEIGHT = 30;
105+
106+
public Knob(int x, int y, int height) {
107+
super(x, y, Scrollbar.this.width(), height);
108+
}
109+
110+
@Override
111+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY) {
112+
this.renderBackground(guiGraphics);
113+
}
114+
115+
@Override
116+
public void renderBackground(GuiGraphics guiGraphics) {
117+
guiGraphics.fill(this.x(), this.y(), this.x() + this.width(), this.y() + this.height(), ARGB.color(1.0F, 0xAAFE00));
118+
}
119+
}
56120
}
57121
}

0 commit comments

Comments
 (0)