Add menubar rendering to DiceOS
This commit is contained in:
@@ -5,6 +5,7 @@ import be.seeseemelk.diceos.system.OnStartup;
|
|||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.ApplicationAdapter;
|
||||||
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.NinePatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
import com.badlogic.gdx.utils.viewport.ScreenViewport;
|
||||||
@@ -24,6 +25,7 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
private Texture background;
|
private Texture background;
|
||||||
private Texture clouds;
|
private Texture clouds;
|
||||||
private Texture border;
|
private Texture border;
|
||||||
|
private NinePatch menubar;
|
||||||
private Viewport vmViewport;
|
private Viewport vmViewport;
|
||||||
private Viewport screenViewport;
|
private Viewport screenViewport;
|
||||||
private int scaling = 1;
|
private int scaling = 1;
|
||||||
@@ -36,6 +38,7 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
background = new Texture("src/main/resources/background.png");
|
background = new Texture("src/main/resources/background.png");
|
||||||
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();
|
||||||
|
|
||||||
screenViewport = new ScreenViewport();
|
screenViewport = new ScreenViewport();
|
||||||
vmViewport = new ScreenViewport();
|
vmViewport = new ScreenViewport();
|
||||||
@@ -49,6 +52,11 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
log.info("DiceOS started!");
|
log.info("DiceOS started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadMenubar() {
|
||||||
|
var texture = new Texture("src/main/resources/menubar.png");
|
||||||
|
menubar = new NinePatch(texture, 9, 9, 15, 1);
|
||||||
|
}
|
||||||
|
|
||||||
@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 +78,7 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
|
|
||||||
ScreenUtils.clear(Color.GREEN);
|
ScreenUtils.clear(Color.GREEN);
|
||||||
|
|
||||||
|
// Render background
|
||||||
for (int y = 0; y < display.getHeight(); y += 8) {
|
for (int y = 0; y < display.getHeight(); y += 8) {
|
||||||
for (int x = 0; x < display.getWidth(); x += 8) {
|
for (int x = 0; x < display.getWidth(); x += 8) {
|
||||||
display.draw(background, x, y);
|
display.draw(background, x, y);
|
||||||
@@ -77,6 +86,10 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
}
|
}
|
||||||
display.draw(clouds, 0, 0);
|
display.draw(clouds, 0, 0);
|
||||||
|
|
||||||
|
// Render menubar
|
||||||
|
menubar.draw(display.getBatch(), 0, display.getHeight() - 16, display.getWidth(), 16);
|
||||||
|
|
||||||
|
// Render borders
|
||||||
var param = new DisplayService.Parameters();
|
var param = new DisplayService.Parameters();
|
||||||
display.draw(border, 0, 0, param);
|
display.draw(border, 0, 0, param);
|
||||||
param.flipX = true;
|
param.flipX = true;
|
||||||
@@ -86,9 +99,11 @@ public class DiceOS extends ApplicationAdapter {
|
|||||||
param.flipX = false;
|
param.flipX = false;
|
||||||
display.draw(border, 0, display.getHeight() - 8, param);
|
display.draw(border, 0, display.getHeight() - 8, param);
|
||||||
|
|
||||||
|
// Finish rendering to screen buffer
|
||||||
display.getBatch().end();
|
display.getBatch().end();
|
||||||
display.getScreenBuffer().end();
|
display.getScreenBuffer().end();
|
||||||
|
|
||||||
|
// Render screen buffer to actual screen
|
||||||
screenViewport.apply();
|
screenViewport.apply();
|
||||||
display.getBatch().setProjectionMatrix(screenViewport.getCamera().combined);
|
display.getBatch().setProjectionMatrix(screenViewport.getCamera().combined);
|
||||||
display.getBatch().begin();
|
display.getBatch().begin();
|
||||||
|
|||||||
BIN
src/main/resources/menubar.png
Normal file
BIN
src/main/resources/menubar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 303 B |
Reference in New Issue
Block a user