horizontal, for some things.

bottom-bar
Ivory 2023-01-18 08:20:27 -05:00
parent 0f73574f13
commit f19cfccf1a
3 changed files with 152 additions and 76 deletions

View File

@ -30,14 +30,13 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
} }
public void renderAlpha() { public void renderAlpha() {
// float f = 99;
float f = 99; // Assets.flat.pushColor(new Vector4f(1, 0, 0, 0.3f));
Assets.flat.pushColor(new Vector4f(1, 0, 0, 0.3f)); // for(Vector4f box : guiAreas) {
for(Vector4f box : guiAreas) { // Drawing.setLayer(f += 0.001f);
Drawing.setLayer(f += 0.001f); // Assets.fillColor.draw(box);
Assets.fillColor.draw(box); // }
} // Assets.flat.popColor();
Assets.flat.popColor();
} }
@Override @Override
@ -71,9 +70,14 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
boolean fixedSize, boolean fixedSize,
Vector4f box, Vector4f box,
Vector4f occlusionBox, Vector4f occlusionBox,
boolean hasRegisteredGuiArea boolean hasRegisteredGuiArea,
boolean horizontal
// layout manager? // layout manager?
) {} ) {
public boolean vertical() {
return !horizontal;
}
}
private transient StackingContext context; private transient StackingContext context;
private transient Stack<StackingContext> contextStack = new Stack<StackingContext>();; private transient Stack<StackingContext> contextStack = new Stack<StackingContext>();;
@ -116,12 +120,22 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
return false; return false;
} }
private void adjustBox(float h) { private void adjustBox(float w, float h) {
if(context.fixedSize) { if(context.vertical()) {
context.box.y += h; if(context.fixedSize) {
context.box.w -= h; context.box.y += h;
context.box.w -= h;
} else {
context.box.w += h;
}
} else { } else {
context.box.w += h; if(context.fixedSize) {
context.box.x += w;
context.box.z -= w;
} else {
context.box.z += w;
context.box.w = Math.max(context.box.w, h);
}
} }
} }
@ -132,6 +146,11 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
private transient List<Vector4f> guiAreas = new ArrayList<Vector4f>(); private transient List<Vector4f> guiAreas = new ArrayList<Vector4f>();
@FunctionalInterface
public interface RenderCallback {
public void apply();
}
// === ELEMENTS === // === ELEMENTS ===
// //
@ -142,10 +161,26 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
guiAreas.clear(); guiAreas.clear();
} }
protected void root(int x, int y, int w, int h, RenderCallback cb) {
root(x, y, w, h);
cb.apply();
rootEnd();
}
protected void window(int x, int y, int w, int h, RenderCallback cb) {
root(x, y, w, h);
fixedFrame(w, h);
pad();
cb.apply();
padEnd();
frameEnd();
rootEnd();
}
protected void root(int x, int y, int w, int h) { protected void root(int x, int y, int w, int h) {
assert context == null : "root can only be a root element"; assert context == null : "root can only be a root element";
Vector4f box = new Vector4f(x, y, w, h); Vector4f box = new Vector4f(x, y, w, h);
context = new StackingContext(true, box, box, false); context = new StackingContext(true, box, box, false, false);
} }
protected void rootEnd() { protected void rootEnd() {
@ -159,7 +194,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
true, true,
new Vector4f(context.box.x, context.box.y, w, h), new Vector4f(context.box.x, context.box.y, w, h),
context.occlusionBox.copy(), context.occlusionBox.copy(),
true true,
context.horizontal
); );
} }
@ -169,7 +205,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
false, false,
new Vector4f(context.box.x, context.box.y, context.box.z, 0), new Vector4f(context.box.x, context.box.y, context.box.z, 0),
context.occlusionBox.copy(), context.occlusionBox.copy(),
true true,
context.horizontal
); );
} }
@ -204,7 +241,23 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
if(expand && context.fixedSize) { if(expand && context.fixedSize) {
h = context.box.w; h = context.box.w;
} }
Vector4f buttonBox = new Vector4f(context.box.x, context.box.y, context.box.z, h); float w = context.box.z;
if(context.horizontal && !context.fixedSize) {
w = 100;
}
int x = (int) context.box.x;
int y = (int) context.box.y;
if(!context.fixedSize) {
if(context.vertical()) {
y += (int) context.box.w;
} else {
x += (int) context.box.z;
}
}
Vector4f buttonBox = new Vector4f(x, y, w, h);
Button btn = getButton(id); Button btn = getButton(id);
if(!context.hasRegisteredGuiArea) { if(!context.hasRegisteredGuiArea) {
@ -212,21 +265,19 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
} }
btn.setText(text); btn.setText(text);
btn.setPosition((int) buttonBox.x, (int) buttonBox.y); btn.setPosition(x, y);
btn.setSize((int) buttonBox.z, (int) buttonBox.w); btn.setSize((int) buttonBox.z, (int) buttonBox.w);
btn.setLayer(getLayer() + contextStack.size() + 1); btn.setLayer(getLayer() + contextStack.size() + 1);
adjustBox(h); adjustBox(buttonBox.z, buttonBox.w);
return getClick(btn); return getClick(btn);
} }
protected void horizontal(int columns) { protected void group(RenderCallback cb) {
group();
} cb.apply();
groupEnd();
protected void horizontalEnd() {
} }
protected void group() { protected void group() {
@ -236,7 +287,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
context.box.x, context.box.y, context.box.z, 0 context.box.x, context.box.y, context.box.z, 0
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea context.hasRegisteredGuiArea,
context.horizontal
); );
pad(); pad();
} }
@ -247,7 +299,7 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
float h = context.box.w; float h = context.box.w;
Assets.uiFrame.draw(context.box); Assets.uiFrame.draw(context.box);
context = contextStack.pop(); context = contextStack.pop();
adjustBox(h); adjustBox(context.box.z, h);
} }
protected void pad() { protected void pad() {
@ -258,7 +310,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
context.box.x + 8, context.box.y + 8, context.box.z - 16, context.box.w - 16 context.box.x + 8, context.box.y + 8, context.box.z - 16, context.box.w - 16
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea context.hasRegisteredGuiArea,
context.horizontal
); );
} else { } else {
context = new StackingContext(false, context = new StackingContext(false,
@ -266,7 +319,8 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
context.box.x + 8, context.box.y + 8, context.box.z - 16, 0 context.box.x + 8, context.box.y + 8, context.box.z - 16, 0
), ),
context.occlusionBox.copy(), context.occlusionBox.copy(),
context.hasRegisteredGuiArea context.hasRegisteredGuiArea,
context.horizontal
); );
} }
} }
@ -274,7 +328,30 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
protected void padEnd() { protected void padEnd() {
float h = context.box.w + 16; float h = context.box.w + 16;
context = contextStack.pop(); context = contextStack.pop();
adjustBox(h); adjustBox(context.box.z + 16, h);
}
protected void horizontal(RenderCallback cb) {
contextStack.push(context);
context = new StackingContext(
false,
new Vector4f(context.box.x, context.box.y, 0, 0),
context.occlusionBox,
context.hasRegisteredGuiArea,
true
);
cb.apply();
float w = context.box.z;
float h = context.box.w;
context = contextStack.pop();
adjustBox(w, h);
}
protected void space(int space) {
if(context.horizontal)
adjustBox(space, 1);
else
adjustBox(1, space);
} }
protected void end() { protected void end() {
@ -308,20 +385,19 @@ public abstract class ImmediateUI extends GameObject implements IMouseCaptureAre
Vector4i measured = font.measure(text); Vector4i measured = font.measure(text);
Drawing.setLayer(getLayer() + contextStack.size()); Drawing.setLayer(getLayer() + contextStack.size());
// layout manager things... int x = (int) context.box.x;
if(context.fixedSize) { int y = (int) context.box.y;
font.drawString(text,
(int) context.box.x, if(!context.fixedSize) {
(int) context.box.y if(context.vertical()) {
); y += (int) context.box.w;
context.box.y += measured.y; } else {
context.box.w -= measured.y; x += (int) context.box.z;
} else { }
font.drawString(text,
(int) context.box.x,
(int) context.box.y + (int) context.box.w
);
context.box.w += measured.y;
} }
font.drawString(text, x, y);
adjustBox(measured.x, measured.y);
} }
} }

