aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuuxel <kasperi.kauppi@gmail.com>2019-08-28 19:07:35 +0300
committerJuuxel <kasperi.kauppi@gmail.com>2019-08-28 19:07:35 +0300
commitdc70d8fbdc98a3f09dc9fb2477dc2210b8f82a25 (patch)
treeb4e9ebd0e0e0d8e0cc5fff42b9d8bc56bdf4c0a8 /src
parentdbc6d43b92c7032fa989ee99415d64f28ae6ca97 (diff)
downloadLibGui-dc70d8fbdc98a3f09dc9fb2477dc2210b8f82a25.tar.gz
LibGui-dc70d8fbdc98a3f09dc9fb2477dc2210b8f82a25.tar.bz2
LibGui-dc70d8fbdc98a3f09dc9fb2477dc2210b8f82a25.zip
Move thumb painting code to paintBg, remove fake mouse events
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java60
2 files changed, 26 insertions, 38 deletions
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java
index 1b5bf42..9a95405 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/client/modmenu/ConfigGui.java
@@ -27,8 +27,8 @@ public class ConfigGui extends LightweightGuiDescription {
WTextField testField = new WTextField();
testField.setSuggestion("test");
root.add(testField, 0, 3, 4, 1);
- root.add(new WSlider(50, 100, Axis.VERTICAL).setValueChangeListener(System.out::println), 6, 0, 1, 3);
- root.add(new WSlider(0, 123, Axis.HORIZONTAL).setValueChangeListener(System.out::println), 1, 4, 4, 1);
+ root.add(new WSlider(-150, -123, Axis.VERTICAL).setValueChangeListener(System.out::println), 6, 0, 1, 3);
+ root.add(new WSlider(-150, -123, Axis.HORIZONTAL).setValueChangeListener(System.out::println), 1, 4, 4, 1);
root.add(new WKirbSprite(), 5, 4);
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java
index d475fe4..d253cea 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/WSlider.java
@@ -4,10 +4,8 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
import io.github.cottonmc.cotton.gui.client.ScreenDrawing;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
-import org.lwjgl.glfw.GLFW;
import javax.annotation.Nullable;
import java.util.function.IntConsumer;
@@ -118,60 +116,38 @@ public class WSlider extends WWidget {
@Environment(EnvType.CLIENT)
@Override
- public void paintBackground(int x, int y) {
+ public void paintBackground(int x, int y, int mouseX, int mouseY) {
if (backgroundPainter != null) {
backgroundPainter.paintBackground(x, y, this);
} else {
float px = 1 / 32f;
+ int thumbX, thumbY, thumbXOffset;
if (axis == Axis.VERTICAL) {
int trackX = x + width / 2 - TRACK_WIDTH / 2;
+ thumbX = x + width / 2 - THUMB_SIZE / 2;
+ thumbY = y + height - THUMB_SIZE + 1 - (int) (coordToValueRatio * (value - min));
+ thumbXOffset = 0;
ScreenDrawing.rect(TEXTURE, trackX, y + 1, TRACK_WIDTH, 1, 16*px, 0*px, 22*px, 1*px, 0xFFFFFFFF);
ScreenDrawing.rect(TEXTURE, trackX, y + 2, TRACK_WIDTH, height - 2, 16*px, 1*px, 22*px, 2*px, 0xFFFFFFFF);
ScreenDrawing.rect(TEXTURE, trackX, y + height, TRACK_WIDTH, 1, 16*px, 2*px, 22*px, 3*px, 0xFFFFFFFF);
} else {
int trackY = y + height / 2 - TRACK_WIDTH / 2;
+ thumbX = x + (int) (coordToValueRatio * (value - min));
+ thumbY = y + height / 2 - THUMB_SIZE / 2;
+ thumbXOffset = 8;
ScreenDrawing.rect(TEXTURE, x, trackY, 1, TRACK_WIDTH, 16*px, 3*px, 17*px, 9*px, 0xFFFFFFFF);
ScreenDrawing.rect(TEXTURE, x + 1, trackY, width - 2, TRACK_WIDTH, 17*px, 3*px, 18*px, 9*px, 0xFFFFFFFF);
ScreenDrawing.rect(TEXTURE, x + width - 1, trackY, 1, TRACK_WIDTH, 18*px, 3*px, 19*px, 9*px, 0xFFFFFFFF);
}
- }
- }
- @Environment(EnvType.CLIENT)
- @Override
- public void paintForeground(int x, int y, int mouseX, int mouseY) {
- float px = 1 / 32f;
- int thumbX, thumbY, thumbXOffset;
-
- if (axis == Axis.VERTICAL) {
- thumbX = x + width / 2 - THUMB_SIZE / 2;
- thumbY = y + height - THUMB_SIZE + 1 - (int) (coordToValueRatio * (value - min));
- thumbXOffset = 0;
- } else {
- thumbX = x + (int) (coordToValueRatio * (value - min));
- thumbY = y + height / 2 - THUMB_SIZE / 2;
- thumbXOffset = 8;
- }
-
- boolean dragging = isFocused();
- // TODO: Replace with proper mouse events
- if (dragging) {
- if (GLFW.glfwGetMouseButton(MinecraftClient.getInstance().window.getHandle(), GLFW.GLFW_MOUSE_BUTTON_1) == GLFW.GLFW_PRESS) {
- onMouseDrag(mouseX - x, mouseY - y, 0);
- } else {
- onMouseUp(mouseX - x, mouseY - y, 0);
- }
+ // thumbState values:
+ // 0: default, 1: dragging, 2: hovered
+ int thumbState = isFocused() ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0);
+ ScreenDrawing.rect(TEXTURE, thumbX, thumbY, THUMB_SIZE, THUMB_SIZE, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF);
}
-
- // thumbState values:
- // 0: default, 1: dragging, 2: hovered
- int thumbState = dragging ? 1 : (mouseX >= thumbX && mouseX <= thumbX + THUMB_SIZE && mouseY >= thumbY && mouseY <= thumbY + THUMB_SIZE ? 2 : 0);
- ScreenDrawing.rect(TEXTURE, thumbX, thumbY, THUMB_SIZE, THUMB_SIZE, thumbXOffset*px, 0*px + thumbState * 8*px, (thumbXOffset + 8)*px, 8*px + thumbState * 8*px, 0xFFFFFFFF);
-
- super.paintForeground(x, y, mouseX, mouseY);
}
public int getValue() {
@@ -192,6 +168,18 @@ public class WSlider extends WWidget {
return this;
}
+ public int getMinValue() {
+ return min;
+ }
+
+ public int getMaxValue() {
+ return max;
+ }
+
+ public Axis getAxis() {
+ return axis;
+ }
+
@Environment(EnvType.CLIENT)
public void setBackgroundPainter(BackgroundPainter backgroundPainter) {
this.backgroundPainter = backgroundPainter;