Latest Sync

This commit is contained in:
Speiger 2023-05-19 21:26:57 +02:00
parent c95e7ce20d
commit b42e680b8a
63 changed files with 13681 additions and 12857 deletions

View File

@ -3,7 +3,6 @@ apply plugin: 'eclipse'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.compilerArgs << "-Xlint:deprecation"
}
eclipse {
@ -66,5 +65,5 @@ dependencies {
compile 'com.google.code.gson:gson:2.8.6'
//Primitive Collections
compile 'de.speiger:Primitive-Collections:0.6.1'
compile 'de.speiger:Primitive-Collections:0.7.0'
}

View File

@ -47,6 +47,7 @@ public abstract class GuiComponent extends FlagHolder
public static final int FLAG_SUPPORT_BINDING = 128;
public static final int FLAG_TEST_SCISSORS = 256;
static final int FLAG_CLOSING = 512;
public static final int FLAG_RENDER_BOUNDS = 1024;
public static final int LAST_FLAG = 1 << 19;// This is the last flag and then
// anything behind this is custom
@ -138,10 +139,7 @@ public abstract class GuiComponent extends FlagHolder
public boolean isTopHovered(int mouseX, int mouseY)
{
if(!isHovered(mouseX, mouseY))
{
return false;
}
if(!isHovered(mouseX, mouseY)) return false;
GuiComponent top = getTopComponent();
return !getGui().hasComponentInTheWay(top, mouseX, mouseY) && top.isChildAtTop(this, mouseX, mouseY);
}
@ -309,9 +307,10 @@ public abstract class GuiComponent extends FlagHolder
return this;
}
@SuppressWarnings("unchecked")
public final <T extends GuiComponent> T setMassChanging(Class<T> clz)
{
setFlag(FLAG_MASS_CHANGE);
setMassChanging();
return (T)this;
}
@ -343,6 +342,12 @@ public abstract class GuiComponent extends FlagHolder
return this;
}
public final GuiComponent setRenderBounds()
{
setFlag(FLAG_RENDER_BOUNDS);
return this;
}
public final GuiComponent setVisible(boolean value)
{
if(!setFlag(FLAG_VISIBLE, value)) return this;
@ -438,6 +443,7 @@ public abstract class GuiComponent extends FlagHolder
return this;
}
@SuppressWarnings("unchecked")
public <T extends GuiComponent> GuiComponent setCustomRenderer(IComponentRenderer<T> renderer)
{
customRenderer = (IComponentRenderer<GuiComponent>)renderer;
@ -512,7 +518,7 @@ public abstract class GuiComponent extends FlagHolder
public <T extends GuiComponent> T addPopup(T popup)
{
popupChildren.add(popup.addCloseListener(popupChildren::remove));
popupChildren.add(popup.onClose(popupChildren::remove));
getGui().addComponent(popup);
return popup;
}
@ -527,6 +533,16 @@ public abstract class GuiComponent extends FlagHolder
}
}
protected void updateConstrains(GuiComponent comp, Constrains constrains)
{
comp.constraints = constrains;
if(constrains != null)
{
constrains.setOwner(comp, comp.parent);
constrains.onComponentChanged();
}
}
public final UUID getTooltipId()
{
return tooltipId;
@ -642,32 +658,32 @@ public abstract class GuiComponent extends FlagHolder
return this;
}
public final GuiComponent addUserActionListener(Consumer<GuiComponent> listener)
public final GuiComponent onAction(Consumer<GuiComponent> listener)
{
return addListener(listener, GuiComponent.LISTENER_USER_ACTION);
}
public final GuiComponent addUserActionListener(Runnable listener)
public final GuiComponent onAction(Runnable listener)
{
return addListener(listener, GuiComponent.LISTENER_USER_ACTION);
}
public final GuiComponent addChangeListener(Consumer<GuiComponent> listener)
public final GuiComponent onChange(Consumer<GuiComponent> listener)
{
return addListener(listener, GuiComponent.LISTENER_ON_CHANGE);
}
public final GuiComponent addChangeListener(Runnable listener)
public final GuiComponent onChange(Runnable listener)
{
return addListener(listener, GuiComponent.LISTENER_ON_CHANGE);
}
public final GuiComponent addCloseListener(Consumer<GuiComponent> listener)
public final GuiComponent onClose(Consumer<GuiComponent> listener)
{
return addListener(listener, GuiComponent.LISTENER_CLOSED);
}
public final GuiComponent addCloseListener(Runnable listener)
public final GuiComponent onClose(Runnable listener)
{
return addListener(listener, GuiComponent.LISTENER_CLOSED);
}
@ -919,16 +935,19 @@ public abstract class GuiComponent extends FlagHolder
return animation;
}
@SuppressWarnings("unchecked")
public <T> T cast()
{
return (T)this;
}
@SuppressWarnings("unchecked")
public <T> T cast(Class<T> clz)
{
return (T)this;
}
@SuppressWarnings("unchecked")
public <T> T tryCast(Class<T> clz)
{
return clz.isInstance(this) ? (T)this : null;

View File

@ -238,7 +238,7 @@ public class GuiScreenBase extends GuiBase
public void drawBox(GuiComponent comp)
{
if(!getUIManager().isRenderUIBoxes()) return;
if(!getUIManager().isRenderUIBoxes() && comp.isFlagNotSet(GuiComponent.FLAG_RENDER_BOUNDS)) return;
UIRenderer render = getRenderer();
render.translate(0F, 0F, 100F);
render.drawFrame(comp.getBox(), ColorUtils.RED);

View File

@ -11,13 +11,23 @@ public class ButtonComponent extends GuiComponent implements IButtonComponent
public ButtonComponent(String text, int color)
{
this(0F, 0F, 0F, 0F, text, color);
this(0F, 0F, 0F, 0F, text, color, 1F);
}
public ButtonComponent(String text, int color, float textScale)
{
this(0F, 0F, 0F, 0F, text, color, textScale);
}
public ButtonComponent(float x, float y, float width, float height, String text, int color)
{
this(x, y, width, height, text, color, 1F);
}
public ButtonComponent(float x, float y, float width, float height, String text, int color, float textScale)
{
super(x, y, width, height);
this.text.setText(text);
this.text.setText(text).setTextScale(textScale);
this.color = color;
setFlag(FLAG_SUPPORT_BINDING);
}

View File

@ -44,7 +44,7 @@ public class CheckBoxComponent extends GuiComponent implements IButtonComponent,
@Override
public void init()
{
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
}
@Override

View File

@ -13,10 +13,20 @@ public class LabelComponent extends GuiComponent
this(0F, 0F, 0F, 0F, text, color);
}
public LabelComponent(String text, int color, float textScale)
{
this(0F, 0F, 0F, 0F, text, color, textScale);
}
public LabelComponent(float x, float y, float width, float height, String text, int color)
{
this(x, y, width, height, text, color, 1F);
}
public LabelComponent(float x, float y, float width, float height, String text, int color, float textScale)
{
super(x, y, width, height);
this.text.setText(text);
this.text.setText(text).setTextScale(textScale);
this.color = color;
}

View File

@ -38,8 +38,8 @@ public class ListComponent<T extends IListEntry> extends GuiComponent
public static final int UPDATE_MODE_VISIBLE = 1;
public static final int UPDATE_MODE_ALL = 2;
public static final int FLAG_DISABLE_BACKGROUND = 1024;
public static final int FLAG_START_AT_BOTTOM = 2048;
public static final int FLAG_DISABLE_BACKGROUND = 1 << 20;
public static final int FLAG_START_AT_BOTTOM = 1 << 21;
protected int color;
protected int hoverColor = ColorUtils.LIGHT_GRAY;

View File

@ -4,6 +4,8 @@ import speiger.src.coreengine.rendering.gui.GuiComponent;
public class PanelComponent extends GuiComponent
{
public static final int FLAG_ENABLE_SCISSORS = 1 << 20;
public PanelComponent()
{
super(0F, 0F, 0F, 0F);
@ -18,4 +20,28 @@ public class PanelComponent extends GuiComponent
public void init()
{
}
public PanelComponent setScissors(boolean value)
{
setFlag(FLAG_ENABLE_SCISSORS, value);
return this;
}
public boolean isScissoring()
{
return isFlagSet(FLAG_ENABLE_SCISSORS);
}
@Override
public void renderChildren(int mouseX, int mouseY, float particalTicks)
{
if(isFlagSet(FLAG_ENABLE_SCISSORS))
{
enableScissors(getBox());
super.renderChildren(mouseX, mouseY, particalTicks);
disableScissors();
return;
}
super.renderChildren(mouseX, mouseY, particalTicks);
}
}

View File

@ -12,6 +12,7 @@ import speiger.src.coreengine.rendering.gui.renderer.buffer.RenderBuffer;
import speiger.src.coreengine.rendering.tesselation.Tesselator;
import speiger.src.coreengine.rendering.tesselation.VertexType;
import speiger.src.coreengine.rendering.utils.GLUtils;
import speiger.src.coreengine.utils.profiler.IProfiler.ProfilerData;
public class PieComponent extends GuiComponent
{
@ -37,7 +38,7 @@ public class PieComponent extends GuiComponent
@Override
public void init()
{
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
}
public final PieComponent setAutoUpdate(boolean value)
@ -95,7 +96,7 @@ public class PieComponent extends GuiComponent
float xSize = getBox().getWidth() / 2F;
float ySize = getBox().getHeight() / 2F;
float extra = getBox().getHeight() / 10F;
float value = -3.17F;
float value = -3.14F;
float spaceScale = 0.0495F * (127.0F / maxSteps);
List<IPieIndex> indexes = parts.get();
int stepsDone = 0;
@ -148,6 +149,11 @@ public class PieComponent extends GuiComponent
int steps;
int color;
public PieIndex(ProfilerData data)
{
this(MathUtils.floor(data.getEffect() * 1.28D), data.getColor());
}
public PieIndex(int steps, int color)
{
this.steps = steps;

View File

@ -24,20 +24,41 @@ public class ProgressBarComponent extends GuiComponent
this(color, value, max, null);
}
public ProgressBarComponent(int color, float textScale, int value, int max)
{
this(color, textScale, value, max, null);
}
public ProgressBarComponent(int color, int value, int max, IntFunction<String> name)
{
this(0F, 0F, 0F, 0F, color, value, max, name);
}
public ProgressBarComponent(int color, float textScale, int value, int max, IntFunction<String> name)
{
this(0F, 0F, 0F, 0F, color, textScale, value, max, name);
}
public ProgressBarComponent(float x, float y, float width, float height, int color, int value, int max)
{
this(x, y, width, height, color, value, max, null);
}
public ProgressBarComponent(float x, float y, float width, float height, int color, float textScale, int value, int max)
{
this(x, y, width, height, color, textScale, value, max, null);
}
public ProgressBarComponent(float x, float y, float width, float height, int color, int value, int max, IntFunction<String> name)
{
this(x, y, width, height, color, 1F, value, max, name);
}
public ProgressBarComponent(float x, float y, float width, float height, int color, float textScale, int value, int max, IntFunction<String> name)
{
super(x, y, width, height);
this.name = name;
text.setTextScale(textScale);
setColor(color);
setMax(max);
setValue(value);
@ -69,6 +90,12 @@ public class ProgressBarComponent extends GuiComponent
return this;
}
public ProgressBarComponent setTextGenerator(IntFunction<String> name)
{
this.name = name;
return this;
}
public ProgressBarComponent setValue(int newValue)
{
if(value != newValue)
@ -101,6 +128,16 @@ public class ProgressBarComponent extends GuiComponent
return max == 0 ? 0F : (float)value / (float)max;
}
public int getValue()
{
return value;
}
public int getMax()
{
return max;
}
@Override
protected boolean fixedUpdateSelf()
{

View File

@ -7,8 +7,8 @@ import speiger.src.coreengine.rendering.gui.helper.box.IGuiBox;
public class ScrollBarComponent extends GuiComponent implements IButtonComponent
{
public static final int FLAG_HORIZONTAL = 1024;
public static final int FLAG_INVERTED = 2048;
public static final int FLAG_HORIZONTAL = 1 << 20;
public static final int FLAG_INVERTED = 1 << 21;
int color;
float lastMouse = -1;
int current;

View File

@ -31,7 +31,7 @@ public class ScrollPanelComponent extends GuiComponent
addChild(horizontalBar, Constrains.scrollBar(isFlagSet(FLAG_CORNER) ? () -> true : verticalBar::isInUse, true, 5F));
addChild(verticalBar, Constrains.scrollBar(isFlagSet(FLAG_CORNER) ? () -> true : horizontalBar::isInUse, false, 5F));
viewPort.addChild(container);
container.addChangeListener(this::recalculateSize);
container.onChange(this::recalculateSize);
addChild(viewPort, Constrains.width(ConditionalConstraint.parent(verticalBar::isInUse, 0F, 5F)).height(ConditionalConstraint.parent(horizontalBar::isInUse, 0F, 5F)).build());
}

View File

@ -28,10 +28,10 @@ public class ScrollWindowComponent extends WindowComponent
public void init()
{
super.init();
addChild(horizontalBar.addChangeListener(minimizedListener), Constrains.scrollBar(isFlagSet(FLAG_CORNER) ? () -> true : verticalBar::isInUse, true, 5F));
addChild(verticalBar.addChangeListener(minimizedListener), Constrains.verticalScrollBar(isFlagSet(FLAG_CORNER) ? () -> true : horizontalBar::isInUse, 7.5F, 5F));
addChild(horizontalBar.onChange(minimizedListener), Constrains.scrollBar(isFlagSet(FLAG_CORNER) ? () -> true : verticalBar::isInUse, true, 5F));
addChild(verticalBar.onChange(minimizedListener), Constrains.verticalScrollBar(isFlagSet(FLAG_CORNER) ? () -> true : horizontalBar::isInUse, 7.5F, 5F));
viewPort.addChild(container);
container.addChangeListener(this::recalculateSize).addChangeListener(minimizedListener);
container.onChange(this::recalculateSize).onChange(minimizedListener);
addChild(viewPort.set(0F, 7.5F), Constrains.width(ConditionalConstraint.parent(verticalBar::isInUse, 0F, 5F)).height(ConditionalConstraint.parent(horizontalBar::isInUse, 0F, 5F)).build());
}

View File

@ -69,10 +69,10 @@ public class SelectionComponent extends GuiComponent implements IButtonComponent
@Override
public void init()
{
list.setEntryHeight(getGui().getFont().height()).addUserActionListener(this);
list.setEntryHeight(getGui().getFont().height()).onAction(this);
addChild(text, Constrains.parent(21F, 0F, 10.5F, 0F));
addChild(list, Constrains.parent(Target.X).invParent(Target.Y).parent(Target.WIDTH).build());
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
createArrow();
}

View File

@ -0,0 +1,334 @@
package speiger.src.coreengine.rendering.gui.components;
import speiger.src.collections.objects.functions.function.Object2FloatFunction;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.math.misc.Facing;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain.Target;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.DynamicConstrain;
import speiger.src.coreengine.utils.functions.FloatSupplier;
public class SingleTabPanelComponent extends PanelComponent
{
PanelComponent selection = new PanelComponent();
PanelComponent panel = new PanelComponent().setScissors(true);
ObjectList<Tab> tabs = new ObjectArrayList<>();
int selectedTab = -1;
float tabScale = 1F;
Facing facing;
int backgroundColor = ColorUtils.GRAY;
int unselectedColor = ColorUtils.GRAY;
int selectedColor = ColorUtils.DARK_GRAY;
float padding = 30F;
public SingleTabPanelComponent()
{
this(Facing.NORTH);
}
public SingleTabPanelComponent(Facing facing)
{
this(0F, 0F, 0F, 0F, facing);
}
public SingleTabPanelComponent(float x, float y, float width, float height)
{
this(x, y, width, height, Facing.NORTH);
}
public SingleTabPanelComponent(float x, float y, float width, float height, Facing facing)
{
super(x, y, width, height);
this.facing = facing;
}
public SingleTabPanelComponent setFacing(Facing facing)
{
this.facing = facing;
updateConstrains(selection, createView());
for(Tab tab : tabs)
{
updateConstrains(tab.align(facing.isZAxis() ? Align.CENTER : (facing == Facing.WEST ? Align.LEFT_TOP : Align.RIGHT_BOTTOM)), createConstraint(tab));
}
updateConstrains(panel, createPanel());
onChanged(true);
return this;
}
public SingleTabPanelComponent setPadding(float padding)
{
this.padding = padding;
for(Tab tab : tabs)
{
tab.updatePadding();
}
onChanged(true);
return this;
}
public SingleTabPanelComponent addTab(String name)
{
Tab newTab = new Tab(name).align(facing.isZAxis() ? Align.CENTER : (facing == Facing.WEST ? Align.LEFT_TOP : Align.RIGHT_BOTTOM));
tabs.add(newTab);
if(selectedTab == -1) {
selectedTab = tabs.size()-1;
}
newTab.onAction(() -> selectTab(newTab));
selection.addChild(newTab, createConstraint(newTab));
onChanged(true);
return this;
}
public Facing getFacing()
{
return facing;
}
public int findTab(String name)
{
for(int i = 0,m=tabs.size();i<m;i++) {
if(tabs.get(i).name.equals(name)) return i;
}
return -1;
}
public int getActiveIndex()
{
return selectedTab;
}
public PanelComponent getPanel()
{
return panel;
}
@Override
protected boolean renderSelf(int mouseX, int mouseY, float particalTicks)
{
getRenderer().drawQuad(selection.getBox(), backgroundColor);
return true;
}
@Override
public void init()
{
addChild(selection, createView());
addChild(panel, createPanel());
super.init();
}
@Override
protected void repaint()
{
if(facing.isZAxis())
{
float room = getBox().getBaseWidth();
float requiredSpace = 0F;
for(int i = 0,m=tabs.size();i<m;i++)
{
Tab tab = tabs.get(i);
float width = tab.getWidth() * tab.getTextScale();
if(i == selectedTab) room -= width;
else requiredSpace += width;
}
tabScale = Math.min(1F, room / requiredSpace);
}
else
{
tabScale = 0F;
for(int i = 0,m=tabs.size();i<m;i++)
{
Tab tab = tabs.get(i);
tabScale = Math.max(tabScale, tab.getWidth() * tab.getTextScale());
}
tabScale *= getBox().getScale();
tabScale += 1F;
}
}
protected Constrains createView()
{
switch(facing)
{
case NORTH: return Constrains.parent(Target.X).parent(Target.Y).parent(Target.WIDTH).height(7.5F).build();
case SOUTH: return Constrains.parent(Target.X).invParent(7.7F, Target.Y).parent(Target.WIDTH).height(7.5F).build();
case EAST: return Constrains.xPos(new DynamicConstrain(this::getXOffset).setInverted(true)).parent(Target.Y).dynamic(this::getPanelWidth, Target.WIDTH).parent(Target.HEIGHT).build();
case WEST: return Constrains.parent(Target.X).parent(Target.Y).dynamic(this::getPanelWidth, Target.WIDTH).parent(Target.HEIGHT).build();
default: return Constrains.parent();
}
}
protected Constrains createPanel()
{
switch(facing)
{
case NORTH: return Constrains.parent(0F, 7.2F, 0F, 3.6F);
case SOUTH: return Constrains.parent(0F, 0F, 0F, 3.6F);
case EAST: return Constrains.parent(Target.X).parent(Target.Y).width(new DynamicConstrain(this::getPanelWidth).setInverted(true)).parent(Target.HEIGHT).build();
case WEST: return Constrains.dynamic(this::getXOffset, Target.X).parent(0F, Target.Y).width(new DynamicConstrain(this::getPanelWidth).setInverted(true)).parent(Target.HEIGHT).build();
default: return Constrains.parent();
}
}
protected Constrains createConstraint(Tab tab)
{
if(facing.isZAxis()) return Constrains.parent(Target.Y).parent(Target.HEIGHT).dynamic(new DynamicTab(tab, this::getOffset), Target.X).dynamic(new DynamicTab(tab, this::getWidth), Target.WIDTH).build();
return Constrains.parent(Target.X).dynamic(new DynamicTab(tab, this::getOffset), Target.Y).parent(Target.WIDTH).height(7.5F).build();
}
protected void selectTab(Tab tab)
{
if(selectTab(tabs.indexOf(tab)))
{
notifyListeners(LISTENER_USER_ACTION);
}
}
public boolean selectTab(int index)
{
if(index < 0 || index >= tabs.size()) return false;
if(selectedTab == index) return false;
selectedTab = index;
onChanged(true);
return true;
}
protected float getOffset(Tab tab)
{
int index = tabs.indexOf(tab);
float offset = 0F;
for(int i = 0;i<index;i++)
{
Tab entry = tabs.get(i);
if(facing.isZAxis()) offset += entry.getWidth() * (i == selectedTab ? 1F : tabScale) * entry.getTextScale();
else offset += tab.getBox().getBaseHeight();
}
return offset;
}
protected float getPanelOffset()
{
return facing == Facing.EAST ? 0F : tabScale + 0.25F;
}
protected float getPanelWidth()
{
return tabScale + 0.25F;
}
protected float getXOffset()
{
return tabScale + 0.25F;
}
protected float getWidth(Tab tab)
{
return facing.isZAxis() ? tab.getWidth() * (selectedTab == tabs.indexOf(tab) ? 1F : tabScale) * tab.getTextScale() : tabScale;
}
private static class DynamicTab implements FloatSupplier
{
Tab tab;
Object2FloatFunction<Tab> function;
public DynamicTab(Tab tab, Object2FloatFunction<Tab> function)
{
this.tab = tab;
this.function = function;
}
@Override
public float getAsFloat()
{
return function.getFloat(tab);
}
}
private class Tab extends GuiComponent implements IButtonComponent
{
String name;
float width = -1F;
TextComponent comp;
public Tab(String name)
{
super(0F, 0F, 100F, 7.5F);
this.name = name;
comp = new TextComponent(name).setTextScale(0.4F).singleLine(true).horizontal(Align.LEFT_TOP);
setFlag(FLAG_SUPPORT_BINDING);
}
public Tab align(Align align)
{
comp.horizontal(align);
return this;
}
public void updatePadding()
{
if(getGui() != null) width = getFont().width(name)+padding;
}
@Override
public void init()
{
addChild(comp, Constrains.parent());
updatePadding();
}
public float getWidth()
{
return width;
}
public float getTextScale()
{
return comp.getTextScale();
}
@Override
protected void repaint()
{
String s = name;
float scale = comp.getTextScale();
float width = (this.width-padding)*scale;
float desiredWidth = getBox().getBaseWidth();
if(width > desiredWidth) {
while(s.length() >= 1 && getFont().width(s+"...") * scale > desiredWidth) {
s = s.substring(0, s.length()-1);
}
comp.setText(s+"...");
return;
}
comp.setText(s);
}
@Override
protected boolean renderSelf(int mouseX, int mouseY, float particalTicks)
{
boolean notSelected = tabs.indexOf(this) != selectedTab;
getRenderer().drawQuad(getBox(), notSelected ? unselectedColor : selectedColor);
if(notSelected) getRenderer().drawFrame(getBox(), selectedColor);
return true;
}
@Override
public void onRelease(int button, int mouseX, int mouseY)
{
notifyListeners(LISTENER_USER_ACTION);
}
@Override
protected boolean onUserKey()
{
notifyListeners(LISTENER_USER_ACTION);
return true;
}
}
}

View File

@ -25,16 +25,27 @@ public class SliderComponent extends GuiComponent implements IButtonComponent
public SliderComponent(int min, int max, int value, int color, IntFunction<String> textBuilder)
{
this(0F, 0F, 0F, 0F, min, max, value, color, textBuilder);
this(0F, 0F, 0F, 0F, min, max, value, color, 1F, textBuilder);
}
public SliderComponent(int min, int max, int value, int color, float textScale, IntFunction<String> textBuilder)
{
this(0F, 0F, 0F, 0F, min, max, value, color, textScale, textBuilder);
}
public SliderComponent(float x, float y, float width, float height, int min, int max, int value, int color, IntFunction<String> textBuilder)
{
this(x, y, width, height, min, max, value, color, 1F, textBuilder);
}
public SliderComponent(float x, float y, float width, float height, int min, int max, int value, int color, float textScale, IntFunction<String> textBuilder)
{
super(x, y, width, height);
this.min = min;
this.max = max;
this.value = MathUtils.clamp(min, max, value);
this.color = color;
text.setTextScale(textScale);
this.textBuilder = textBuilder;
updateText(false);
}
@ -55,7 +66,7 @@ public class SliderComponent extends GuiComponent implements IButtonComponent
}
if(buffer == null)
{
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
}
buffer.clear();
UIShapes.createArrow(buffer, 12F, 12F, color, vertical ? Facing.EAST : Facing.SOUTH);

View File

@ -0,0 +1,339 @@
package speiger.src.coreengine.rendering.gui.components;
import speiger.src.collections.objects.functions.function.Object2FloatFunction;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.math.misc.Facing;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.base.IButtonComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain.Target;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.DynamicConstrain;
import speiger.src.coreengine.utils.functions.FloatSupplier;
public class TabbedPanelComponent extends PanelComponent
{
PanelComponent selection = new PanelComponent();
ObjectList<Tab> tabs = new ObjectArrayList<>();
int selectedTab = -1;
float tabScale = 1F;
Facing facing;
int backgroundColor = ColorUtils.GRAY;
int unselectedColor = ColorUtils.GRAY;
int selectedColor = ColorUtils.DARK_GRAY;
float padding = 30F;
public TabbedPanelComponent()
{
this(Facing.NORTH);
}
public TabbedPanelComponent(Facing facing)
{
this(0F, 0F, 0F, 0F, facing);
}
public TabbedPanelComponent(float x, float y, float width, float height)
{
this(x, y, width, height, Facing.NORTH);
}
public TabbedPanelComponent(float x, float y, float width, float height, Facing facing)
{
super(x, y, width, height);
this.facing = facing;
}
public TabbedPanelComponent setFacing(Facing facing)
{
this.facing = facing;
updateConstrains(selection, createView());
for(Tab tab : tabs)
{
updateConstrains(tab.align(facing.isZAxis() ? Align.CENTER : (facing == Facing.WEST ? Align.LEFT_TOP : Align.RIGHT_BOTTOM)), createConstraint(tab));
updateConstrains(tab.getPanel(), createPanel());
}
onChanged(true);
return this;
}
public TabbedPanelComponent setPadding(float padding)
{
this.padding = padding;
for(Tab tab : tabs)
{
tab.updatePadding();
}
onChanged(true);
return this;
}
public Facing getFacing()
{
return facing;
}
public PanelComponent addTab(String name)
{
Tab newTab = new Tab(name).align(facing.isZAxis() ? Align.CENTER : (facing == Facing.WEST ? Align.LEFT_TOP : Align.RIGHT_BOTTOM));
tabs.add(newTab);
if(selectedTab == -1) {
selectedTab = tabs.size()-1;
newTab.getPanel().setVisible(true);
}
newTab.onAction(() -> selectTab(newTab));
selection.addChild(newTab, createConstraint(newTab));
addChild(newTab.getPanel(), createPanel());
onChanged(true);
return newTab.getPanel();
}
public int findTab(String name)
{
for(int i = 0,m=tabs.size();i<m;i++) {
if(tabs.get(i).name.equals(name)) return i;
}
return -1;
}
public int getActiveIndex()
{
return selectedTab;
}
public PanelComponent getActiveTab()
{
return selectedTab == -1 ? null : tabs.get(selectedTab).getPanel();
}
@Override
protected boolean renderSelf(int mouseX, int mouseY, float particalTicks)
{
getRenderer().drawQuad(selection.getBox(), backgroundColor);
return true;
}
@Override
public void init()
{
addChild(selection, createView());
super.init();
}
@Override
protected void repaint()
{
if(facing.isZAxis())
{
float room = getBox().getBaseWidth();
float requiredSpace = 0F;
for(int i = 0,m=tabs.size();i<m;i++)
{
Tab tab = tabs.get(i);
float width = tab.getWidth() * tab.getTextScale();
if(i == selectedTab) room -= width;
else requiredSpace += width;
}
tabScale = Math.min(1F, room / requiredSpace);
}
else
{
tabScale = 0F;
for(int i = 0,m=tabs.size();i<m;i++)
{
Tab tab = tabs.get(i);
tabScale = Math.max(tabScale, tab.getWidth() * tab.getTextScale());
}
tabScale *= getBox().getScale();
tabScale += 1F;
}
}
protected Constrains createView()
{
switch(facing)
{
case NORTH: return Constrains.parent(Target.X).parent(Target.Y).parent(Target.WIDTH).height(7.5F).build();
case SOUTH: return Constrains.parent(Target.X).invParent(7.7F, Target.Y).parent(Target.WIDTH).height(7.5F).build();
case EAST: return Constrains.xPos(new DynamicConstrain(this::getXOffset).setInverted(true)).parent(Target.Y).dynamic(this::getPanelWidth, Target.WIDTH).parent(Target.HEIGHT).build();
case WEST: return Constrains.parent(Target.X).parent(Target.Y).dynamic(this::getPanelWidth, Target.WIDTH).parent(Target.HEIGHT).build();
default: return Constrains.parent();
}
}
protected Constrains createPanel()
{
switch(facing)
{
case NORTH: return Constrains.parent(0F, 7.2F, 0F, 3.6F);
case SOUTH: return Constrains.parent(0F, 0F, 0F, 3.6F);
case EAST: return Constrains.parent(Target.X).parent(Target.Y).width(new DynamicConstrain(this::getPanelWidth).setInverted(true)).parent(Target.HEIGHT).build();
case WEST: return Constrains.dynamic(this::getXOffset, Target.X).parent(0F, Target.Y).width(new DynamicConstrain(this::getPanelWidth).setInverted(true)).parent(Target.HEIGHT).build();
default: return Constrains.parent();
}
}
protected Constrains createConstraint(Tab tab)
{
if(facing.isZAxis()) return Constrains.parent(Target.Y).parent(Target.HEIGHT).dynamic(new DynamicTab(tab, this::getOffset), Target.X).dynamic(new DynamicTab(tab, this::getWidth), Target.WIDTH).build();
return Constrains.parent(Target.X).dynamic(new DynamicTab(tab, this::getOffset), Target.Y).parent(Target.WIDTH).height(7.5F).build();
}
protected void selectTab(Tab tab)
{
selectTab(tabs.indexOf(tab));
}
public boolean selectTab(int index)
{
if(index < 0 || index >= tabs.size()) return false;
if(selectedTab == index) return false;
if(selectedTab != -1) tabs.get(selectedTab).getPanel().setVisible(false);
selectedTab = index;
tabs.get(selectedTab).getPanel().setVisible(true);
onChanged(true);
return true;
}
protected float getOffset(Tab tab)
{
int index = tabs.indexOf(tab);
float offset = 0F;
for(int i = 0;i<index;i++)
{
Tab entry = tabs.get(i);
if(facing.isZAxis()) offset += entry.getWidth() * (i == selectedTab ? 1F : tabScale) * entry.getTextScale();
else offset += tab.getBox().getBaseHeight();
}
return offset;
}
protected float getPanelOffset()
{
return facing == Facing.EAST ? 0F : tabScale + 0.25F;
}
protected float getPanelWidth()
{
return tabScale + 0.25F;
}
protected float getXOffset()
{
return tabScale + 0.25F;
}
protected float getWidth(Tab tab)
{
return facing.isZAxis() ? tab.getWidth() * (selectedTab == tabs.indexOf(tab) ? 1F : tabScale) * tab.getTextScale() : tabScale;
}
private static class DynamicTab implements FloatSupplier
{
Tab tab;
Object2FloatFunction<Tab> function;
public DynamicTab(Tab tab, Object2FloatFunction<Tab> function)
{
this.tab = tab;
this.function = function;
}
@Override
public float getAsFloat()
{
return function.getFloat(tab);
}
}
private class Tab extends GuiComponent implements IButtonComponent
{
String name;
float width = -1F;
TextComponent comp;
PanelComponent panel = new PanelComponent().setScissors(true).setVisible(false).cast();
public Tab(String name)
{
super(0F, 0F, 100F, 7.5F);
this.name = name;
comp = new TextComponent(name).setTextScale(0.4F).singleLine(true).horizontal(Align.LEFT_TOP);
setFlag(FLAG_SUPPORT_BINDING);
}
public Tab align(Align align)
{
comp.horizontal(align);
return this;
}
public void updatePadding()
{
if(getGui() != null) width = getFont().width(name)+padding;
}
@Override
public void init()
{
addChild(comp, Constrains.parent());
updatePadding();
}
public float getWidth()
{
return width;
}
public float getTextScale()
{
return comp.getTextScale();
}
@Override
protected void repaint()
{
String s = name;
float scale = comp.getTextScale();
float width = (this.width-padding)*scale;
float desiredWidth = getBox().getBaseWidth();
if(width > desiredWidth) {
while(s.length() >= 1 && getFont().width(s+"...") * scale > desiredWidth) {
s = s.substring(0, s.length()-1);
}
comp.setText(s+"...");
return;
}
comp.setText(s);
}
public PanelComponent getPanel()
{
return panel;
}
@Override
protected boolean renderSelf(int mouseX, int mouseY, float particalTicks)
{
boolean notSelected = tabs.indexOf(this) != selectedTab;
getRenderer().drawQuad(getBox(), notSelected ? unselectedColor : selectedColor);
if(notSelected) getRenderer().drawFrame(getBox(), selectedColor);
return true;
}
@Override
public void onRelease(int button, int mouseX, int mouseY)
{
notifyListeners(LISTENER_USER_ACTION);
}
@Override
protected boolean onUserKey()
{
notifyListeners(LISTENER_USER_ACTION);
return true;
}
}
}

View File

@ -1,61 +0,0 @@
package speiger.src.coreengine.rendering.gui.components;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
public class TabbedWindowComponent extends WindowComponent
{
public TabbedWindowComponent(float x, float y, float width, float height)
{
super(x, y, width, height, DEFAULT_FLAGS, "Test");
}
@Override
public void init()
{
super.init();
addChild(new Tab("Testing My theory with the full lenght text"), null, null, new ParentConstrain(), null);
}
public static class Tab extends GuiComponent
{
String name;
float width = -1F;
boolean closeable;
TextComponent comp;
public Tab(String name)
{
super(0F, 7F, 100F, 10F);
this.name = name;
comp = new TextComponent(name).setTextScale(0.4F).singleLine(true).horizontal(Align.LEFT_TOP);
}
@Override
public void init()
{
width = getFont().width(name);
addChild(comp, Constrains.parent());
}
@Override
protected void repaint()
{
String s = name;
float scale = comp.getTextScale();
float width = getFont().width(s)*scale;
float desiredWidth = getBox().getBaseWidth();
if(width > desiredWidth) {
while(getFont().width(s+"...") * scale > desiredWidth) {
s = s.substring(0, s.length()-1);
}
comp.setText(s+"...");
return;
}
comp.setText(s);
}
}
}

View File

@ -59,7 +59,7 @@ public class TextComponent extends GuiComponent
@Override
public void init()
{
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
if(font == null)
{
setFont(getGui().getFont());

View File

@ -43,6 +43,11 @@ public class TextFieldComponent extends GuiComponent
IGuiBox viewPort = new ParentBox(1F);
public TextFieldComponent(int color)
{
this(color, 1F);
}
public TextFieldComponent(int color, float textScale)
{
super(0F, 0F, 0F, 0F);
setFlag(FLAG_CAN_LOSE_FOCUS);
@ -50,6 +55,11 @@ public class TextFieldComponent extends GuiComponent
}
public TextFieldComponent(float x, float y, float width, float height, int color)
{
this(x, y, width, height, color, 1F);
}
public TextFieldComponent(float x, float y, float width, float height, int color, float textScale)
{
super(x, y, width, height);
setFlag(FLAG_CAN_LOSE_FOCUS);

View File

@ -22,8 +22,8 @@ import speiger.src.coreengine.utils.functions.Functions;
public class TextPanelComponent extends GuiComponent implements IButtonComponent, IKeyComponent
{
public static final int FLAG_FOCUS = 1024;
public static final int FLAG_CAN_LOSE_FOCUS = 2048;
public static final int FLAG_FOCUS = 1 << 20;
public static final int FLAG_CAN_LOSE_FOCUS = 1 << 21;
TextComponent text = new TextComponent().align(Align.LEFT_TOP, Align.LEFT_TOP).singleLine(true).special(false).cast();
int color;
@ -37,15 +37,27 @@ public class TextPanelComponent extends GuiComponent implements IButtonComponent
Predicate<String> validator = Functions.getAlwaysTrue();
public TextPanelComponent(int color)
{
this(color, 1F);
}
public TextPanelComponent(int color, float textScale)
{
super(0F, 0F, 0F, 0F);
this.color = color;
text.setTextScale(textScale);
}
public TextPanelComponent(float x, float y, float width, float height, int color)
{
this(x, y, width, height, color, 1F);
}
public TextPanelComponent(float x, float y, float width, float height, int color, float textScale)
{
super(x, y, width, height);
this.color = color;
text.setTextScale(textScale);
}
@Override

View File

@ -97,7 +97,7 @@ public class TreeComponent<T extends ITreeEntry> extends GuiComponent implements
@Override
public void init()
{
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
addChild(horizontalBar, Constrains.scrollBar(verticalBar::isInUse, true, 5F));
addChild(verticalBar, Constrains.scrollBar(horizontalBar::isInUse, false, 5F));
List<T> entries = new ObjectArrayList<T>();

View File

@ -22,6 +22,7 @@ import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
import speiger.src.coreengine.rendering.utils.Cursor;
import speiger.src.coreengine.utils.functions.ConsumerConverter;
import speiger.src.coreengine.utils.helpers.InternalThreadPools;
import speiger.src.coreengine.utils.io.GameLog;
public class WindowComponent extends PanelComponent implements IButtonComponent, ObjIntConsumer<GuiComponent>
{
@ -75,12 +76,12 @@ public class WindowComponent extends PanelComponent implements IButtonComponent,
float offset = 9F;
if((flags & WINDOW_FLAG_CLOSEABLE) != 0)
{
addChild(new IconButtonComponent(0F, 0F, 7.5F, 7.5F, ColorUtils.RED, new CrossIcon(ColorUtils.WHITE).setPadding(2.5F, 2F)).addUserActionListener(new ConsumerConverter<>(0, this)).setZOffset(0.001F), new Constrains(new PixelConstrain(offset).setInverted(), null, null, null));
addChild(new IconButtonComponent(0F, 0F, 7.5F, 7.5F, ColorUtils.RED, new CrossIcon(ColorUtils.WHITE).setPadding(2.5F, 2F)).onAction(new ConsumerConverter<>(0, this)).setZOffset(0.001F), new Constrains(new PixelConstrain(offset).setInverted(), null, null, null));
offset += 7.5F;
}
if((flags & WINDOW_FLAG_MINIMIZEABLE) != 0)
{
addChild(new IconButtonComponent(0F, 0F, 7.5F, 7.5F, ColorUtils.GRAY, new LineIcon(ColorUtils.WHITE, 0.7F, 0.25F)).addUserActionListener(new ConsumerConverter<>(1, this)).setZOffset(0.001F), new Constrains(new PixelConstrain(offset).setInverted(), null, null, null));
addChild(new IconButtonComponent(0F, 0F, 7.5F, 7.5F, ColorUtils.GRAY, new LineIcon(ColorUtils.WHITE, 0.7F, 0.25F)).onAction(new ConsumerConverter<>(1, this)).setZOffset(0.001F), new Constrains(new PixelConstrain(offset).setInverted(), null, null, null));
}
if(canMoveIntoForground())
{
@ -255,7 +256,7 @@ public class WindowComponent extends PanelComponent implements IButtonComponent,
@Override
public boolean onClick(int button, int mouseX, int mouseY)
{
if(isOverChild(mouseX, mouseY) || getGui().hasComponentInTheWay(getTopComponent(), mouseX, mouseY))
if(getGui().hasComponentInTheWay(getTopComponent(), mouseX, mouseY))
{
return false;
}
@ -263,11 +264,18 @@ public class WindowComponent extends PanelComponent implements IButtonComponent,
lastClick.set(mouseX, mouseY);
if(facing != null)
{
GameLog.info("Testing: "+facing.getCode());
if(isFlagNotSet(FLAG_RESIZEABLE_HORIZONTAL)) facing = facing.remove(FacingList.HORIZONTAL);
if(isFlagNotSet(FLAG_RESIZEABLE_VERTICAL)) facing = facing.remove(FacingList.VERTICAL);
if(isOverChild(mouseX, mouseY) && facing.isEmpty())
{
facing = null;
return false;
}
return true;
}
return false;
}
@Override
public boolean onDrag(int mouseX, int mouseY)

View File

@ -20,7 +20,7 @@ public class VerticalLayout implements Consumer<GuiComponent>
this.components.addAll(components);
for(int i = 0;i<components.size();i++)
{
components.get(i).addChangeListener(this).addCloseListener(this::removeComponent);
components.get(i).onChange(this).onClose(this::removeComponent);
}
this.box = box;
this.padding = padding;
@ -40,8 +40,8 @@ public class VerticalLayout implements Consumer<GuiComponent>
public <T extends GuiComponent> T addComponent(T gui)
{
components.add(gui);
gui.addChangeListener(this);
gui.addCloseListener(this::removeComponent);
gui.onChange(this);
gui.onClose(this::removeComponent);
accept(null);
return gui;
}

View File

@ -67,7 +67,7 @@ public class MenuBarComponent extends GuiComponent
public MenuComponent addMenu(String name)
{
return addMenuItem(new MenuComponent(name)).addUserActionListener(this::closeMenus).cast();
return addMenuItem(new MenuComponent(name)).onAction(this::closeMenus).cast();
}
public MenuItemComponent addMenuItem(MenuItemComponent item)

View File

@ -44,7 +44,7 @@ public class MenuCheckBoxComponent extends MenuItemComponent implements ICheckBo
public void init()
{
addChild(text, new Constrains(new PixelConstrain(getBox().getHeight() + 1F), new ParentConstrain(), new DynamicConstrain(() -> text.getMetadata().getMaxWidth() + 0.5F), new ParentConstrain()));
addCloseListener(buffer = getRenderer().createBuffer());
onClose(buffer = getRenderer().createBuffer());
}
@Override

View File

@ -5,8 +5,8 @@ import java.util.function.Consumer;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.DynamicConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.MenuConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
@ -15,7 +15,7 @@ public class MenuComponent extends MenuItemComponent implements Consumer<GuiComp
{
static final int FLAG_OPEN = 1 << 21;
static final int FLAG_SUB_MENU = 1 << 22;
List<MenuItemComponent> components = new ObjectArrayList<MenuItemComponent>();
List<MenuItemComponent> components = new ObjectArrayList<>();
float defaultScale = 1F;
float width = 0F;
float entryHeight = 10F;
@ -127,7 +127,7 @@ public class MenuComponent extends MenuItemComponent implements Consumer<GuiComp
components.add(comp);
comp.setScale(defaultScale);
comp.setMenuColor(color);
addChild(comp.setIgnoreBounds(true).addUserActionListener(this), createConstrains(comp)).onChanged(false);
addChild(comp.setIgnoreBounds(true).onAction(this), createConstrains(comp)).onChanged(false);
comp.setVisible(isFlagSet(FLAG_OPEN));
comp.setTextScale(textScale);
return comp;

View File

@ -34,7 +34,7 @@ public class CheckBoxGroup<T extends GuiComponent & ICheckBox<T>> implements Con
box.setChecked(false);
}
}
box.addUserActionListener(this);
box.onAction(this);
return box;
}

View File

@ -49,7 +49,7 @@ public class ConsoleComponent extends GuiComponent implements IKeyComponent
public void init()
{
chat.getRawText().setTextScale(0.45F);
chat.addUserActionListener(this::onEnter);
chat.onAction(this::onEnter);
list.setSelectionMode(ListComponent.SELECTION_MODE_DISABLE);
list.setStartAtBottom(true);
addChild(chat, new Constrains(new ParentConstrain(), new ParentConstrain(12F).invert(), new ParentConstrain(), new PixelConstrain(12F)));

View File

@ -7,7 +7,7 @@ import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.rendering.gui.GuiBase;
import speiger.src.coreengine.rendering.gui.GuiComponent;
import speiger.src.coreengine.rendering.gui.components.TextComponent;
import speiger.src.coreengine.rendering.gui.components.window.debug.PieProfilerWindowComponent;
import speiger.src.coreengine.rendering.gui.components.window.debug.PieProfilerWindow;
import speiger.src.coreengine.rendering.gui.helper.Align;
import speiger.src.coreengine.rendering.input.Keyboard;
import speiger.src.coreengine.utils.profiler.IProfiler.IProfilerEntry;
@ -94,13 +94,13 @@ public class ProfilerTreeEntry extends BaseTreeEntry
{
if(time >= 2000000L)
{
return PieProfilerWindowComponent.PERCENT_FORMAT.format(time / 1000000.0D) + "ms";
return PieProfilerWindow.PERCENT_FORMAT.format(time / 1000000.0D) + "ms";
}
if(time >= 2000L)
{
return PieProfilerWindowComponent.PERCENT_FORMAT.format(time / 1000.0D) + "µs";
return PieProfilerWindow.PERCENT_FORMAT.format(time / 1000.0D) + "µs";
}
return PieProfilerWindowComponent.PERCENT_FORMAT.format(time) + "ns";
return PieProfilerWindow.PERCENT_FORMAT.format(time) + "ns";
}
public String getColor(long time)

View File

@ -56,11 +56,11 @@ public class ColorPickerWindowComponent extends WindowComponent
super.init();
addBox(wheelBox);
addBox(selectedBox);
addChild(brightness.addChangeListener(minimizedListener).addUserActionListener(T -> setColor(hsv[0], hsv[1], T.cast(SliderComponent.class).getValue() * 0.01F)));
addChild(saturation.addChangeListener(minimizedListener).addUserActionListener(T -> setColor(hsv[0], T.cast(SliderComponent.class).getValue() * 0.01F, hsv[2])));
addChild(code.setScale(0.5F).addChangeListener(minimizedListener).addUserActionListener(T -> onTyped()));
addChild(new ButtonComponent(0F, 0F, 0F, 20F, "Select", ColorUtils.GREEN).setScale(0.4F).addUserActionListener(T -> apply()), new Constrains(null, new ParentConstrain(8F).invert(), new RelativeConstrain(0.5F / 0.4F), null));
addChild(new ButtonComponent(0F, 0F, 0F, 20F, "Cancel", ColorUtils.RED).setScale(0.4F).addUserActionListener(T -> T.getGui().removeComponent(this)), new Constrains(new RelativeConstrain(0.5F), new ParentConstrain(8F).invert(), new RelativeConstrain(0.5F / 0.4F), null));
addChild(brightness.onChange(minimizedListener).onAction(T -> setColor(hsv[0], hsv[1], T.cast(SliderComponent.class).getValue() * 0.01F)));
addChild(saturation.onChange(minimizedListener).onAction(T -> setColor(hsv[0], T.cast(SliderComponent.class).getValue() * 0.01F, hsv[2])));
addChild(code.setScale(0.5F).onChange(minimizedListener).onAction(T -> onTyped()));
addChild(new ButtonComponent(0F, 0F, 0F, 20F, "Select", ColorUtils.GREEN).setScale(0.4F).onAction(T -> apply()), new Constrains(null, new ParentConstrain(8F).invert(), new RelativeConstrain(0.5F / 0.4F), null));
addChild(new ButtonComponent(0F, 0F, 0F, 20F, "Cancel", ColorUtils.RED).setScale(0.4F).onAction(T -> T.getGui().removeComponent(this)), new Constrains(new RelativeConstrain(0.5F), new ParentConstrain(8F).invert(), new RelativeConstrain(0.5F / 0.4F), null));
setColor(hsv[0], hsv[1], hsv[2]);
}

View File

@ -2,6 +2,7 @@ package speiger.src.coreengine.rendering.gui.components.window.debug;
import java.text.DecimalFormat;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.lwjgl.glfw.GLFW;
@ -10,43 +11,46 @@ import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.utils.ObjectLists;
import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.math.misc.Facing;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.rendering.gui.GuiManager;
import speiger.src.coreengine.rendering.gui.base.IKeyComponent;
import speiger.src.coreengine.rendering.gui.components.ButtonComponent;
import speiger.src.coreengine.rendering.gui.components.PieComponent;
import speiger.src.coreengine.rendering.gui.components.PieComponent.IPieIndex;
import speiger.src.coreengine.rendering.gui.components.PieComponent.PieIndex;
import speiger.src.coreengine.rendering.gui.components.SingleTabPanelComponent;
import speiger.src.coreengine.rendering.gui.components.TextComponent;
import speiger.src.coreengine.rendering.gui.components.WindowComponent;
import speiger.src.coreengine.rendering.gui.helper.Align;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain.Target;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.DynamicConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.RelativeConstrain;
import speiger.src.coreengine.rendering.input.Keyboard;
import speiger.src.coreengine.utils.profiler.IProfiler;
import speiger.src.coreengine.utils.profiler.IProfiler.IProfilerEntry;
import speiger.src.coreengine.utils.profiler.IProfiler.ProfilerData;
public class PieProfilerWindowComponent extends WindowComponent
implements Supplier<List<IPieIndex>>, IKeyComponent
public class PieProfilerWindow extends WindowComponent implements Supplier<List<IPieIndex>>, IKeyComponent
{
public static final DecimalFormat PERCENT_FORMAT = new DecimalFormat("##0.00");
PieComponent pie = new PieComponent(127, this);
ButtonComponent[] buttons = new ButtonComponent[3];
TextComponent[] extraFeatures = new TextComponent[3];
List<TextComponent[]> entries = new ObjectArrayList<TextComponent[]>();
SingleTabPanelComponent panel = new SingleTabPanelComponent(Facing.SOUTH).onAction(this::onProfilerChanged).cast();
PieComponent pie = panel.getPanel().addChild(new PieComponent(127, this).setAutoUpdate(true), Constrains.parent(Target.WIDTH).dynamic(this::calculatePieHeight, Target.HEIGHT).build());
TextComponent[] extraFeatures = new TextComponent[] {
new TextComponent(0F, 0F, 18F, 7F),
new TextComponent(0F, 0F, 0F, 8F),
new TextComponent(0F, 8F, 0F, 7F)
};
List<TextComponent[]> entries = new ObjectArrayList<>();
List<ProfilerTab> tabs = new ObjectArrayList<>();
int previouseTab = -1;
int textInUse = 0;
IProfiler profiler;
IProfilerEntry currentEntry;
String entryName;
List<ProfilerData> lastValues = null;
public PieProfilerWindowComponent(float x, float y, float width, float height, String name)
public PieProfilerWindow(float x, float y, float width, float height, String name)
{
super(x, y, width, height, DEFAULT_FLAGS, name);
}
@ -61,54 +65,65 @@ public class PieProfilerWindowComponent extends WindowComponent
public void init()
{
super.init();
addChild(pie.setAutoUpdate(true).set(0F, 5F).addChangeListener(minimizedListener), new Constrains(null, null, new ParentConstrain(), new DynamicConstrain(this::calculatePieHeight)));
buttons[0] = createButton(0, "Client");
buttons[1] = createButton(1, "GPU");
buttons[2] = createButton(2, "Server");
extraFeatures[0] = new TextComponent(0F, 0F, 18F, 5.5F).setTextScale(0.3F).setText("[0] Back").align(Align.LEFT_TOP, Align.CENTER);
extraFeatures[0].addChangeListener(T -> T.setVisible(!isMinimized() && currentEntry != null && currentEntry.getParent() != null));
addChild(extraFeatures[0], new Constrains(null, new DynamicConstrain(() -> pie.getBox().getBaseHeight() + (-5.5F)), new PixelConstrain(38).setInverted(), null));
addChild(panel.set(0F, 7.5F).onChange(minimizedListener), Constrains.parent(0.25F, Target.WIDTH).parent(4F, Target.HEIGHT).build());
extraFeatures[0].setTextScale(0.3F).setText("[0] Back").horizontal(Align.LEFT_TOP);
extraFeatures[0].onChange(T -> T.setVisible(currentEntry != null && currentEntry.getParent() != null));
panel.getPanel().addChild(extraFeatures[0], Constrains.dynamic(() -> pie.getBox().getBaseHeight() - 7F, Target.Y).invPixel(38F, Target.WIDTH).build());
extraFeatures[1] = new TextComponent(0F, 0F, 0F, 7F).setTextScale(0.4F).setText("Client Thread");
addChild(extraFeatures[1].addChangeListener(minimizedListener), new Constrains(null, new PixelConstrain(8F), new ParentConstrain(), null));
extraFeatures[2] = new TextComponent(0F, 0F, 0F, 6F).setTextScale(0.33F).setText("Client");
addChild(extraFeatures[2].addChangeListener(minimizedListener), new Constrains(null, new PixelConstrain(15F), new ParentConstrain(), null));
panel.getPanel().addChild(extraFeatures[1].setTextScale(0.4F), Constrains.parent(0F, Target.Y).parent(Target.WIDTH).build());
panel.getPanel().addChild(extraFeatures[2].setTextScale(0.33F), Constrains.pixel(8F, Target.Y).parent(Target.WIDTH).build());
}
public PieProfilerWindow addProfiler(IProfiler profiler, String root)
{
String name = profiler.getName();
panel.addTab(name);
tabs.add(new ProfilerTab(name, profiler, root));
if(tabs.size() == 1)
{
onProfilerChanged();
}
return this;
}
protected IProfiler getActive()
{
return tabs.get(panel.getActiveIndex()).getProfiler();
}
protected void applyProfiler(boolean prev, Consumer<IProfiler> action)
{
int index = prev ? previouseTab : panel.getActiveIndex();
if(index >= 0) action.accept(tabs.get(index).getProfiler());
}
@Override
public void onClosed()
{
super.onClosed();
if(profiler != null)
{
profiler.disable();
profiler = null;
}
applyProfiler(false, IProfiler::disable);
}
public PieProfilerWindowComponent setProfiler(IProfiler profiler, String root)
protected void onProfilerChanged()
{
if(this.profiler != null)
{
buttons[getProfilerIndex(this.profiler)].setEnabled(true);
this.profiler.disable();
}
this.profiler = profiler;
if(profiler != null)
{
profiler.enable();
setCurrentEntry(root);
buttons[getProfilerIndex(this.profiler)].setEnabled(false);
extraFeatures[1].setText(profiler.getName());
}
return this;
if(previouseTab == panel.getActiveIndex()) return;
applyProfiler(true, IProfiler::disable);
applyProfiler(false, IProfiler::enable);
previouseTab = panel.getActiveIndex();
ProfilerTab tab = tabs.get(previouseTab);
extraFeatures[1].setText(tab.getName());
setCurrentEntry(tab.getRoot());
}
public PieProfilerWindowComponent setCurrentEntry(String name)
public SingleTabPanelComponent getTab()
{
return panel;
}
public PieProfilerWindow setCurrentEntry(String name)
{
entryName = name;
currentEntry = profiler.getEntry(name);
currentEntry = getActive().getEntry(name);
lastValues = null;
extraFeatures[2].setText(currentEntry == null ? "Unknown" : currentEntry.getName());
return this;
@ -132,7 +147,7 @@ public class PieProfilerWindowComponent extends WindowComponent
@Override
protected boolean fixedUpdateSelf()
{
if(profiler == null)
if(panel.getActiveIndex() < 0)
{
return true;
}
@ -164,7 +179,11 @@ public class PieProfilerWindowComponent extends WindowComponent
}
if(last != textInUse)
{
resize(0F, (textInUse - last) * 5.5F);
float diff = 80F + (textInUse * 7F) - this.getBox().getHeight();
if(diff > 0) {
resize(0F, diff);
}
onChanged(true);
}
else if(lastEmpty)
{
@ -176,6 +195,10 @@ public class PieProfilerWindowComponent extends WindowComponent
@Override
public boolean onClick(int button, int mouseX, int mouseY)
{
if(super.onClick(button, mouseX, mouseY))
{
return true;
}
if(currentEntry != null && currentEntry.getParent() != null && extraFeatures[0].isHovered(mouseX, mouseY))
{
setCurrentEntry(currentEntry.getParent().getPathName());
@ -198,7 +221,7 @@ public class PieProfilerWindowComponent extends WindowComponent
}
}
}
return super.onClick(button, mouseX, mouseY);
return false;
}
@Override
@ -236,7 +259,7 @@ public class PieProfilerWindowComponent extends WindowComponent
@Override
public Vec2f getMinimumBounds()
{
return Vec2f.of(80F, 80F + (textInUse * 5.5F));
return Vec2f.of(80F, 80F + (textInUse * 7F));
}
@Override
@ -244,7 +267,7 @@ public class PieProfilerWindowComponent extends WindowComponent
{
if(lastValues != null)
{
List<IPieIndex> entries = new ObjectArrayList<IPieIndex>();
List<IPieIndex> entries = new ObjectArrayList<>();
for(int i = 0, m = lastValues.size();i < m;i++)
{
entries.add(new PieIndex(MathUtils.floor(lastValues.get(i).getEffect() * 1.28D), lastValues.get(i).getColor()));
@ -256,51 +279,46 @@ public class PieProfilerWindowComponent extends WindowComponent
protected float calculatePieHeight()
{
return getBox().getBaseHeight() - ((textInUse * 5.5F) + 9F);
}
public IProfiler getProfiler(int index)
{
GuiManager manager = getGui().getUIManager();
switch(index)
{
case 1:
return manager.getGPUProfiler();
case 2:
return manager.getServerProfiler();
default:
return manager.getCPUProfiler();
}
}
public int getProfilerIndex(IProfiler prof)
{
GuiManager manager = getGui().getUIManager();
return manager.getGPUProfiler() == prof ? 1 : manager.getServerProfiler() == prof ? 2 : 0;
}
public static String getRoot(int index)
{
return index < 2 ? "Client" : "Server";
return getBox().getBaseHeight() - ((textInUse * 7) + 17F);
}
protected TextComponent createComponent(int column)
{
final int index = entries.size();
String text = column == 0 ? "[" + (entries.size() + 1) + "] Unknown" : PERCENT_FORMAT.format(0D) + "%";
TextComponent comp = new TextComponent(0F, 0F, 18F, 5.5F).setTextScale(0.3F).setText(text).align(column == 0 ? Align.LEFT_TOP : Align.RIGHT_BOTTOM, Align.CENTER);
comp.addChangeListener(T -> T.setVisible(!isMinimized() && index < textInUse));
TextComponent comp = new TextComponent(0F, 0F, 18F, 7F).setTextScale(0.33F).setText(text).align(column == 0 ? Align.LEFT_TOP : Align.RIGHT_BOTTOM, Align.CENTER);
comp.onChange(T -> T.setVisible(index < textInUse));
Constrain xPos = column == 0 ? null : (column == 1 ? new PixelConstrain(38F).setInverted() : new PixelConstrain(19F).setInverted());
addChild(comp, new Constrains(xPos, new DynamicConstrain(() -> pie.getBox().getBaseHeight() + (index * 5.5F)), column == 0 ? new PixelConstrain(38).setInverted() : null, null));
panel.getPanel().addChild(comp, new Constrains(xPos, new DynamicConstrain(() -> pie.getBox().getBaseHeight() + (index * 7F)), column == 0 ? new PixelConstrain(38).setInverted() : null, null));
return comp;
}
protected ButtonComponent createButton(int index, String name)
private static class ProfilerTab
{
ButtonComponent button = new ButtonComponent(name, ColorUtils.GRAY);
button.getText().setTextScale(0.3F);
button.addChangeListener(minimizedListener).addUserActionListener(T -> setProfiler(getProfiler(index), getRoot(index)));
addChild(button, new Constrains(new RelativeConstrain(index * 0.3333F), new PixelConstrain(8F).setInverted(), new RelativeConstrain(0.3333F), new PixelConstrain(7F)));
return button;
String name;
IProfiler profiler;
String root;
public ProfilerTab(String name, IProfiler profiler, String root)
{
this.name = name;
this.profiler = profiler;
this.root = root;
}
public String getName()
{
return name;
}
public IProfiler getProfiler()
{
return profiler;
}
public String getRoot()
{
return root;
}
}
}

View File

@ -0,0 +1,216 @@
package speiger.src.coreengine.rendering.gui.components.window.debug;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.ObjIntConsumer;
import speiger.src.collections.ints.queues.IntArrayFIFOQueue;
import speiger.src.collections.ints.queues.IntPriorityQueue;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.math.misc.Facing;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.rendering.gui.components.SingleTabPanelComponent;
import speiger.src.coreengine.rendering.gui.components.TreeComponent;
import speiger.src.coreengine.rendering.gui.components.WindowComponent;
import speiger.src.coreengine.rendering.gui.components.tree.ProfilerTreeEntry;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrain.Target;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.utils.profiler.IProfiler;
import speiger.src.coreengine.utils.profiler.IProfiler.IProfilerEntry;
public class TreeProfilerWindow extends WindowComponent
{
IntPriorityQueue todoList = new IntArrayFIFOQueue().synchronizeQueue();
ObjIntConsumer<IProfiler> listener = (T, V) -> todoList.enqueue(V);
SingleTabPanelComponent panel = new SingleTabPanelComponent(Facing.SOUTH).onAction(this::onProfilerChanged).cast();
TreeComponent<ProfilerTreeEntry> tree = panel.addChild(new TreeComponent<>(ColorUtils.GRAY, 9F).disableBackground(true).setSelectionMode(TreeComponent.SELECTION_MODE_INTERACT).cast(), Constrains.parent(Target.WIDTH).parent(4, Target.HEIGHT).build());
List<ProfilerTab> tabs = new ObjectArrayList<>();
int previouseTab = -1;
public TreeProfilerWindow(float x, float y, float width, float height, String name)
{
super(x, y, width, height, DEFAULT_FLAGS, name);
}
public TreeProfilerWindow addProfiler(IProfiler profiler, String root)
{
panel.addTab(profiler.getName());
tabs.add(new ProfilerTab(profiler, root));
if(tabs.size() == 1)
{
onProfilerChanged();
}
return this;
}
@Override
public boolean canMoveIntoForground()
{
return true;
}
@Override
public Vec2f getMinimumBounds()
{
return Vec2f.of(100F, 50F);
}
@Override
public void init()
{
super.init();
addChild(panel.set(0F, 7.5F).onChange(minimizedListener), Constrains.parent(0.25F, Target.WIDTH).parent(4F, Target.HEIGHT).build());
}
@Override
public void onClosed()
{
super.onClosed();
applyProfiler(false, this::disable);
}
@Override
protected boolean fixedUpdateSelf()
{
ProfilerTab entry = getActiveTab();
if(entry == null)
{
todoList.clear();
return true;
}
while(!todoList.isEmpty())
{
int index = todoList.dequeue();
switch(index)
{
case 0:
addEntries(entry.getRootEntry());
break;
case 1:
tree.setTree(null);
break;
case 2:
if(tree.getTree() == null)
{
addEntries(entry.getRootEntry());
break;
}
updateChildren(entry.getRootEntry(), tree.getTree());
tree.onTreeChanged();
break;
}
}
return true;
}
protected void onProfilerChanged()
{
if(previouseTab == panel.getActiveIndex()) return;
applyProfiler(true, this::disable);
applyProfiler(false, this::enable);
previouseTab = panel.getActiveIndex();
ProfilerTab tab = tabs.get(previouseTab);
setCurrentEntry(tab.getRoot());
}
protected void enable(IProfiler profiler)
{
profiler.enable();
profiler.addListener(listener);
}
protected void disable(IProfiler profiler)
{
profiler.removeListener(listener);
profiler.disable();
}
protected void addEntries(IProfilerEntry entry)
{
if(entry == null) return;
ProfilerTreeEntry child = new ProfilerTreeEntry(entry);
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), child);
}
tree.setTree(child);
tree.openAll();
}
public TreeProfilerWindow setCurrentEntry(String name)
{
addEntries(getActive().getEntry(name));
return this;
}
protected void updateChildren(IProfilerEntry entry, ProfilerTreeEntry tree)
{
if(entry == null || tree == null) return;
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), tree);
}
}
protected void addChildren(IProfilerEntry entry, ProfilerTreeEntry tree)
{
if(entry == null || tree == null) return;
ProfilerTreeEntry child = new ProfilerTreeEntry(entry);
int index = tree.indexOf(child);
if(index != -1) child = (ProfilerTreeEntry)tree.getChild(index);
else tree.addChild(child);
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), child);
}
}
protected IProfiler getActive()
{
return tabs.get(panel.getActiveIndex()).getProfiler();
}
protected ProfilerTab getActiveTab()
{
int index = panel.getActiveIndex();
return index < 0 || index >= tabs.size() ? null : tabs.get(index);
}
protected void applyProfiler(boolean prev, Consumer<IProfiler> action)
{
int index = prev ? previouseTab : panel.getActiveIndex();
if(index >= 0) action.accept(tabs.get(index).getProfiler());
}
private static class ProfilerTab
{
IProfiler profiler;
String root;
public ProfilerTab(IProfiler profiler, String root)
{
this.profiler = profiler;
this.root = root;
}
public IProfiler getProfiler()
{
return profiler;
}
public String getRoot()
{
return root;
}
public IProfilerEntry getRootEntry()
{
return profiler.getEntry(root);
}
}
}

View File

@ -1,184 +0,0 @@
package speiger.src.coreengine.rendering.gui.components.window.debug;
import java.util.function.ObjIntConsumer;
import speiger.src.collections.ints.queues.IntArrayFIFOQueue;
import speiger.src.collections.ints.queues.IntPriorityQueue;
import speiger.src.collections.ints.utils.IntPriorityQueues;
import speiger.src.coreengine.math.misc.ColorUtils;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.rendering.gui.GuiManager;
import speiger.src.coreengine.rendering.gui.components.ButtonComponent;
import speiger.src.coreengine.rendering.gui.components.TreeComponent;
import speiger.src.coreengine.rendering.gui.components.WindowComponent;
import speiger.src.coreengine.rendering.gui.components.tree.ProfilerTreeEntry;
import speiger.src.coreengine.rendering.gui.helper.constrains.Constrains;
import speiger.src.coreengine.rendering.gui.helper.constrains.ParentConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.PixelConstrain;
import speiger.src.coreengine.rendering.gui.helper.constrains.RelativeConstrain;
import speiger.src.coreengine.utils.profiler.IProfiler;
import speiger.src.coreengine.utils.profiler.IProfiler.IProfilerEntry;
public class TreeProfilerWindowComponent extends WindowComponent
{
IntPriorityQueue todoList = IntPriorityQueues.synchronize(new IntArrayFIFOQueue());
TreeComponent<ProfilerTreeEntry> tree = new TreeComponent<ProfilerTreeEntry>(ColorUtils.GRAY, 9F).disableBackground(true).setSelectionMode(TreeComponent.SELECTION_MODE_INTERACT);
ButtonComponent[] buttons = new ButtonComponent[3];
ObjIntConsumer<IProfiler> listener = (T, V) -> todoList.enqueue(V);
IProfiler profiler;
String root;
public TreeProfilerWindowComponent(float x, float y, float width, float height, String name)
{
super(x, y, width, height, DEFAULT_FLAGS, name);
}
@Override
public boolean canMoveIntoForground()
{
return true;
}
@Override
public void init()
{
super.init();
addChild(tree.addChangeListener(minimizedListener), new Constrains(new PixelConstrain(2F), new PixelConstrain(getMinimizedY()), new ParentConstrain(1.5F), new PixelConstrain(getMinimizedY() + 8.5F).setInverted()));
buttons[0] = createButton(0, "Client");
buttons[1] = createButton(1, "GPU");
buttons[2] = createButton(2, "Server");
}
@Override
protected boolean fixedUpdateSelf()
{
while(!todoList.isEmpty())
{
int index = todoList.dequeue();
switch(index)
{
case 0:
addEntries(profiler.getEntry(root));
break;
case 1:
tree.setTree(null);
break;
case 2:
if(tree.getTree() == null)
{
addEntries(profiler.getEntry(root));
break;
}
updateChildren(profiler.getEntry(root), tree.getTree());
tree.onTreeChanged();
break;
}
}
return true;
}
public TreeProfilerWindowComponent setProfiler(IProfiler profiler, String root)
{
if(this.profiler != null)
{
buttons[getProfilerIndex(this.profiler)].setEnabled(true);
this.profiler.removeListener(listener);
this.profiler.disable();
tree.setTree(null);
}
this.profiler = profiler;
this.root = root;
if(this.profiler != null)
{
buttons[getProfilerIndex(this.profiler)].setEnabled(false);
this.profiler.enable();
this.profiler.addListener(listener);
addEntries(this.profiler.getEntry(this.root));
}
return this;
}
protected void addEntries(IProfilerEntry entry)
{
if(entry == null)
{
return;
}
ProfilerTreeEntry child = new ProfilerTreeEntry(entry);
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), child);
}
tree.setTree(child);
tree.openAll();
}
protected void updateChildren(IProfilerEntry entry, ProfilerTreeEntry tree)
{
if(entry == null || tree == null)
{
return;
}
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), tree);
}
}
protected void addChildren(IProfilerEntry entry, ProfilerTreeEntry tree)
{
if(entry == null || tree == null)
{
return;
}
ProfilerTreeEntry child = new ProfilerTreeEntry(entry);
int index = tree.indexOf(child);
if(index != -1)
{
child = (ProfilerTreeEntry)tree.getChild(index);
}
else
{
tree.addChild(child);
}
for(int i = 0,m=entry.getChildCount();i<m;i++)
{
addChildren(entry.getChild(i), child);
}
}
public IProfiler getProfiler(int index)
{
GuiManager manager = getGui().getUIManager();
switch(index)
{
case 1:
return manager.getGPUProfiler();
case 2:
return manager.getServerProfiler();
default:
return manager.getCPUProfiler();
}
}
public int getProfilerIndex(IProfiler prof)
{
GuiManager manager = getGui().getUIManager();
return manager.getGPUProfiler() == prof ? 1 : manager.getServerProfiler() == prof ? 2 : 0;
}
protected ButtonComponent createButton(int index, String name)
{
ButtonComponent button = new ButtonComponent(name, ColorUtils.GRAY);
button.getText().setTextScale(0.3F);
button.addChangeListener(minimizedListener).addUserActionListener(T -> setProfiler(getProfiler(index), PieProfilerWindowComponent.getRoot(index)));
addChild(button, new Constrains(new RelativeConstrain(index * 0.3333F), new PixelConstrain(8F).setInverted(), new RelativeConstrain(0.3333F), new PixelConstrain(7F)));
return button;
}
@Override
public Vec2f getMinimumBounds()
{
return Vec2f.of(100F, 50F);
}
}

