Started work on the GuiContainer implementation
This commit is contained in:
parent
21386d3703
commit
3139dff800
|
@ -4,7 +4,6 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
import speiger.src.collections.floats.lists.FloatList;
|
import speiger.src.collections.floats.lists.FloatList;
|
||||||
import speiger.src.coreengine.math.MathUtils;
|
|
||||||
|
|
||||||
public class ColorUtils {
|
public class ColorUtils {
|
||||||
static final float DEVIDER = 1F / 255F;
|
static final float DEVIDER = 1F / 255F;
|
||||||
|
@ -71,7 +70,7 @@ public class ColorUtils {
|
||||||
list.add(((color >> 16) & 0xFF) * DEVIDER);
|
list.add(((color >> 16) & 0xFF) * DEVIDER);
|
||||||
list.add(((color >> 8) & 0xFF) * DEVIDER);
|
list.add(((color >> 8) & 0xFF) * DEVIDER);
|
||||||
list.add((color & 0xFF) * DEVIDER);
|
list.add((color & 0xFF) * DEVIDER);
|
||||||
if(alpha) { list.add(((color >> 24) & 0xFF) * DEVIDER); }
|
if(alpha) list.add(((color >> 24) & 0xFF) * DEVIDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int read(ByteBuffer buffer, boolean alpha) { return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
public static int read(ByteBuffer buffer, boolean alpha) { return alpha ? rgb(buffer.get(), buffer.get(), buffer.get()) : rgb(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
|
||||||
|
@ -92,76 +91,6 @@ public class ColorUtils {
|
||||||
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | b & 0xFF;
|
return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | b & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int darker(int color) { return darker(color, 0.7F); }
|
|
||||||
public static int darker(int color, float factor) {
|
|
||||||
int r = Math.max(0, (int)(((color >> 16) & 0xFF) * factor));
|
|
||||||
int g = Math.max(0, (int)(((color >> 8) & 0xFF) * factor));
|
|
||||||
int b = Math.max(0, (int)((color & 0xFF) * factor));
|
|
||||||
return (color & A) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int brighter(int color) { return brighter(color, 0.7F); }
|
|
||||||
public static int brighter(int color, float factor) {
|
|
||||||
int r = (color >> 16) & 0xFF;
|
|
||||||
int g = (color >> 8) & 0xFF;
|
|
||||||
int b = color & 0xFF;
|
|
||||||
int i = (int)(1.0 / (1.0 - factor));
|
|
||||||
if(r == 0 && g == 0 && b == 0) { return (color & A) | ((i & 0xFF) << 16) | ((i & 0xFF) << 8) | (i & 0xFF); }
|
|
||||||
if(r > 0 && r < i) r = i;
|
|
||||||
if(g > 0 && g < i) g = i;
|
|
||||||
if(b > 0 && b < i) b = i;
|
|
||||||
return (color & A) | Math.min(255, (int)(r / factor)) << 16 | Math.min(255, (int)(g / factor)) << 8 | Math.min(255, (int)(b / factor));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int toRGB(float hue, float saturation, float brightness) {
|
|
||||||
if(saturation == 0) {
|
|
||||||
int result = (int)(brightness * 255F + 0.5F);
|
|
||||||
return rgb(result, result, result);
|
|
||||||
}
|
|
||||||
float h = (hue - MathUtils.floor(hue)) * 6F;
|
|
||||||
float f = h - MathUtils.floor(h);
|
|
||||||
float p = brightness * (1F - saturation);
|
|
||||||
float q = brightness * (1F - saturation * f);
|
|
||||||
float t = brightness * (1F - (saturation * (1F - f)));
|
|
||||||
switch((int)h) {
|
|
||||||
case 0: return rgb(brightness, t, p);
|
|
||||||
case 1: return rgb(q, brightness, p);
|
|
||||||
case 2: return rgb(p, brightness, t);
|
|
||||||
case 3: return rgb(p, q, brightness);
|
|
||||||
case 4: return rgb(t, p, brightness);
|
|
||||||
case 5: return rgb(brightness, p, q);
|
|
||||||
default: return BLACK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] toHue(int rgba) {
|
|
||||||
int r = getR(rgba);
|
|
||||||
int g = getG(rgba);
|
|
||||||
int b = getB(rgba);
|
|
||||||
int cmax = (r > g) ? r : g;
|
|
||||||
if(b > cmax) cmax = b;
|
|
||||||
int cmin = (r < g) ? r : g;
|
|
||||||
if(b < cmin) cmin = b;
|
|
||||||
float length = cmax - cmin;
|
|
||||||
|
|
||||||
float[] result = new float[3];
|
|
||||||
result[1] = cmax == 0 ? 0F : length / cmax;
|
|
||||||
result[2] = cmax * DEVIDER;
|
|
||||||
float hue = 0F;
|
|
||||||
if(result[1] != 0F) {
|
|
||||||
float redc = (cmax - r) / length;
|
|
||||||
float greenc = (cmax - g) / length;
|
|
||||||
float bluec = (cmax - b) / length;
|
|
||||||
if(r == cmax) hue = bluec - greenc;
|
|
||||||
else if(g == cmax) hue = 2F + redc - bluec;
|
|
||||||
else hue = 4F + greenc - redc;
|
|
||||||
hue /= 6F;
|
|
||||||
if(hue < 0) hue += 1F;
|
|
||||||
}
|
|
||||||
result[0] = hue;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int rgb(int rgb) { return rgb | (255 << 24); }
|
public static int rgb(int rgb) { return rgb | (255 << 24); }
|
||||||
public static int rgb(int r, int g, int b) { return A | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF); }
|
public static int rgb(int r, int g, int b) { return A | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF); }
|
||||||
public static int rgb(float r, float g, float b) { return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F)); }
|
public static int rgb(float r, float g, float b) { return rgb((int)(r * 255F + 0.5F), (int)(g * 255F + 0.5F), (int)(b * 255F + 0.5F)); }
|
||||||
|
|
|
@ -166,6 +166,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
||||||
public IComponentScreen screen() { return screen; }
|
public IComponentScreen screen() { return screen; }
|
||||||
@Override
|
@Override
|
||||||
public IGuiBox getBox() { return box; }
|
public IGuiBox getBox() { return box; }
|
||||||
|
public IInteractable interactContainer() { return interactions; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuiComponent set(float x, float y) {
|
public GuiComponent set(float x, float y) {
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package speiger.src.coreengine.rendering.gui.components.base;
|
package speiger.src.coreengine.rendering.gui.components.base;
|
||||||
|
|
||||||
|
import speiger.src.coreengine.rendering.gui.layout.constraints.ConstraintContainer;
|
||||||
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||||
|
|
||||||
public interface IComponentScreen {
|
public interface IComponentScreen {
|
||||||
public IGuiBox getBox();
|
public IGuiBox getBox();
|
||||||
public long clock();
|
public long clock();
|
||||||
|
|
||||||
|
public void pushLayer();
|
||||||
|
public void popLayer();
|
||||||
|
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints);
|
||||||
|
public boolean removeComponent(GuiComponent component);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.screen;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.sets.IntOpenHashSet;
|
||||||
|
import speiger.src.collections.ints.sets.IntSet;
|
||||||
|
import speiger.src.collections.objects.lists.ObjectArrayList;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectIterables;
|
||||||
|
import speiger.src.collections.objects.utils.ObjectIterators;
|
||||||
|
import speiger.src.coreengine.rendering.gui.components.base.GuiComponent;
|
||||||
|
import speiger.src.coreengine.rendering.gui.components.base.IComponentScreen;
|
||||||
|
import speiger.src.coreengine.rendering.gui.components.base.IInteractable;
|
||||||
|
import speiger.src.coreengine.rendering.gui.components.base.IInteractableContainer;
|
||||||
|
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||||
|
|
||||||
|
public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
|
LayeredContainer container = new LayeredContainer();
|
||||||
|
IntSet activeButtons = new IntOpenHashSet();
|
||||||
|
IInteractable focused;
|
||||||
|
IGuiBox box = IGuiBox.of(0F, 0F, 0F, 0F);
|
||||||
|
long tick;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IGuiBox getBox() { return box; }
|
||||||
|
@Override
|
||||||
|
public long clock() { return tick; }
|
||||||
|
@Override
|
||||||
|
public boolean isFocused() { return focused != null; }
|
||||||
|
@Override
|
||||||
|
public void setFocused(boolean value) { if(!value) setFocusedChild(null); }
|
||||||
|
@Override
|
||||||
|
public List<? extends IInteractable> getChildren() { return container.interactables(); }
|
||||||
|
@Override
|
||||||
|
public void setFocusedChild(IInteractable child) {
|
||||||
|
if(focused != null) focused.setFocused(false);
|
||||||
|
this.focused = child;
|
||||||
|
if(focused != null) focused.setFocused(true);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public IInteractable getFocusedChild() { return focused; }
|
||||||
|
@Override
|
||||||
|
public IntSet getActiveButtons() { return activeButtons; }
|
||||||
|
|
||||||
|
public static class LayeredContainer {
|
||||||
|
List<List<GuiComponent>> components = new ObjectArrayList<>();
|
||||||
|
List<List<IInteractable>> interactables = new ObjectArrayList<>();
|
||||||
|
int layer = -1;
|
||||||
|
|
||||||
|
public LayeredContainer() { pushLayer(); }
|
||||||
|
|
||||||
|
public void pushLayer() {
|
||||||
|
layer++;
|
||||||
|
components.add(new ObjectArrayList<>());
|
||||||
|
interactables.add(new ObjectArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void popLayer() {
|
||||||
|
if(layer == 0) return;
|
||||||
|
layer--;
|
||||||
|
components.removeLast();
|
||||||
|
interactables.removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(GuiComponent component) {
|
||||||
|
children().add(component);
|
||||||
|
interactables().add(component.interactContainer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GuiComponent> children() {
|
||||||
|
return components.get(layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<IInteractable> interactables() {
|
||||||
|
return interactables.get(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import java.util.function.Supplier;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import speiger.src.coreengine.math.MathUtils;
|
import speiger.src.coreengine.math.MathUtils;
|
||||||
import speiger.src.coreengine.math.misc.ColorUtils;
|
import speiger.src.coreengine.math.misc.ColorSpaces;
|
||||||
import speiger.src.coreengine.rendering.guiOld.GuiComponent;
|
import speiger.src.coreengine.rendering.guiOld.GuiComponent;
|
||||||
import speiger.src.coreengine.rendering.guiOld.renderer.buffer.RenderBuffer;
|
import speiger.src.coreengine.rendering.guiOld.renderer.buffer.RenderBuffer;
|
||||||
import speiger.src.coreengine.rendering.tesselationOld.Tesselator;
|
import speiger.src.coreengine.rendering.tesselationOld.Tesselator;
|
||||||
|
@ -106,7 +106,7 @@ public class PieComponent extends GuiComponent
|
||||||
IPieIndex pieIndex = indexes.get(j);
|
IPieIndex pieIndex = indexes.get(j);
|
||||||
int steps = j == 0 ? maxSteps - stepsDone : pieIndex.getSteps();
|
int steps = j == 0 ? maxSteps - stepsDone : pieIndex.getSteps();
|
||||||
int color = pieIndex.getColor();
|
int color = pieIndex.getColor();
|
||||||
int darker = ColorUtils.darker(color);
|
int darker = ColorSpaces.ABGR.darker(color);
|
||||||
tes.offset(0F, 0F, 0.01F);
|
tes.offset(0F, 0F, 0.01F);
|
||||||
for(int i = 0;i<steps;i++)
|
for(int i = 0;i<steps;i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.awt.Color;
|
||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
|
|
||||||
import speiger.src.coreengine.math.MathUtils;
|
import speiger.src.coreengine.math.MathUtils;
|
||||||
|
import speiger.src.coreengine.math.misc.ColorSpaces;
|
||||||
import speiger.src.coreengine.math.misc.ColorUtils;
|
import speiger.src.coreengine.math.misc.ColorUtils;
|
||||||
import speiger.src.coreengine.math.misc.Facing;
|
import speiger.src.coreengine.math.misc.Facing;
|
||||||
import speiger.src.coreengine.math.vector.floats.Vec2f;
|
import speiger.src.coreengine.math.vector.floats.Vec2f;
|
||||||
|
@ -42,7 +43,7 @@ public class ColorPickerWindowComponent extends WindowComponent
|
||||||
super(x, y, 125, 140, FIXED_SIZE_POPUP, name);
|
super(x, y, 125, 140, FIXED_SIZE_POPUP, name);
|
||||||
this.pool = pool;
|
this.pool = pool;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
hsv = ColorUtils.toHue(defaultColor);
|
hsv = ColorSpaces.ABGR.toHue(defaultColor);
|
||||||
colorBoxes = new IGuiBox[Math.min(18, pool.size())];
|
colorBoxes = new IGuiBox[Math.min(18, pool.size())];
|
||||||
for(int i = 0,m=colorBoxes.length;i<m;i++)
|
for(int i = 0,m=colorBoxes.length;i<m;i++)
|
||||||
{
|
{
|
||||||
|
@ -141,11 +142,11 @@ public class ColorPickerWindowComponent extends WindowComponent
|
||||||
hsv[0] = MathUtils.clamp(0F, 1F, hue);
|
hsv[0] = MathUtils.clamp(0F, 1F, hue);
|
||||||
hsv[1] = MathUtils.clamp(0F, 1F, saturation);
|
hsv[1] = MathUtils.clamp(0F, 1F, saturation);
|
||||||
hsv[2] = MathUtils.clamp(0F, 1F, brightness);
|
hsv[2] = MathUtils.clamp(0F, 1F, brightness);
|
||||||
colors[0] = ColorUtils.toRGB(hsv[0], 0F, 1F);
|
colors[0] = ColorSpaces.ABGR.fromHue(hsv[0], 0F, 1F);
|
||||||
colors[1] = ColorUtils.toRGB(hsv[0], 1F, 1F);
|
colors[1] = ColorSpaces.ABGR.fromHue(hsv[0], 1F, 1F);
|
||||||
colors[2] = ColorUtils.toRGB(hsv[0], 1F, 0F);
|
colors[2] = ColorSpaces.ABGR.fromHue(hsv[0], 1F, 0F);
|
||||||
colors[3] = ColorUtils.toRGB(hsv[0], 1F, 1F);
|
colors[3] = ColorSpaces.ABGR.fromHue(hsv[0], 1F, 1F);
|
||||||
colors[4] = ColorUtils.toRGB(hsv[0], hsv[1], hsv[2]);
|
colors[4] = ColorSpaces.ABGR.fromHue(hsv[0], hsv[1], hsv[2]);
|
||||||
code.setText(ColorUtils.toHTML(colors[4], false));
|
code.setText(ColorUtils.toHTML(colors[4], false));
|
||||||
this.brightness.setValue((int)(hsv[2] * 100F));
|
this.brightness.setValue((int)(hsv[2] * 100F));
|
||||||
this.saturation.setValue((int)(hsv[1] * 100F));
|
this.saturation.setValue((int)(hsv[1] * 100F));
|
||||||
|
|
|
@ -3,7 +3,6 @@ package speiger.src.coreengine.rendering.input.window;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
|
|
||||||
public record VideoMode(int width, int height, int redBits, int greenBits, int blueBits, int refreshrate) {
|
public record VideoMode(int width, int height, int redBits, int greenBits, int blueBits, int refreshrate) {
|
||||||
|
|
||||||
public VideoMode(GLFWVidMode buffer) {
|
public VideoMode(GLFWVidMode buffer) {
|
||||||
this(buffer.width(), buffer.height(), buffer.redBits(), buffer.greenBits(), buffer.blueBits(), buffer.refreshRate());
|
this(buffer.width(), buffer.height(), buffer.redBits(), buffer.greenBits(), buffer.blueBits(), buffer.refreshRate());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue