This commit is contained in:
Andrea Cavalli 2019-11-02 23:13:19 +01:00
parent 70ff11da7f
commit 26dc8369a7
18 changed files with 264 additions and 159 deletions

View File

@ -210,8 +210,8 @@ public class MarioScreen extends Screen {
for (int ix = 0; ix < width; ix++) { for (int ix = 0; ix < width; ix++) {
for (int iy = 0; iy < height; iy++) { for (int iy = 0; iy < height; iy++) {
final double distX = Math.abs(playerX - ix); final double distX = Math.abs(playerX - ix);
final double distY = Math.abs(playerY - iy - 1.5d); final double distY = Math.abs(playerY - iy - 1.2d);
if (distX * distX + distY * distY / 2d < 25d) { if (distX * distX + distY * distY / 2d < 270d) {
final byte b = w.getBlockIdAt(ix, iy); final byte b = w.getBlockIdAt(ix, iy);
if (b == 0) { if (b == 0) {
if (blue != 1) { if (blue != 1) {

View File

@ -377,6 +377,10 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
BlockContainer.initialized = true; BlockContainer.initialized = true;
} }
public static boolean isInitialized() {
return BlockContainer.initialized;
}
public static BinaryFont getDefaultFont(final boolean small) { public static BinaryFont getDefaultFont(final boolean small) {
BlockContainer.checkInitialized(); BlockContainer.checkInitialized();
return BlockContainer.defFonts[small ? 1 : 0]; return BlockContainer.defFonts[small ? 1 : 0];

View File

@ -50,7 +50,7 @@ public class LoadingScreen extends Screen {
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 MarioScreen()); WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
} }
mustRefresh = true; mustRefresh = true;
} }
@ -58,7 +58,7 @@ public class LoadingScreen extends Screen {
@Override @Override
public void render(RenderContext ctx) { 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(display);
ctx.getRenderer().glColor3i(255, 255, 255); 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 - 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); ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 24, ctx.getHeight() / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);

View File

@ -45,6 +45,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class MathInputScreen extends Screen { public class MathInputScreen extends Screen {
private static final BinaryFont fontBig = Utils.getFont(false); private static final BinaryFont fontBig = Utils.getFont(false);
private final boolean isCloned;
public MathContext calc; public MathContext calc;
public InputContext ic; public InputContext ic;
@ -64,6 +65,7 @@ public class MathInputScreen extends Screen {
public MathInputScreen() { public MathInputScreen() {
super(); super();
historyBehavior = HistoryBehavior.NORMAL; historyBehavior = HistoryBehavior.NORMAL;
isCloned = false;
} }
/** /**
@ -81,6 +83,7 @@ public class MathInputScreen extends Screen {
this.mustRefresh = old.mustRefresh; this.mustRefresh = old.mustRefresh;
this.result = new NormalOutputContainer(old.result); this.result = new NormalOutputContainer(old.result);
this.userInput = new NormalInputContainer(old.userInput, this.ic); this.userInput = new NormalInputContainer(old.userInput, this.ic);
this.isCloned = true;
} }
@Override @Override
@ -100,15 +103,19 @@ public class MathInputScreen extends Screen {
public void graphicInitialized(ScreenContext ctx) throws InterruptedException { public void graphicInitialized(ScreenContext ctx) throws InterruptedException {
/* Fine caricamento */ /* Fine caricamento */
try { try {
if (!BlockContainer.isInitialized()) {
BlockContainer.initializeFonts(ctx.getGraphicEngine().loadFont("norm"), ctx.getGraphicEngine().loadFont("smal")); BlockContainer.initializeFonts(ctx.getGraphicEngine().loadFont("norm"), ctx.getGraphicEngine().loadFont("smal"));
}
} catch (final IOException e) { } catch (final IOException e) {
e.printStackTrace(); e.printStackTrace();
WarpPI.getPlatform().exit(1); WarpPI.getPlatform().exit(1);
} }
if (!isCloned) {
userInput = new NormalInputContainer(ic); userInput = new NormalInputContainer(ic);
result = new NormalOutputContainer(); result = new NormalOutputContainer();
} }
}
@Override @Override
public void beforeRender(final ScreenContext ctx, final float dt) { public void beforeRender(final ScreenContext ctx, final float dt) {

View File

@ -27,7 +27,7 @@ public class Timer {
} }
}); });
WarpPI.getPlatform().setThreadName(thread, "Timer"); WarpPI.getPlatform().setThreadName(thread, "Timer");
thread.setDaemon(true); WarpPI.getPlatform().setThreadDaemon(thread, true);
thread.start(); thread.start();
} }
} }

View File

@ -52,6 +52,25 @@
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>build-desktop-jar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<!-- Maven Assembly Plugin --> <!-- Maven Assembly Plugin -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -81,14 +100,8 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</profile>
</profiles>
</project> </project>

View File

@ -5,6 +5,7 @@ import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import it.cavallium.warppi.WarpPI; import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.StaticVars; import it.cavallium.warppi.StaticVars;
@ -118,9 +119,10 @@ public class SwingEngine implements GraphicEngine {
@Deprecated() @Deprecated()
public void refresh() { public void refresh() {
if (WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen() == null || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error != null && WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error.length() > 0 || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen() == null || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen().mustBeRefreshed()) if (WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen() == null || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error != null && WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error.length() > 0 || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen() == null || WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen().mustBeRefreshed()) {
INSTANCE.c.paintImmediately(0, 0, getWidth(), getHeight()); INSTANCE.c.paintImmediately(0, 0, getWidth(), getHeight());
} }
}
@Override @Override
public void repaint() { public void repaint() {

View File

@ -1,34 +1,20 @@
package it.cavallium.warppi.gui.graphicengine.impl.swing; package it.cavallium.warppi.gui.graphicengine.impl.swing;
import java.awt.*; import it.cavallium.warppi.StaticVars;
import java.awt.event.ComponentEvent; import it.cavallium.warppi.WarpPI;
import java.awt.event.ComponentListener; import it.cavallium.warppi.device.input.Keyboard;
import java.awt.event.KeyEvent; import it.cavallium.warppi.gui.graphicengine.RenderingLoop;
import java.awt.event.KeyListener; import it.cavallium.warppi.util.EventSubmitter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt; import java.awt.image.DataBufferInt;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import it.cavallium.warppi.WarpPI;
import it.cavallium.warppi.device.input.Keyboard;
import it.cavallium.warppi.StaticVars;
import it.cavallium.warppi.event.TouchEndEvent;
import it.cavallium.warppi.event.TouchMoveEvent;
import it.cavallium.warppi.event.TouchPoint;
import it.cavallium.warppi.event.TouchStartEvent;
import it.cavallium.warppi.gui.graphicengine.RenderingLoop;
import it.cavallium.warppi.util.EventSubmitter;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class SwingWindow extends JFrame { public class SwingWindow extends JFrame {
private static final long serialVersionUID = 2945898937634075491L; private static final long serialVersionUID = 2945898937634075491L;
private final int defaultWidth; private final int defaultWidth;
@ -124,7 +110,8 @@ public class SwingWindow extends JFrame {
} }
@Override @Override
public void componentMoved(final ComponentEvent e) {} public void componentMoved(final ComponentEvent e) {
}
@Override @Override
public void componentResized(final ComponentEvent e) { public void componentResized(final ComponentEvent e) {
@ -232,11 +219,13 @@ public class SwingWindow extends JFrame {
Keyboard.keyRaw(row, col, true); Keyboard.keyRaw(row, col, true);
c.grabFocus(); c.grabFocus();
} }
@Override @Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
Keyboard.keyRaw(row, col, false); Keyboard.keyRaw(row, col, false);
c.grabFocus(); c.grabFocus();
} }
@Override @Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
if (b.state == 2) { if (b.state == 2) {
@ -247,6 +236,7 @@ public class SwingWindow extends JFrame {
b.hover = false; b.hover = false;
b.repaint(); b.repaint();
} }
@Override @Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
if (b.state == 2) { if (b.state == 2) {
@ -257,6 +247,7 @@ public class SwingWindow extends JFrame {
b.hover = true; b.hover = true;
b.repaint(); b.repaint();
} }
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -173,7 +173,102 @@ class NEWTWindow implements GLEventListener {
glWindow.addKeyListener(new KeyListener() { glWindow.addKeyListener(new KeyListener() {
@Override @Override
public void keyPressed(final KeyEvent arg0) { public void keyPressed(final KeyEvent arg0) {
Keyboard.debugKeyCode = arg0.getKeyCode(); switch (arg0.getKeyCode()) {
case KeyEvent.VK_ESCAPE:
Keyboard.keyPressed(Key.POWEROFF);
break;
case KeyEvent.VK_D:
Keyboard.keyPressed(Key.debug_DEG);
break;
case KeyEvent.VK_R:
Keyboard.keyPressed(Key.debug_RAD);
break;
case KeyEvent.VK_G:
Keyboard.keyPressed(Key.debug_GRA);
break;
case KeyEvent.VK_X:
if (Keyboard.alpha)
Keyboard.keyPressed(Key.LETTER_X);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_P:
if (Keyboard.alpha)
Keyboard.keyPressed(Key.PI);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_B:
if (Keyboard.shift)
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE_REVERSE);
else if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE);
else
Keyboard.keyPressed(Key.ZOOM_MODE);
break;
case KeyEvent.VK_ENTER:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.SIMPLIFY);
else
Keyboard.keyPressed(Key.NONE);
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row - 1][col - 1] = true;
break;
case KeyEvent.VK_1:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.debug1);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_2:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.debug2);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_3:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.debug3);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_4:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.debug4);
else
Keyboard.keyPressed(Key.NONE);
break;
case KeyEvent.VK_5:
if (!Keyboard.shift && !Keyboard.alpha)
Keyboard.keyPressed(Key.debug5);
else
Keyboard.keyPressed(Key.NONE);
break;
case 0x15:
case KeyEvent.VK_SHIFT:
Keyboard.keyPressed(Key.SHIFT);
break;
case KeyEvent.VK_CONTROL:
Keyboard.keyPressed(Key.ALPHA);
break;
case KeyEvent.VK_M:
Keyboard.keyPressed(Key.SURD_MODE);
break;
case KeyEvent.VK_LEFT:
Keyboard.keyPressed(Key.LEFT);
break;
case KeyEvent.VK_RIGHT:
Keyboard.keyPressed(Key.RIGHT);
break;
case KeyEvent.VK_UP:
Keyboard.keyPressed(Key.UP);
break;
case KeyEvent.VK_DOWN:
case (short) 12:
Keyboard.keyPressed(Key.DOWN);
break;
}
} }
@Override @Override
@ -269,34 +364,17 @@ class NEWTWindow implements GLEventListener {
Keyboard.keyPressed(Key.SURD_MODE); Keyboard.keyPressed(Key.SURD_MODE);
break; break;
case KeyEvent.VK_LEFT: case KeyEvent.VK_LEFT:
//LEFT Keyboard.keyReleased(Key.LEFT);
row = 2;
col = 3;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break; break;
case KeyEvent.VK_RIGHT: case KeyEvent.VK_RIGHT:
//RIGHT Keyboard.keyReleased(Key.RIGHT);
row = 2;
col = 5;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break; break;
case KeyEvent.VK_UP: case KeyEvent.VK_UP:
//UP Keyboard.keyReleased(Key.UP);
row = 1;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break; break;
case KeyEvent.VK_DOWN: case KeyEvent.VK_DOWN:
//Down
row = 3;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case (short) 12: case (short) 12:
//Down Keyboard.keyReleased(Key.DOWN);
row = 2;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break; break;
} }
} }