View File

@ -46,8 +46,8 @@ public class ChoiceComponent extends WindowComponent
super.init();
yesButton.getText().setTextScale(0.5F);
noButton.getText().setTextScale(0.5F);
addChild(yesButton.addChangeListener(minimizedListener).addUserActionListener(closeListener).addUserActionListener(T -> listener.accept(true)), new Constrains(new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(noButton.addChangeListener(minimizedListener).addUserActionListener(closeListener).addUserActionListener(T -> listener.accept(false)), new Constrains(new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(yesButton.onChange(minimizedListener).onAction(closeListener).onAction(T -> listener.accept(true)), new Constrains(new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(noButton.onChange(minimizedListener).onAction(closeListener).onAction(T -> listener.accept(false)), new Constrains(new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F)));
addChild(message, new Constrains(new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message)));
getBox().setHeight(25F + message.getMetadata().getMaxHeight());
}

View File

@ -61,7 +61,7 @@ public class MessageComponent extends WindowComponent
{
super.init();
resultButton.getText().setTextScale(0.5F);
addChild(resultButton.addChangeListener(minimizedListener).addUserActionListener(closeListener), new Constrains(new ParentConstrain(), new ParentConstrain(10F).invert(), new ParentConstrain(), new PixelConstrain(10F)));
addChild(resultButton.onChange(minimizedListener).onAction(closeListener), new Constrains(new ParentConstrain(), new ParentConstrain(10F).invert(), new ParentConstrain(), new PixelConstrain(10F)));
addChild(message, new Constrains(new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message)));
getBox().setHeight(25F + message.getMetadata().getMaxHeight());
}

View File

@ -45,10 +45,10 @@ public class TextInputComponent extends WindowComponent
confirm.getText().setTextScale(0.5F);
cancel.getText().setTextScale(0.5F);
input.getRawText().setTextScale(0.5F);
addChild(confirm.addChangeListener(minimizedListener).addUserActionListener(this::onListen), new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(cancel.addChangeListener(minimizedListener).addUserActionListener(closeListener), new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(message.addChangeListener(minimizedListener), new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message));
addChild(input.addChangeListener(minimizedListener).addUserActionListener(this::onListen), new PixelConstrain(10F), TextConstrain.height(message).setPadding(15F), new ParentConstrain(10F), new PixelConstrain(12F));
addChild(confirm.onChange(minimizedListener).onAction(this::onListen), new RelativeConstrain(0F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(cancel.onChange(minimizedListener).onAction(closeListener), new RelativeConstrain(0.5F), new ParentConstrain(10F).invert(), new RelativeConstrain(0.5F), new PixelConstrain(10F));
addChild(message.onChange(minimizedListener), new PixelConstrain(10F), new PixelConstrain(11F), new ParentConstrain(10F), TextConstrain.height(message));
addChild(input.onChange(minimizedListener).onAction(this::onListen), new PixelConstrain(10F), TextConstrain.height(message).setPadding(15F), new ParentConstrain(10F), new PixelConstrain(12F));
getBox().setHeight(45F + message.getMetadata().getMaxHeight());
}

View File

@ -64,6 +64,8 @@ public class Constrains
}
}
public static ConstrainBuilder builder() { return new ConstrainBuilder(); };
public static ConstrainBuilder xPos(Constrain xPos) { return new ConstrainBuilder().set(xPos, Target.X); }
public static ConstrainBuilder yPos(Constrain yPos) { return new ConstrainBuilder().set(yPos, Target.Y); }
public static ConstrainBuilder width(Constrain width) { return new ConstrainBuilder().set(width, Target.WIDTH); }
@ -83,6 +85,8 @@ public class Constrains
public static ConstrainBuilder invParent(Target target) { return new ConstrainBuilder().set(new ParentConstrain().invert(), target); }
public static ConstrainBuilder parent(float padding, Target target) { return new ConstrainBuilder().set(new ParentConstrain(padding), target); }
public static ConstrainBuilder invParent(float padding, Target target) { return new ConstrainBuilder().set(new ParentConstrain(padding).invert(), target); }
public static ConstrainBuilder pixel(float pixels, Target target) { return new ConstrainBuilder().set(new PixelConstrain(pixels), target); }
public static ConstrainBuilder invPixel(float pixels, Target target) { return new ConstrainBuilder().set(new PixelConstrain(pixels).setInverted(), target); }
public static ConstrainBuilder center(Target target) { return new ConstrainBuilder().set(new CenterConstrain(), target); }
public static ConstrainBuilder dynamic(FloatSupplier provider, Target target) { return new ConstrainBuilder().set(new DynamicConstrain(provider), target); }
@ -114,6 +118,8 @@ public class Constrains
public ConstrainBuilder invParent(Target target) { return set(new ParentConstrain().invert(), target); }
public ConstrainBuilder parent(float padding, Target target) { return set(new ParentConstrain(padding), target); }
public ConstrainBuilder invParent(float padding, Target target) { return set(new ParentConstrain(padding).invert(), target); }
public ConstrainBuilder pixel(float pixels, Target target) { return set(new PixelConstrain(pixels), target); }
public ConstrainBuilder invPixel(float pixels, Target target) { return set(new PixelConstrain(pixels).setInverted(), target); }
public ConstrainBuilder center(Target target) { return set(new CenterConstrain(), target); }
public ConstrainBuilder dynamic(FloatSupplier provider, Target target) { return set(new DynamicConstrain(provider), target); }

View File

@ -38,7 +38,7 @@ public class UIRenderer implements IReloadableResource
Stack<Matrix4f> transformStack = new ObjectArrayList<>();
Matrix4f transform = new Matrix4f();
boolean isFastTransform = true;
SimplePool<Vec4f> fastPool = new SimplePool<>(100, () -> Vec4f.mutable(0F, 0F, 0F, 1F));
SimplePool<Vec4f> fastPool = new SimplePool<>(100, Vec4f::of);
Stack<Vec4f> fastStack = new ObjectArrayList<>();
Vec4f fastTransform = Vec4f.mutable(0F, 0F, 0F, 1F);

View File

@ -14,7 +14,7 @@ import speiger.src.coreengine.utils.collections.iterators.IterableWrapper;
public class RenderBuffer implements Consumer<GuiComponent>, Iterable<DrawCall>
{
List<DrawCall> drawCalls = new ObjectArrayList<DrawCall>();
List<DrawCall> drawCalls = new ObjectArrayList<>();
Tesselator tesselator;
public RenderBuffer(Tesselator tesselator)

View File

@ -14,7 +14,7 @@ public class Line
float width;
int totalLetters = 0;
String result = null;
List<Word> words = new ObjectArrayList<Word>();
List<Word> words = new ObjectArrayList<>();
public Line(float totalWidth)
{

View File

@ -10,7 +10,7 @@ import speiger.src.coreengine.rendering.gui.components.TextComponent;
public class TextMetadata
{
TextComponent owner;
List<Line> lines = new ObjectArrayList<Line>();
List<Line> lines = new ObjectArrayList<>();
float startX;
float startY;
float maxHeight;

View File

@ -49,8 +49,8 @@ public class Window
Matrix4f projection = new Matrix4f();
Matrix4f invertedProjection = new Matrix4f();
List<WindowCallback> callbacks = new ObjectArrayList<WindowCallback>();
List<IWindowListener> listeners = new ObjectArrayList<IWindowListener>();
List<WindowCallback> callbacks = new ObjectArrayList<>();
List<IWindowListener> listeners = new ObjectArrayList<>();
GLCapabilities capabilities;
public Window()
@ -141,6 +141,7 @@ public class Window
callback.destroy();
callback.reload(windowId);
}
GLUtils.reapplyState();
}
protected void updateViewPort()

View File

@ -41,7 +41,7 @@ public class Tesselator implements IVertexBuilder
drawType = glType;
drawing = true;
currentList = list;
currentElement = list.getElement(0);
currentElement = list.get(0);
currentIndex = 0;
buffer.clear();
vertexes = 0;
@ -265,8 +265,8 @@ public class Tesselator implements IVertexBuilder
protected void nextElement()
{
currentIndex = (currentIndex + 1) % currentList.getElementCount();
currentElement = currentList.getElement(currentIndex);
currentIndex = (currentIndex + 1) % currentList.size();
currentElement = currentList.get(currentIndex);
}
public int getVertexCount()

View File

@ -18,9 +18,7 @@ public class VertexList implements Iterable<VertexElement>
IntList offsets = new IntArrayList();
int totalOffset;
public VertexList()
{
}
public VertexList() {}
public VertexList(VertexList vertexList)
{
@ -29,12 +27,13 @@ public class VertexList implements Iterable<VertexElement>
totalOffset = vertexList.totalOffset;
}
public void addElement(VertexElement element)
public VertexList add(VertexElement element)
{
elements.add(element);
offsets.add(totalOffset);
totalOffset += element.getSize();
types.add(element.getUsage());
return this;
}
public int getOffsets()
@ -42,12 +41,12 @@ public class VertexList implements Iterable<VertexElement>
return totalOffset;
}
public int getElementCount()
public int size()
{
return elements.size();
}
public VertexElement getElement(int index)
public VertexElement get(int index)
{
return elements.get(index);
}
@ -60,12 +59,11 @@ public class VertexList implements Iterable<VertexElement>
@Override
public Iterator<VertexElement> iterator()
{
return new ReadOnlyIterator<VertexElement>(elements.iterator());
return new ReadOnlyIterator<>(elements.iterator());
}
public boolean hasType(ElementUsage type)
{
return types.contains(type);
}
}

View File

@ -12,36 +12,12 @@ public class VertexType
public static final VertexElement NORMAL_3F = new VertexElement(3, ElementUsage.NORMAL);
public static final VertexElement CUSTOM_4F = new VertexElement(4, ElementUsage.CUSTOM);
public static final VertexList POS_COLOR_3F = new VertexList();
public static final VertexList POS_COLOR_4F = new VertexList();
public static final VertexList POS_COLOR_2F = new VertexList();
public static final VertexList POS_TEX = new VertexList();
public static final VertexList TERRAIN = new VertexList();
public static final VertexList POS_COLOR_2F = new VertexList().add(POSITION_2F).add(COLOR_4F);
public static final VertexList POS_COLOR_3F = new VertexList().add(POSITION_3F).add(COLOR_3F);
public static final VertexList POS_COLOR_4F = new VertexList().add(POSITION_3F).add(COLOR_4F);
public static final VertexList POS_TEX = new VertexList().add(POSITION_3F).add(TEXTURE_2F);
public static final VertexList TERRAIN = new VertexList().add(POSITION_3F).add(COLOR_3F).add(NORMAL_3F);
public static final VertexList UI = new VertexList();
public static final VertexList IN_WORLD_UI = new VertexList();
static
{
UI.addElement(POSITION_3F);
UI.addElement(TEXTURE_2F);
UI.addElement(COLOR_4F);
IN_WORLD_UI.addElement(POSITION_3F);
IN_WORLD_UI.addElement(TEXTURE_2F);
IN_WORLD_UI.addElement(COLOR_4F);
IN_WORLD_UI.addElement(CUSTOM_4F);
TERRAIN.addElement(POSITION_3F);
TERRAIN.addElement(COLOR_3F);
TERRAIN.addElement(NORMAL_3F);
POS_COLOR_2F.addElement(POSITION_2F);
POS_COLOR_2F.addElement(COLOR_4F);
POS_COLOR_3F.addElement(POSITION_3F);
POS_COLOR_3F.addElement(COLOR_3F);
POS_COLOR_4F.addElement(POSITION_3F);
POS_COLOR_4F.addElement(COLOR_4F);
POS_TEX.addElement(POSITION_3F);
POS_TEX.addElement(TEXTURE_2F);
}
public static final VertexList UI = new VertexList().add(POSITION_3F).add(TEXTURE_2F).add(COLOR_4F);
public static final VertexList IN_WORLD_UI = new VertexList().add(POSITION_3F).add(TEXTURE_2F).add(COLOR_4F).add(CUSTOM_4F);
}

