@@ -16,6 +16,7 @@ The project uses Gradle.
|
|||||||
* **Dependency Injection:** Uses `avaje-inject`. Components are marked with `@Component` and injected via constructor.
|
* **Dependency Injection:** Uses `avaje-inject`. Components are marked with `@Component` and injected via constructor.
|
||||||
* **Boilerplate:** Uses `lombok` for boilerplate reduction.
|
* **Boilerplate:** Uses `lombok` for boilerplate reduction.
|
||||||
* **Rendering:** Built on LibGDX. Main entry point is `DiceOS.java` which extends `ApplicationAdapter`.
|
* **Rendering:** Built on LibGDX. Main entry point is `DiceOS.java` which extends `ApplicationAdapter`.
|
||||||
|
* **Asset Loading:** All assets, including textures, fonts, and NinePatches, must be loaded via the `ResourceLoader` service to ensure proper lifecycle management and caching.
|
||||||
* **Project Structure:**
|
* **Project Structure:**
|
||||||
* `src/main/java/be/seeseemelk/diceos/system`: Core OS services (Display, Window, Input, etc.).
|
* `src/main/java/be/seeseemelk/diceos/system`: Core OS services (Display, Window, Input, etc.).
|
||||||
* `src/main/resources`: Assets (backgrounds, system textures, fonts).
|
* `src/main/resources`: Assets (backgrounds, system textures, fonts).
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package be.seeseemelk.diceos.system;
|
|||||||
|
|
||||||
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
@@ -71,6 +72,10 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
int mouseX = Gdx.input.getX();
|
||||||
|
int mouseY = display.getHeight() - Gdx.input.getY();
|
||||||
|
windowService.update(mouseX, mouseY, Gdx.input.isTouched());
|
||||||
|
|
||||||
cursorService.updateCursor();
|
cursorService.updateCursor();
|
||||||
|
|
||||||
ScreenUtils.clear(Color.BLACK);
|
ScreenUtils.clear(Color.BLACK);
|
||||||
@@ -84,6 +89,9 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
// Render background
|
// Render background
|
||||||
gc.draw(clouds, 0, 0);
|
gc.draw(clouds, 0, 0);
|
||||||
|
|
||||||
|
// Render windows
|
||||||
|
windowService.render(gc);
|
||||||
|
|
||||||
gc.scissor(0, 0, gc.getWidth(), gc.getHeight(), windowService::paint);
|
gc.scissor(0, 0, gc.getWidth(), gc.getHeight(), windowService::paint);
|
||||||
|
|
||||||
// Render borders
|
// Render borders
|
||||||
|
|||||||
@@ -2,26 +2,49 @@ package be.seeseemelk.diceos.system;
|
|||||||
|
|
||||||
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
||||||
import be.seeseemelk.diceos.system.toolkit.Menubar;
|
import be.seeseemelk.diceos.system.toolkit.Menubar;
|
||||||
|
import be.seeseemelk.diceos.system.toolkit.Window;
|
||||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||||
import io.avaje.inject.Component;
|
import io.avaje.inject.Component;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Component
|
@Component
|
||||||
public class WindowService implements OnStartup {
|
public class WindowService implements OnStartup {
|
||||||
private final ResourceLoader resourceLoader;
|
private final ResourceLoader resourceLoader;
|
||||||
|
private final List<Window> windows = new ArrayList<>();
|
||||||
private NinePatch menubar;
|
private NinePatch menubar;
|
||||||
|
private NinePatch windowDecoration;
|
||||||
private Menubar systemMenubar;
|
private Menubar systemMenubar;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStartup() {
|
public void onStartup() {
|
||||||
menubar = resourceLoader.loadNinePatch("system/menubar.png");
|
menubar = resourceLoader.loadNinePatch("system/menubar.png");
|
||||||
|
windowDecoration = resourceLoader.loadNinePatch("system/window.png");
|
||||||
|
|
||||||
systemMenubar = new Menubar()
|
systemMenubar = new Menubar()
|
||||||
.addItem("Dice")
|
.addItem("Dice")
|
||||||
.addItem("System");
|
.addItem("System");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void spawnWindow(int x, int y, int width, int height) {
|
||||||
|
windows.add(new Window(x, y, width, height, windowDecoration));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(int mouseX, int mouseY, boolean isTouched) {
|
||||||
|
for (Window window : windows) {
|
||||||
|
window.handleInput(mouseX, mouseY, isTouched);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(GraphicsContext gc) {
|
||||||
|
for (Window window : windows) {
|
||||||
|
window.paint(gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void paint(GraphicsContext gc) {
|
void paint(GraphicsContext gc) {
|
||||||
// Render menubar
|
// Render menubar
|
||||||
gc.draw(menubar, 0, 0, gc.getWidth(), 14);
|
gc.draw(menubar, 0, 0, gc.getWidth(), 14);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package be.seeseemelk.diceos.system.toolkit;
|
package be.seeseemelk.diceos.system.toolkit;
|
||||||
|
|
||||||
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
import be.seeseemelk.diceos.system.gfx.GraphicsContext;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -8,9 +9,43 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
public class Window extends Container {
|
public class Window extends Container {
|
||||||
private String title;
|
private String title;
|
||||||
|
private int x, y, width, height;
|
||||||
|
private boolean active;
|
||||||
|
private NinePatch decoration;
|
||||||
|
|
||||||
|
public Window(int x, int y, int width, int height, NinePatch decoration) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.decoration = decoration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int dragOffsetX, dragOffsetY;
|
||||||
|
private boolean isDragging;
|
||||||
|
|
||||||
|
public void handleInput(int mouseX, int mouseY, boolean isTouched) {
|
||||||
|
if (isTouched) {
|
||||||
|
if (!isDragging && isHovered(mouseX, mouseY)) {
|
||||||
|
isDragging = true;
|
||||||
|
dragOffsetX = mouseX - x;
|
||||||
|
dragOffsetY = mouseY - y;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
isDragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDragging) {
|
||||||
|
x = mouseX - dragOffsetX;
|
||||||
|
y = mouseY - dragOffsetY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paint(GraphicsContext gc) {
|
public void paint(GraphicsContext gc) {
|
||||||
|
if (decoration != null) {
|
||||||
|
decoration.draw(gc.getBatch(), x, y, width, height);
|
||||||
|
}
|
||||||
super.paint(gc);
|
super.paint(gc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user