Add support for Alt+Enter toggling fullscreen
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package be.seeseemelk.diceos.system;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Pixmap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
@@ -26,6 +27,14 @@ public class DisplayService implements OnStartup {
|
||||
batch = new SpriteBatch();
|
||||
}
|
||||
|
||||
public void toggleFullscreen() {
|
||||
if (Gdx.graphics.isFullscreen()) {
|
||||
Gdx.graphics.setWindowedMode(getWidth(), getHeight());
|
||||
} else {
|
||||
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
|
||||
}
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return 640;
|
||||
}
|
||||
|
||||
36
src/main/java/be/seeseemelk/diceos/system/InputService.java
Normal file
36
src/main/java/be/seeseemelk/diceos/system/InputService.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package be.seeseemelk.diceos;
|
||||
|
||||
import be.seeseemelk.diceos.system.DisplayService;
|
||||
import be.seeseemelk.diceos.system.OnStartup;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.InputAdapter;
|
||||
import io.avaje.inject.Component;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class InputService implements OnStartup {
|
||||
private final DisplayService displayService;
|
||||
|
||||
@Override
|
||||
public void onStartup() {
|
||||
Gdx.input.setInputProcessor(new InputAdapter() {
|
||||
@Override
|
||||
public boolean keyDown(int keycode) {
|
||||
log.info("Key pressed: {}", keycode);
|
||||
if (keycode == Input.Keys.ENTER && isAltDown()) {
|
||||
displayService.toggleFullscreen();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isAltDown() {
|
||||
return Gdx.input.isKeyPressed(com.badlogic.gdx.Input.Keys.ALT_LEFT) ||
|
||||
Gdx.input.isKeyPressed(com.badlogic.gdx.Input.Keys.ALT_RIGHT);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user