View File

@ -41,6 +41,14 @@ public class GLUtils
return state;
}
public static void reapplyState()
{
for(int i = 0;i<ALL_STATES.size();i++)
{
ALL_STATES.get(i).reapply();
}
}
public static void onFrameEnded()
{
for(int i = 0,m=COUNTERS.length;i<m;i++)

View File

@ -30,6 +30,13 @@ public class BlendState extends GLState
return this;
}
@Override
public void reapply()
{
super.reapply();
GL11.glBlendFunc(src, func);
}
public void setDefault()
{
setFunction(GL11.GL_ONE, GL11.GL_ONE);

View File

@ -30,4 +30,11 @@ public class CullState extends GLState
}
}
}
@Override
public void reapply()
{
super.reapply();
GL11.glCullFace(type);
}
}

View File

@ -1,12 +1,12 @@
package speiger.src.coreengine.rendering.utils.states;
import speiger.src.collections.floats.collections.FloatStack;
import speiger.src.collections.floats.lists.FloatArrayList;
import speiger.src.collections.floats.lists.FloatList;
public abstract class FloatState implements IGLState
{
protected final float defaultValue;
protected FloatList states = new FloatArrayList();
protected FloatStack states = new FloatArrayList();
public FloatState(float defaultValue)
{
@ -15,25 +15,19 @@ public abstract class FloatState implements IGLState
public void push(float newValue)
{
if((states.isEmpty() && equalsNot(newValue, defaultValue)) || (states.size() > 0 && equalsNot(states.getFloat(states.size()-1), newValue)))
if((states.isEmpty() && equalsNot(newValue, defaultValue)) || (states.size() > 0 && equalsNot(states.top(), newValue)))
{
setValue(newValue);
}
states.add(newValue);
states.push(newValue);
}
public void pop()
{
if(states.isEmpty()) throw new IllegalStateException("State is already reset");
if(states.size() == 1 && equalsNot(defaultValue, states.getFloat(0)))
{
setValue(defaultValue);
}
else if(states.size() > 1 && equalsNot(states.getFloat(states.size()-2), states.getFloat(states.size()-1)))
{
setValue(states.getFloat(states.size()-2));
}
states.removeFloat(states.size()-1);
float prev = states.pop();
if(states.isEmpty() && equalsNot(defaultValue, prev)) setValue(defaultValue);
else if(!states.isEmpty() && equalsNot(states.top(), prev)) setValue(states.top());
}
protected abstract void setValue(float value);
@ -45,14 +39,21 @@ public abstract class FloatState implements IGLState
return Float.floatToIntBits(key) != Float.floatToIntBits(value);
}
@Override
public void reapply()
{
if(states.isEmpty()) setValue(defaultValue);
else setValue(states.top());
}
@Override
public void cleanup()
{
if(states.size() > 1)
{
float value = states.getFloat(states.size()-1);
float value = states.top();
states.clear();
states.add(value);
states.push(value);
}
}
}

