Skip to content

Commit 3ba0789

Browse files
committed
stuff.
1 parent 449d4fb commit 3ba0789

7 files changed

Lines changed: 223 additions & 43 deletions

File tree

editor/src/main/java/oxy/bascenario/editor/EditorValues.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package oxy.bascenario.editor;
22

3-
import lombok.AccessLevel;
43
import lombok.Getter;
54
import lombok.Setter;
65
import lombok.experimental.Accessors;
@@ -17,6 +16,11 @@ public class EditorValues {
1716

1817
private boolean playing;
1918
private long timestamp = 1000L;
19+
public void timestamp(long timestamp) {
20+
this.timestamp = timestamp;
21+
this.playing = false;
22+
}
23+
2024
private float scale = 1;
2125
private float scroll;
2226

Lines changed: 120 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,172 @@
11
package oxy.bascenario.editor.containers;
22

3+
import lombok.RequiredArgsConstructor;
4+
import lombok.Setter;
5+
import lombok.experimental.Accessors;
36
import net.lenni0451.commons.color.Color;
47
import net.lenni0451.rivet.backend.render.Renderer;
8+
import net.lenni0451.rivet.component.Component;
59
import net.lenni0451.rivet.component.container.Container;
10+
import net.lenni0451.rivet.input.keyboard.Key;
11+
import net.lenni0451.rivet.input.keyboard.KeyEvent;
612
import net.lenni0451.rivet.input.mouse.MouseButton;
713
import net.lenni0451.rivet.input.mouse.MouseButtonEvent;
814
import net.lenni0451.rivet.input.mouse.MouseMoveEvent;
15+
import net.lenni0451.rivet.layout.Layout;
916
import net.lenni0451.rivet.layout.dock.DockLayout;
1017
import net.lenni0451.rivet.layout.dock.DockPosition;
1118
import net.lenni0451.rivet.math.Rectangle;
1219
import net.lenni0451.rivet.math.Size;
1320
import net.raphimc.thingl.ThinGL;
1421
import net.raphimc.thingl.implementation.window.GLFWWindowInterface;
1522
import org.lwjgl.glfw.GLFW;
23+
import oxy.bascenario.editor.EditorValues;
24+
import oxy.bascenario.editor.containers.assets.AssetsContainer;
1625
import oxy.bascenario.editor.containers.timeline.TimelineContainer;
1726

18-
public class GlobalContainer extends Container {
19-
private final TimelineContainer timeline;
27+
import java.util.HashMap;
28+
import java.util.Map;
2029

30+
public class GlobalContainer extends Container {
2131
public GlobalContainer() {
22-
super(new DockLayout());
32+
super(new DockLayout(3));
2333

24-
addChild(timeline = new TimelineContainer(), c -> c.layoutOptions(DockPosition.BOTTOM));
34+
addChild(new TimelineContainer(), c -> c.layoutOptions(DockPosition.BOTTOM));
35+
addChild(new AssetsContainer(), c -> c.layoutOptions(DockPosition.LEFT));
36+
37+
for (Component component : children()) {
38+
resizableComponents.put((ResizeableContainer) component, new ResizeComponent(
39+
component.layoutOptions() == DockPosition.BOTTOM || component.layoutOptions() == DockPosition.TOP ?
40+
ResizeComponent.ResizeType.Vertical : ResizeComponent.ResizeType.Horizontal,
41+
(DockPosition) component.layoutOptions()
42+
));
43+
}
2544
}
2645

27-
float prevMouseY;
28-
boolean nearTimeline, nearTimelineAndMouseDown;
46+
final Map<ResizeableContainer, ResizeComponent> resizableComponents = new HashMap<>();
47+
2948
@Override
3049
public void render(Renderer renderer, Size size) {
3150
super.render(renderer, size);
3251

33-
if (nearTimelineAndMouseDown) {
34-
Rectangle bounds = this.childBounds(timeline);
35-
renderer.fillRect(bounds.x(), bounds.y() - 5, bounds.width(), 2, Color.fromRGB(115, 115, 115));
52+
for (Map.Entry<ResizeableContainer, ResizeComponent> entry : resizableComponents.entrySet()) {
53+
if (!entry.getValue().nearAndMouseDown) {
54+
continue;
55+
}
56+
final ResizeComponent component = entry.getValue();
57+
58+
Rectangle bounds = this.childBounds(entry.getKey());
59+
60+
if (component.type == ResizeComponent.ResizeType.Horizontal) {
61+
if (component.position == DockPosition.LEFT) {
62+
renderer.fillRect(bounds.maxX() + 5, bounds.y(), 2, bounds.height(), Color.fromRGB(115, 115, 115));
63+
} else {
64+
renderer.fillRect(bounds.x() + 5, bounds.y(), 2, bounds.height(), Color.fromRGB(115, 115, 115));
65+
}
66+
} else {
67+
renderer.fillRect(bounds.x(), bounds.y() - 5, bounds.width(), 2, Color.fromRGB(115, 115, 115));
68+
}
3669
}
3770
}
3871

3972
@Override
4073
protected boolean onComponentMouseMove(MouseMoveEvent event, Size size) {
4174
super.onComponentMouseMove(event, size);
4275

43-
Rectangle timelineBounds = this.childBounds(timeline);
44-
boolean nearTimeline = Math.abs(event.y() - timelineBounds.y()) < 8;
45-
if (nearTimeline && !this.nearTimeline) {
46-
GLFW.glfwSetCursor(((GLFWWindowInterface) ThinGL.windowInterface()).getWindowHandle(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_VRESIZE_CURSOR));
47-
} else if (!nearTimeline && this.nearTimeline && !nearTimelineAndMouseDown) {
48-
GLFW.glfwSetCursor(((GLFWWindowInterface) ThinGL.windowInterface()).getWindowHandle(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR));
49-
}
50-
this.nearTimeline = nearTimeline;
51-
if (!nearTimelineAndMouseDown) {
52-
this.nearTimelineAndMouseDown = event.isHeld(MouseButton.LEFT) && nearTimeline;
53-
}
76+
for (Map.Entry<ResizeableContainer, ResizeComponent> entry : resizableComponents.entrySet()) {
77+
final ResizeComponent component = entry.getValue();
78+
Rectangle bounds = this.childBounds(entry.getKey());
5479

55-
if (nearTimelineAndMouseDown && prevMouseY != Float.MAX_VALUE) {
56-
float newHeight = timelineBounds.height() - (event.y() - prevMouseY);
57-
float ratio = newHeight / size.height();
58-
timeline.relativeScale(ratio);
59-
timeline.requestLayoutRecalculation();
60-
}
80+
boolean near;
81+
if (component.type == ResizeComponent.ResizeType.Vertical) {
82+
near = Math.abs(event.y() - bounds.y()) < 4;
83+
} else {
84+
if (component.position == DockPosition.LEFT) {
85+
near = Math.abs(event.x() - bounds.maxX()) < 4;
86+
} else {
87+
near = Math.abs(event.x() - bounds.x()) < 4;
88+
}
89+
}
90+
91+
if (near && !component.near) {
92+
int mouse = component.type == ResizeComponent.ResizeType.Vertical ? GLFW.GLFW_VRESIZE_CURSOR : GLFW.GLFW_HRESIZE_CURSOR;
93+
GLFW.glfwSetCursor(((GLFWWindowInterface) ThinGL.windowInterface()).getWindowHandle(), GLFW.glfwCreateStandardCursor(mouse));
94+
} else if (!near && component.near && !component.nearAndMouseDown) {
95+
GLFW.glfwSetCursor(((GLFWWindowInterface) ThinGL.windowInterface()).getWindowHandle(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR));
96+
}
97+
98+
component.near = near;
99+
if (!component.nearAndMouseDown) {
100+
component.nearAndMouseDown = event.isHeld(MouseButton.LEFT) && near;
101+
}
102+
103+
if (component.nearAndMouseDown && component.prevMouse != Float.MAX_VALUE) {
104+
if (component.type == ResizeComponent.ResizeType.Vertical) {
105+
float newHeight = bounds.height() - (event.y() - component.prevMouse);
106+
entry.getKey().relativeScale = newHeight / size.height();
107+
entry.getKey().requestLayoutRecalculation();
108+
} else {
109+
float newWidth = bounds.width() - (event.x() - component.prevMouse) * (component.position == DockPosition.LEFT ? -1 : 1);
110+
entry.getKey().relativeScale = newWidth / size.width();
111+
entry.getKey().requestLayoutRecalculation();
112+
}
113+
}
61114

62-
prevMouseY = event.y();
63-
if (!nearTimeline || !nearTimelineAndMouseDown) {
64-
prevMouseY = Float.MAX_VALUE;
115+
component.prevMouse = component.type == ResizeComponent.ResizeType.Vertical ? event.y() : event.x();
116+
if (!component.near || !component.nearAndMouseDown) {
117+
component.prevMouse = Float.MAX_VALUE;
118+
}
65119
}
66120

67121
return true;
68122
}
69123

70124
@Override
71125
protected boolean onComponentMouseUp(MouseButtonEvent event, Size size) {
72-
this.nearTimelineAndMouseDown = false;
126+
this.resizableComponents.values().forEach(c -> c.nearAndMouseDown = false);
73127
return super.onComponentMouseUp(event, size);
74128
}
75129

76130
@Override
77131
protected boolean onComponentMouseDown(MouseButtonEvent event, Size size) {
78-
this.nearTimelineAndMouseDown = event.button() == MouseButton.LEFT && nearTimeline;
79-
if (!nearTimelineAndMouseDown) {
80-
prevMouseY = Float.MAX_VALUE;
81-
}
132+
this.resizableComponents.values().forEach(c -> {
133+
c.nearAndMouseDown = event.button() == MouseButton.LEFT && c.near;
134+
if (!c.nearAndMouseDown) {
135+
c.prevMouse = Float.MAX_VALUE;
136+
}
137+
});
82138

83139
super.onComponentMouseDown(event, size);
84140
return true;
85141
}
142+
143+
@Override
144+
protected boolean onComponentKeyUp(KeyEvent event) {
145+
if (event.key() == Key.SPACE) {
146+
EditorValues.instance().playing(!EditorValues.instance().playing());
147+
}
148+
149+
return super.onComponentKeyUp(event);
150+
}
151+
152+
@RequiredArgsConstructor
153+
private static class ResizeComponent {
154+
private final ResizeType type;
155+
private final DockPosition position;
156+
private boolean near, nearAndMouseDown;
157+
private float prevMouse = Float.MAX_VALUE;
158+
159+
public enum ResizeType {
160+
Horizontal, Vertical
161+
}
162+
}
163+
164+
@Accessors(fluent = true)
165+
public static class ResizeableContainer extends Container {
166+
@Setter
167+
protected float relativeScale = 0.2f;
168+
public ResizeableContainer(Layout layout) {
169+
super(layout);
170+
}
171+
}
86172
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package oxy.bascenario.editor.containers.assets;
2+
3+
import lombok.experimental.Accessors;
4+
import net.lenni0451.commons.color.Color;
5+
import net.lenni0451.rivet.backend.render.Renderer;
6+
import net.lenni0451.rivet.layout.dock.DockLayout;
7+
import net.lenni0451.rivet.math.Size;
8+
import oxy.bascenario.editor.containers.GlobalContainer;
9+
10+
@Accessors(fluent = true)
11+
public class AssetsContainer extends GlobalContainer.ResizeableContainer {
12+
public AssetsContainer() {
13+
super(new DockLayout(0));
14+
}
15+
16+
@Override
17+
public void render(Renderer renderer, Size size) {
18+
renderer.fillRoundedRect(0, 0, size.width(), size.height(), 5, Color.fromRGB(48, 48, 48));
19+
super.render(renderer, size);
20+
renderer.outlineRoundedRect(0, 0, size.width(), size.height(), 5, 1, Color.fromRGB(59, 59, 59));
21+
}
22+
23+
@Override
24+
public Size computeIdealSize(Size constraints) {
25+
return constraints.withWidth(constraints.width() * relativeScale);
26+
}
27+
}

editor/src/main/java/oxy/bascenario/editor/containers/sequencer/SequencerTimeSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void render(Renderer renderer, Size size) {
2525
ShapedText text = this.rivet().backend().font().shapeText(format(time), Color.GRAY);
2626
float currentX = x;
2727

28-
renderer.scale(0.38f, () -> renderer.text(text, currentX / 0.38f, (5 / 35f) * size.height(), TextOrigin.Horizontal.VISUAL_LEFT, TextOrigin.Vertical.LOGICAL_TOP));
28+
renderer.scale(0.3f, () -> renderer.text(text, currentX / 0.3f, (5 / 35f) * size.height(), TextOrigin.Horizontal.VISUAL_LEFT, TextOrigin.Vertical.LOGICAL_TOP));
2929

3030
x += EditorValues.instance().oneSecondWidth();
3131
}

editor/src/main/java/oxy/bascenario/editor/containers/timeline/TimelineContainer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
11
package oxy.bascenario.editor.containers.timeline;
22

3-
import lombok.Setter;
43
import lombok.experimental.Accessors;
54
import net.lenni0451.commons.color.Color;
65
import net.lenni0451.rivet.backend.render.Renderer;
7-
import net.lenni0451.rivet.component.container.Container;
86
import net.lenni0451.rivet.component.container.DecoratedContainer;
97
import net.lenni0451.rivet.component.impl.SolidColor;
108
import net.lenni0451.rivet.layout.dock.DockLayout;
119
import net.lenni0451.rivet.layout.dock.DockPosition;
1210
import net.lenni0451.rivet.math.Padding;
1311
import net.lenni0451.rivet.math.Size;
12+
import oxy.bascenario.editor.containers.GlobalContainer;
1413
import oxy.bascenario.editor.containers.sequencer.VideoSequencerContainer;
1514

1615
@Accessors(fluent = true)
17-
public class TimelineContainer extends Container {
18-
@Setter
19-
private float relativeScale = 0.34f;
20-
16+
public class TimelineContainer extends GlobalContainer.ResizeableContainer {
2117
public TimelineContainer() {
2218
super(new DockLayout(0));
2319

@@ -27,6 +23,8 @@ public TimelineContainer() {
2723
});
2824
this.addChild(new TimelineTimeControl(), c -> c.layoutOptions(DockPosition.BOTTOM));
2925
this.addChild(new VideoSequencerContainer(), c -> c.layoutOptions(DockPosition.CENTER));
26+
27+
relativeScale = 0.34f;
3028
}
3129

3230
@Override

editor/src/main/java/oxy/bascenario/editor/containers/timeline/TimelineDockBar.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,54 @@
11
package oxy.bascenario.editor.containers.timeline;
22

3-
import net.lenni0451.rivet.component.container.Container;
3+
import net.lenni0451.commons.color.Color;
4+
import net.lenni0451.rivet.component.container.*;
5+
import net.lenni0451.rivet.component.impl.Label;
6+
import net.lenni0451.rivet.component.impl.SolidColor;
7+
import net.lenni0451.rivet.layout.grid.GridAnchor;
8+
import net.lenni0451.rivet.layout.grid.GridFill;
9+
import net.lenni0451.rivet.layout.grid.GridLayoutOptions;
410
import net.lenni0451.rivet.layout.list.HorizontalListLayout;
11+
import net.lenni0451.rivet.layout.list.VerticalListLayout;
12+
import net.lenni0451.rivet.math.Padding;
513
import net.lenni0451.rivet.math.Size;
614
import oxy.bascenario.utils.components.TimelineDockExpandButton;
715

16+
import static net.lenni0451.rivet.utils.MathUtils.roundMin;
17+
818
public class TimelineDockBar extends Container {
919
public TimelineDockBar() {
1020
super(new HorizontalListLayout(12, false));
1121

1222
addChild(new TimelineDockExpandButton());
23+
24+
{
25+
Container container = new Container(new VerticalListLayout(5, true));
26+
final ComboBox box = new ComboBox("Select", new DecoratedContainer(
27+
new SolidColor(Color.fromRGB(24, 24, 24)).cornerRadius(5), container));
28+
29+
Button button = box.button();
30+
((Label)button.child()).scale(0.3f);
31+
button.inactiveOutlineColor().set(Color.TRANSPARENT);
32+
button.activeOutlineColor().set(Color.TRANSPARENT);
33+
button.inactiveColor().set(Color.TRANSPARENT);
34+
35+
box.arrowSize().set(0f);
36+
box.layoutOptions(new GridLayoutOptions(0, 6).withAnchor(GridAnchor.LEFT).withWeightX(1).withFill(GridFill.HORIZONTAL).withColumnSpan(2));
37+
addChild(box);
38+
39+
float textHeight = 11f;
40+
Padding padding = new Padding(roundMin(textHeight / 3F, 0), roundMin(textHeight / 10F, 0), roundMin(textHeight / 3F, 0), roundMin(textHeight / 10F, 0));
41+
button.innerPadding().set(padding.withTop(3f));
42+
43+
container.addChild(new Button("All", c -> {}), b -> {
44+
((Label)b.child()).scale(0.3f);
45+
b.inactiveOutlineColor().set(Color.TRANSPARENT);
46+
b.activeOutlineColor().set(Color.TRANSPARENT);
47+
b.inactiveColor().set(Color.TRANSPARENT);
48+
});
49+
// container.addChild(new Button("None", c -> {}));
50+
// container.addChild(new Button("Invert", c -> {}));
51+
}
1352
}
1453

1554
@Override
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
11
package oxy.bascenario.editor.containers.timeline;
22

3+
import net.lenni0451.rivet.backend.render.Renderer;
34
import net.lenni0451.rivet.component.container.Container;
5+
import net.lenni0451.rivet.component.impl.Label;
46
import net.lenni0451.rivet.layout.anchor.AnchorLayout;
7+
import net.lenni0451.rivet.layout.anchor.AnchorLayoutOptions;
58
import net.lenni0451.rivet.math.Size;
9+
import oxy.bascenario.editor.EditorValues;
610

711
public class TimelineTimeControl extends Container {
12+
private final Label timeLabel;
13+
814
public TimelineTimeControl() {
915
super(AnchorLayout.INSTANCE);
16+
17+
timeLabel = new Label("");
18+
timeLabel.layoutOptions(AnchorLayoutOptions.EMPTY.withAnchorMinX(0.95f).withAnchorMinY(0.5f).pivot(0.5f, 0.5f));
19+
timeLabel.scale(.45f);
20+
21+
this.addChild(timeLabel);
22+
}
23+
24+
@Override
25+
public void render(Renderer renderer, Size size) {
26+
timeLabel.text(format(EditorValues.instance().timestamp()));
27+
super.render(renderer, size);
1028
}
1129

1230
@Override
1331
public Size computeIdealSize(Size constraints) {
1432
return constraints.withHeight(25);
1533
}
34+
35+
private String format(long ms) {
36+
long millis = ms % 1000;
37+
long second = (ms / 1000) % 60;
38+
long minute = (ms / (1000 * 60)) % 60;
39+
long hour = (ms / (1000 * 60 * 60)) % 24;
40+
return (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + ":" + (millis < 10 ? "0" + millis : millis);
41+
}
1642
}

0 commit comments

Comments
 (0)