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.properties4
-rw-r--r--src/main/java/io/github/cottonmc/cotton/gui/widget/data/Color.java146
7 files changed, 212 insertions, 18 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 488f62d..39a32c0 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..bb87be7 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -8,11 +8,11 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.6.2+build.166
# Mod Properties
- mod_version = 1.3.3-beta.5
+ mod_version = 1.3.3-beta.6
maven_group = io.github.cottonmc
archives_base_name = LibGui
# 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..3dbbe39 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,104 @@ 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 HSL(int rgb) {
+ float r = i_f(rgb >> 16);
+ float g = i_f(rgb >> 8);
+ float b = i_f(rgb);
+
+ float max = Math.max(r, Math.max(g, b));
+ float min = Math.min(r, Math.min(g, b));
+
+ hue = 0;
+ if (max==min) {
+ hue = 0;
+ } else if (max==r) {
+ hue = (g-b)/(max-min);
+ hue *= 60f/360f;
+ } else if (max==g) {
+ hue = 2 + (b-r)/(max-min);
+ hue *= 60f/360f;
+ } else { //max==b
+ hue = 4 + (r-g)/(max-min);
+ hue *= 60f/360f;
+ }
+ if (hue<0) hue+=1;
+
+ luma = (max+min)/2f;
+
+ sat = 0;
+ if (max==0) {
+ // the saturation of black is zero, special-cased because (0-0)/0 is undefined
+ } else if (min==1) {
+ // the saturation of white is zero: (1-1)/1, special-cased for kicks I guess
+ } else {
+ sat = (max-luma) / Math.min(luma, 1-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 +284,51 @@ 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));
+ }
+
+ private static float i_f(int i) {
+ return (i & 0xFF) / 255f;
+ }
+ }
+
+ 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;
+ }
}
}