aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--GuiTest/build.gradle9
-rw-r--r--GuiTest/gradle.properties2
-rw-r--r--GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java63
-rw-r--r--GuiTest/src/main/resources/fabric.mod.json2
-rw-r--r--build.gradle4
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java107
7 files changed, 172 insertions, 17 deletions
diff --git a/GuiTest/build.gradle b/GuiTest/build.gradle
index 1d08396..849cf3e 100644
--- a/GuiTest/build.gradle
+++ b/GuiTest/build.gradle
@@ -5,7 +5,7 @@ buildscript {
}
plugins {
- id 'fabric-loom' version '0.2.4-SNAPSHOT'
+ id 'fabric-loom' version '0.2.5-SNAPSHOT'
}
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -36,13 +36,14 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modApi "net.fabricmc:fabric-loader:${project.loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
- modApi "io.github.cottonmc:Jankson:${project.jankson_version}"
- include "io.github.cottonmc:Jankson:${project.jankson_version}"
+ modApi "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
+ include "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
compileOnly ("com.google.code.findbugs:jsr305:3.0.2") { transitive = false }
- modApi ("io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2")// { transitive = false }
+ //modApi ("io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2")// { transitive = false }
+ modCompileOnly "io.github.prospector:modmenu:1.7.10-unstable.19w35a+build.2"
//modApi ("io.github.cottonmc:LibGui:1.3.1-SNAPSHOT") { changing = true }
compile (project(":LibGUI")) { transitive = false };
runtime (project(":LibGUI")) { transitive = false };
diff --git a/GuiTest/gradle.properties b/GuiTest/gradle.properties
index 9ae5f8f..921cf11 100644
--- a/GuiTest/gradle.properties
+++ b/GuiTest/gradle.properties
@@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1G
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
fabric_version=0.3.2+build.230-1.15
- jankson_version=1.0.0+j1.1.2
+ jankson_version=2.0.0+j1.2.0
diff --git a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
index 4c16b81..e1e23d5 100644
--- a/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
+++ b/GuiTest/src/main/java/io/github/cottonmc/test/client/TestClientGui.java
@@ -12,8 +12,12 @@ import io.github.cottonmc.cotton.gui.widget.WGridPanel;
import io.github.cottonmc.cotton.gui.widget.WLabel;
import io.github.cottonmc.cotton.gui.widget.WListPanel;
import io.github.cottonmc.cotton.gui.widget.WPlainPanel;
+import io.github.cottonmc.cotton.gui.widget.WSlider;
import io.github.cottonmc.cotton.gui.widget.WSprite;
import io.github.cottonmc.cotton.gui.widget.WTextField;
+import io.github.cottonmc.cotton.gui.widget.WWidget;
+import io.github.cottonmc.cotton.gui.widget.data.Axis;
+import io.github.cottonmc.cotton.gui.widget.data.Color;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.text.LiteralText;
@@ -26,8 +30,12 @@ public class TestClientGui extends LightweightGuiDescription {
ScreenDrawing.drawBeveledPanel(x-1, y-1, panel.getWidth()+2, panel.getHeight()+2);
};
- private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png");
- private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png");
+ //private static final Identifier PORTAL1 = new Identifier("libgui-test:portal.png");
+ //private static final Identifier PORTAL2 = new Identifier("libgui-test:portal2.png");
+
+ private int r = 0;
+ private int g = 0;
+ private int b = 0;
public TestClientGui() {
WGridPanel root = new WGridPanel(22);
@@ -45,7 +53,7 @@ public class TestClientGui extends LightweightGuiDescription {
text.setSuggestion("Search");
root.add(text, 0, 1, 8, 1);
text.setSize(7*18, 20);
-
+ /*
ArrayList<String> data = new ArrayList<>();
data.add("Wolfram Alpha");
data.add("Strange Home");
@@ -72,11 +80,35 @@ public class TestClientGui extends LightweightGuiDescription {
list.setBackgroundPainter(PANEL);
root.add(list, 0, 2, 7, 6);
- root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1);
+ root.add(new WButton(new LiteralText("Teleport")), 3,8,4,1);*/
+ WColorBox col = new WColorBox();
+ root.add(col, 3,2,1,3);
+
+ WSlider r = new WSlider(0, 100, Axis.VERTICAL);
+ root.add(r, 0, 2, 1, 3);
+ r.setValueChangeListener((i)->{
+ this.r = i;
+ updateCol(col);
+ System.out.println("h: "+this.r+" s: "+this.g+ " l: "+this.b);
+ System.out.println("col is now "+Integer.toHexString(col.color));
+ });
+ WSlider g = new WSlider(0, 100, Axis.VERTICAL);
+ root.add(g, 1, 2, 1, 3);
+ g.setValueChangeListener((i)->{
+ this.g = i;
+ updateCol(col);
+ });
+ WSlider b = new WSlider(0, 100, Axis.VERTICAL);
+ root.add(b, 2, 2, 1, 3);
+ b.setValueChangeListener((i)->{
+ this.b = i;
+ updateCol(col);
+ });
+
root.validate(this);
}
-
+ /*
public static class PortalDestination extends WPlainPanel {
WSprite sprite;
WLabel label;
@@ -94,6 +126,27 @@ public class TestClientGui extends LightweightGuiDescription {
this.setBackgroundPainter(PANEL); //Would fail on a serverside gui
}
+ }*/
+
+ private void updateCol(WColorBox col) {
+ Color.HSL hsl = new Color.HSL(r/100f, g/100f, b/100f);
+ col.setColor(hsl.toRgb());
+ }
+
+ public static class WColorBox extends WWidget {
+ protected int color = 0xFF_FFFFFF;
+ public WColorBox() {}
+
+ public void setColor(int col) {
+ this.color = col;
+ }
+
+ @Override
+ public void paintBackground(int x, int y, int mouseX, int mouseY) {
+ super.paintBackground(x, y, mouseX, mouseY);
+
+ ScreenDrawing.coloredRect(x, y, this.getWidth(), this.getHeight(), color);
+ }
}
}
diff --git a/GuiTest/src/main/resources/fabric.mod.json b/GuiTest/src/main/resources/fabric.mod.json
index df68f07..b514f2b 100644
--- a/GuiTest/src/main/resources/fabric.mod.json
+++ b/GuiTest/src/main/resources/fabric.mod.json
@@ -23,7 +23,7 @@
"depends": {
"fabricloader": ">=0.4.0",
"libgui": "*",
- "jankson": "1.0.x",
+ "jankson": "2.x.x",
"fabric": "*"
}
}
diff --git a/build.gradle b/build.gradle
index 1532dec..874b6dd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -54,8 +54,8 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
- modImplementation "io.github.cottonmc:Jankson:${project.jankson_version}"
- include "io.github.cottonmc:Jankson:${project.jankson_version}"
+ modImplementation "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
+ include "io.github.cottonmc:Jankson-Fabric:${project.jankson_version}"
compileOnly ("com.google.code.findbugs:jsr305:3.0.2") { transitive = false }
diff --git a/gradle.properties b/gradle.properties
index 75f7131..08b5f7d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1G
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric
fabric_version=0.3.3+build.235-1.15
- jankson_version=1.0.0+j1.1.2
+ jankson_version=2.0.0+j1.2.0
diff --git a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java
index ec40500..bc985b4 100644
--- a/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java
+++ b/src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java
@@ -173,10 +173,69 @@ public interface Color {
/** HSL Luma, from 0..1 */
private float luma;
+ /**
+ *
+ * @param hue hue angle, between 0 and 1
+ * @param sat saturation, between 0 and 1
+ * @param luma luminance, between 0 and 1
+ */
+ public HSL(float hue, float sat, float luma) {
+ this.hue = hue;
+ this.sat = sat;
+ this.luma = luma;
+ }
+
public int toRgb() {
- float chroma = 1 - (Math.abs(2*luma - 1));
- //TODO: Finish implementing
- return 0;
+ float chroma = (1 - (Math.abs(2*luma - 1))) * sat;
+
+ int h = (int)(hue*6); h %= 6;
+
+ float x = 1f-Math.abs((hue*6 % 2)-1f); x *= chroma;
+ float m = luma - (chroma/2);
+
+ while (h<0) h+=6;
+ if (h>=6) h = h % 6;
+ float rf = 0;
+ float gf = 0;
+ float bf = 0;
+
+ switch(h) {
+ case 0:
+ rf = chroma+m;
+ gf = x+m;
+ bf = 0+m;
+ break;
+ case 1:
+ rf = x+m;
+ gf = chroma+m;
+ bf = 0+m;
+ break;
+ case 2:
+ rf = 0+m;
+ gf = chroma+m;
+ bf = x+m;
+ break;
+ case 3:
+ rf = 0+m;
+ gf = x+m;
+ bf = chroma+m;
+ break;
+ case 4:
+ rf = x+m;
+ gf = 0+m;
+ bf = chroma+m;
+ break;
+ case 5:
+ rf = chroma+m;
+ gf = 0+m;
+ bf = x+m;
+ }
+
+ int r = f_255(rf);
+ int g = f_255(gf);
+ int b = f_255(bf);
+
+ return 0xFF_000000 | (r << 16) | (g << 8) | b;
}
public float getHue() {
@@ -190,5 +249,47 @@ public interface Color {
public float getLuma() {
return luma;
}
+
+ private static int f_255(float f) {
+ int result = (int)(f*255);
+ return Math.min(255,Math.max(0, result));
+ }
+ }
+
+ public static class LCH implements Color {
+ /** HCL Luma, from 0..1 */
+ private float luma;
+ /** HCL Chroma, from 0..1 */
+ private float chroma;
+ /** HCL Hue, from 0..1 */
+ private float hue;
+
+
+
+ public LCH(float luma, float chroma, float hue) {
+ this.luma = luma;
+ this.chroma = chroma;
+ this.hue = hue;
+ }
+
+ @Override
+ public int toRgb() {
+
+
+ //Was going to steal Grondag code but then I looked at it
+ return 0; //TODO: Implement
+ }
+
+ public float getHue() {
+ return hue;
+ }
+
+ public float getChroma() {
+ return chroma;
+ }
+
+ public float getLuma() {
+ return luma;
+ }
}
}