Add custom cursor support in DiceOS

This commit is contained in:
2025-12-16 11:26:04 +01:00
parent c62cb0b6e2
commit 11dd9b589d
2 changed files with 17 additions and 0 deletions

View File

@@ -3,7 +3,9 @@ package be.seeseemelk.diceos;
import be.seeseemelk.diceos.system.DisplayService; import be.seeseemelk.diceos.system.DisplayService;
import be.seeseemelk.diceos.system.OnStartup; import be.seeseemelk.diceos.system.OnStartup;
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.Pixmap;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.NinePatch; import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -39,6 +41,7 @@ public class DiceOS extends ApplicationAdapter {
clouds = new Texture("src/main/resources/clouds.png"); clouds = new Texture("src/main/resources/clouds.png");
border = new Texture("src/main/resources/border.png"); border = new Texture("src/main/resources/border.png");
loadMenubar(); loadMenubar();
loadCursor();
screenViewport = new ScreenViewport(); screenViewport = new ScreenViewport();
vmViewport = new ScreenViewport(); vmViewport = new ScreenViewport();
@@ -57,6 +60,19 @@ public class DiceOS extends ApplicationAdapter {
menubar = new NinePatch(texture, 9, 9, 15, 1); menubar = new NinePatch(texture, 9, 9, 15, 1);
} }
private void loadCursor() {
var pixmap = new Pixmap(Gdx.files.internal("cursor.png"));
var scaled = new Pixmap(pixmap.getWidth() * scaling, pixmap.getHeight() * scaling, pixmap.getFormat());
scaled.setFilter(Pixmap.Filter.NearestNeighbour);
scaled.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(),
0, 0, scaled.getWidth(), scaled.getHeight());
var cursor = Gdx.graphics.newCursor(scaled, 0, 0);
Gdx.graphics.setCursor(cursor);
pixmap.dispose();
}
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
screenViewport.update(width, height, true); screenViewport.update(width, height, true);
@@ -70,6 +86,7 @@ public class DiceOS extends ApplicationAdapter {
@Override @Override
public void render() { public void render() {
loadCursor(); // Dispose the old cursor first
ScreenUtils.clear(Color.BLACK); ScreenUtils.clear(Color.BLACK);
vmViewport.apply(); vmViewport.apply();
display.getScreenBuffer().begin(); display.getScreenBuffer().begin();

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 B