11
pom.xml
View File

@ -45,8 +45,19 @@
<!-- <module>hardware</module> --> <!-- <module>hardware</module> -->
<module>desktop</module> <module>desktop</module>
<module>engine-jogl</module> <module>engine-jogl</module>
</modules>
<profiles>
<profile>
<id>generate-js</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>teavm</module> <module>teavm</module>
</modules> </modules>
</profile>
</profiles>
<repositories> <repositories>
<repository> <repository>

6
rules/rules.list Normal file
View File

@ -0,0 +1,6 @@
expand.rules
exponent.rules
fractions.rules
number.rules
undefined.rules
variable.rules

View File

@ -22,7 +22,7 @@
<dependency> <dependency>
<groupId>org.teavm</groupId> <groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId> <artifactId>teavm-classlib</artifactId>
<version>0.7.0-dev-916</version> <version>0.7.0-dev-859</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@ -81,7 +81,7 @@
<plugin> <plugin>
<groupId>org.teavm</groupId> <groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId> <artifactId>teavm-maven-plugin</artifactId>
<version>0.7.0-dev-916</version> <version>0.7.0-dev-859</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -91,10 +91,12 @@
<configuration> <configuration>
<mainClass>it.cavallium.warppi.teavm.TeaVMBoot</mainClass> <mainClass>it.cavallium.warppi.teavm.TeaVMBoot</mainClass>
<mainPageIncluded>true</mainPageIncluded> <mainPageIncluded>true</mainPageIncluded>
<debugInformationGenerated>true</debugInformationGenerated> <debugInformationGenerated>false</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated> <sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied> <sourceFilesCopied>true</sourceFilesCopied>
<optimizationLevel>FULL</optimizationLevel> <optimizationLevel>FULL</optimizationLevel>
<minifying>true</minifying>
<runtime>SEPARATE</runtime>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -1,6 +1,7 @@
package it.cavallium.warppi.gui.graphicengine.html; package it.cavallium.warppi.gui.graphicengine.html;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;
import it.cavallium.warppi.util.EventSubmitter; import it.cavallium.warppi.util.EventSubmitter;
import org.teavm.jso.JSBody; import org.teavm.jso.JSBody;
@ -28,7 +29,6 @@ import it.unimi.dsi.fastutil.objects.Object2IntArrayMap;
public class HtmlEngine implements GraphicEngine { public class HtmlEngine implements GraphicEngine {
private boolean initialized; private boolean initialized;
public Semaphore exitSemaphore;
private static final HTMLDocument document = Window.current().getDocument(); private static final HTMLDocument document = Window.current().getDocument();
private HTMLCanvasElement canvas; private HTMLCanvasElement canvas;
private CanvasRenderingContext2D g; private CanvasRenderingContext2D g;
@ -39,6 +39,7 @@ public class HtmlEngine implements GraphicEngine {
private final int frameTime = (int) (1000d / 10d); private final int frameTime = (int) (1000d / 10d);
private final EventSubmitter<Integer[]> onResize = EventSubmitter.create(); private final EventSubmitter<Integer[]> onResize = EventSubmitter.create();
private final EventSubmitter<Float> onZoom = EventSubmitter.create(); private final EventSubmitter<Float> onZoom = EventSubmitter.create();
private AtomicBoolean exitRequested = new AtomicBoolean();
@Override @Override
public int[] getSize() { public int[] getSize() {
@ -85,7 +86,6 @@ public class HtmlEngine implements GraphicEngine {
@Override @Override
public void create(final Runnable onInitialized) { public void create(final Runnable onInitialized) {
exitSemaphore = WarpPI.getPlatform().newSemaphore(0);
width = -1; width = -1;
height = -1; height = -1;
canvas = (HTMLCanvasElement) HtmlEngine.document.createElement("canvas"); canvas = (HTMLCanvasElement) HtmlEngine.document.createElement("canvas");
@ -253,7 +253,7 @@ public class HtmlEngine implements GraphicEngine {
private void destroyEngine() { private void destroyEngine() {
HtmlEngine.document.getBody().removeChild(canvas); HtmlEngine.document.getBody().removeChild(canvas);
initialized = false; initialized = false;
exitSemaphore.release(); exitRequested.set(true);
} }
@Override @Override
@ -313,11 +313,13 @@ public class HtmlEngine implements GraphicEngine {
public void subscribeExit(Runnable subscriber) { public void subscribeExit(Runnable subscriber) {
var thr = new Thread(() -> { var thr = new Thread(() -> {
try { try {
exitSemaphore.acquire(); while(!exitRequested.get()) {
Thread.sleep(1000);
}
} catch (final InterruptedException e) {} } catch (final InterruptedException e) {}
subscriber.run(); subscriber.run();
}); });
thr.setDaemon(true); WarpPI.getPlatform().setThreadDaemon(thr, true);
thr.start(); thr.start();
} }

View File

@ -46,10 +46,14 @@ public class HtmlFont extends RFTFont {
} }
} }
@Override
public boolean isInitialized() {
return super.isInitialized();
}
@Override @Override
public void use(final DisplayOutputDevice d) { public void use(final DisplayOutputDevice d) {
if (d.getGraphicEngine().getRenderer() instanceof HtmlRenderer) ((HtmlEngine) d.getGraphicEngine()).getRenderer().f = this;
((HtmlRenderer) d.getGraphicEngine().getRenderer()).f = this;
} }
} }

View File

@ -230,54 +230,4 @@ 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

@ -2,6 +2,7 @@ package it.cavallium.warppi.gui.graphicengine.html;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
@ -30,11 +31,9 @@ public class HtmlSkin implements Skin {
@Override @Override
public void use(final DisplayOutputDevice d) { public void use(final DisplayOutputDevice d) {
if (d instanceof HtmlEngine) {
if (!initd) if (!initd)
initialize(d); initialize(d);
((HtmlEngine) d).getRenderer().currentSkin = this; ((HtmlEngine) d.getGraphicEngine()).getRenderer().currentSkin = this;
}
} }
@Override @Override
@ -45,13 +44,13 @@ public class HtmlSkin implements Skin {
@Override @Override
public void initialize(final DisplayOutputDevice d) { public void initialize(final DisplayOutputDevice d) {
final HTMLDocument doc = Window.current().getDocument(); final HTMLDocument doc = Window.current().getDocument();
Boolean[] done = new Boolean[]{false}; AtomicBoolean done = new AtomicBoolean(false);
imgEl = doc.createElement("img").cast(); imgEl = doc.createElement("img").cast();
imgEl.addEventListener("load", (Event e) -> { imgEl.addEventListener("load", (Event e) -> {
done[0] = true; done.set(true);
}); });
imgEl.setSrc(url); imgEl.setSrc(url);
while (!done[0]) { while (!done.get()) {
try {Thread.sleep(15);} catch (Exception e) {} try {Thread.sleep(15);} catch (Exception e) {}
} }
skinSize = new int[] { imgEl.getNaturalWidth(), imgEl.getNaturalHeight() }; skinSize = new int[] { imgEl.getNaturalWidth(), imgEl.getNaturalHeight() };

View File

@ -7,6 +7,7 @@ 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 java.util.function.Consumer;
import it.cavallium.warppi.boot.StartupArguments; import it.cavallium.warppi.boot.StartupArguments;
import it.cavallium.warppi.device.DeviceStateDevice; import it.cavallium.warppi.device.DeviceStateDevice;
@ -15,6 +16,7 @@ import it.cavallium.warppi.device.display.NoDisplaysAvailableException;
import it.cavallium.warppi.device.display.NullBacklightOutputDevice; import it.cavallium.warppi.device.display.NullBacklightOutputDevice;
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.event.TouchEvent;
import it.cavallium.warppi.gui.graphicengine.html.HtmlDeviceState; import it.cavallium.warppi.gui.graphicengine.html.HtmlDeviceState;
import it.cavallium.warppi.gui.graphicengine.html.HtmlDisplayOutputDevice; import it.cavallium.warppi.gui.graphicengine.html.HtmlDisplayOutputDevice;
import org.teavm.jso.browser.Window; import org.teavm.jso.browser.Window;
@ -224,7 +226,41 @@ public class TeaVMPlatform implements Platform {
if (displayOutputDevice instanceof HtmlDisplayOutputDevice) { if (displayOutputDevice instanceof HtmlDisplayOutputDevice) {
//this.touchInputDevice = new HtmlTouchInputDevice((HtmlEngine) displayOutputDevice.getGraphicEngine()); //this.touchInputDevice = new HtmlTouchInputDevice((HtmlEngine) displayOutputDevice.getGraphicEngine());
this.keyboardInputDevice = null; //todo: implement
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
this.keyboardInputDevice = new KeyboardInputDevice() {
@Override
public void initialize() {
}
};
this.deviceStateDevice = new HtmlDeviceState((HtmlEngine) displayOutputDevice.getGraphicEngine()); this.deviceStateDevice = new HtmlDeviceState((HtmlEngine) displayOutputDevice.getGraphicEngine());

View File

@ -87,7 +87,7 @@ public class TeaVMStorageUtils implements StorageUtils {
return new FileInputStream(targetFile); return new FileInputStream(targetFile);
else else
TeaVMStorageUtils.resourcesCache.remove(path); TeaVMStorageUtils.resourcesCache.remove(path);
final URL res = new URL(getBasePath() + path); final URL res = new URL(getBasePath() + (path.startsWith("/") ? path : "/" + path));
final InputStream initialStream = res.openStream(); final InputStream initialStream = res.openStream();
final byte[] buffer = new byte[initialStream.available()]; final byte[] buffer = new byte[initialStream.available()];
initialStream.read(buffer); initialStream.read(buffer);