From 280f294b5780bba2c0f91952e4f07f26eae0b378 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Thu, 14 May 2026 22:03:17 +0200 Subject: [PATCH] Add Bootloader configuration and enhance clipping functionality in GraphicsContext --- .run/Bootloader.run.xml | 15 ++++++++++ .../diceos/system/WindowService.java | 5 +++- .../diceos/system/gfx/GraphicsContext.java | 29 ++++++++++++++----- .../diceos/system/toolkit/menu/Menu.java | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 .run/Bootloader.run.xml diff --git a/.run/Bootloader.run.xml b/.run/Bootloader.run.xml new file mode 100644 index 0000000..3ea1f46 --- /dev/null +++ b/.run/Bootloader.run.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/src/main/java/be/seeseemelk/diceos/system/WindowService.java b/src/main/java/be/seeseemelk/diceos/system/WindowService.java index 93cb110..3045901 100644 --- a/src/main/java/be/seeseemelk/diceos/system/WindowService.java +++ b/src/main/java/be/seeseemelk/diceos/system/WindowService.java @@ -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(); diff --git a/src/main/java/be/seeseemelk/diceos/system/gfx/GraphicsContext.java b/src/main/java/be/seeseemelk/diceos/system/gfx/GraphicsContext.java index 67c7b4a..78f7c9d 100644 --- a/src/main/java/be/seeseemelk/diceos/system/gfx/GraphicsContext.java +++ b/src/main/java/be/seeseemelk/diceos/system/gfx/GraphicsContext.java @@ -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(); } } diff --git a/src/main/java/be/seeseemelk/diceos/system/toolkit/menu/Menu.java b/src/main/java/be/seeseemelk/diceos/system/toolkit/menu/Menu.java index 7902238..ab86f86 100644 --- a/src/main/java/be/seeseemelk/diceos/system/toolkit/menu/Menu.java +++ b/src/main/java/be/seeseemelk/diceos/system/toolkit/menu/Menu.java @@ -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);