1
0
mirror of https://github.com/fazo96/AIrium.git synced 2025-01-25 11:54:20 +01:00

improved GUI

This commit is contained in:
Enrico Fasoli 2015-08-07 12:16:01 +02:00
parent dc6a4a2a01
commit b8a71d8716
3 changed files with 30 additions and 30 deletions

View File

@ -2,10 +2,9 @@ package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.Map; import java.util.Map;
@ -19,7 +18,7 @@ public class Game extends ApplicationAdapter {
ShapeRenderer renderer, overlayRenderer; ShapeRenderer renderer, overlayRenderer;
private World world; private World world;
private float cameraSpeed = 15; private float cameraSpeed = 15;
private BitmapFont font; private OrthographicCamera camera;
private boolean paused = false; private boolean paused = false;
private InputProcessor input; private InputProcessor input;
@ -55,7 +54,9 @@ public class Game extends ApplicationAdapter {
@Override @Override
public boolean touchDragged(int i, int i1, int i2) { public boolean touchDragged(int i, int i1, int i2) {
renderer.translate(Gdx.input.getDeltaX(), -Gdx.input.getDeltaY(), 0); //renderer.translate(Gdx.input.getDeltaX(), -Gdx.input.getDeltaY(), 0);
camera.translate(-Gdx.input.getDeltaX(), Gdx.input.getDeltaY());
camera.update();
return true; return true;
} }
@ -66,11 +67,15 @@ public class Game extends ApplicationAdapter {
@Override @Override
public boolean scrolled(int i) { public boolean scrolled(int i) {
/*
if (i>0) { if (i>0) {
renderer.scale(0.9f, 0.9f, 1); renderer.scale(0.9f, 0.9f, 1);
} else { } else {
renderer.scale(1.1f, 1.1f, 1); renderer.scale(1.1f, 1.1f, 1);
} }
*/
camera.zoom += i;
camera.update();
return true; return true;
} }
}; };
@ -79,7 +84,9 @@ public class Game extends ApplicationAdapter {
renderer.setAutoShapeType(true); renderer.setAutoShapeType(true);
overlayRenderer = new ShapeRenderer(); overlayRenderer = new ShapeRenderer();
overlayRenderer.setAutoShapeType(true); overlayRenderer.setAutoShapeType(true);
font = new BitmapFont(); camera = new OrthographicCamera();
camera.setToOrtho(false);
camera.update();
Thread worldThread = new Thread(world); Thread worldThread = new Thread(world);
worldThread.setName("Worker"); worldThread.setName("Worker");
worldThread.setPriority(Thread.MAX_PRIORITY); worldThread.setPriority(Thread.MAX_PRIORITY);
@ -94,11 +101,18 @@ public class Game extends ApplicationAdapter {
world = new World(options); world = new World(options);
} }
@Override
public void resize(int width, int height){
camera.setToOrtho(false, width, height);
camera.update();
}
@Override @Override
public void render() { public void render() {
// Draw // Draw
Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setProjectionMatrix(camera.combined);
renderer.begin(ShapeRenderer.ShapeType.Line); renderer.begin(ShapeRenderer.ShapeType.Line);
try { try {
for (Element e : world.getElements()) { for (Element e : world.getElements()) {

View File

@ -18,29 +18,14 @@ public class DesktopLauncher {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) { public static void main(String args[]) {
/* Set the Nimbus look and feel */ // Show menu bar to the top osx bar
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> System.setProperty("apple.laf.useScreenMenuBar", "true");
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. /* Show application name correctly
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html However it doesn't work, see
*/ http://stackoverflow.com/questions/3154638/setting-java-swing-application-name-on-mac */
try { System.setProperty("com.apple.mrj.application.apple.menu.about.name", "AIrium");
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) { /*
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
Setting the native OS look and feel. This way the program uses the OS's Setting the native OS look and feel. This way the program uses the OS's
window toolkit instead of the Java one to render the application, if it window toolkit instead of the Java one to render the application, if it
is possible. is possible.

View File

@ -784,8 +784,9 @@ public class GUI extends javax.swing.JFrame implements LogListener, Listener {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.height = 600; config.height = 600;
config.width = 800; config.width = 800;
config.resizable = false; config.resizable = true;
config.title = "AIrium Renderer"; config.title = "AIrium Renderer";
config.allowSoftwareMode = true;
app = new LwjglApplication(game = new Game(options), config); app = new LwjglApplication(game = new Game(options), config);
startButton.setText("Restart"); startButton.setText("Restart");
pauseButton.setEnabled(true); pauseButton.setEnabled(true);