View File

@ -53,6 +53,13 @@ public class GLState implements IGLState
else GL11.glDisable(id);
}
@Override
public void reapply()
{
if(index < 0) setValue(defaultValue);
else setValue(memory.get(index));
}
@Override
public void cleanup()
{

View File

@ -3,4 +3,5 @@ package speiger.src.coreengine.rendering.utils.states;
public interface IGLState
{
public void cleanup();
public void reapply();
}

View File

@ -42,15 +42,19 @@ public class ThreadPool<T> implements IPool<T>
@Override
public synchronized void accept(T[] array)
{
stack.addAll(array, 0, Math.min(array.length, cap - stack.size()));
for(int i = 0,m=Math.min(array.length, cap - stack.size());i<m;acceptor.accept(array[i++]));
int size = Math.min(array.length, cap - stack.size());
if(size <= 0) return;
stack.addAll(array, 0, size);
for(int i = 0;i<size;acceptor.accept(array[i++]));
}
@Override
public synchronized void accept(Collection<T> array)
{
int size = Math.min(array.size(), cap - stack.size());
if(size <= 0) return;
Iterator<T> iter = array.iterator();
for(int i = 0,m=Math.min(array.size(), cap - stack.size());i<m && iter.hasNext();i++)
for(int i = 0;i<size && iter.hasNext();i++)
{
T next = iter.next();
stack.add(next);

View File

@ -73,7 +73,7 @@ public class GPUProfilerEntry implements IProfilerEntry
}
average += currentTime;
entries.enqueue(currentTime);
if(entries.size() > 20)
if(entries.size() > 100)
{
average -= entries.dequeue();
}

View File

@ -1,15 +1,13 @@
package speiger.src.coreengine.utils.profiler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.ObjIntConsumer;
import speiger.src.collections.objects.lists.ObjectArrayList;
import speiger.src.collections.objects.lists.ObjectList;
import speiger.src.coreengine.utils.helpers.TextUtil;
public interface IProfiler
{
public String getName();
public IProfilerEntry getEntry(String name);
@ -81,9 +79,9 @@ public interface IProfiler
return entry.getNanoTime();
}
public default List<ProfilerData> getData()
public default ObjectList<ProfilerData> getData()
{
List<ProfilerData> list = new ArrayList<ProfilerData>();
ObjectList<ProfilerData> list = new ObjectArrayList<>();
long time = getNanoTime();
long totalTime = getTotalTime();
long used = 0L;
@ -101,9 +99,9 @@ public interface IProfiler
long nanoTime = time - used;
double percent = (((double)nanoTime / (double)time) * 100D);
double totalPercent = (((double)nanoTime / (double)totalTime) * 100D);
list.add(new ProfilerData("Nameless", nanoTime, percent, totalPercent));
list.add(new ProfilerData("self", nanoTime, percent, totalPercent));
}
Collections.sort(list);
list.sort(null);
return list;
}
}

View File

@ -65,8 +65,8 @@ public class ProfilerEntry implements IProfilerEntry
{
if(end && totalTicks++ >= 10)
{
minTime = 0;
maxTime = 0;
minTime = Long.MAX_VALUE;
maxTime = Long.MIN_VALUE;
totalTicks = 0;
}
return;
@ -74,7 +74,7 @@ public class ProfilerEntry implements IProfilerEntry
didTick = false;
average += currentTime;
entries.enqueue(currentTime);
if(entries.size() > 20)
if(entries.size() > 100)
{
average -= entries.dequeue();
}

View File

@ -7,7 +7,7 @@ import speiger.src.coreengine.utils.counters.timers.CountdownSync;
public class MainThreadTaskProcessor
{
ObjectPriorityDequeue<ITask> tasks = ObjectPriorityQueues.synchronize(new ObjectArrayFIFOQueue<ITask>());
ObjectPriorityDequeue<ITask> tasks = ObjectPriorityQueues.synchronize(new ObjectArrayFIFOQueue<>());
Watchdog watch;
Thread watchThread;
boolean running = false;