Add custom cursor support in DiceOS
This commit is contained in:
@@ -3,7 +3,9 @@ package be.seeseemelk.diceos;
|
||||
import be.seeseemelk.diceos.system.DisplayService;
|
||||
import be.seeseemelk.diceos.system.OnStartup;
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
@@ -39,6 +41,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
clouds = new Texture("src/main/resources/clouds.png");
|
||||
border = new Texture("src/main/resources/border.png");
|
||||
loadMenubar();
|
||||
loadCursor();
|
||||
|
||||
screenViewport = new ScreenViewport();
|
||||
vmViewport = new ScreenViewport();
|
||||
@@ -57,6 +60,19 @@ public class DiceOS extends ApplicationAdapter {
|
||||
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
|
||||
public void resize(int width, int height) {
|
||||
screenViewport.update(width, height, true);
|
||||
@@ -70,6 +86,7 @@ public class DiceOS extends ApplicationAdapter {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
loadCursor(); // Dispose the old cursor first
|
||||
ScreenUtils.clear(Color.BLACK);
|
||||
vmViewport.apply();
|
||||
display.getScreenBuffer().begin();
|
||||
|
||||
BIN
src/main/resources/cursor.png
Normal file
BIN
src/main/resources/cursor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 234 B |
Reference in New Issue
Block a user