Added bounded render contexts

This commit is contained in:
Andrea Cavalli 2019-11-01 18:04:01 +01:00
parent a9dd7de800
commit 70ff11da7f
31 changed files with 636 additions and 248 deletions

View File

@ -1,11 +1,5 @@
package it.cavallium.warppi; package it.cavallium.warppi;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import it.cavallium.warppi.Platform.ConsoleUtils; import it.cavallium.warppi.Platform.ConsoleUtils;
import it.cavallium.warppi.boot.StartupArguments; import it.cavallium.warppi.boot.StartupArguments;
import it.cavallium.warppi.device.Device; import it.cavallium.warppi.device.Device;
@ -16,53 +10,51 @@ import it.cavallium.warppi.device.input.InputManager;
import it.cavallium.warppi.device.input.Keyboard; import it.cavallium.warppi.device.input.Keyboard;
import it.cavallium.warppi.device.input.KeyboardInputDevice; import it.cavallium.warppi.device.input.KeyboardInputDevice;
import it.cavallium.warppi.device.input.TouchInputDevice; import it.cavallium.warppi.device.input.TouchInputDevice;
import it.cavallium.warppi.flow.BehaviorSubject;
import it.cavallium.warppi.flow.Observable;
import it.cavallium.warppi.gui.DisplayManager; import it.cavallium.warppi.gui.DisplayManager;
import it.cavallium.warppi.gui.HUD; import it.cavallium.warppi.gui.HUD;
import it.cavallium.warppi.gui.screens.Screen; import it.cavallium.warppi.gui.screens.Screen;
import it.cavallium.warppi.util.ClassUtils; import it.cavallium.warppi.util.ClassUtils;
import it.cavallium.warppi.util.EventSubmitter;
import it.cavallium.warppi.util.RunnableWithException; import it.cavallium.warppi.util.RunnableWithException;
import java.io.IOException;
public class WarpPI { public class WarpPI {
public static final WarpPI INSTANCE = new WarpPI(); public static final WarpPI INSTANCE = new WarpPI();
private static Platform platform; private static Platform platform;
private static boolean running = false; private static boolean running = false;
private final BehaviorSubject<Boolean> loaded = BehaviorSubject.create(false); private final EventSubmitter<Boolean> loaded = EventSubmitter.create(false);
private Device device; private Device device;
private WarpPI() {} private WarpPI() {
}
/** /**
* Start an instance of the calculator. * Start an instance of the calculator.
* *
* @param platform * @param platform Platform implementation
* Platform implementation * @param screen Default screen to show at startup
* @param screen * @param hud Head-up display
* Default screen to show at startup * @param args Startup arguments
* @param hud * @throws InterruptedException
* Head-up display * @throws IOException
* @param args */
* Startup arguments public static void start(final Platform platform, final Screen screen, final HUD hud, final StartupArguments args, final RunnableWithException onLoading) throws IOException {
* @throws InterruptedException
* @throws IOException
*/
public static Future<Void> start(final Platform platform, final Screen screen, final HUD hud, final StartupArguments args, final RunnableWithException onLoading) throws IOException {
if (WarpPI.running) { if (WarpPI.running) {
throw new RuntimeException("Already running!"); throw new RuntimeException("Already running!");
} else { } else {
WarpPI.running = true; WarpPI.running = true;
return WarpPI.INSTANCE.startInstance(platform, screen, hud, args, onLoading); WarpPI.INSTANCE.startInstance(platform, screen, hud, args, onLoading);
} }
} }
private Future<Void> startInstance(final Platform platform, final Screen screen, private void startInstance(final Platform platform, final Screen screen,
final HUD hud, final StartupArguments args, final RunnableWithException onLoading) final HUD hud, final StartupArguments args, final RunnableWithException onLoading)
throws IOException { throws IOException {
WarpPI.platform = platform; WarpPI.platform = platform;
// Set arguments on platform before everything else // Set arguments on platform before everything else
platform.setArguments(args); platform.setArguments(args);
platform.getConsoleUtils().out().println("WarpPI Calculator"); platform.getConsoleUtils().out().println("WarpPI Calculator");
initializeEnvironment(args); initializeEnvironment(args);
@ -70,23 +62,22 @@ public class WarpPI {
currentThread.setPriority(Thread.MAX_PRIORITY); currentThread.setPriority(Thread.MAX_PRIORITY);
WarpPI.getPlatform().setThreadName(currentThread, "Main thread"); WarpPI.getPlatform().setThreadName(currentThread, "Main thread");
return CompletableFuture.runAsync(() -> { try {
try { final DisplayOutputDevice display = platform.getDisplayOutputDevice();
final DisplayOutputDevice display = platform.getDisplayOutputDevice(); final BacklightOutputDevice backlight = platform.getBacklightOutputDevice();
final BacklightOutputDevice backlight = platform.getBacklightOutputDevice(); final DisplayManager dm = new DisplayManager(display, backlight, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
final DisplayManager dm = new DisplayManager(display, backlight, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)"); final KeyboardInputDevice keyboard = platform.getKeyboardInputDevice();
final KeyboardInputDevice keyboard = platform.getKeyboardInputDevice(); final TouchInputDevice touchscreen = platform.getTouchInputDevice();
final TouchInputDevice touchscreen = platform.getTouchInputDevice(); final DeviceStateDevice deviceState = platform.getDeviceStateDevice();
final DeviceStateDevice deviceState = platform.getDeviceStateDevice(); final InputManager im = new InputManager(keyboard, touchscreen);
final InputManager im = new InputManager(keyboard, touchscreen); device = new Device(dm, im, deviceState);
device = new Device(dm, im, deviceState); device.setup();
device.setup(); onLoading.run();
onLoading.run(); this.loadingCompleted();
this.loadingCompleted(); } catch (Exception ex) {
} catch (Exception ex) { this.loadingFailed(ex);
this.loadingFailed(ex); }
} this.onShutdown();
}).thenRun(this::onShutdown);
} }
private void onShutdown() { private void onShutdown() {
@ -128,7 +119,7 @@ public class WarpPI {
Keyboard.stopKeyboard(); Keyboard.stopKeyboard();
} }
public Observable<Boolean> isLoaded() { public EventSubmitter<Boolean> isLoaded() {
return loaded; return loaded;
} }
@ -142,12 +133,8 @@ public class WarpPI {
private void loadingCompleted() { private void loadingCompleted() {
try { WarpPI.INSTANCE.loaded.submit(true);
WarpPI.INSTANCE.loaded.onNext(true); WarpPI.INSTANCE.device.getDeviceStateDevice().waitForExit();
WarpPI.INSTANCE.device.getDeviceStateDevice().waitForExit().get();
} catch (InterruptedException | ExecutionException e) {
throw new CompletionException(e);
}
} }
private void loadingFailed(Exception e) { private void loadingFailed(Exception e) {

View File

@ -12,13 +12,12 @@ import it.cavallium.warppi.math.rules.RulesManager;
public class Boot { public class Boot {
public static void boot(final Platform platform, final String[] args) throws Exception { public static void boot(final Platform platform, final String[] args) throws Exception {
Future<Void> execution = WarpPI.start( WarpPI.start(
platform, platform,
new LoadingScreen(), new LoadingScreen(),
new CalculatorHUD(), new CalculatorHUD(),
Boot.parseStartupArguments(args), Boot.parseStartupArguments(args),
Boot::loadCalculator); Boot::loadCalculator);
execution.get();
} }
private static void loadCalculator() throws Exception { private static void loadCalculator() throws Exception {

View File

@ -6,7 +6,7 @@ public interface DeviceStateDevice {
void initialize(); void initialize();
Future<?> waitForExit(); void waitForExit();
void powerOff(); void powerOff();
} }

View File

@ -941,7 +941,7 @@ public class Keyboard {
break; break;
case ZOOM_MODE: case ZOOM_MODE:
final float newZoom = StaticVars.windowZoom.getLastValue() % 3 + 1; final float newZoom = StaticVars.windowZoom.getLastValue() % 3 + 1;
StaticVars.windowZoom.onNext(newZoom); StaticVars.windowZoom.submit(newZoom);
WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Keyboard", "Zoom: " + newZoom); WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Keyboard", "Zoom: " + newZoom);
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f; // StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
refresh = true; refresh = true;

View File

@ -10,6 +10,8 @@ import it.cavallium.warppi.device.input.Keyboard;
import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent; import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
import it.cavallium.warppi.gui.graphicengine.BinaryFont; import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.Skin; import it.cavallium.warppi.gui.graphicengine.Skin;
import it.cavallium.warppi.gui.screens.Screen; import it.cavallium.warppi.gui.screens.Screen;
@ -46,7 +48,7 @@ public class MarioScreen extends Screen {
} }
@Override @Override
public void graphicInitialized() { public void graphicInitialized(ScreenContext ctx) {
try { try {
if (MarioScreen.skin == null) { if (MarioScreen.skin == null) {
MarioScreen.skin = d.display.getGraphicEngine().loadSkin("/marioskin.png"); MarioScreen.skin = d.display.getGraphicEngine().loadSkin("/marioskin.png");
@ -56,17 +58,17 @@ public class MarioScreen extends Screen {
} }
if (MarioScreen.gpuTest2 == null) { if (MarioScreen.gpuTest2 == null) {
try { try {
MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest2"); MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest2");
} catch (final Exception ex) {} } catch (final Exception ex) {}
} }
if (MarioScreen.gpuTest1 == null) { if (MarioScreen.gpuTest1 == null) {
try { try {
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest12"); MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest12");
MarioScreen.gpuTest12 = true; MarioScreen.gpuTest12 = true;
} catch (final Exception ex) { } catch (final Exception ex) {
MarioScreen.gpuTest12 = false; MarioScreen.gpuTest12 = false;
try { try {
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest1"); MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest1");
} catch (final Exception ex2) {} } catch (final Exception ex2) {}
} }
} }
@ -167,7 +169,7 @@ public class MarioScreen extends Screen {
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
if (!errored) { if (!errored) {
final boolean upPressed = false, downPressed = false, runPressed = false; final boolean upPressed = false, downPressed = false, runPressed = false;
g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed); g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed);
@ -188,7 +190,7 @@ public class MarioScreen extends Screen {
} }
@Override @Override
public void render() { public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display; DisplayOutputDevice display = d.display;
if (errored) { if (errored) {
d.renderer.glDrawStringLeft(0, 20, "ERROR"); d.renderer.glDrawStringLeft(0, 20, "ERROR");
@ -200,8 +202,8 @@ public class MarioScreen extends Screen {
final MarioWorld w = g.getCurrentWorld(); final MarioWorld w = g.getCurrentWorld();
final int width = w.getWidth(); final int width = w.getWidth();
final int height = w.getHeight(); final int height = w.getHeight();
final float screenX = d.display.getGraphicEngine().getWidth() / 2f - 8f; final float screenX = ctx.getWidth() / 2f - 8f;
final float screenY = d.display.getGraphicEngine().getHeight() / 2f - 8f; final float screenY = ctx.getHeight() / 2f - 8f;
final float shiftX = -8 + 16 * (float) playerX; final float shiftX = -8 + 16 * (float) playerX;
final float shiftY = -8 + 16 * (height - (float) playerY); final float shiftY = -8 + 16 * (height - (float) playerY);
int blue = -1; int blue = -1;
@ -241,10 +243,10 @@ public class MarioScreen extends Screen {
// GPU PERFORMANCE TEST // GPU PERFORMANCE TEST
if (MarioScreen.gpuTest1 != null) { if (MarioScreen.gpuTest1 != null) {
d.renderer.glColor3f(1, 1, 1); d.renderer.glColor3f(1, 1, 1);
d.renderer.glFillColor(d.display.getGraphicEngine().getWidth() - (MarioScreen.gpuTest12 ? 512 : 256), d.display.getGraphicEngine().getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), MarioScreen.gpuTest12 ? 512 : 256, MarioScreen.gpuTest12 ? 512 : 256); d.renderer.glFillColor(ctx.getWidth() - (MarioScreen.gpuTest12 ? 512 : 256), ctx.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), MarioScreen.gpuTest12 ? 512 : 256, MarioScreen.gpuTest12 ? 512 : 256);
MarioScreen.gpuTest1.use(d.display); MarioScreen.gpuTest1.use(d.display);
d.renderer.glColor3f(0, 0, 0); d.renderer.glColor3f(0, 0, 0);
d.renderer.glDrawStringRight(d.display.getGraphicEngine().getWidth(), d.display.getGraphicEngine().getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]); d.renderer.glDrawStringRight(ctx.getWidth(), ctx.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]);
} }
if (MarioScreen.gpuTest3 != null) { if (MarioScreen.gpuTest3 != null) {
MarioScreen.gpuTest3.use(d.display); MarioScreen.gpuTest3.use(d.display);
@ -254,19 +256,19 @@ public class MarioScreen extends Screen {
if (MarioScreen.gpuTest2 != null) { if (MarioScreen.gpuTest2 != null) {
MarioScreen.gpuTest2.use(d.display); MarioScreen.gpuTest2.use(d.display);
d.renderer.glColor(0xFF000000); d.renderer.glColor(0xFF000000);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "A"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "A");
d.renderer.glColor(0xFF800000); d.renderer.glColor(0xFF800000);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "B"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "B");
d.renderer.glColor(0xFFeea28e); d.renderer.glColor(0xFFeea28e);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "C"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "C");
d.renderer.glColor(0xFFee7255); d.renderer.glColor(0xFFee7255);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "D"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "D");
d.renderer.glColor(0xFFeac0b0); d.renderer.glColor(0xFFeac0b0);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "E"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "E");
d.renderer.glColor(0xFFf3d8ce); d.renderer.glColor(0xFFf3d8ce);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "F"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "F");
d.renderer.glColor(0xFFffede7); d.renderer.glColor(0xFFffede7);
d.renderer.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G"); d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G");
} }
} }
} }

View File

@ -9,6 +9,8 @@ import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent; import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
import it.cavallium.warppi.gui.graphicengine.BinaryFont; import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.gui.graphicengine.Renderer;
import it.cavallium.warppi.gui.graphicengine.Skin; import it.cavallium.warppi.gui.graphicengine.Skin;
@ -47,7 +49,7 @@ public class TetrisScreen extends Screen {
} }
@Override @Override
public void graphicInitialized() { public void graphicInitialized(ScreenContext ctx) {
try { try {
e = d.display; e = d.display;
r = d.renderer; r = d.renderer;
@ -65,23 +67,23 @@ public class TetrisScreen extends Screen {
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
d.renderer.glClearColor(0xff000000); d.renderer.glClearColor(0xff000000);
g.update(dt, leftPressed, rightPressed, downPressed, upPressed, okPressed, backPressed); g.update(dt, leftPressed, rightPressed, downPressed, upPressed, okPressed, backPressed);
} }
@Override @Override
public void render() { public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display; DisplayOutputDevice display = d.display;
if (TetrisScreen.skin != null) { if (TetrisScreen.skin != null) {
TetrisScreen.skin.use(e); TetrisScreen.skin.use(e);
} }
r.glColor3f(1, 1, 1); r.glColor3f(1, 1, 1);
BlockColor[] renderedGrid = g.getRenderedGrid(); BlockColor[] renderedGrid = g.getRenderedGrid();
int centerScreen = display.getDisplaySize()[0]/2; int centerScreen = ctx.getWidth()/2;
int centerGrid = TetrisGame.WIDTH*6/2-1; int centerGrid = TetrisGame.WIDTH*6/2-1;
final int leftOffset = centerScreen - centerGrid; final int leftOffset = centerScreen - centerGrid;
final int topOffset = display.getDisplaySize()[1] - TetrisGame.HEIGHT*6-1; final int topOffset = ctx.getHeight() - TetrisGame.HEIGHT*6-1;
for (int y = 0; y < TetrisGame.HEIGHT; y++) { for (int y = 0; y < TetrisGame.HEIGHT; y++) {
for (int x = 0; x < TetrisGame.WIDTH; x++) { for (int x = 0; x < TetrisGame.WIDTH; x++) {
final int offset = x+y*TetrisGame.WIDTH; final int offset = x+y*TetrisGame.WIDTH;

View File

@ -32,7 +32,7 @@ public class CalculatorHUD extends HUD {
} }
@Override @Override
public void render() { public void render(RenderContext ctx) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@ -48,8 +48,8 @@ public class CalculatorHUD extends HUD {
} }
@Override @Override
public void renderTopmost() { public void renderTopmost(RenderContext ctx) {
final Renderer r = d.renderer; final Renderer r = ctx.getRenderer();
final DisplayOutputDevice display = d.display; final DisplayOutputDevice display = d.display;
final GraphicEngine engine = display.getGraphicEngine(); final GraphicEngine engine = display.getGraphicEngine();
final Skin guiSkin = d.guiSkin; final Skin guiSkin = d.guiSkin;
@ -74,7 +74,7 @@ public class CalculatorHUD extends HUD {
final int brightness = (int) Math.ceil(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getBrightness() * 9); final int brightness = (int) Math.ceil(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getBrightness() * 9);
if (brightness <= 10) { if (brightness <= 10) {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
} else { } else {
WarpPI.getPlatform().getConsoleUtils().out().println(1, "Brightness error"); WarpPI.getPlatform().getConsoleUtils().out().println(1, "Brightness error");
} }
@ -85,18 +85,18 @@ public class CalculatorHUD extends HUD {
final boolean canGoForward = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().canGoForward(); final boolean canGoForward = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().canGoForward();
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) { if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
padding += 18 + 6; padding += 18 + 6;
} }
if (canGoBack && canGoForward) { if (canGoBack && canGoForward) {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
} else if (canGoBack) { } else if (canGoBack) {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
} else if (canGoForward) { } else if (canGoForward) {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
} else { } else {
r.glFillRect(display.getDisplaySize()[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16); r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
} }
padding += 18; padding += 18;
@ -106,13 +106,13 @@ public class CalculatorHUD extends HUD {
Utils.getFont(true, false).use(display); Utils.getFont(true, false).use(display);
r.glColor4i(255, 0, 0, 40); r.glColor4i(255, 0, 0, 40);
r.glDrawStringLeft(1 + 1, display.getDisplaySize()[1] - 7 - 7 + 1, "WORK IN"); r.glDrawStringLeft(1 + 1, ctx.getHeight() - 7 - 7 + 1, "WORK IN");
r.glColor4i(255, 0, 0, 80); r.glColor4i(255, 0, 0, 80);
r.glDrawStringLeft(1, display.getDisplaySize()[1] - 7 - 7, "WORK IN"); r.glDrawStringLeft(1, ctx.getHeight() - 7 - 7, "WORK IN");
r.glColor4i(255, 0, 0, 40); r.glColor4i(255, 0, 0, 40);
r.glDrawStringLeft(1 + 1, display.getDisplaySize()[1] - 7 + 1, "PROGRESS."); r.glDrawStringLeft(1 + 1, ctx.getHeight() - 7 + 1, "PROGRESS.");
r.glColor4i(255, 0, 0, 80); r.glColor4i(255, 0, 0, 80);
r.glDrawStringLeft(1, display.getDisplaySize()[1] - 7, "PROGRESS."); r.glDrawStringLeft(1, ctx.getHeight() - 7, "PROGRESS.");
int currentDebugLine = 2; int currentDebugLine = 2;
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) { if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
@ -137,28 +137,48 @@ public class CalculatorHUD extends HUD {
} else { } else {
r.glColor(0xFF990000); r.glColor(0xFF990000);
} }
r.glDrawStringLeft(0, display.getDisplaySize()[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "[" + String.format("%1$03d", session.debugScreenID) + "] " + title.toUpperCase()); r.glDrawStringLeft(0, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "[" + String.format("%1$03d", session.debugScreenID) + "] " + title.toUpperCase());
if (session == WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen()) { if (session == WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen()) {
r.glColor(0xFF00CC00); r.glColor(0xFF00CC00);
} else { } else {
r.glColor(0xFF990000); r.glColor(0xFF990000);
} }
r.glDrawStringLeft(0, display.getDisplaySize()[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), " " + title.toUpperCase()); r.glDrawStringLeft(0, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), " " + title.toUpperCase());
} }
currentDebugLine++; currentDebugLine++;
} }
} }
r.glColor(0xFF000000); r.glColor(0xFF000000);
r.glDrawStringLeft(5, display.getDisplaySize()[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "DEBUG ENABLED"); r.glDrawStringLeft(5, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "DEBUG ENABLED");
} }
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public int getMarginLeft() {
return 0;
}
@Override
public int getMarginTop() {
return 20;
}
@Override
public int getMarginRight() {
return 0;
}
@Override
public int getMarginBottom() {
return 0;
}
@Override @Override
public void renderBackground() { public void renderBackground() {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -1,36 +1,22 @@
package it.cavallium.warppi.gui; package it.cavallium.warppi.gui;
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Flow.Subscriber;
import java.util.function.Consumer;
import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.Platform.ConsoleUtils;
import it.cavallium.warppi.Platform.Semaphore; import it.cavallium.warppi.Platform.Semaphore;
import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.device.display.BacklightOutputDevice; import it.cavallium.warppi.device.display.BacklightOutputDevice;
import it.cavallium.warppi.device.display.DisplayOutputDevice; import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.device.input.Keyboard; import it.cavallium.warppi.device.input.Keyboard;
import it.cavallium.warppi.event.TouchCancelEvent; import it.cavallium.warppi.event.*;
import it.cavallium.warppi.event.TouchEndEvent; import it.cavallium.warppi.gui.graphicengine.*;
import it.cavallium.warppi.event.TouchEvent;
import it.cavallium.warppi.event.TouchMoveEvent;
import it.cavallium.warppi.event.TouchStartEvent;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.device.Keyboard;
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
import it.cavallium.warppi.gui.graphicengine.Renderer;
import it.cavallium.warppi.gui.graphicengine.RenderingLoop;
import it.cavallium.warppi.gui.graphicengine.Skin;
import it.cavallium.warppi.gui.graphicengine.impl.nogui.NoGuiEngine;
import it.cavallium.warppi.gui.screens.Screen; import it.cavallium.warppi.gui.screens.Screen;
import it.cavallium.warppi.util.Timer; import it.cavallium.warppi.util.Timer;
import it.cavallium.warppi.util.Utils; import it.cavallium.warppi.util.Utils;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
public final class DisplayManager implements RenderingLoop { public final class DisplayManager implements RenderingLoop {
private static final int tickDuration = 50; private static final int tickDuration = 50;
@ -72,7 +58,7 @@ public final class DisplayManager implements RenderingLoop {
screenChange = WarpPI.getPlatform().newSemaphore(); screenChange = WarpPI.getPlatform().newSemaphore();
supportsPauses = graphicEngine.doesRefreshPauses(); supportsPauses = graphicEngine.doesRefreshPauses();
glyphsHeight = new int[] { 9, 6, 12, 9 }; glyphsHeight = new int[]{9, 6, 12, 9};
displayDebugString = ""; displayDebugString = "";
errorMessages = new ObjectArrayList<>(); errorMessages = new ObjectArrayList<>();
} }
@ -153,10 +139,10 @@ public final class DisplayManager implements RenderingLoop {
} }
if (mustBeAddedToHistory) { if (mustBeAddedToHistory) {
if (screen.historyBehavior == HistoryBehavior.NORMAL if (screen.historyBehavior == HistoryBehavior.NORMAL
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) { || screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
if (currentSession > 0) { if (currentSession > 0) {
final int sl = sessions.length; // TODO: I don't know why if i don't add +5 or more some items final int sl = sessions.length; // TODO: I don't know why if i don't add +5 or more some items
// disappear // disappear
List<Screen> newSessions = new LinkedList<>(); List<Screen> newSessions = new LinkedList<>();
int i = 0; int i = 0;
for (Screen s : sessions) { for (Screen s : sessions) {
@ -217,7 +203,7 @@ public final class DisplayManager implements RenderingLoop {
public void replaceScreen(final Screen screen) { public void replaceScreen(final Screen screen) {
if (screen.initialized == false) { if (screen.initialized == false) {
if (screen.historyBehavior == HistoryBehavior.NORMAL if (screen.historyBehavior == HistoryBehavior.NORMAL
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) { || screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
sessions[currentSession] = screen; sessions[currentSession] = screen;
} else { } else {
currentSession = -1; currentSession = -1;
@ -339,8 +325,10 @@ public final class DisplayManager implements RenderingLoop {
if (!screen.graphicInitialized) { if (!screen.graphicInitialized) {
try { try {
var displaySize = display.getDisplaySize(); var displaySize = display.getDisplaySize();
var fullCtx = new RenderContext(graphicEngine, renderer, displaySize[0], displaySize[1]); var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
screen.initializeGraphic(fullCtx); var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
var scrCtx = new ScreenContext(graphicEngine, scrWidth, scrHeight);
screen.initializeGraphic(scrCtx);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -353,7 +341,7 @@ public final class DisplayManager implements RenderingLoop {
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight(); var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom(); var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
var scrCtx = new RenderContext(graphicEngine, renderer.getBoundedInstance(hud.getMarginLeft(), hud.getMarginTop(), scrWidth, scrHeight), scrWidth, scrHeight); var scrCtx = new RenderContext(graphicEngine, renderer.getBoundedInstance(hud.getMarginLeft(), hud.getMarginTop(), scrWidth, scrHeight), scrWidth, scrHeight);
var fullCtdx = new RenderContext(graphicEngine, renderer, displaySize[0], displaySize[1]); var fullCtx = new RenderContext(graphicEngine, renderer, displaySize[0], displaySize[1]);
renderer.glColor3i(255, 255, 255); renderer.glColor3i(255, 255, 255);
@ -364,8 +352,8 @@ public final class DisplayManager implements RenderingLoop {
} }
renderer.glColor3i(129, 28, 22); renderer.glColor3i(129, 28, 22);
renderer.glDrawStringRight(display.getDisplaySize()[0] - 2, renderer.glDrawStringRight(display.getDisplaySize()[0] - 2,
display.getDisplaySize()[1] - (fnt.getCharacterHeight() + 2), display.getDisplaySize()[1] - (fnt.getCharacterHeight() + 2),
WarpPI.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR"); WarpPI.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR");
renderer.glColor3i(149, 32, 26); renderer.glColor3i(149, 32, 26);
renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, 22, error); renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, 22, error);
renderer.glColor3i(164, 34, 28); renderer.glColor3i(164, 34, 28);
@ -387,12 +375,12 @@ public final class DisplayManager implements RenderingLoop {
hud.renderBackground(); hud.renderBackground();
screen.render(scrCtx); screen.render(scrCtx);
if (hud.visible) { if (hud.visible) {
hud.render(fullCtdx); hud.render(fullCtx);
hud.renderTopmostBackground(); hud.renderTopmostBackground();
} }
screen.renderTopmost(scrCtx); screen.renderTopmost(fullCtx);
if (hud.visible) if (hud.visible)
hud.renderTopmost(fullCtdx); hud.renderTopmost(fullCtx);
} }
} }
@ -429,9 +417,9 @@ public final class DisplayManager implements RenderingLoop {
var displayRefreshManager = new DisplayRefreshManager(this::onRefresh); var displayRefreshManager = new DisplayRefreshManager(this::onRefresh);
new Timer(DisplayManager.tickDuration, displayRefreshManager::onTick); new Timer(DisplayManager.tickDuration, displayRefreshManager::onTick);
engine.onResize().subscribe(displayRefreshManager::onResize); graphicEngine.onResize().subscribe(displayRefreshManager::onResize);
engine.start(getDrawable()); graphicEngine.start(getDrawable());
} catch (final Exception ex) { } catch (final Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} finally { } finally {
@ -449,11 +437,15 @@ public final class DisplayManager implements RenderingLoop {
precTime = newtime; precTime = newtime;
if (windowSize != null) { if (windowSize != null) {
StaticVars.screenSize[0] = windowSize[0]; display.getDisplaySize()[0] = windowSize[0];
StaticVars.screenSize[1] = windowSize[1]; display.getDisplaySize()[1] = windowSize[1];
} }
screen.beforeRender((float) (dt / 1000d)); var displaySize = display.getDisplaySize();
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
var scrCtx = new ScreenContext(graphicEngine, scrWidth, scrHeight);
screen.beforeRender(scrCtx, (float) (dt / 1000d));
} }
public void changeBrightness(final float change) { public void changeBrightness(final float change) {
@ -512,7 +504,7 @@ public final class DisplayManager implements RenderingLoop {
} }
}; };
} }
private boolean executeTouchEventOnScreen(TouchEvent t, Screen scr) { private boolean executeTouchEventOnScreen(TouchEvent t, Screen scr) {
if (t instanceof TouchStartEvent) { if (t instanceof TouchStartEvent) {
return scr.onTouchStart((TouchStartEvent) t); return scr.onTouchStart((TouchStartEvent) t);

View File

@ -1,13 +1,12 @@
package it.cavallium.warppi.gui; package it.cavallium.warppi.gui;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer; import java.util.function.Consumer;
public class DisplayRefreshManager { public class DisplayRefreshManager {
private final Consumer<Integer[]> refreshConsumer; private final Consumer<Integer[]> refreshConsumer;
private AtomicBoolean ticked = new AtomicBoolean(false);
private AtomicBoolean sizeSet = new AtomicBoolean(false);
private volatile Integer[] size; private volatile Integer[] size;
public DisplayRefreshManager(Consumer<Integer[]> refreshConsumer) { public DisplayRefreshManager(Consumer<Integer[]> refreshConsumer) {
@ -15,18 +14,13 @@ public class DisplayRefreshManager {
} }
public void onTick() { public void onTick() {
ticked.set(true); refreshConsumer.accept(size);
refreshIfNeeded();
} }
public void onResize(Integer[] newSize) { public void onResize(Integer[] newSize) {
size = newSize; var oldSize = size;
sizeSet.set(true); if (oldSize == null || !Arrays.equals(oldSize, newSize)) {
refreshIfNeeded(); size = newSize;
}
private void refreshIfNeeded() {
if (ticked.get() && sizeSet.get()) {
refreshConsumer.accept(size); refreshConsumer.accept(size);
} }
} }

View File

@ -1,5 +1,7 @@
package it.cavallium.warppi.gui.graphicengine; package it.cavallium.warppi.gui.graphicengine;
import it.cavallium.warppi.gui.graphicengine.impl.common.ReboundedRenderer;
public interface Renderer { public interface Renderer {
void glColor3i(int r, int gg, int b); void glColor3i(int r, int gg, int b);
@ -43,5 +45,7 @@ public interface Renderer {
BinaryFont getCurrentFont(); BinaryFont getCurrentFont();
Renderer getBoundedInstance(int dx, int dy, int width, int height); default Renderer getBoundedInstance(int dx, int dy, int width, int height) {
return new ReboundedRenderer(this, dx, dy, width, height);
}
} }

View File

@ -0,0 +1,130 @@
package it.cavallium.warppi.gui.graphicengine.impl.common;
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
import it.cavallium.warppi.gui.graphicengine.Renderer;
public class ReboundedRenderer implements Renderer {
private final Renderer renderer;
private final int dx;
private final int dy;
private final int width;
private final int height;
public ReboundedRenderer(Renderer renderer, int dx, int dy, int width, int height) {
this.renderer = renderer;
this.dx = dx;
this.dy = dy;
this.width = width;
this.height = height;
}
@Override
public void glColor3i(int r, int gg, int b) {
renderer.glColor3i(r, gg, b);
}
@Override
public void glColor(int c) {
renderer.glColor(c);
}
@Override
public void glColor4i(int red, int green, int blue, int alpha) {
renderer.glColor4i(red, green, blue, alpha);
}
@Override
public void glColor3f(float red, float green, float blue) {
renderer.glColor3f(red, green, blue);
}
@Override
public void glColor4f(float red, float green, float blue, float alpha) {
renderer.glColor4f(red, green, blue, alpha);
}
@Override
public void glClearColor4i(int red, int green, int blue, int alpha) {
renderer.glClearColor4i(red, green, blue, alpha);
}
@Override
public void glClearColor4f(float red, float green, float blue, float alpha) {
renderer.glClearColor4f(red, green, blue, alpha);
}
@Override
public int glGetClearColor() {
return renderer.glGetClearColor();
}
@Override
public void glClearColor(int c) {
renderer.glClearColor(c);
}
@Override
public void glClear(int screenWidth, int screenHeight) {
renderer.glClear(screenWidth, screenHeight);
}
@Override
public void glDrawLine(float x0, float y0, float x1, float y1) {
renderer.glDrawLine(this.dx + x0, this.dy + y0, this.dx + x1, this.dy + y1);
}
@Override
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
renderer.glFillRect(this.dx + x, this.dy + y, width, height, uvX, uvY, uvWidth, uvHeight);
}
@Override
public void glFillColor(float x, float y, float width, float height) {
renderer.glFillColor(this.dx + x, this.dy + y, width, height);
}
@Override
public void glDrawCharLeft(int x, int y, char ch) {
renderer.glDrawCharLeft(this.dx + x, this.dy + y, ch);
}
@Override
public void glDrawCharCenter(int x, int y, char ch) {
renderer.glDrawCharCenter(this.dx + x, this.dy + y, ch);
}
@Override
public void glDrawCharRight(int x, int y, char ch) {
renderer.glDrawCharRight(this.dx + x, this.dy + y, ch);
}
@Override
public void glDrawStringLeft(float x, float y, String text) {
renderer.glDrawStringLeft(this.dx + x, this.dy + y, text);
}
@Override
public void glDrawStringCenter(float x, float y, String text) {
renderer.glDrawStringCenter(this.dx + x, this.dy + y, text);
}
@Override
public void glDrawStringRight(float x, float y, String text) {
renderer.glDrawStringRight(this.dx + x, this.dy + y, text);
}
@Override
public void glClearSkin() {
renderer.glClearSkin();
}
@Override
public BinaryFont getCurrentFont() {
return renderer.getCurrentFont();
}
@Override
public Renderer getBoundedInstance(int dx, int dy, int width, int height) {
return renderer.getBoundedInstance(this.dx + dx, this.dy + dy, width, height);
}
}

View File

@ -140,6 +140,11 @@ public class NoGuiEngine implements GraphicEngine {
public BinaryFont getCurrentFont() { public BinaryFont getCurrentFont() {
return null; return null;
} }
@Override
public Renderer getBoundedInstance(int dx, int dy, int width, int height) {
return getRenderer();
}
}; };
} }

View File

@ -5,6 +5,8 @@ import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.StaticVars; import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
import it.cavallium.warppi.math.Function; import it.cavallium.warppi.math.Function;
import it.cavallium.warppi.math.functions.Variable.VariableValue; import it.cavallium.warppi.math.functions.Variable.VariableValue;
import it.cavallium.warppi.util.Utils; import it.cavallium.warppi.util.Utils;
@ -29,30 +31,29 @@ public class ChooseVariableValueScreen extends Screen {
public void initialized() throws InterruptedException {} public void initialized() throws InterruptedException {}
@Override @Override
public void graphicInitialized() throws InterruptedException {} public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
@Override @Override
public void render() { public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display;
Utils.getFont(false, true).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); Utils.getFont(false, true).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64); ctx.getRenderer().glColor4i(0, 0, 0, 64);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 2 - 20, "WORK IN PROGRESS."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 2 - 20 + 1, "WORK IN PROGRESS."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 2 - 20 + 1, "WORK IN PROGRESS."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0); ctx.getRenderer().glColor3i(255, 0, 0);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 2 - 20, "WORK IN PROGRESS."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
Utils.getFont(false, false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); Utils.getFont(false, false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64); ctx.getRenderer().glColor4i(0, 0, 0, 64);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0); ctx.getRenderer().glColor3i(255, 0, 0);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
} }

View File

@ -1,6 +1,8 @@
package it.cavallium.warppi.gui.screens; package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
public class EmptyScreen extends Screen { public class EmptyScreen extends Screen {
@ -20,16 +22,16 @@ public class EmptyScreen extends Screen {
public void initialized() throws InterruptedException {} public void initialized() throws InterruptedException {}
@Override @Override
public void graphicInitialized() throws InterruptedException {} public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
@Override @Override
public void render() { public void render(RenderContext ctx) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
} }

View File

@ -5,6 +5,8 @@ import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.event.KeyReleasedEvent; import it.cavallium.warppi.event.KeyReleasedEvent;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
import it.cavallium.warppi.gui.graphicengine.Renderer; import it.cavallium.warppi.gui.graphicengine.Renderer;
public class KeyboardDebugScreen extends Screen { public class KeyboardDebugScreen extends Screen {
@ -28,14 +30,14 @@ public class KeyboardDebugScreen extends Screen {
public void initialized() throws InterruptedException {} public void initialized() throws InterruptedException {}
@Override @Override
public void graphicInitialized() throws InterruptedException {} public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
@Override @Override
public void render() { public void render(RenderContext ctx) {
final Renderer renderer = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer; final Renderer renderer = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f); renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f);
renderer.glDrawStringRight(d.display.getDisplaySize()[0] - 10, 30, "-" + keyevent.toUpperCase() + "-"); renderer.glDrawStringRight(ctx.getWidth() - 10, 30, "-" + keyevent.toUpperCase() + "-");
if (keyevent != "NONE") { if (keyevent != "NONE") {
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f); renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
@ -176,7 +178,7 @@ public class KeyboardDebugScreen extends Screen {
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
if (System.currentTimeMillis() - beforetime >= 1000) { if (System.currentTimeMillis() - beforetime >= 1000) {
keyevent = "NONE"; keyevent = "NONE";
KeyboardDebugScreen.keyX = 0; KeyboardDebugScreen.keyX = 0;

View File

@ -3,8 +3,11 @@ package it.cavallium.warppi.gui.screens;
import it.cavallium.warppi.WarpPI; import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.device.display.DisplayOutputDevice; import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.StaticVars; import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.extra.mario.MarioScreen;
import it.cavallium.warppi.gui.GraphicUtils; import it.cavallium.warppi.gui.GraphicUtils;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
public class LoadingScreen extends Screen { public class LoadingScreen extends Screen {
@ -36,32 +39,32 @@ public class LoadingScreen extends Screen {
} }
@Override @Override
public void graphicInitialized() throws InterruptedException {} public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f; loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
endLoading += dt; endLoading += dt;
if (!ended && loaded && (WarpPI.getPlatform().getSettings().isDebugEnabled() || endLoading >= 3.5f)) { if (!ended && loaded && ((WarpPI.getPlatform().getSettings().isDebugEnabled() && endLoading >= 1.5f) || endLoading >= 3.5f)) {
ended = true; ended = true;
StaticVars.windowZoom.submit(previousZoomValue); StaticVars.windowZoom.submit(previousZoomValue);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show(); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen()); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MarioScreen());
} }
mustRefresh = true; mustRefresh = true;
} }
@Override @Override
public void render() { public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display; DisplayOutputDevice display = d.display;
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 255, 255); ctx.getRenderer().glColor3i(255, 255, 255);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(display.getDisplaySize()[0] / 2f - 80, display.getDisplaySize()[1] / 2f - 64, 160, 48, 0, 32, 160, 48); ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 80, ctx.getHeight() / 2f - 64, 160, 48, 0, 32, 160, 48);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(display.getDisplaySize()[0] / 2f - 24, display.getDisplaySize()[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48); ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 24, ctx.getHeight() / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(display.getDisplaySize()[0] - 224, display.getDisplaySize()[1] - 48, 224, 48, 0, 80, 224, 48); ctx.getRenderer().glFillRect(ctx.getWidth() - 224, ctx.getHeight() - 48, 224, 48, 0, 80, 224, 48);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(display.getDisplaySize()[0] - 160 - 24 - 224, display.getDisplaySize()[1] - 48, 160, 48, 224, 80, 160, 48); ctx.getRenderer().glFillRect(ctx.getWidth() - 160 - 24 - 224, ctx.getHeight() - 48, 160, 48, 224, 80, 160, 48);
} }

View File

@ -88,9 +88,6 @@ public class MathInputScreen extends Screen {
ic = new InputContext(); ic = new InputContext();
calc = new MathContext(); calc = new MathContext();
userInput = new NormalInputContainer(ic);
result = new NormalOutputContainer();
calc.init(); calc.init();
} }
@ -108,6 +105,9 @@ public class MathInputScreen extends Screen {
e.printStackTrace(); e.printStackTrace();
WarpPI.getPlatform().exit(1); WarpPI.getPlatform().exit(1);
} }
userInput = new NormalInputContainer(ic);
result = new NormalOutputContainer();
} }
@Override @Override
@ -117,9 +117,10 @@ public class MathInputScreen extends Screen {
} else { } else {
ctx.getGraphicEngine().getRenderer().glClearColor(0xFFDC3C32); ctx.getGraphicEngine().getRenderer().glClearColor(0xFFDC3C32);
} }
if (userInput.beforeRender(dt)) { if (userInput != null)
mustRefresh = true; if (userInput.beforeRender(dt)) {
} mustRefresh = true;
}
if (computingResult) { if (computingResult) {
computingElapsedTime += dt; computingElapsedTime += dt;
computingAnimationElapsedTime += dt; computingAnimationElapsedTime += dt;
@ -147,7 +148,7 @@ public class MathInputScreen extends Screen {
final int padding = 4; final int padding = 4;
renderer.glColor(textColor); renderer.glColor(textColor);
userInput.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, padding, padding + 20); userInput.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, padding, padding);
if (computingResult) { if (computingResult) {
renderer.glColor3f(1, 1, 1); renderer.glColor3f(1, 1, 1);
@ -156,14 +157,14 @@ public class MathInputScreen extends Screen {
final int size = 32; final int size = 32;
final int posY = computingAnimationIndex % 2; final int posY = computingAnimationIndex % 2;
final int posX = (computingAnimationIndex - posY) / 2; final int posX = (computingAnimationIndex - posY) / 2;
renderer.glFillRect(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getWidth() - size - 4, WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getHeight() - size - 4, size, size, leftX + size * posX, leftY + size * posY, size, size); renderer.glFillRect(ctx.getWidth() - size - 4, ctx.getHeight() - size - 4, size, size, leftX + size * posX, leftY + size * posY, size, size);
if (computingBreakTipVisible) { if (computingBreakTipVisible) {
Utils.getFont(false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display); Utils.getFont(false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
renderer.glColor3f(0.75f, 0, 0); renderer.glColor3f(0.75f, 0, 0);
renderer.glDrawStringRight(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getWidth() - 4 - size - 4, WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getHeight() - size / 2 - renderer.getCurrentFont().getCharacterHeight() / 2 - 4, "Press (=) to stop"); renderer.glDrawStringRight(ctx.getWidth() - 4 - size - 4, ctx.getHeight() - size / 2 - renderer.getCurrentFont().getCharacterHeight() / 2 - 4, "Press (=) to stop");
} }
} else if (!result.isContentEmpty()) { } else if (!result.isContentEmpty()) {
result.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getWidth() - result.getWidth() - 2, WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display.getGraphicEngine().getHeight() - result.getHeight() - 2); result.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, ctx.getWidth() - result.getWidth() - 2, ctx.getHeight() - result.getHeight() - 2);
} }
} }

View File

@ -5,6 +5,8 @@ import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.StaticVars; import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.KeyPressedEvent; import it.cavallium.warppi.event.KeyPressedEvent;
import it.cavallium.warppi.gui.HistoryBehavior; import it.cavallium.warppi.gui.HistoryBehavior;
import it.cavallium.warppi.gui.RenderContext;
import it.cavallium.warppi.gui.ScreenContext;
public class SolveForXScreen extends Screen { public class SolveForXScreen extends Screen {
@ -25,21 +27,21 @@ public class SolveForXScreen extends Screen {
public void initialized() throws InterruptedException {} public void initialized() throws InterruptedException {}
@Override @Override
public void graphicInitialized() throws InterruptedException {} public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
@Override @Override
public void render() { public void render(RenderContext ctx) {
DisplayOutputDevice display = d.display; DisplayOutputDevice display = d.display;
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64); ctx.getRenderer().glColor4i(0, 0, 0, 64);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0); ctx.getRenderer().glColor3i(255, 0, 0);
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE."); ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
} }
@Override @Override
public void beforeRender(final float dt) { public void beforeRender(ScreenContext ctx, final float dt) {
} }

View File

@ -2,7 +2,6 @@ package it.cavallium.warppi.math.rules;
import it.cavallium.warppi.WarpPI; import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.Platform; import it.cavallium.warppi.Platform;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.Platform.ConsoleUtils; import it.cavallium.warppi.Platform.ConsoleUtils;
import it.cavallium.warppi.math.Function; import it.cavallium.warppi.math.Function;
import it.cavallium.warppi.math.MathContext; import it.cavallium.warppi.math.MathContext;
@ -45,7 +44,7 @@ public class RulesManager {
System.err.println(); System.err.println();
System.err.print(((DslFilesException) e).format()); System.err.print(((DslFilesException) e).format());
} }
Engine.getPlatform().exit(1); WarpPI.getPlatform().exit(1);
} }
} }
@ -68,7 +67,7 @@ public class RulesManager {
} }
private static void loadDslRules() throws IOException, DslFilesException { private static void loadDslRules() throws IOException, DslFilesException {
final Platform platform = Engine.getPlatform(); final Platform platform = WarpPI.getPlatform();
final DslFilesException fileErrors = new DslFilesException(); final DslFilesException fileErrors = new DslFilesException();
for (final String path : platform.getRuleFilePaths()) { for (final String path : platform.getRuleFilePaths()) {

View File

@ -1,6 +1,6 @@
package it.cavallium.warppi.util; package it.cavallium.warppi.util;
import it.cavallium.warppi.Engine; import it.cavallium.warppi.WarpPI;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -8,6 +8,8 @@ public class Timer {
public Timer(int intervalMillis, Runnable action) { public Timer(int intervalMillis, Runnable action) {
var thread = new Thread(() -> { var thread = new Thread(() -> {
try { try {
Thread.sleep(intervalMillis);
AtomicLong lostTime = new AtomicLong(); AtomicLong lostTime = new AtomicLong();
while (!Thread.interrupted()) { while (!Thread.interrupted()) {
var time1 = System.currentTimeMillis(); var time1 = System.currentTimeMillis();
@ -24,7 +26,7 @@ public class Timer {
e.printStackTrace(); e.printStackTrace();
} }
}); });
Engine.getPlatform().setThreadName(thread, "Timer"); WarpPI.getPlatform().setThreadName(thread, "Timer");
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
} }

View File

@ -7,7 +7,9 @@ import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Consumer;
import it.cavallium.warppi.event.TouchEvent;
import it.cavallium.warppi.gui.graphicengine.impl.jogl.JOGLDisplayOutputDevice; import it.cavallium.warppi.gui.graphicengine.impl.jogl.JOGLDisplayOutputDevice;
import it.cavallium.warppi.gui.graphicengine.impl.jogl.JOGLEngine; import it.cavallium.warppi.gui.graphicengine.impl.jogl.JOGLEngine;
import it.cavallium.warppi.gui.graphicengine.impl.swing.SwingDeviceState; import it.cavallium.warppi.gui.graphicengine.impl.swing.SwingDeviceState;
@ -249,6 +251,7 @@ public class DesktopPlatform implements Platform {
if (device instanceof SwingDisplayOutputDevice) { if (device instanceof SwingDisplayOutputDevice) {
if (args.isCPUEngineForced()) { if (args.isCPUEngineForced()) {
this.displayOutputDevice = device; this.displayOutputDevice = device;
break;
} }
} else if (device instanceof JOGLDisplayOutputDevice) { } else if (device instanceof JOGLDisplayOutputDevice) {
if (args.isGPUEngineForced()) { if (args.isGPUEngineForced()) {
@ -275,9 +278,62 @@ public class DesktopPlatform implements Platform {
this.deviceStateDevice = new SwingDeviceState((SwingEngine) displayOutputDevice.getGraphicEngine()); this.deviceStateDevice = new SwingDeviceState((SwingEngine) displayOutputDevice.getGraphicEngine());
} else if (displayOutputDevice instanceof JOGLDisplayOutputDevice) { } else if (displayOutputDevice instanceof JOGLDisplayOutputDevice) {
this.touchInputDevice = null; //TODO: implement a touch input device
this.keyboardInputDevice = null; this.touchInputDevice = new TouchInputDevice() {
this.deviceStateDevice = null; //TODO: Implement @Override
public boolean getSwappedAxes() {
return false;
}
@Override
public boolean getInvertedX() {
return false;
}
@Override
public boolean getInvertedY() {
return false;
}
@Override
public void listenTouchEvents(Consumer<TouchEvent> touchEventListener) {
}
@Override
public void initialize() {
}
};
//TODO: implement a keyboard input device
this.keyboardInputDevice = new KeyboardInputDevice() {
@Override
public void initialize() {
}
};
this.deviceStateDevice = new DeviceStateDevice() {
@Override
public void initialize() {
}
@Override
public void waitForExit() {
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void powerOff() {
}
}; //TODO: Implement
} }
} }

View File

@ -4,26 +4,32 @@ import it.cavallium.warppi.device.DeviceStateDevice;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
public class SwingDeviceState implements DeviceStateDevice { public class SwingDeviceState implements DeviceStateDevice {
private final SwingEngine graphicEngine; private final SwingEngine graphicEngine;
private final CompletableFuture<Void> exitWait; private final AtomicBoolean exitWait = new AtomicBoolean(false);
public SwingDeviceState(SwingEngine graphicEngine) { public SwingDeviceState(SwingEngine graphicEngine) {
this.graphicEngine = graphicEngine; this.graphicEngine = graphicEngine;
this.exitWait = new CompletableFuture<>();
} }
@Override @Override
public void initialize() { public void initialize() {
graphicEngine.subscribeExit(() -> { graphicEngine.subscribeExit(() -> {
exitWait.complete(null); exitWait.set(true);
}); });
} }
@Override @Override
public Future<?> waitForExit() { public void waitForExit() {
return exitWait; try {
while (!exitWait.get()) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
@Override @Override

View File

@ -6,7 +6,7 @@ public class JOGLDisplayOutputDevice implements DisplayOutputDevice {
private JOGLEngine engine; private JOGLEngine engine;
public JOGLDisplayOutputDevice() { public JOGLDisplayOutputDevice() {
this.engine = new JOGLEngine(); this.engine = new JOGLEngine(480, 320);
} }
@Override @Override

View File

@ -34,7 +34,8 @@ public class JOGLEngine implements GraphicEngine {
protected LinkedList<Texture> registeredTextures; protected LinkedList<Texture> registeredTextures;
protected LinkedList<Texture> unregisteredTextures; protected LinkedList<Texture> unregisteredTextures;
public JOGLEngine() { public JOGLEngine(int defaultWidth, int defaultHeight) {
this.size = new int[]{defaultWidth, defaultHeight};
} }
@Override @Override

View File

@ -43,7 +43,7 @@ public class JOGLSkin implements Skin {
t = JOGLRenderer.importTexture(i.f, i.deleteOnExit); t = JOGLRenderer.importTexture(i.f, i.deleteOnExit);
w = i.w; w = i.w;
h = i.h; h = i.h;
((JOGLEngine) d).registerTexture(t); ((JOGLEngine) d.getGraphicEngine()).registerTexture(t);
initialized = true; initialized = true;
} catch (GLException | IOException e) { } catch (GLException | IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -81,17 +81,17 @@ class NEWTWindow implements GLEventListener {
engine.size[1] = engine.getSize()[1]; engine.size[1] = engine.getSize()[1];
realWindowSize = new int[] { engine.getSize()[0], engine.getSize()[1] }; realWindowSize = new int[] { engine.getSize()[0], engine.getSize()[1] };
windowZoom = StaticVars.windowZoomFunction.apply(StaticVars.windowZoom.getLastValue()); windowZoom = StaticVars.windowZoomFunction.apply(StaticVars.windowZoom.getLastValue());
onRealResize = BehaviorSubject.create(new Integer[] { (int) (engine.getSize()[0] * windowZoom), (int) (engine.getSize()[1] * windowZoom) }); onRealResize = EventSubmitter.create(new Integer[] { (int) (engine.getSize()[0] * windowZoom), (int) (engine.getSize()[1] * windowZoom) });
onRealResize.subscribe((realSize) -> { onRealResize.subscribe((realSize) -> {
realWindowSize[0] = realSize[0]; realWindowSize[0] = realSize[0];
realWindowSize[1] = realSize[1]; realWindowSize[1] = realSize[1];
engine.size[0] = realSize[0] / (int) windowZoom; engine.size[0] = realSize[0] / (int) windowZoom;
engine.size[1] = realSize[1] / (int) windowZoom; engine.size[1] = realSize[1] / (int) windowZoom;
onResizeEvent.onNext(new Integer[] { engine.size[0], engine.size[1] }); onResizeEvent.submit(new Integer[] { engine.size[0], engine.size[1] });
refreshViewport = true; refreshViewport = true;
}); });
StaticVars.windowZoom$.subscribe(onZoom::onNext); StaticVars.windowZoom$.subscribe(onZoom::submit);
onZoom.subscribe((z) -> { onZoom.subscribe((z) -> {
if (windowZoom != 0) { if (windowZoom != 0) {
windowZoom = z; windowZoom = z;

View File

@ -0,0 +1,37 @@
package it.cavallium.warppi.gui.graphicengine.html;
import it.cavallium.warppi.device.DeviceStateDevice;
import java.util.concurrent.atomic.AtomicBoolean;
public class HtmlDeviceState implements DeviceStateDevice {
private final HtmlEngine graphicEngine;
private final AtomicBoolean exitWait = new AtomicBoolean(false);
public HtmlDeviceState(HtmlEngine graphicEngine) {
this.graphicEngine = graphicEngine;
}
@Override
public void initialize() {
graphicEngine.subscribeExit(() -> {
exitWait.set(true);
});
}
@Override
public void waitForExit() {
try {
while (!exitWait.get()) {
Thread.sleep(500);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void powerOff() {
graphicEngine.sendPowerOffSignal();
}
}

View File

@ -0,0 +1,23 @@
package it.cavallium.warppi.gui.graphicengine.html;
import it.cavallium.warppi.device.display.DisplayOutputDevice;
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
public class HtmlDisplayOutputDevice implements DisplayOutputDevice {
private final HtmlEngine engine;
public HtmlDisplayOutputDevice() {
this.engine = new HtmlEngine();
}
@Override
public HtmlEngine getGraphicEngine() {
return engine;
}
@Override
public int[] getDisplaySize() {
return engine.getSize();
}
}

View File

@ -108,8 +108,7 @@ public class HtmlEngine implements GraphicEngine {
width = 480 / windowZoom.intValue(); width = 480 / windowZoom.intValue();
height = 320 / windowZoom.intValue(); height = 320 / windowZoom.intValue();
this.mult = windowZoom.intValue(); this.mult = windowZoom.intValue();
StaticVars.screenSize[0] = width; onResize.submit(new Integer[] {width, height});
StaticVars.screenSize[1] = height;
} }
}); });
keyInput.setType("text"); keyInput.setType("text");
@ -248,6 +247,10 @@ public class HtmlEngine implements GraphicEngine {
@Override @Override
public void destroy() { public void destroy() {
sendPowerOffSignal();
}
private void destroyEngine() {
HtmlEngine.document.getBody().removeChild(canvas); HtmlEngine.document.getBody().removeChild(canvas);
initialized = false; initialized = false;
exitSemaphore.release(); exitSemaphore.release();
@ -283,7 +286,7 @@ public class HtmlEngine implements GraphicEngine {
@Override @Override
public void repaint() { public void repaint() {
renderingLoop.refresh(); renderingLoop.refresh(false);
} }
@Override @Override
@ -306,11 +309,16 @@ public class HtmlEngine implements GraphicEngine {
return new HtmlSkin(file); return new HtmlSkin(file);
} }
@Override
public void waitForExit() { public void subscribeExit(Runnable subscriber) {
try { var thr = new Thread(() -> {
exitSemaphore.acquire(); try {
} catch (final InterruptedException e) {} exitSemaphore.acquire();
} catch (final InterruptedException e) {}
subscriber.run();
});
thr.setDaemon(true);
thr.start();
} }
@Override @Override
@ -328,4 +336,7 @@ public class HtmlEngine implements GraphicEngine {
return onResize; return onResize;
} }
public void sendPowerOffSignal() {
destroyEngine();
}
} }

View File

@ -58,8 +58,6 @@ public class HtmlRenderer implements Renderer {
final boolean transparent) { final boolean transparent) {
final int[] size = e.getSize(); final int[] size = e.getSize();
x0 += StaticVars.screenPos[0];
y0 += StaticVars.screenPos[1];
final double incrementX = Math.abs((double) (x1 - x0) / (double) (s1 - s0)); final double incrementX = Math.abs((double) (x1 - x0) / (double) (s1 - s0));
final double incrementY = Math.abs((double) (y1 - y0) / (double) (t1 - t0)); final double incrementY = Math.abs((double) (y1 - y0) / (double) (t1 - t0));
final boolean flippedX = (x1 - x0) / (s1 - s0) < 0; final boolean flippedX = (x1 - x0) / (s1 - s0) < 0;
@ -110,8 +108,6 @@ public class HtmlRenderer implements Renderer {
@Override @Override
public void glFillColor(float x, float y, final float width, final float height) { public void glFillColor(float x, float y, final float width, final float height) {
x += StaticVars.screenPos[0];
y += StaticVars.screenPos[1];
g.setFillStyle(currentColor); g.setFillStyle(currentColor);
g.fillRect(x * e.mult, y * e.mult, width * e.mult, height * e.mult); g.fillRect(x * e.mult, y * e.mult, width * e.mult, height * e.mult);
} }
@ -123,8 +119,6 @@ public class HtmlRenderer implements Renderer {
@Override @Override
public void glDrawStringLeft(float x, float y, final String textString) { public void glDrawStringLeft(float x, float y, final String textString) {
x += StaticVars.screenPos[0];
y += StaticVars.screenPos[1];
f.imgElCtx.setGlobalCompositeOperation("source-in"); f.imgElCtx.setGlobalCompositeOperation("source-in");
f.imgElCtx.setFillStyle(currentColor); f.imgElCtx.setFillStyle(currentColor);
@ -236,4 +230,54 @@ public class HtmlRenderer implements Renderer {
public HtmlFont getCurrentFont() { public HtmlFont getCurrentFont() {
return f; return f;
} }
@Override
public HtmlRenderer getBoundedInstance(int dx, int dy, int width, int height) {
return new HtmlRenderer(e, g) {
@Override
public void glDrawLine(float x0, float y0, float x1, float y1) {
super.glDrawLine(x0 + dx, y0 + dy, x1, y1);
}
@Override
public void glDrawCharCenter(int x, int y, char ch) {
super.glDrawCharCenter(x + dx, y + dy, ch);
}
@Override
public void glDrawCharLeft(int x, int y, char ch) {
super.glDrawCharLeft(x + dx, y + dy, ch);
}
@Override
public void glDrawCharRight(int x, int y, char ch) {
super.glDrawCharRight(x + dx, y + dy, ch);
}
@Override
public void glFillColor(float x0, float y0, float w1, float h1) {
super.glFillColor(x0 + dx, y0 + dy, w1, h1);
}
@Override
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
super.glFillRect(x + dx, y + dy, width, height, uvX, uvY, uvWidth, uvHeight);
}
@Override
public void glDrawStringCenter(float x, float y, String text) {
super.glDrawStringCenter(x + dx, y + dy, text);
}
@Override
public void glDrawStringLeft(float x, float y, String text) {
super.glDrawStringLeft(x + dx, y + dy, text);
}
@Override
public void glDrawStringRight(float x, float y, String text) {
super.glDrawStringRight(x + dx, y + dy, text);
}
};
}
} }

View File

@ -3,10 +3,20 @@ package it.cavallium.warppi.teavm;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import it.cavallium.warppi.boot.StartupArguments;
import it.cavallium.warppi.device.DeviceStateDevice;
import it.cavallium.warppi.device.display.BacklightOutputDevice;
import it.cavallium.warppi.device.display.NoDisplaysAvailableException;
import it.cavallium.warppi.device.display.NullBacklightOutputDevice;
import it.cavallium.warppi.device.input.KeyboardInputDevice;
import it.cavallium.warppi.device.input.TouchInputDevice;
import it.cavallium.warppi.gui.graphicengine.html.HtmlDeviceState;
import it.cavallium.warppi.gui.graphicengine.html.HtmlDisplayOutputDevice;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
import org.teavm.jso.dom.html.HTMLDocument; import org.teavm.jso.dom.html.HTMLDocument;
@ -22,10 +32,14 @@ public class TeaVMPlatform implements Platform {
private final TeaVMGpio gi; private final TeaVMGpio gi;
private final TeaVMStorageUtils su; private final TeaVMStorageUtils su;
private final String on; private final String on;
private final Map<String, GraphicEngine> el;
private final TeaVMImageUtils pu; private final TeaVMImageUtils pu;
private final TeaVMSettings settings; private final TeaVMSettings settings;
private Boolean runningOnRaspberryOverride = null; private Boolean runningOnRaspberryOverride = null;
private StartupArguments args;
private DisplayOutputDevice displayOutputDevice;
private DeviceStateDevice deviceStateDevice;
private TouchInputDevice touchInputDevice;
private KeyboardInputDevice keyboardInputDevice;
public TeaVMPlatform() { public TeaVMPlatform() {
cu = new TeaVMConsoleUtils(); cu = new TeaVMConsoleUtils();
@ -33,8 +47,6 @@ public class TeaVMPlatform implements Platform {
su = new TeaVMStorageUtils(); su = new TeaVMStorageUtils();
pu = new TeaVMImageUtils(); pu = new TeaVMImageUtils();
on = "JavaScript"; on = "JavaScript";
el = new HashMap<>();
el.put("HTML5 engine", new HtmlEngine());
settings = new TeaVMSettings(); settings = new TeaVMSettings();
} }
@ -123,16 +135,6 @@ public class TeaVMPlatform implements Platform {
return new TeaVMURLClassLoader(urls); return new TeaVMURLClassLoader(urls);
} }
@Override
public Map<String, GraphicEngine> getGraphicEnginesList() {
return el;
}
@Override
public DisplayOutputDevice getGraphicEngine(final String string) throws NullPointerException {
return el.get(string);
}
@Override @Override
public void throwNewExceptionInInitializerError(final String text) { public void throwNewExceptionInInitializerError(final String text) {
throw new NullPointerException(); throw new NullPointerException();
@ -167,4 +169,65 @@ public class TeaVMPlatform implements Platform {
return false; return false;
} }
@Override
public TouchInputDevice getTouchInputDevice() {
return touchInputDevice;
}
@Override
public KeyboardInputDevice getKeyboardInputDevice() {
return keyboardInputDevice;
}
@Override
public DisplayOutputDevice getDisplayOutputDevice() {
return this.displayOutputDevice;
}
@Override
public BacklightOutputDevice getBacklightOutputDevice() {
return new NullBacklightOutputDevice();
}
@Override
public DeviceStateDevice getDeviceStateDevice() {
return this.deviceStateDevice;
}
@Override
public void setArguments(StartupArguments args) {
this.args = args;
this.chooseDevices();
}
private void chooseDevices() {
List<DisplayOutputDevice> availableDevices = new ArrayList<>();
List<DisplayOutputDevice> guiDevices = new ArrayList<>();
guiDevices.add(new HtmlDisplayOutputDevice());
List<DisplayOutputDevice> consoleDevices = new ArrayList<>();
if (args.isMSDOSModeEnabled() || args.isNoGUIEngineForced()) {
availableDevices.addAll(consoleDevices);
}
if (!args.isNoGUIEngineForced()) {
availableDevices.addAll(guiDevices);
}
if (availableDevices.size() == 0) {
throw new NoDisplaysAvailableException();
}
if (this.displayOutputDevice == null) this.displayOutputDevice = availableDevices.get(0);
if (displayOutputDevice instanceof HtmlDisplayOutputDevice) {
//this.touchInputDevice = new HtmlTouchInputDevice((HtmlEngine) displayOutputDevice.getGraphicEngine());
this.keyboardInputDevice = null;
this.deviceStateDevice = new HtmlDeviceState((HtmlEngine) displayOutputDevice.getGraphicEngine());
}
}
} }