Add Bootloader configuration and enhance clipping functionality in GraphicsContext

This commit is contained in:
2026-05-14 22:03:17 +02:00
parent 412e3adf2a
commit 280f294b57
4 changed files with 41 additions and 10 deletions
+15
View File
@@ -0,0 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Bootloader" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="be.seeseemelk.diceos.Bootloader" />
<module name="diceos.main" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="be.seeseemelk.diceos.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
@@ -69,9 +69,12 @@ public class WindowService implements OnStartup {
// Render menubar items
gc.save();
gc.translate(10, 0);
gc.translate(5, 0);
for (var submenu : menu.getItems()) {
gc.save();
gc.clip(0, 0, submenu.getWidth(), submenu.getHeight());
submenu.paint(gc);
gc.restore();
gc.translate(submenu.getWidth() + 4, 0);
}
gc.restore();
@@ -30,11 +30,11 @@ public class GraphicsContext {
private static class GraphicsState {
private final Matrix4 transform;
private boolean scissorEnabled;
private int scissorCount;
public GraphicsState(Matrix4 transform, boolean scissorEnabled) {
public GraphicsState(Matrix4 transform, int scissorCount) {
this.transform = transform.cpy();
this.scissorEnabled = scissorEnabled;
this.scissorCount = scissorCount;
}
}
@@ -137,11 +137,24 @@ public class GraphicsContext {
* @param height The height of the clipping area.
*/
public void clip(int width, int height) {
var scissors = new Rectangle(0, 0, width, height);
clip(0, 0, width, height);
}
/**
* Sets a clipping rectangle for subsequent draw operations.
*
* @param x The x-coordinate of the clipping area.
* @param y The y-coordinate of the clipping area.
* @param width The width of the clipping area.
* @param height The height of the clipping area.
*/
public void clip(int x, int y, int width, int height) {
var scissors = new Rectangle(x, getHeight() - y - height, width - getXTranslation(), height - getYTranslation());
ScissorStack.calculateScissors(camera, batch.getTransformMatrix(), scissors, scissors);
batch.flush();
ScissorStack.pushScissors(scissors);
getCurrentState().scissorEnabled = true;
if (ScissorStack.pushScissors(scissors)) {
getCurrentState().scissorCount++;
}
}
/**
@@ -157,7 +170,7 @@ public class GraphicsContext {
* The state can later be restored using {@link #restore()}.
*/
public void save() {
stateStack.push(new GraphicsState(batch.getTransformMatrix(), false));
stateStack.push(new GraphicsState(batch.getTransformMatrix(), 0));
}
/**
@@ -171,7 +184,7 @@ public class GraphicsContext {
batch.flush();
GraphicsState state = stateStack.pop();
batch.setTransformMatrix(state.transform);
if (state.scissorEnabled) {
for (int i = 0; i < state.scissorCount; i++) {
ScissorStack.popScissors();
}
}
@@ -56,8 +56,8 @@ public class Menu implements MenuItem {
gc.setColour(0, 0, 255);
}
gc.fillRect(-100, -100, 500, 500);
gc.setColour(255, 255, 255);
gc.fillRect(0, 1, getWidth() + 3, getHeight() - 1);
// Renders the menu as a simple menu button
gc.draw(title, 2, 5);