2017-01-31 22:29:49 +01:00
|
|
|
package org.warp.picalculator.gui;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2018-04-02 18:29:55 +02:00
|
|
|
import java.util.Arrays;
|
2017-09-23 23:23:26 +02:00
|
|
|
import java.util.List;
|
2017-09-15 23:24:12 +02:00
|
|
|
import java.util.concurrent.Semaphore;
|
2017-05-16 22:02:44 +02:00
|
|
|
|
2017-10-17 22:49:21 +02:00
|
|
|
import org.warp.picalculator.StaticVars;
|
2017-01-31 22:29:49 +01:00
|
|
|
import org.warp.picalculator.Utils;
|
|
|
|
import org.warp.picalculator.device.Keyboard;
|
2017-05-16 22:02:44 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
2017-01-31 22:29:49 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
2017-05-16 22:02:44 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.Skin;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
2017-12-13 18:09:57 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.framebuffer.FBEngine;
|
2017-02-02 10:30:45 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
|
2017-07-16 13:47:29 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitEngine;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.headless256.Headless256Engine;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.headless8.Headless8Engine;
|
2018-03-21 15:18:44 +01:00
|
|
|
import org.warp.picalculator.gui.graphicengine.nogui.NoGuiEngine;
|
2017-01-31 22:29:49 +01:00
|
|
|
import org.warp.picalculator.gui.screens.Screen;
|
2017-05-16 22:02:44 +02:00
|
|
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-02-02 10:30:45 +01:00
|
|
|
public final class DisplayManager implements RenderingLoop {
|
2017-01-31 22:29:49 +01:00
|
|
|
public static DisplayManager INSTANCE;
|
2017-09-24 18:47:30 +02:00
|
|
|
private float brightness;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public final GraphicEngine engine;
|
2018-03-17 00:09:40 +01:00
|
|
|
public final HardwareDisplay monitor;
|
2017-09-24 18:47:30 +02:00
|
|
|
public final boolean supportsPauses;
|
|
|
|
public Renderer renderer;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public Skin guiSkin;
|
|
|
|
public BinaryFont[] fonts;
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public String error;
|
2017-09-23 23:23:26 +02:00
|
|
|
public String[] errorStackTrace;
|
2017-09-24 18:47:30 +02:00
|
|
|
public final int[] glyphsHeight;
|
|
|
|
|
|
|
|
private Screen screen;
|
2018-03-17 00:09:40 +01:00
|
|
|
private HUD hud;
|
2017-09-24 18:47:30 +02:00
|
|
|
public Semaphore screenChange = new Semaphore(0);
|
|
|
|
public String displayDebugString;
|
|
|
|
public ObjectArrayList<GUIErrorMessage> errorMessages;
|
|
|
|
|
2018-03-17 00:09:40 +01:00
|
|
|
public DisplayManager(HardwareDisplay monitor, HUD hud, Screen screen, String title) {
|
2017-09-24 18:53:49 +02:00
|
|
|
INSTANCE = this;
|
2017-09-23 23:23:26 +02:00
|
|
|
engine = chooseGraphicEngine();
|
|
|
|
supportsPauses = engine.doesRefreshPauses();
|
2018-03-17 00:09:40 +01:00
|
|
|
|
|
|
|
this.monitor = monitor;
|
|
|
|
this.hud = hud;
|
|
|
|
|
|
|
|
monitor.initialize();
|
2017-09-23 23:23:26 +02:00
|
|
|
glyphsHeight = new int[] { 9, 6, 12, 9 };
|
|
|
|
displayDebugString = "";
|
|
|
|
errorMessages = new ObjectArrayList<>();
|
2018-03-17 00:09:40 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
hud.d = this;
|
|
|
|
hud.create();
|
|
|
|
if (!hud.initialized) hud.initialize();
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
setScreen(screen);
|
2018-03-17 00:09:40 +01:00
|
|
|
try {
|
|
|
|
engine.create();
|
|
|
|
renderer = engine.getRenderer();
|
|
|
|
engine.setTitle(title);
|
|
|
|
loop();
|
|
|
|
} catch (Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
monitor.shutdown();
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* private void load_skin() {
|
|
|
|
* try {
|
|
|
|
* skin_tex = glGenTextures();
|
|
|
|
* glBindTexture(GL_TEXTURE_2D, skin_tex);
|
|
|
|
* glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
*
|
|
|
|
* InputStream in = new FileInputStream("skin.png");
|
|
|
|
* PNGDecoder decoder = new PNGDecoder(in);
|
|
|
|
*
|
|
|
|
* System.out.println("width="+decoder.getWidth());
|
|
|
|
* System.out.println("height="+decoder.getHeight());
|
|
|
|
*
|
|
|
|
* ByteBuffer buf =
|
|
|
|
* ByteBuffer.allocateDirect(4*decoder.getWidth()*decoder.getHeight());
|
|
|
|
* decoder.decode(buf, decoder.getWidth()*4, Format.RGBA);
|
|
|
|
* buf.flip();
|
|
|
|
*
|
|
|
|
* skin = buf;
|
|
|
|
* skin_w = decoder.getWidth();
|
|
|
|
* skin_h = decoder.getHeight();
|
|
|
|
* glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, skin_w,
|
|
|
|
* skin_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, skin);
|
|
|
|
* } catch (IOException ex) {
|
|
|
|
* ex.printStackTrace();
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
private GraphicEngine chooseGraphicEngine() {
|
2017-02-02 10:30:45 +01:00
|
|
|
GraphicEngine d;
|
2018-03-21 15:18:44 +01:00
|
|
|
d = new NoGuiEngine();
|
|
|
|
if (d.isSupported()) {
|
|
|
|
Utils.out.println(1, "Using NoGui Graphic Engine");
|
|
|
|
return d;
|
|
|
|
}
|
2017-12-20 18:07:11 +01:00
|
|
|
if (!StaticVars.debugOn) {
|
|
|
|
d = new FBEngine();
|
|
|
|
if (d.isSupported()) {
|
|
|
|
Utils.out.println(1, "Using FB Graphic Engine");
|
|
|
|
return d;
|
|
|
|
}
|
2017-12-13 18:09:57 +01:00
|
|
|
}
|
2017-02-02 10:30:45 +01:00
|
|
|
d = new GPUEngine();
|
|
|
|
if (d.isSupported()) {
|
2017-06-09 22:47:30 +02:00
|
|
|
Utils.out.println(1, "Using GPU Graphic Engine");
|
2017-02-02 10:30:45 +01:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
d = new CPUEngine();
|
|
|
|
if (d.isSupported()) {
|
2017-06-09 22:47:30 +02:00
|
|
|
Utils.out.println(1, "Using CPU Graphic Engine");
|
2017-02-02 10:30:45 +01:00
|
|
|
return d;
|
|
|
|
}
|
2017-07-16 13:47:29 +02:00
|
|
|
d = new Headless24bitEngine();
|
|
|
|
if (d.isSupported()) {
|
|
|
|
System.err.println("Using Headless 24 bit Engine! This is a problem! No other graphic engines are available.");
|
|
|
|
return d;
|
|
|
|
}
|
2017-05-05 22:27:11 +02:00
|
|
|
d = new Headless256Engine();
|
2017-05-01 22:30:39 +02:00
|
|
|
if (d.isSupported()) {
|
2017-05-05 22:27:11 +02:00
|
|
|
System.err.println("Using Headless 256 Engine! This is a problem! No other graphic engines are available.");
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
d = new Headless8Engine();
|
|
|
|
if (d.isSupported()) {
|
|
|
|
System.err.println("Using Headless basic Engine! This is a problem! No other graphic engines are available.");
|
2017-05-01 22:39:00 +02:00
|
|
|
return d;
|
2017-05-01 22:30:39 +02:00
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
throw new UnsupportedOperationException("No graphic engines available.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setScreen(Screen screen) {
|
|
|
|
if (screen.initialized == false) {
|
|
|
|
if (screen.canBeInHistory) {
|
2018-04-02 18:29:55 +02:00
|
|
|
if (DisplayManager.INSTANCE.currentSession > 0) {
|
|
|
|
int sl = DisplayManager.INSTANCE.sessions.length + 5; //TODO: I don't know why if i don't add +5 or more some items disappear
|
|
|
|
DisplayManager.INSTANCE.sessions = Arrays.copyOfRange(DisplayManager.INSTANCE.sessions, DisplayManager.INSTANCE.currentSession, sl);
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.currentSession = 0;
|
|
|
|
for (int i = DisplayManager.INSTANCE.sessions.length - 1; i >= 1; i--) {
|
|
|
|
DisplayManager.INSTANCE.sessions[i] = DisplayManager.INSTANCE.sessions[i - 1];
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.sessions[0] = screen;
|
2017-01-31 22:29:49 +01:00
|
|
|
} else {
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.currentSession = -1;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.d = this;
|
|
|
|
try {
|
|
|
|
screen.create();
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.screen = screen;
|
2017-09-24 13:09:30 +02:00
|
|
|
screenChange.release();
|
2017-01-31 22:29:49 +01:00
|
|
|
if (screen.initialized == false) {
|
|
|
|
screen.initialize();
|
|
|
|
}
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void replaceScreen(Screen screen) {
|
|
|
|
if (screen.initialized == false) {
|
|
|
|
if (screen.canBeInHistory) {
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] = screen;
|
2017-01-31 22:29:49 +01:00
|
|
|
} else {
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.currentSession = -1;
|
|
|
|
for (int i = 0; i < DisplayManager.INSTANCE.sessions.length - 2; i++) {
|
|
|
|
DisplayManager.INSTANCE.sessions[i] = DisplayManager.INSTANCE.sessions[i + 1];
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
screen.d = this;
|
|
|
|
try {
|
|
|
|
screen.create();
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.screen = screen;
|
2017-09-24 13:09:30 +02:00
|
|
|
screenChange.release();
|
2017-01-31 22:29:49 +01:00
|
|
|
if (screen.initialized == false) {
|
|
|
|
screen.initialize();
|
|
|
|
}
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGoBack() {
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.currentSession == -1) {
|
|
|
|
return DisplayManager.INSTANCE.sessions[0] != null;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
} else if (DisplayManager.INSTANCE.currentSession + 1 < DisplayManager.INSTANCE.sessions.length) {
|
|
|
|
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession + 1] != null) {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] != null) {
|
2017-01-31 22:29:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void goBack() {
|
|
|
|
if (canGoBack()) {
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.currentSession >= 0 && DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {} else {
|
|
|
|
DisplayManager.INSTANCE.currentSession += 1;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.screen = DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession];
|
2017-09-24 13:09:30 +02:00
|
|
|
screenChange.release();
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGoForward() {
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.currentSession <= 0) { // -1 e 0
|
2017-01-31 22:29:49 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
} else if (DisplayManager.INSTANCE.currentSession > 0) {
|
|
|
|
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession - 1] != null) {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] != null) {
|
2017-01-31 22:29:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void goForward() {
|
|
|
|
if (canGoForward()) {
|
2017-09-24 18:47:30 +02:00
|
|
|
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
} else {
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.currentSession -= 1;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
DisplayManager.INSTANCE.screen = DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession];
|
2017-09-24 13:09:30 +02:00
|
|
|
screenChange.release();
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public Screen getScreen() {
|
2018-03-17 00:09:40 +01:00
|
|
|
return screen;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HUD getHUD() {
|
|
|
|
return hud;
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void load_skin() throws IOException {
|
2017-02-02 10:30:45 +01:00
|
|
|
guiSkin = engine.loadSkin("skin.png");
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void load_fonts() throws IOException {
|
2017-02-02 10:30:45 +01:00
|
|
|
fonts = new BinaryFont[7];
|
2017-11-19 12:55:48 +01:00
|
|
|
fonts[0] = engine.loadFont("smal");
|
|
|
|
fonts[1] = engine.loadFont("smallest");
|
|
|
|
fonts[2] = engine.loadFont("norm");
|
|
|
|
fonts[3] = engine.loadFont("smal");
|
2017-09-24 18:47:30 +02:00
|
|
|
//4
|
2017-10-17 22:49:21 +02:00
|
|
|
//fonts[5] = engine.loadFont("square");
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void draw_init() {
|
2017-09-15 23:24:12 +02:00
|
|
|
if (engine.supportsFontRegistering()) {
|
2017-09-23 23:23:26 +02:00
|
|
|
List<BinaryFont> fontsIterator = engine.getRegisteredFonts();
|
|
|
|
for (BinaryFont f : fontsIterator) {
|
2017-09-15 23:24:12 +02:00
|
|
|
if (!f.isInitialized()) {
|
|
|
|
f.initialize(engine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-02 10:30:45 +01:00
|
|
|
renderer.glClear(engine.getWidth(), engine.getHeight());
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void draw_world() {
|
|
|
|
renderer.glColor3i(255, 255, 255);
|
|
|
|
|
|
|
|
if (error != null) {
|
2017-09-24 13:09:30 +02:00
|
|
|
BinaryFont fnt = Utils.getFont(false, false);
|
2018-03-29 00:30:47 +02:00
|
|
|
if (fnt != null && fnt != engine.getRenderer().getCurrentFont()) {
|
|
|
|
fnt.use(engine);
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
renderer.glColor3i(129, 28, 22);
|
2017-10-17 22:49:21 +02:00
|
|
|
renderer.glDrawStringRight(StaticVars.screenSize[0] - 2, StaticVars.screenSize[1] - (fnt.getCharacterHeight() + 2), StaticVars.calculatorNameUPPER + " CALCULATOR");
|
2017-01-31 22:29:49 +01:00
|
|
|
renderer.glColor3i(149, 32, 26);
|
2017-10-17 22:49:21 +02:00
|
|
|
renderer.glDrawStringCenter((StaticVars.screenSize[0] / 2), 22, error);
|
2017-01-31 22:29:49 +01:00
|
|
|
renderer.glColor3i(164, 34, 28);
|
|
|
|
int i = 22;
|
|
|
|
for (final String stackPart : errorStackTrace) {
|
|
|
|
renderer.glDrawStringLeft(2, 22 + i, stackPart);
|
|
|
|
i += 11;
|
|
|
|
}
|
2018-03-29 00:30:47 +02:00
|
|
|
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
|
|
|
|
fonts[0].use(engine);
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
renderer.glColor3i(129, 28, 22);
|
2017-10-17 22:49:21 +02:00
|
|
|
renderer.glDrawStringCenter((StaticVars.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION");
|
2017-01-31 22:29:49 +01:00
|
|
|
} else {
|
2018-03-29 00:30:47 +02:00
|
|
|
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
|
|
|
|
fonts[0].use(engine);
|
|
|
|
}
|
2018-03-17 00:09:40 +01:00
|
|
|
hud.renderBackground();
|
|
|
|
screen.render();
|
|
|
|
hud.render();
|
|
|
|
hud.renderTopmostBackground();
|
|
|
|
screen.renderTopmost();
|
|
|
|
hud.renderTopmost();
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void draw() {
|
|
|
|
draw_init();
|
|
|
|
draw_world();
|
|
|
|
}
|
|
|
|
|
|
|
|
private long precTime = -1;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refresh() {
|
2017-02-06 21:38:17 +01:00
|
|
|
if (supportsPauses == false || (Keyboard.popRefreshRequest() || screen.mustBeRefreshed())) {
|
2017-01-31 22:29:49 +01:00
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkDisplayResized() {
|
2017-02-02 10:30:45 +01:00
|
|
|
if (engine.wasResized()) {
|
2017-10-17 22:49:21 +02:00
|
|
|
StaticVars.screenSize[0] = engine.getWidth();
|
|
|
|
StaticVars.screenSize[1] = engine.getHeight();
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
};
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
public void loop() {
|
|
|
|
try {
|
2017-09-15 23:24:12 +02:00
|
|
|
load_skin();
|
|
|
|
load_fonts();
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-01-31 22:29:49 +01:00
|
|
|
try {
|
|
|
|
screen.initialize();
|
|
|
|
} catch (final Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
2017-02-06 21:38:17 +01:00
|
|
|
//Working thread
|
2017-04-10 22:50:43 +02:00
|
|
|
final Thread workThread = new Thread(() -> {
|
2017-01-31 22:29:49 +01:00
|
|
|
try {
|
|
|
|
while (true) {
|
2017-02-06 21:38:17 +01:00
|
|
|
float dt = 0;
|
|
|
|
final long newtime = System.nanoTime();
|
|
|
|
if (precTime == -1) {
|
|
|
|
dt = 0;
|
|
|
|
} else {
|
|
|
|
dt = (float) ((newtime - precTime) / 1000000000d);
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-02-06 21:38:17 +01:00
|
|
|
precTime = newtime;
|
|
|
|
/*
|
|
|
|
* Calcoli
|
|
|
|
*/
|
|
|
|
checkDisplayResized();
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-02-06 21:38:17 +01:00
|
|
|
screen.beforeRender(dt);
|
|
|
|
|
|
|
|
Thread.sleep(50);
|
|
|
|
// for (int i = 0; i < 10; i++) {
|
|
|
|
// System.out.println("============");
|
|
|
|
// OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
|
|
|
// for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
|
|
|
|
// method.setAccessible(true);
|
|
|
|
// if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
|
|
|
|
// Object value;
|
|
|
|
// try {
|
|
|
|
// value = method.invoke(operatingSystemMXBean);
|
|
|
|
// } catch (Exception e) {
|
|
|
|
// value = e;
|
|
|
|
// } // try
|
|
|
|
// boolean percent = false;
|
|
|
|
// boolean mb = false;
|
|
|
|
// String displayName = method.getName();
|
|
|
|
// String displayValue = value.toString();
|
|
|
|
// if (displayName.endsWith("CpuLoad")) {
|
|
|
|
// percent = true;
|
|
|
|
// }
|
|
|
|
// if (displayName.endsWith("MemorySize")) {
|
|
|
|
// mb = true;
|
|
|
|
// }
|
2017-03-03 23:06:43 +01:00
|
|
|
// ObjectArrayList<String> arr = new ObjectArrayList<>();
|
2017-02-06 21:38:17 +01:00
|
|
|
// arr.add("getFreePhysicalMemorySize");
|
|
|
|
// arr.add("getProcessCpuLoad");
|
|
|
|
// arr.add("getSystemCpuLoad");
|
|
|
|
// arr.add("getTotalPhysicalMemorySize");
|
|
|
|
// if (arr.contains(displayName)) {
|
|
|
|
// if (percent) {
|
|
|
|
// try {
|
|
|
|
// System.out.println(displayName + " = " + (((int)(Float.parseFloat(displayValue) * 10000f))/100f) + "%");
|
|
|
|
// }catch(Exception ex) {
|
|
|
|
// System.out.println(displayName + " = " + displayValue);
|
|
|
|
// }
|
|
|
|
// } else if (mb) {
|
|
|
|
// try {
|
|
|
|
// System.out.println(displayName + " = " + (Long.parseLong(displayValue) / 1024L / 1024L) + " MB");
|
|
|
|
// }catch(Exception ex) {
|
|
|
|
// System.out.println(displayName + " = " + displayValue);
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// System.out.println(displayName + " = " + displayValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// } // if
|
|
|
|
// } // for
|
|
|
|
// System.out.println("============");
|
|
|
|
// Thread.sleep(5000);
|
|
|
|
// }
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
} catch (final InterruptedException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
2017-02-06 21:38:17 +01:00
|
|
|
workThread.setDaemon(true);
|
|
|
|
workThread.setName("Work thread");
|
|
|
|
workThread.start();
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-03 23:06:43 +01:00
|
|
|
engine.start(getDrawable());
|
2017-01-31 22:29:49 +01:00
|
|
|
} catch (final Exception ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
} finally {}
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public void changeBrightness(float change) {
|
2017-01-31 22:29:49 +01:00
|
|
|
setBrightness(brightness + change);
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public void setBrightness(float newval) {
|
2017-01-31 22:29:49 +01:00
|
|
|
if (newval >= 0 && newval <= 1) {
|
|
|
|
brightness = newval;
|
2018-03-17 00:09:40 +01:00
|
|
|
monitor.setBrightness(brightness);
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public void cycleBrightness(boolean reverse) {
|
2017-01-31 22:29:49 +01:00
|
|
|
final float step = reverse ? -0.1f : 0.1f;
|
|
|
|
if (brightness + step > 1f) {
|
|
|
|
setBrightness(0f);
|
|
|
|
} else if (brightness + step <= 0f) {
|
|
|
|
setBrightness(1.0f);
|
|
|
|
} else {
|
|
|
|
changeBrightness(step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public float getBrightness() {
|
2017-01-31 22:29:49 +01:00
|
|
|
return brightness;
|
|
|
|
}
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public int currentSession = 0;
|
|
|
|
public Screen[] sessions = new Screen[5];
|
2017-01-31 22:29:49 +01:00
|
|
|
|
|
|
|
@Deprecated
|
2017-09-24 18:47:30 +02:00
|
|
|
public void colore(float f1, float f2, float f3, float f4) {
|
2017-04-10 22:50:43 +02:00
|
|
|
renderer.glColor4f(f1, f2, f3, f4);
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
|
|
|
|
2017-09-24 18:47:30 +02:00
|
|
|
public RenderingLoop getDrawable() {
|
2017-01-31 22:29:49 +01:00
|
|
|
return INSTANCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
2017-09-24 18:47:30 +02:00
|
|
|
public void drawSkinPart(int x, int y, int uvX, int uvY, int uvX2, int uvY2) {
|
2017-04-10 22:50:43 +02:00
|
|
|
renderer.glFillRect(x, y, uvX2 - uvX, uvY2 - uvY, uvX, uvY, uvX2 - uvX, uvY2 - uvY);
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
|
|
|
public void waitForExit() {
|
|
|
|
engine.waitForExit();
|
|
|
|
}
|
2017-01-31 22:29:49 +01:00
|
|
|
}
|