Added bounded render contexts
This commit is contained in:
parent
a9dd7de800
commit
70ff11da7f
@ -1,11 +1,5 @@
|
||||
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.boot.StartupArguments;
|
||||
import it.cavallium.warppi.device.Device;
|
||||
@ -16,49 +10,47 @@ import it.cavallium.warppi.device.input.InputManager;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.device.input.KeyboardInputDevice;
|
||||
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.HUD;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
import it.cavallium.warppi.util.ClassUtils;
|
||||
import it.cavallium.warppi.util.EventSubmitter;
|
||||
import it.cavallium.warppi.util.RunnableWithException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WarpPI {
|
||||
public static final WarpPI INSTANCE = new WarpPI();
|
||||
private static Platform platform;
|
||||
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 WarpPI() {}
|
||||
private WarpPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an instance of the calculator.
|
||||
*
|
||||
* @param platform
|
||||
* Platform implementation
|
||||
* @param screen
|
||||
* Default screen to show at startup
|
||||
* @param hud
|
||||
* Head-up display
|
||||
* @param args
|
||||
* Startup arguments
|
||||
* @param platform Platform implementation
|
||||
* @param screen Default screen to show at startup
|
||||
* @param hud Head-up display
|
||||
* @param args Startup arguments
|
||||
* @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 {
|
||||
public static void start(final Platform platform, final Screen screen, final HUD hud, final StartupArguments args, final RunnableWithException onLoading) throws IOException {
|
||||
if (WarpPI.running) {
|
||||
throw new RuntimeException("Already running!");
|
||||
} else {
|
||||
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,
|
||||
final HUD hud, final StartupArguments args, final RunnableWithException onLoading)
|
||||
throws IOException {
|
||||
private void startInstance(final Platform platform, final Screen screen,
|
||||
final HUD hud, final StartupArguments args, final RunnableWithException onLoading)
|
||||
throws IOException {
|
||||
WarpPI.platform = platform;
|
||||
// Set arguments on platform before everything else
|
||||
platform.setArguments(args);
|
||||
@ -70,23 +62,22 @@ public class WarpPI {
|
||||
currentThread.setPriority(Thread.MAX_PRIORITY);
|
||||
WarpPI.getPlatform().setThreadName(currentThread, "Main thread");
|
||||
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
final DisplayOutputDevice display = platform.getDisplayOutputDevice();
|
||||
final BacklightOutputDevice backlight = platform.getBacklightOutputDevice();
|
||||
final DisplayManager dm = new DisplayManager(display, backlight, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
|
||||
final KeyboardInputDevice keyboard = platform.getKeyboardInputDevice();
|
||||
final TouchInputDevice touchscreen = platform.getTouchInputDevice();
|
||||
final DeviceStateDevice deviceState = platform.getDeviceStateDevice();
|
||||
final InputManager im = new InputManager(keyboard, touchscreen);
|
||||
device = new Device(dm, im, deviceState);
|
||||
device.setup();
|
||||
onLoading.run();
|
||||
this.loadingCompleted();
|
||||
} catch (Exception ex) {
|
||||
this.loadingFailed(ex);
|
||||
}
|
||||
}).thenRun(this::onShutdown);
|
||||
try {
|
||||
final DisplayOutputDevice display = platform.getDisplayOutputDevice();
|
||||
final BacklightOutputDevice backlight = platform.getBacklightOutputDevice();
|
||||
final DisplayManager dm = new DisplayManager(display, backlight, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
|
||||
final KeyboardInputDevice keyboard = platform.getKeyboardInputDevice();
|
||||
final TouchInputDevice touchscreen = platform.getTouchInputDevice();
|
||||
final DeviceStateDevice deviceState = platform.getDeviceStateDevice();
|
||||
final InputManager im = new InputManager(keyboard, touchscreen);
|
||||
device = new Device(dm, im, deviceState);
|
||||
device.setup();
|
||||
onLoading.run();
|
||||
this.loadingCompleted();
|
||||
} catch (Exception ex) {
|
||||
this.loadingFailed(ex);
|
||||
}
|
||||
this.onShutdown();
|
||||
}
|
||||
|
||||
private void onShutdown() {
|
||||
@ -128,7 +119,7 @@ public class WarpPI {
|
||||
Keyboard.stopKeyboard();
|
||||
}
|
||||
|
||||
public Observable<Boolean> isLoaded() {
|
||||
public EventSubmitter<Boolean> isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@ -142,12 +133,8 @@ public class WarpPI {
|
||||
|
||||
|
||||
private void loadingCompleted() {
|
||||
try {
|
||||
WarpPI.INSTANCE.loaded.onNext(true);
|
||||
WarpPI.INSTANCE.device.getDeviceStateDevice().waitForExit().get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new CompletionException(e);
|
||||
}
|
||||
WarpPI.INSTANCE.loaded.submit(true);
|
||||
WarpPI.INSTANCE.device.getDeviceStateDevice().waitForExit();
|
||||
}
|
||||
|
||||
private void loadingFailed(Exception e) {
|
||||
|
@ -12,13 +12,12 @@ import it.cavallium.warppi.math.rules.RulesManager;
|
||||
public class Boot {
|
||||
|
||||
public static void boot(final Platform platform, final String[] args) throws Exception {
|
||||
Future<Void> execution = WarpPI.start(
|
||||
WarpPI.start(
|
||||
platform,
|
||||
new LoadingScreen(),
|
||||
new CalculatorHUD(),
|
||||
Boot.parseStartupArguments(args),
|
||||
Boot::loadCalculator);
|
||||
execution.get();
|
||||
}
|
||||
|
||||
private static void loadCalculator() throws Exception {
|
||||
|
@ -6,7 +6,7 @@ public interface DeviceStateDevice {
|
||||
|
||||
void initialize();
|
||||
|
||||
Future<?> waitForExit();
|
||||
void waitForExit();
|
||||
|
||||
void powerOff();
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ public class Keyboard {
|
||||
break;
|
||||
case ZOOM_MODE:
|
||||
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);
|
||||
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
|
||||
refresh = true;
|
||||
|
@ -10,6 +10,8 @@ import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
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.Skin;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
@ -46,7 +48,7 @@ public class MarioScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() {
|
||||
public void graphicInitialized(ScreenContext ctx) {
|
||||
try {
|
||||
if (MarioScreen.skin == null) {
|
||||
MarioScreen.skin = d.display.getGraphicEngine().loadSkin("/marioskin.png");
|
||||
@ -56,17 +58,17 @@ public class MarioScreen extends Screen {
|
||||
}
|
||||
if (MarioScreen.gpuTest2 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest2");
|
||||
MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest2");
|
||||
} catch (final Exception ex) {}
|
||||
}
|
||||
if (MarioScreen.gpuTest1 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest12");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest12");
|
||||
MarioScreen.gpuTest12 = true;
|
||||
} catch (final Exception ex) {
|
||||
MarioScreen.gpuTest12 = false;
|
||||
try {
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest1");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest1");
|
||||
} catch (final Exception ex2) {}
|
||||
}
|
||||
}
|
||||
@ -167,7 +169,7 @@ public class MarioScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
if (!errored) {
|
||||
final boolean upPressed = false, downPressed = false, runPressed = false;
|
||||
g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed);
|
||||
@ -188,7 +190,7 @@ public class MarioScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
if (errored) {
|
||||
d.renderer.glDrawStringLeft(0, 20, "ERROR");
|
||||
@ -200,8 +202,8 @@ public class MarioScreen extends Screen {
|
||||
final MarioWorld w = g.getCurrentWorld();
|
||||
final int width = w.getWidth();
|
||||
final int height = w.getHeight();
|
||||
final float screenX = d.display.getGraphicEngine().getWidth() / 2f - 8f;
|
||||
final float screenY = d.display.getGraphicEngine().getHeight() / 2f - 8f;
|
||||
final float screenX = ctx.getWidth() / 2f - 8f;
|
||||
final float screenY = ctx.getHeight() / 2f - 8f;
|
||||
final float shiftX = -8 + 16 * (float) playerX;
|
||||
final float shiftY = -8 + 16 * (height - (float) playerY);
|
||||
int blue = -1;
|
||||
@ -241,10 +243,10 @@ public class MarioScreen extends Screen {
|
||||
// GPU PERFORMANCE TEST
|
||||
if (MarioScreen.gpuTest1 != null) {
|
||||
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);
|
||||
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) {
|
||||
MarioScreen.gpuTest3.use(d.display);
|
||||
@ -254,19 +256,19 @@ public class MarioScreen extends Screen {
|
||||
if (MarioScreen.gpuTest2 != null) {
|
||||
MarioScreen.gpuTest2.use(d.display);
|
||||
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.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.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.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.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.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.glDrawStringRight(display.getDisplaySize()[0], d.display.getGraphicEngine().getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G");
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
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.Renderer;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
@ -47,7 +49,7 @@ public class TetrisScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() {
|
||||
public void graphicInitialized(ScreenContext ctx) {
|
||||
try {
|
||||
e = d.display;
|
||||
r = d.renderer;
|
||||
@ -65,23 +67,23 @@ public class TetrisScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
d.renderer.glClearColor(0xff000000);
|
||||
g.update(dt, leftPressed, rightPressed, downPressed, upPressed, okPressed, backPressed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
if (TetrisScreen.skin != null) {
|
||||
TetrisScreen.skin.use(e);
|
||||
}
|
||||
r.glColor3f(1, 1, 1);
|
||||
BlockColor[] renderedGrid = g.getRenderedGrid();
|
||||
int centerScreen = display.getDisplaySize()[0]/2;
|
||||
int centerScreen = ctx.getWidth()/2;
|
||||
int centerGrid = TetrisGame.WIDTH*6/2-1;
|
||||
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 x = 0; x < TetrisGame.WIDTH; x++) {
|
||||
final int offset = x+y*TetrisGame.WIDTH;
|
||||
|
@ -32,7 +32,7 @@ public class CalculatorHUD extends HUD {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@ -48,8 +48,8 @@ public class CalculatorHUD extends HUD {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTopmost() {
|
||||
final Renderer r = d.renderer;
|
||||
public void renderTopmost(RenderContext ctx) {
|
||||
final Renderer r = ctx.getRenderer();
|
||||
final DisplayOutputDevice display = d.display;
|
||||
final GraphicEngine engine = display.getGraphicEngine();
|
||||
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);
|
||||
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 {
|
||||
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();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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 {
|
||||
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;
|
||||
@ -106,13 +106,13 @@ public class CalculatorHUD extends HUD {
|
||||
|
||||
Utils.getFont(true, false).use(display);
|
||||
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.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.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.glDrawStringLeft(1, display.getDisplaySize()[1] - 7, "PROGRESS.");
|
||||
r.glDrawStringLeft(1, ctx.getHeight() - 7, "PROGRESS.");
|
||||
|
||||
int currentDebugLine = 2;
|
||||
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
|
||||
@ -137,28 +137,48 @@ public class CalculatorHUD extends HUD {
|
||||
} else {
|
||||
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()) {
|
||||
r.glColor(0xFF00CC00);
|
||||
} else {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
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
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
// 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
|
||||
public void renderBackground() {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -1,36 +1,22 @@
|
||||
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.WarpPI;
|
||||
import it.cavallium.warppi.device.display.BacklightOutputDevice;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.event.TouchCancelEvent;
|
||||
import it.cavallium.warppi.event.TouchEndEvent;
|
||||
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.event.*;
|
||||
import it.cavallium.warppi.gui.graphicengine.*;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
import it.cavallium.warppi.util.Timer;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
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 {
|
||||
private static final int tickDuration = 50;
|
||||
|
||||
@ -72,7 +58,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
screenChange = WarpPI.getPlatform().newSemaphore();
|
||||
supportsPauses = graphicEngine.doesRefreshPauses();
|
||||
|
||||
glyphsHeight = new int[] { 9, 6, 12, 9 };
|
||||
glyphsHeight = new int[]{9, 6, 12, 9};
|
||||
displayDebugString = "";
|
||||
errorMessages = new ObjectArrayList<>();
|
||||
}
|
||||
@ -153,10 +139,10 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
if (mustBeAddedToHistory) {
|
||||
if (screen.historyBehavior == HistoryBehavior.NORMAL
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
if (currentSession > 0) {
|
||||
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<>();
|
||||
int i = 0;
|
||||
for (Screen s : sessions) {
|
||||
@ -217,7 +203,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
public void replaceScreen(final Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.historyBehavior == HistoryBehavior.NORMAL
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
sessions[currentSession] = screen;
|
||||
} else {
|
||||
currentSession = -1;
|
||||
@ -339,8 +325,10 @@ public final class DisplayManager implements RenderingLoop {
|
||||
if (!screen.graphicInitialized) {
|
||||
try {
|
||||
var displaySize = display.getDisplaySize();
|
||||
var fullCtx = new RenderContext(graphicEngine, renderer, displaySize[0], displaySize[1]);
|
||||
screen.initializeGraphic(fullCtx);
|
||||
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
|
||||
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
|
||||
var scrCtx = new ScreenContext(graphicEngine, scrWidth, scrHeight);
|
||||
screen.initializeGraphic(scrCtx);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -353,7 +341,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
|
||||
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
|
||||
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);
|
||||
|
||||
@ -364,8 +352,8 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
renderer.glColor3i(129, 28, 22);
|
||||
renderer.glDrawStringRight(display.getDisplaySize()[0] - 2,
|
||||
display.getDisplaySize()[1] - (fnt.getCharacterHeight() + 2),
|
||||
WarpPI.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR");
|
||||
display.getDisplaySize()[1] - (fnt.getCharacterHeight() + 2),
|
||||
WarpPI.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR");
|
||||
renderer.glColor3i(149, 32, 26);
|
||||
renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, 22, error);
|
||||
renderer.glColor3i(164, 34, 28);
|
||||
@ -387,12 +375,12 @@ public final class DisplayManager implements RenderingLoop {
|
||||
hud.renderBackground();
|
||||
screen.render(scrCtx);
|
||||
if (hud.visible) {
|
||||
hud.render(fullCtdx);
|
||||
hud.render(fullCtx);
|
||||
hud.renderTopmostBackground();
|
||||
}
|
||||
screen.renderTopmost(scrCtx);
|
||||
screen.renderTopmost(fullCtx);
|
||||
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);
|
||||
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) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
@ -449,11 +437,15 @@ public final class DisplayManager implements RenderingLoop {
|
||||
precTime = newtime;
|
||||
|
||||
if (windowSize != null) {
|
||||
StaticVars.screenSize[0] = windowSize[0];
|
||||
StaticVars.screenSize[1] = windowSize[1];
|
||||
display.getDisplaySize()[0] = windowSize[0];
|
||||
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) {
|
||||
|
@ -1,13 +1,12 @@
|
||||
package it.cavallium.warppi.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DisplayRefreshManager {
|
||||
private final Consumer<Integer[]> refreshConsumer;
|
||||
private AtomicBoolean ticked = new AtomicBoolean(false);
|
||||
private AtomicBoolean sizeSet = new AtomicBoolean(false);
|
||||
private volatile Integer[] size;
|
||||
|
||||
public DisplayRefreshManager(Consumer<Integer[]> refreshConsumer) {
|
||||
@ -15,18 +14,13 @@ public class DisplayRefreshManager {
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
ticked.set(true);
|
||||
refreshIfNeeded();
|
||||
refreshConsumer.accept(size);
|
||||
}
|
||||
|
||||
public void onResize(Integer[] newSize) {
|
||||
size = newSize;
|
||||
sizeSet.set(true);
|
||||
refreshIfNeeded();
|
||||
}
|
||||
|
||||
private void refreshIfNeeded() {
|
||||
if (ticked.get() && sizeSet.get()) {
|
||||
var oldSize = size;
|
||||
if (oldSize == null || !Arrays.equals(oldSize, newSize)) {
|
||||
size = newSize;
|
||||
refreshConsumer.accept(size);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package it.cavallium.warppi.gui.graphicengine;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.impl.common.ReboundedRenderer;
|
||||
|
||||
public interface Renderer {
|
||||
void glColor3i(int r, int gg, int b);
|
||||
|
||||
@ -43,5 +45,7 @@ public interface Renderer {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -140,6 +140,11 @@ public class NoGuiEngine implements GraphicEngine {
|
||||
public BinaryFont getCurrentFont() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderer getBoundedInstance(int dx, int dy, int width, int height) {
|
||||
return getRenderer();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
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.functions.Variable.VariableValue;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
@ -29,30 +31,29 @@ public class ChooseVariableValueScreen extends Screen {
|
||||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
DisplayOutputDevice display = d.display;
|
||||
public void render(RenderContext ctx) {
|
||||
Utils.getFont(false, true).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2 + 1, display.getDisplaySize()[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 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.");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, display.getDisplaySize()[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glColor4i(0, 0, 0, 64);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
|
||||
|
||||
Utils.getFont(false, false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.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.");
|
||||
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.");
|
||||
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.");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.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().glColor4i(0, 0, 0, 64);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2, "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.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class EmptyScreen extends Screen {
|
||||
|
||||
@ -20,16 +22,16 @@ public class EmptyScreen extends Screen {
|
||||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
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;
|
||||
|
||||
public class KeyboardDebugScreen extends Screen {
|
||||
@ -28,14 +30,14 @@ public class KeyboardDebugScreen extends Screen {
|
||||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
final Renderer renderer = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
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") {
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
@ -176,7 +178,7 @@ public class KeyboardDebugScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
if (System.currentTimeMillis() - beforetime >= 1000) {
|
||||
keyevent = "NONE";
|
||||
KeyboardDebugScreen.keyX = 0;
|
||||
|
@ -3,8 +3,11 @@ package it.cavallium.warppi.gui.screens;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.extra.mario.MarioScreen;
|
||||
import it.cavallium.warppi.gui.GraphicUtils;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class LoadingScreen extends Screen {
|
||||
|
||||
@ -36,32 +39,32 @@ public class LoadingScreen extends Screen {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
|
||||
|
||||
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;
|
||||
StaticVars.windowZoom.submit(previousZoomValue);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MarioScreen());
|
||||
}
|
||||
mustRefresh = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.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);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(display.getDisplaySize()[0] / 2f - 24, display.getDisplaySize()[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
|
||||
ctx.getRenderer().glColor3i(255, 255, 255);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 80, ctx.getHeight() / 2f - 64, 160, 48, 0, 32, 160, 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);
|
||||
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() - 224, ctx.getHeight() - 48, 224, 48, 0, 80, 224, 48);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() - 160 - 24 - 224, ctx.getHeight() - 48, 160, 48, 224, 80, 160, 48);
|
||||
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,6 @@ public class MathInputScreen extends Screen {
|
||||
ic = new InputContext();
|
||||
calc = new MathContext();
|
||||
|
||||
userInput = new NormalInputContainer(ic);
|
||||
result = new NormalOutputContainer();
|
||||
|
||||
calc.init();
|
||||
}
|
||||
|
||||
@ -108,6 +105,9 @@ public class MathInputScreen extends Screen {
|
||||
e.printStackTrace();
|
||||
WarpPI.getPlatform().exit(1);
|
||||
}
|
||||
|
||||
userInput = new NormalInputContainer(ic);
|
||||
result = new NormalOutputContainer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -117,9 +117,10 @@ public class MathInputScreen extends Screen {
|
||||
} else {
|
||||
ctx.getGraphicEngine().getRenderer().glClearColor(0xFFDC3C32);
|
||||
}
|
||||
if (userInput.beforeRender(dt)) {
|
||||
mustRefresh = true;
|
||||
}
|
||||
if (userInput != null)
|
||||
if (userInput.beforeRender(dt)) {
|
||||
mustRefresh = true;
|
||||
}
|
||||
if (computingResult) {
|
||||
computingElapsedTime += dt;
|
||||
computingAnimationElapsedTime += dt;
|
||||
@ -147,7 +148,7 @@ public class MathInputScreen extends Screen {
|
||||
final int padding = 4;
|
||||
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) {
|
||||
renderer.glColor3f(1, 1, 1);
|
||||
@ -156,14 +157,14 @@ public class MathInputScreen extends Screen {
|
||||
final int size = 32;
|
||||
final int posY = computingAnimationIndex % 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) {
|
||||
Utils.getFont(false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
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()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class SolveForXScreen extends Screen {
|
||||
|
||||
@ -25,21 +27,21 @@ public class SolveForXScreen extends Screen {
|
||||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.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.");
|
||||
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.");
|
||||
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.");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer.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().glColor4i(0, 0, 0, 64);
|
||||
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.");
|
||||
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.");
|
||||
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.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
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
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package it.cavallium.warppi.math.rules;
|
||||
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform;
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
@ -45,7 +44,7 @@ public class RulesManager {
|
||||
System.err.println();
|
||||
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 {
|
||||
final Platform platform = Engine.getPlatform();
|
||||
final Platform platform = WarpPI.getPlatform();
|
||||
|
||||
final DslFilesException fileErrors = new DslFilesException();
|
||||
for (final String path : platform.getRuleFilePaths()) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package it.cavallium.warppi.util;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@ -8,6 +8,8 @@ public class Timer {
|
||||
public Timer(int intervalMillis, Runnable action) {
|
||||
var thread = new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(intervalMillis);
|
||||
|
||||
AtomicLong lostTime = new AtomicLong();
|
||||
while (!Thread.interrupted()) {
|
||||
var time1 = System.currentTimeMillis();
|
||||
@ -24,7 +26,7 @@ public class Timer {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
Engine.getPlatform().setThreadName(thread, "Timer");
|
||||
WarpPI.getPlatform().setThreadName(thread, "Timer");
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
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.JOGLEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.impl.swing.SwingDeviceState;
|
||||
@ -249,6 +251,7 @@ public class DesktopPlatform implements Platform {
|
||||
if (device instanceof SwingDisplayOutputDevice) {
|
||||
if (args.isCPUEngineForced()) {
|
||||
this.displayOutputDevice = device;
|
||||
break;
|
||||
}
|
||||
} else if (device instanceof JOGLDisplayOutputDevice) {
|
||||
if (args.isGPUEngineForced()) {
|
||||
@ -275,9 +278,62 @@ public class DesktopPlatform implements Platform {
|
||||
this.deviceStateDevice = new SwingDeviceState((SwingEngine) displayOutputDevice.getGraphicEngine());
|
||||
|
||||
} else if (displayOutputDevice instanceof JOGLDisplayOutputDevice) {
|
||||
this.touchInputDevice = null;
|
||||
this.keyboardInputDevice = null;
|
||||
this.deviceStateDevice = null; //TODO: Implement
|
||||
//TODO: implement a touch input device
|
||||
this.touchInputDevice = new TouchInputDevice() {
|
||||
@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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,26 +4,32 @@ import it.cavallium.warppi.device.DeviceStateDevice;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class SwingDeviceState implements DeviceStateDevice {
|
||||
private final SwingEngine graphicEngine;
|
||||
private final CompletableFuture<Void> exitWait;
|
||||
private final AtomicBoolean exitWait = new AtomicBoolean(false);
|
||||
|
||||
public SwingDeviceState(SwingEngine graphicEngine) {
|
||||
this.graphicEngine = graphicEngine;
|
||||
this.exitWait = new CompletableFuture<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
graphicEngine.subscribeExit(() -> {
|
||||
exitWait.complete(null);
|
||||
exitWait.set(true);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<?> waitForExit() {
|
||||
return exitWait;
|
||||
public void waitForExit() {
|
||||
try {
|
||||
while (!exitWait.get()) {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,7 +6,7 @@ public class JOGLDisplayOutputDevice implements DisplayOutputDevice {
|
||||
private JOGLEngine engine;
|
||||
|
||||
public JOGLDisplayOutputDevice() {
|
||||
this.engine = new JOGLEngine();
|
||||
this.engine = new JOGLEngine(480, 320);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,7 +34,8 @@ public class JOGLEngine implements GraphicEngine {
|
||||
protected LinkedList<Texture> registeredTextures;
|
||||
protected LinkedList<Texture> unregisteredTextures;
|
||||
|
||||
public JOGLEngine() {
|
||||
public JOGLEngine(int defaultWidth, int defaultHeight) {
|
||||
this.size = new int[]{defaultWidth, defaultHeight};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +43,7 @@ public class JOGLSkin implements Skin {
|
||||
t = JOGLRenderer.importTexture(i.f, i.deleteOnExit);
|
||||
w = i.w;
|
||||
h = i.h;
|
||||
((JOGLEngine) d).registerTexture(t);
|
||||
((JOGLEngine) d.getGraphicEngine()).registerTexture(t);
|
||||
initialized = true;
|
||||
} catch (GLException | IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -81,17 +81,17 @@ class NEWTWindow implements GLEventListener {
|
||||
engine.size[1] = engine.getSize()[1];
|
||||
realWindowSize = new int[] { engine.getSize()[0], engine.getSize()[1] };
|
||||
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) -> {
|
||||
realWindowSize[0] = realSize[0];
|
||||
realWindowSize[1] = realSize[1];
|
||||
engine.size[0] = realSize[0] / (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;
|
||||
});
|
||||
StaticVars.windowZoom$.subscribe(onZoom::onNext);
|
||||
StaticVars.windowZoom$.subscribe(onZoom::submit);
|
||||
onZoom.subscribe((z) -> {
|
||||
if (windowZoom != 0) {
|
||||
windowZoom = z;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -108,8 +108,7 @@ public class HtmlEngine implements GraphicEngine {
|
||||
width = 480 / windowZoom.intValue();
|
||||
height = 320 / windowZoom.intValue();
|
||||
this.mult = windowZoom.intValue();
|
||||
StaticVars.screenSize[0] = width;
|
||||
StaticVars.screenSize[1] = height;
|
||||
onResize.submit(new Integer[] {width, height});
|
||||
}
|
||||
});
|
||||
keyInput.setType("text");
|
||||
@ -248,6 +247,10 @@ public class HtmlEngine implements GraphicEngine {
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
sendPowerOffSignal();
|
||||
}
|
||||
|
||||
private void destroyEngine() {
|
||||
HtmlEngine.document.getBody().removeChild(canvas);
|
||||
initialized = false;
|
||||
exitSemaphore.release();
|
||||
@ -283,7 +286,7 @@ public class HtmlEngine implements GraphicEngine {
|
||||
|
||||
@Override
|
||||
public void repaint() {
|
||||
renderingLoop.refresh();
|
||||
renderingLoop.refresh(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -306,11 +309,16 @@ public class HtmlEngine implements GraphicEngine {
|
||||
return new HtmlSkin(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
|
||||
public void subscribeExit(Runnable subscriber) {
|
||||
var thr = new Thread(() -> {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
subscriber.run();
|
||||
});
|
||||
thr.setDaemon(true);
|
||||
thr.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -328,4 +336,7 @@ public class HtmlEngine implements GraphicEngine {
|
||||
return onResize;
|
||||
}
|
||||
|
||||
public void sendPowerOffSignal() {
|
||||
destroyEngine();
|
||||
}
|
||||
}
|
@ -58,8 +58,6 @@ public class HtmlRenderer implements Renderer {
|
||||
final boolean transparent) {
|
||||
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 incrementY = Math.abs((double) (y1 - y0) / (double) (t1 - t0));
|
||||
final boolean flippedX = (x1 - x0) / (s1 - s0) < 0;
|
||||
@ -110,8 +108,6 @@ public class HtmlRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
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.fillRect(x * e.mult, y * e.mult, width * e.mult, height * e.mult);
|
||||
}
|
||||
@ -123,8 +119,6 @@ public class HtmlRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
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.setFillStyle(currentColor);
|
||||
@ -236,4 +230,54 @@ public class HtmlRenderer implements Renderer {
|
||||
public HtmlFont getCurrentFont() {
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -3,10 +3,20 @@ package it.cavallium.warppi.teavm;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.dom.html.HTMLDocument;
|
||||
|
||||
@ -22,10 +32,14 @@ public class TeaVMPlatform implements Platform {
|
||||
private final TeaVMGpio gi;
|
||||
private final TeaVMStorageUtils su;
|
||||
private final String on;
|
||||
private final Map<String, GraphicEngine> el;
|
||||
private final TeaVMImageUtils pu;
|
||||
private final TeaVMSettings settings;
|
||||
private Boolean runningOnRaspberryOverride = null;
|
||||
private StartupArguments args;
|
||||
private DisplayOutputDevice displayOutputDevice;
|
||||
private DeviceStateDevice deviceStateDevice;
|
||||
private TouchInputDevice touchInputDevice;
|
||||
private KeyboardInputDevice keyboardInputDevice;
|
||||
|
||||
public TeaVMPlatform() {
|
||||
cu = new TeaVMConsoleUtils();
|
||||
@ -33,8 +47,6 @@ public class TeaVMPlatform implements Platform {
|
||||
su = new TeaVMStorageUtils();
|
||||
pu = new TeaVMImageUtils();
|
||||
on = "JavaScript";
|
||||
el = new HashMap<>();
|
||||
el.put("HTML5 engine", new HtmlEngine());
|
||||
settings = new TeaVMSettings();
|
||||
}
|
||||
|
||||
@ -123,16 +135,6 @@ public class TeaVMPlatform implements Platform {
|
||||
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
|
||||
public void throwNewExceptionInInitializerError(final String text) {
|
||||
throw new NullPointerException();
|
||||
@ -167,4 +169,65 @@ public class TeaVMPlatform implements Platform {
|
||||
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());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user