View File

@ -6,37 +6,37 @@ public class Popup extends ImmediateUI {
@Override @Override
protected void gui() { protected void gui() {
root(100, 100, 200, 200); {
fixedFrame(200, 100); {
pad(); {
header(" Popup Test");
text("1\n1.5");
text("2");
group(); {
text("This should be in a frame!");
text("And this!");
} groupEnd();
text("But not this...");
if(button("Click Me!")) {
System.out.println("The Event!");
}
text("This after button...");
} padEnd();
} frameEnd();
} rootEnd();
window(10, 100, 1004, 200, () -> {
header(" Popup Test");
horizontal(() -> {
text("LEFT");
space(32);
text("RIGHT");
});
group(() -> {
text("This should be in a frame!");
text("And this!");
});
text("But not this...");
if(button("Click Me!")) {
System.out.println("The Event!");
}
text("This after button...");
});
root(10, 350, 1004, 150, () -> {
root(724, 100, 200, 200); horizontal(() -> {
// text("Test Frame!"); button("hey");
button("Test Button Expand!", true); space(8);
button("Test Button Expand 2!", true); button("hello");
rootEnd(); });
});
} }
} }

View File

@ -59,7 +59,7 @@ public class GameScene extends SceneGraph {
objects.add(new SaveTab()); objects.add(new SaveTab());
objects.add(new LoadTab()); objects.add(new LoadTab());
objects.add(new Popup()); // objects.add(new Popup());
} }
} }