Progress on Guis and start on Fontrendering
This commit is contained in:
parent
94f371b4a3
commit
c01d317fdb
|
@ -51,7 +51,6 @@ public class GuiAnimator implements ObjectFloatConsumer<Target> {
|
||||||
heightDiff = 0F;
|
heightDiff = 0F;
|
||||||
scaleDiff = 1F;
|
scaleDiff = 1F;
|
||||||
changeState = 0;
|
changeState = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply() {
|
public void apply() {
|
||||||
|
|
|
@ -102,17 +102,21 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiComponent addChild(GuiComponent child) { return addChild(child, null); }
|
public GuiComponent withConstraints(ConstraintContainer container) {
|
||||||
|
this.constraints = container;
|
||||||
|
if((screen != null || parent != null) && constraints != null) constraints.apply(this, parent);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public GuiComponent addChild(GuiComponent child, ConstraintContainer constraints) {
|
public GuiComponent addChild(GuiComponent child) {
|
||||||
if(child.parent != null) throw new IllegalArgumentException("A Child can not have multiple parents");
|
if(child.parent != null) throw new IllegalArgumentException("A Child can not have multiple parents");
|
||||||
child.constraints = constraints;
|
|
||||||
child.parent = this;
|
child.parent = this;
|
||||||
children.add(child);
|
children.add(child);
|
||||||
box.addChild(child.getBox());
|
box.addChild(child.getBox());
|
||||||
interactions.add(child.interactions);
|
interactions.add(child.interactions);
|
||||||
child.screen = screen;
|
child.setScreen(screen);
|
||||||
child.init();
|
child.init();
|
||||||
|
child.onChanged(true);
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,6 +128,7 @@ public abstract non-sealed class GuiComponent extends FlagObject implements ICas
|
||||||
if(child.parent != this) throw new IllegalArgumentException("Child isn't owned by this Component");
|
if(child.parent != this) throw new IllegalArgumentException("Child isn't owned by this Component");
|
||||||
child.close();
|
child.close();
|
||||||
child.parent = null;
|
child.parent = null;
|
||||||
|
child.screen = null;
|
||||||
children.remove(child);
|
children.remove(child);
|
||||||
box.removeChild(child.getBox());
|
box.removeChild(child.getBox());
|
||||||
interactions.remove(child.interactions);
|
interactions.remove(child.interactions);
|
||||||
|
|
|
@ -10,5 +10,6 @@ public interface IComponentScreen {
|
||||||
public void pushLayer();
|
public void pushLayer();
|
||||||
public void popLayer();
|
public void popLayer();
|
||||||
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints);
|
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints);
|
||||||
|
public boolean hasComponent(GuiComponent component);
|
||||||
public boolean removeComponent(GuiComponent component);
|
public boolean removeComponent(GuiComponent component);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.font;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import speiger.src.collections.ints.maps.impl.hash.Int2ObjectOpenHashMap;
|
||||||
|
import speiger.src.collections.ints.maps.interfaces.Int2ObjectMap;
|
||||||
|
import speiger.src.coreengine.assets.AssetLocation;
|
||||||
|
import speiger.src.coreengine.rendering.gui.font.glyth.Glyth;
|
||||||
|
import speiger.src.coreengine.rendering.gui.font.glyth.GlythData;
|
||||||
|
import speiger.src.coreengine.rendering.gui.font.providers.IFontProvider;
|
||||||
|
|
||||||
|
public class FontGroup {
|
||||||
|
private static final int BOLD_FLAG = 1<<31;
|
||||||
|
AssetLocation locations;
|
||||||
|
List<IFontProvider> providers;
|
||||||
|
Int2ObjectMap<Glyth> bakedGlyths = new Int2ObjectOpenHashMap<>();
|
||||||
|
Int2ObjectMap<GlythData> dataGlyths = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
public FontGroup(AssetLocation locations, List<IFontProvider> providers) {
|
||||||
|
this.locations = locations;
|
||||||
|
this.providers = providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlythData data(int codepoint) {
|
||||||
|
return dataGlyths.computeIfAbsent(codepoint, this::compute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Glyth glyth(int codepoint, boolean bold) {
|
||||||
|
return bakedGlyths.computeIfAbsent(codepoint | (bold ? 0 : BOLD_FLAG), this::bake);
|
||||||
|
}
|
||||||
|
|
||||||
|
private GlythData compute(int codepoint) {
|
||||||
|
for(int i = 0,m=providers.size();i<m;i++) {
|
||||||
|
GlythData data = providers.get(i).glythData(codepoint);
|
||||||
|
if(data != null) return data;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Glyth bake(int codepoint) {
|
||||||
|
boolean bold = (codepoint & BOLD_FLAG) != 0;
|
||||||
|
codepoint &= ~BOLD_FLAG;
|
||||||
|
for(int i = 0,m=providers.size();i<m;i++) {
|
||||||
|
GlythData data = providers.get(i).glythData(codepoint);
|
||||||
|
if(data != null) return data.bake(bold);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.font;
|
||||||
|
|
||||||
|
public class FontManager {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.font.glyth;
|
||||||
|
|
||||||
|
public record Glyth(int texture, boolean bold, float minU, float minV, float maxU, float maxV) {}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.font.glyth;
|
||||||
|
|
||||||
|
public interface GlythData {
|
||||||
|
public float advance(boolean bold);
|
||||||
|
public Glyth bake(boolean bold);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package speiger.src.coreengine.rendering.gui.font.providers;
|
||||||
|
|
||||||
|
import speiger.src.coreengine.rendering.gui.font.glyth.GlythData;
|
||||||
|
|
||||||
|
public interface IFontProvider {
|
||||||
|
public GlythData glythData(int codepoint);
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ 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.IInteractable;
|
||||||
import speiger.src.coreengine.rendering.gui.components.base.IInteractableContainer;
|
import speiger.src.coreengine.rendering.gui.components.base.IInteractableContainer;
|
||||||
import speiger.src.coreengine.rendering.gui.layout.constraints.ConstraintContainer;
|
import speiger.src.coreengine.rendering.gui.layout.constraints.ConstraintContainer;
|
||||||
|
import speiger.src.coreengine.rendering.gui.renderer.IUIRenderer;
|
||||||
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
import speiger.src.coreengine.rendering.guiOld.helper.box.IGuiBox;
|
||||||
|
|
||||||
public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
|
@ -50,20 +51,42 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
public void popLayer() { container.popLayer(); }
|
public void popLayer() { container.popLayer(); }
|
||||||
@Override
|
@Override
|
||||||
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints) {
|
public GuiComponent addComponent(GuiComponent component, ConstraintContainer constraints) {
|
||||||
//TODO change constraints
|
if(component.screen() != null) throw new IllegalArgumentException("A Child can not have multiple Screens");
|
||||||
container.add(component);
|
container.add(component);
|
||||||
component.setScreen(this);
|
component.setScreen(this);
|
||||||
component.init();
|
component.init();
|
||||||
|
component.onChanged(true);
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasComponent(GuiComponent component) {
|
||||||
|
return component.screen() == this && container.contains(component);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeComponent(GuiComponent component) {
|
public boolean removeComponent(GuiComponent component) {
|
||||||
return container.removeChild(component);
|
if(component.screen() == this && container.remove(component)) {
|
||||||
|
component.close();
|
||||||
|
component.setScreen(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void render(IUIRenderer renderer, int mouseX, int mouseY, float partialTicks) {
|
||||||
|
for(Object2BooleanMap.Entry<GuiComponent> entry : container) {
|
||||||
|
boolean keepMouse = entry.getBooleanValue();
|
||||||
|
GuiComponent.renderComponent(entry.getKey(), renderer, keepMouse ? mouseX : -1, keepMouse ? mouseY : -1, partialTicks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tick() {
|
||||||
|
for(Object2BooleanMap.Entry<GuiComponent> entry : container) {
|
||||||
|
entry.getKey().updateComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class LayeredContainer implements Iterable<Object2BooleanMap.Entry<GuiComponent>> {
|
public static class LayeredContainer implements Iterable<Object2BooleanMap.Entry<GuiComponent>> {
|
||||||
List<List<GuiComponent>> components = new ObjectArrayList<>();
|
List<List<GuiComponent>> components = new ObjectArrayList<>();
|
||||||
List<List<IInteractable>> interactables = new ObjectArrayList<>();
|
List<List<IInteractable>> interactables = new ObjectArrayList<>();
|
||||||
|
@ -89,8 +112,15 @@ public class GuiContainer implements IComponentScreen, IInteractableContainer {
|
||||||
interactables().add(component.interactContainer());
|
interactables().add(component.interactContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeChild(GuiComponent component) {
|
public boolean contains(GuiComponent component) {
|
||||||
for(int i = components.size()-1;i>=0;i--) {
|
for(int i = layer;i>=0;i--) {
|
||||||
|
if(components.get(i).contains(component)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean remove(GuiComponent component) {
|
||||||
|
for(int i = layer;i>=0;i--) {
|
||||||
if(components.get(i).remove(component)) {
|
if(components.get(i).remove(component)) {
|
||||||
interactables.get(i).remove(component.interactContainer());
|
interactables.get(i).remove(component.interactContainer());
|
||||||
clearEmptyLayers();
|
clearEmptyLayers();
|
||||||
|
|
Loading…
Reference in New Issue