Merge branch 'master' of https://github.com/Cavallium/WarpPI
This commit is contained in:
commit
6cea02af81
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,6 +5,7 @@
|
||||
|
||||
# Package Files #
|
||||
!/target/*.jar
|
||||
!/libs/*.jar
|
||||
*.war
|
||||
*.jar
|
||||
*.ear
|
||||
@ -20,6 +21,7 @@ VBO_Example.java
|
||||
|
||||
/target/
|
||||
!/target/*.jar
|
||||
!libs/**/*.jar
|
||||
/backups/
|
||||
/Resources_and_Videos/
|
||||
|
||||
|
13
.idea/compiler.xml
Normal file
13
.idea/compiler.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<annotationProcessing>
|
||||
<profile name="Maven default annotation processors profile" enabled="true">
|
||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="warppi-calculator" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
6
.idea/encodings.xml
Normal file
6
.idea/encodings.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
14
.idea/misc.xml
Normal file
14
.idea/misc.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
<option name="originalFiles">
|
||||
<list>
|
||||
<option value="$PROJECT_DIR$/pom.xml" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
98
pom.xml
98
pom.xml
@ -14,6 +14,7 @@
|
||||
<src.dir>src/main/java</src.dir>
|
||||
<src.dir2>src/main/java</src.dir2>
|
||||
<src.resdir>src/main/resources</src.resdir>
|
||||
<buildprops.exclude1>veryverylongandparticularpath/abcd</buildprops.exclude1>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
@ -45,16 +46,29 @@
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>jarprofile</id>
|
||||
<properties>
|
||||
<src.dir>jar-specific</src.dir>
|
||||
<src.resdir>src/main/rules</src.resdir>
|
||||
</properties>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<profile>
|
||||
<id>aarch64</id>
|
||||
<activation>
|
||||
<!--<os>
|
||||
<family>Linux</family>
|
||||
<arch>aarch64</arch>
|
||||
</os>-->
|
||||
<activeByDefault>false</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<buildprops.exclude1>org/warp/picalculator/gui/graphicengine/gpu/*</buildprops.exclude1>
|
||||
</properties>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jarprofile</id>
|
||||
<properties>
|
||||
<src.dir>jar-specific</src.dir>
|
||||
<src.resdir>src/main/rules</src.resdir>
|
||||
</properties>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jogamp.jogl</groupId>
|
||||
<artifactId>jogl-all-main</artifactId>
|
||||
@ -65,27 +79,27 @@
|
||||
<artifactId>gluegen-rt-main</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-core</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.lingala.zip4j</groupId>
|
||||
<artifactId>zip4j</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jdt.core.compiler</groupId>
|
||||
<artifactId>ecj</artifactId>
|
||||
<version>4.6.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>com.pi4j</groupId>
|
||||
<artifactId>pi4j-core</artifactId>
|
||||
<version>1.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.lingala.zip4j</groupId>
|
||||
<artifactId>zip4j</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jdt.core.compiler</groupId>
|
||||
<artifactId>ecj</artifactId>
|
||||
<version>4.6.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- Set a compiler level -->
|
||||
@ -94,22 +108,22 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>org/warp/picalculator/gui/graphicengine/html/*</exclude>
|
||||
</excludes>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<excludes>
|
||||
<exclude>${buildprops.exclude1}</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>jsprofile</id>
|
||||
<properties>
|
||||
<src.dir>js-specific</src.dir>
|
||||
<src.dir2>src/main/rules</src.dir2>
|
||||
<src.dir2>src/main/rules</src.dir2>
|
||||
</properties>
|
||||
<activation>
|
||||
<activeByDefault>false</activeByDefault>
|
||||
@ -186,7 +200,7 @@
|
||||
|
||||
|
||||
<dependencies>
|
||||
<!--<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
|
||||
<!--<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
|
||||
<version>4.12</version> <scope>test</scope> </dependency> -->
|
||||
<dependency>
|
||||
<groupId>it.unimi.dsi</groupId>
|
||||
@ -300,10 +314,10 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration>
|
||||
<failOnError>false</failOnError> <source>1.8</source> <target>1.8</target>
|
||||
<archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.warp.picalculator.Main</mainClass> </manifest> </archive>
|
||||
<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration>
|
||||
<failOnError>false</failOnError> <source>1.8</source> <target>1.8</target>
|
||||
<archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>libs/</classpathPrefix>
|
||||
<mainClass>org.warp.picalculator.Main</mainClass> </manifest> </archive>
|
||||
</configuration> </plugin> </plugins> </build> -->
|
||||
</project>
|
||||
|
@ -1,13 +1,18 @@
|
||||
package org.warp.picalculator.deps;
|
||||
|
||||
import org.warp.picalculator.ClassUtils;
|
||||
import org.warp.picalculator.StaticVars;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.framebuffer.FBEngine;
|
||||
|
||||
public class DEngine {
|
||||
public static GraphicEngine newGPUEngine() {
|
||||
return new org.warp.picalculator.gui.graphicengine.gpu.GPUEngine();
|
||||
try {
|
||||
return (GraphicEngine) ClassUtils.newClassInstance("org.warp.picalculator.gui.graphicengine.gpu.GPUEngine");
|
||||
} catch (NullPointerException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static GraphicEngine newHeadless24bitEngine() {
|
||||
return new org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitEngine();
|
||||
|
@ -25,11 +25,10 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.warp.picalculator.ClassUtils;
|
||||
import org.warp.picalculator.Main;
|
||||
|
||||
import com.jogamp.common.util.IOUtil;
|
||||
|
||||
public class StorageUtils {
|
||||
public static final boolean exists(Path f) {
|
||||
return Files.exists(f);
|
||||
@ -77,7 +76,7 @@ public class StorageUtils {
|
||||
tempFile.deleteOnExit();
|
||||
try (FileOutputStream out = new FileOutputStream(tempFile))
|
||||
{
|
||||
IOUtil.copyStream2Stream(is, out, (int) tempFile.length());
|
||||
IOUtils.copy(is, out, (int) tempFile.length());
|
||||
}
|
||||
resourcesCache.put(string, tempFile);
|
||||
|
||||
|
@ -1,296 +1,296 @@
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.canvas.CanvasGradient;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.dom.events.EventTarget;
|
||||
import org.teavm.jso.dom.events.KeyboardEvent;
|
||||
import org.teavm.jso.dom.html.HTMLButtonElement;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLElement;
|
||||
import org.teavm.jso.dom.html.HTMLInputElement;
|
||||
import org.teavm.jso.dom.xml.NodeList;
|
||||
import org.teavm.jso.json.JSON;
|
||||
import org.warp.picalculator.PlatformUtils;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.deps.DSemaphore;
|
||||
import org.warp.picalculator.deps.StorageUtils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUSkin;
|
||||
|
||||
public class HtmlEngine implements GraphicEngine {
|
||||
|
||||
private boolean initialized;
|
||||
public DSemaphore exitSemaphore = new DSemaphore(0);
|
||||
private static final HTMLDocument document = Window.current().getDocument();
|
||||
private HTMLCanvasElement canvas;
|
||||
private CanvasRenderingContext2D g;
|
||||
private RenderingLoop renderingLoop;
|
||||
private HtmlRenderer renderer;
|
||||
private int width = -1, height = -1;
|
||||
private final int frameTime = (int) (1000d/10d);
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
return new int[] { getWidth(), getHeight() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
HtmlEngine.setHTMLTitle(title);
|
||||
}
|
||||
|
||||
@JSBody(params = {"wndTitle"}, script = "document.title = wndTitle")
|
||||
private static native void setHTMLTitle(String wndTitle);
|
||||
|
||||
@Override
|
||||
public void setResizable(boolean r) {}
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
canvas.setWidth(ww);
|
||||
width = ww;
|
||||
canvas.setHeight(wh);
|
||||
height = wh;
|
||||
}
|
||||
|
||||
private String previousValue="";
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
canvas = (HTMLCanvasElement) document.createElement("canvas");
|
||||
g = (CanvasRenderingContext2D ) canvas.getContext("2d");
|
||||
HTMLInputElement keyInput = (HTMLInputElement) document.createElement("input");
|
||||
keyInput.setType("text");
|
||||
keyInput.getStyle().setProperty("opacity", "0.1");
|
||||
setDisplayMode(480, 320);
|
||||
document.getElementById("container").appendChild(canvas);
|
||||
document.getBody().appendChild(keyInput);
|
||||
keyInput.setTabIndex(0);
|
||||
keyInput.addEventListener("keydown", (KeyboardEvent evt) -> {
|
||||
evt.preventDefault();
|
||||
new Thread(() -> {
|
||||
previousValue = keyInput.getValue();
|
||||
Keyboard.debugKeyPressed(evt.getKeyCode());
|
||||
System.out.println(evt.getKeyCode());
|
||||
System.out.println(""+(int) evt.getKey().charAt(0));
|
||||
}).start();
|
||||
});
|
||||
keyInput.addEventListener("input", (Event evt) -> {
|
||||
evt.preventDefault();
|
||||
final String previousValue = this.previousValue;
|
||||
final String newValue = keyInput.getValue();
|
||||
final int prevLen = previousValue.length();
|
||||
final int newLen = newValue.length();
|
||||
|
||||
new Thread(() -> {
|
||||
if (newLen == prevLen) {
|
||||
|
||||
} else if (newLen - prevLen == 1) {
|
||||
Keyboard.debugKeyPressed((int) newValue.toUpperCase().charAt(newLen-1));
|
||||
} else if (newLen - prevLen > 1) {
|
||||
for (int i = 0; i < newLen - prevLen; i++) {
|
||||
Keyboard.debugKeyPressed((int) newValue.toUpperCase().charAt(prevLen + i));
|
||||
}
|
||||
} else if (newLen - prevLen < 1) {
|
||||
for (int i = 0; i < prevLen - newLen; i++) {
|
||||
Keyboard.debugKeyPressed(8);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
canvas.addEventListener("click", (Event evt) -> {
|
||||
keyInput.focus();
|
||||
});
|
||||
document.addEventListener("DOMContentLoaded", (Event e) -> {
|
||||
keyInput.focus();
|
||||
});
|
||||
NodeList<? extends HTMLElement> buttons = document.getBody().getElementsByTagName("button");
|
||||
for (int i = 0; i < buttons.getLength(); i++) {
|
||||
if (buttons.item(i).hasAttribute("keycode")) {
|
||||
buttons.item(i).addEventListener("click", (Event evt) -> {
|
||||
evt.preventDefault();
|
||||
EventTarget target = evt.getCurrentTarget();
|
||||
HTMLButtonElement button = target.cast();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
if (button.hasAttribute("keycode") && button.getAttribute("keycode").contains(",")) {
|
||||
String code = button.getAttribute("keycode");
|
||||
String[] coordinates = code.split(",", 2);
|
||||
boolean removeshift = Keyboard.shift && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 0;
|
||||
boolean removealpha = Keyboard.alpha && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 1;
|
||||
Keyboard.keyPressedRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]));
|
||||
if (removeshift) {
|
||||
Keyboard.keyPressedRaw(0,0);
|
||||
}
|
||||
if (removealpha) {
|
||||
Keyboard.keyPressedRaw(0,1);
|
||||
}
|
||||
Thread.sleep(100);
|
||||
Keyboard.keyReleasedRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]));
|
||||
if (removeshift) {
|
||||
Keyboard.keyReleasedRaw(0,0);
|
||||
}
|
||||
if (removealpha) {
|
||||
Keyboard.keyReleasedRaw(0,1);
|
||||
}
|
||||
} else {
|
||||
if (Keyboard.alpha && !Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodea")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodea")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
} else if (!Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodes")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
} else if (Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodesa")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodesa")));
|
||||
} else {
|
||||
if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodes")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
}
|
||||
renderer = new HtmlRenderer(this, g);
|
||||
initialized = true;
|
||||
if (onInitialized != null) {
|
||||
onInitialized.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasResized() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
if (width == -1) {
|
||||
width = canvas.getWidth();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
if (height == -1) {
|
||||
height = canvas.getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
document.getBody().removeChild(canvas);
|
||||
initialized = false;
|
||||
exitSemaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(RenderingLoop d) {
|
||||
renderingLoop = d;
|
||||
final Thread th = new Thread(() -> {
|
||||
try {
|
||||
double extratime = 0;
|
||||
while (initialized) {
|
||||
final long start = System.currentTimeMillis();
|
||||
repaint();
|
||||
final long end = System.currentTimeMillis();
|
||||
final double delta = (end - start) / 1000d;
|
||||
final int deltaInt = (int) Math.floor(delta);
|
||||
final int extraTimeInt = (int) Math.floor(extratime);
|
||||
if (extraTimeInt + deltaInt < frameTime) {
|
||||
Thread.sleep(frameTime - (extraTimeInt + deltaInt));
|
||||
extratime = 0;
|
||||
} else {
|
||||
extratime += delta - frameTime;
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
PlatformUtils.setThreadName(th, "Canvas rendering thread");
|
||||
PlatformUtils.setDaemon(th);
|
||||
th.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repaint() {
|
||||
renderingLoop.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont loadFont(String fontName) throws IOException {
|
||||
return new HtmlFont(fontName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont loadFont(String path, String fontName) throws IOException {
|
||||
return new HtmlFont(fontName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlSkin loadSkin(String file) throws IOException {
|
||||
return new HtmlSkin(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return PlatformUtils.isJavascript;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesRefreshPauses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.teavm.jso.JSBody;
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.canvas.CanvasGradient;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
import org.teavm.jso.dom.events.EventListener;
|
||||
import org.teavm.jso.dom.events.EventTarget;
|
||||
import org.teavm.jso.dom.events.KeyboardEvent;
|
||||
import org.teavm.jso.dom.html.HTMLButtonElement;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLElement;
|
||||
import org.teavm.jso.dom.html.HTMLInputElement;
|
||||
import org.teavm.jso.dom.xml.NodeList;
|
||||
import org.teavm.jso.json.JSON;
|
||||
import org.warp.picalculator.PlatformUtils;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.deps.DSemaphore;
|
||||
import org.warp.picalculator.deps.StorageUtils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUSkin;
|
||||
|
||||
public class HtmlEngine implements GraphicEngine {
|
||||
|
||||
private boolean initialized;
|
||||
public DSemaphore exitSemaphore = new DSemaphore(0);
|
||||
private static final HTMLDocument document = Window.current().getDocument();
|
||||
private HTMLCanvasElement canvas;
|
||||
private CanvasRenderingContext2D g;
|
||||
private RenderingLoop renderingLoop;
|
||||
private HtmlRenderer renderer;
|
||||
private int width = -1, height = -1;
|
||||
private final int frameTime = (int) (1000d/10d);
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
return new int[] { getWidth(), getHeight() };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
HtmlEngine.setHTMLTitle(title);
|
||||
}
|
||||
|
||||
@JSBody(params = {"wndTitle"}, script = "document.title = wndTitle")
|
||||
private static native void setHTMLTitle(String wndTitle);
|
||||
|
||||
@Override
|
||||
public void setResizable(boolean r) {}
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
canvas.setWidth(ww);
|
||||
width = ww;
|
||||
canvas.setHeight(wh);
|
||||
height = wh;
|
||||
}
|
||||
|
||||
private String previousValue="";
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
canvas = (HTMLCanvasElement) document.createElement("canvas");
|
||||
g = (CanvasRenderingContext2D ) canvas.getContext("2d");
|
||||
HTMLInputElement keyInput = (HTMLInputElement) document.createElement("input");
|
||||
keyInput.setType("text");
|
||||
keyInput.getStyle().setProperty("opacity", "0.1");
|
||||
setDisplayMode(480, 320);
|
||||
document.getElementById("container").appendChild(canvas);
|
||||
document.getBody().appendChild(keyInput);
|
||||
keyInput.setTabIndex(0);
|
||||
keyInput.addEventListener("keydown", (KeyboardEvent evt) -> {
|
||||
evt.preventDefault();
|
||||
new Thread(() -> {
|
||||
previousValue = keyInput.getValue();
|
||||
Keyboard.debugKeyPressed(evt.getKeyCode());
|
||||
System.out.println(evt.getKeyCode());
|
||||
System.out.println(""+(int) evt.getKey().charAt(0));
|
||||
}).start();
|
||||
});
|
||||
keyInput.addEventListener("input", (Event evt) -> {
|
||||
evt.preventDefault();
|
||||
final String previousValue = this.previousValue;
|
||||
final String newValue = keyInput.getValue();
|
||||
final int prevLen = previousValue.length();
|
||||
final int newLen = newValue.length();
|
||||
|
||||
new Thread(() -> {
|
||||
if (newLen == prevLen) {
|
||||
|
||||
} else if (newLen - prevLen == 1) {
|
||||
Keyboard.debugKeyPressed((int) newValue.toUpperCase().charAt(newLen-1));
|
||||
} else if (newLen - prevLen > 1) {
|
||||
for (int i = 0; i < newLen - prevLen; i++) {
|
||||
Keyboard.debugKeyPressed((int) newValue.toUpperCase().charAt(prevLen + i));
|
||||
}
|
||||
} else if (newLen - prevLen < 1) {
|
||||
for (int i = 0; i < prevLen - newLen; i++) {
|
||||
Keyboard.debugKeyPressed(8);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
canvas.addEventListener("click", (Event evt) -> {
|
||||
keyInput.focus();
|
||||
});
|
||||
document.addEventListener("DOMContentLoaded", (Event e) -> {
|
||||
keyInput.focus();
|
||||
});
|
||||
NodeList<? extends HTMLElement> buttons = document.getBody().getElementsByTagName("button");
|
||||
for (int i = 0; i < buttons.getLength(); i++) {
|
||||
if (buttons.item(i).hasAttribute("keycode")) {
|
||||
buttons.item(i).addEventListener("click", (Event evt) -> {
|
||||
evt.preventDefault();
|
||||
EventTarget target = evt.getCurrentTarget();
|
||||
HTMLButtonElement button = target.cast();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
if (button.hasAttribute("keycode") && button.getAttribute("keycode").contains(",")) {
|
||||
String code = button.getAttribute("keycode");
|
||||
String[] coordinates = code.split(",", 2);
|
||||
boolean removeshift = Keyboard.shift && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 0;
|
||||
boolean removealpha = Keyboard.alpha && Integer.parseInt(coordinates[0]) != 0 && Integer.parseInt(coordinates[1]) != 1;
|
||||
Keyboard.keyPressedRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]));
|
||||
if (removeshift) {
|
||||
Keyboard.keyPressedRaw(0,0);
|
||||
}
|
||||
if (removealpha) {
|
||||
Keyboard.keyPressedRaw(0,1);
|
||||
}
|
||||
Thread.sleep(100);
|
||||
Keyboard.keyReleasedRaw(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]));
|
||||
if (removeshift) {
|
||||
Keyboard.keyReleasedRaw(0,0);
|
||||
}
|
||||
if (removealpha) {
|
||||
Keyboard.keyReleasedRaw(0,1);
|
||||
}
|
||||
} else {
|
||||
if (Keyboard.alpha && !Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodea")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodea")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
} else if (!Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodes")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
} else if (Keyboard.alpha && Keyboard.shift) {
|
||||
if (button.hasAttribute("keycodesa")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodesa")));
|
||||
} else {
|
||||
if (button.hasAttribute("keycodes")) {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycodes")));
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Keyboard.debugKeyPressed(Integer.parseInt(button.getAttribute("keycode")));
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
}
|
||||
}
|
||||
renderer = new HtmlRenderer(this, g);
|
||||
initialized = true;
|
||||
if (onInitialized != null) {
|
||||
onInitialized.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wasResized() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
if (width == -1) {
|
||||
width = canvas.getWidth();
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
if (height == -1) {
|
||||
height = canvas.getHeight();
|
||||
}
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
document.getBody().removeChild(canvas);
|
||||
initialized = false;
|
||||
exitSemaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(RenderingLoop d) {
|
||||
renderingLoop = d;
|
||||
final Thread th = new Thread(() -> {
|
||||
try {
|
||||
double extratime = 0;
|
||||
while (initialized) {
|
||||
final long start = System.currentTimeMillis();
|
||||
repaint();
|
||||
final long end = System.currentTimeMillis();
|
||||
final double delta = (end - start) / 1000d;
|
||||
final int deltaInt = (int) Math.floor(delta);
|
||||
final int extraTimeInt = (int) Math.floor(extratime);
|
||||
if (extraTimeInt + deltaInt < frameTime) {
|
||||
Thread.sleep(frameTime - (extraTimeInt + deltaInt));
|
||||
extratime = 0;
|
||||
} else {
|
||||
extratime += delta - frameTime;
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
PlatformUtils.setThreadName(th, "Canvas rendering thread");
|
||||
PlatformUtils.setDaemon(th);
|
||||
th.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void repaint() {
|
||||
renderingLoop.refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlRenderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont loadFont(String fontName) throws IOException {
|
||||
return new HtmlFont(fontName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont loadFont(String path, String fontName) throws IOException {
|
||||
return new HtmlFont(fontName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlSkin loadSkin(String file) throws IOException {
|
||||
return new HtmlSkin(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return PlatformUtils.isJavascript;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesRefreshPauses() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +1,68 @@
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.teavm.jso.typedarrays.Uint8ClampedArray;
|
||||
import org.warp.picalculator.StaticVars;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
|
||||
|
||||
public class HtmlFont extends CPUFont {
|
||||
|
||||
public HTMLCanvasElement imgEl;
|
||||
public CanvasRenderingContext2D imgElCtx;
|
||||
|
||||
public HtmlFont(String fontName) throws IOException {
|
||||
super(fontName);
|
||||
HTMLDocument doc = Window.current().getDocument();
|
||||
imgEl = doc.createElement("canvas").cast();
|
||||
imgEl.setClassName("hidden");
|
||||
doc.getBody().appendChild(imgEl);
|
||||
imgElCtx = imgEl.getContext("2d").cast();
|
||||
imgEl.setWidth(this.charW);
|
||||
imgEl.setHeight(this.charH * intervalsTotalSize);
|
||||
|
||||
int screenPos = 0;
|
||||
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
int j;
|
||||
imgElCtx.clearRect(0, 0, imgEl.getWidth(), imgEl.getHeight());
|
||||
imgElCtx.setFillStyle("#000");
|
||||
int minBound = 0, maxBound = intervalsTotalSize-1;
|
||||
System.out.println("charIndex:"+0);
|
||||
System.out.println("minBound"+minBound);
|
||||
System.out.println("maxBound"+maxBound);
|
||||
for (int charIndex = minBound; charIndex < maxBound; charIndex++) {
|
||||
for (int dy = 0; dy < charH; dy++) {
|
||||
for (int dx = 0; dx < charW; dx++) {
|
||||
j = dx;
|
||||
final int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor(bit) / (HtmlFont.intBits));
|
||||
currentIntBitPosition = bit - (currentInt * HtmlFont.intBits);
|
||||
final int charIdx = charIndex * charIntCount + currentInt;
|
||||
if (charIdx >= 0 && charIdx < chars32.length) {
|
||||
bitData = (chars32[charIdx] >> currentIntBitPosition) & 1;
|
||||
if (bitData == 1) {
|
||||
imgElCtx.fillRect( dx, charIndex*charH+dy, 1, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
if (d.getRenderer() instanceof HtmlRenderer) {
|
||||
((HtmlRenderer) d.getRenderer()).f = this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.html.HTMLCanvasElement;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.teavm.jso.typedarrays.Uint8ClampedArray;
|
||||
import org.warp.picalculator.StaticVars;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
|
||||
|
||||
public class HtmlFont extends CPUFont {
|
||||
|
||||
public HTMLCanvasElement imgEl;
|
||||
public CanvasRenderingContext2D imgElCtx;
|
||||
|
||||
public HtmlFont(String fontName) throws IOException {
|
||||
super(fontName);
|
||||
HTMLDocument doc = Window.current().getDocument();
|
||||
imgEl = doc.createElement("canvas").cast();
|
||||
imgEl.setClassName("hidden");
|
||||
doc.getBody().appendChild(imgEl);
|
||||
imgElCtx = imgEl.getContext("2d").cast();
|
||||
imgEl.setWidth(this.charW);
|
||||
imgEl.setHeight(this.charH * intervalsTotalSize);
|
||||
|
||||
int screenPos = 0;
|
||||
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
int j;
|
||||
imgElCtx.clearRect(0, 0, imgEl.getWidth(), imgEl.getHeight());
|
||||
imgElCtx.setFillStyle("#000");
|
||||
int minBound = 0, maxBound = intervalsTotalSize-1;
|
||||
System.out.println("charIndex:"+0);
|
||||
System.out.println("minBound"+minBound);
|
||||
System.out.println("maxBound"+maxBound);
|
||||
for (int charIndex = minBound; charIndex < maxBound; charIndex++) {
|
||||
for (int dy = 0; dy < charH; dy++) {
|
||||
for (int dx = 0; dx < charW; dx++) {
|
||||
j = dx;
|
||||
final int bit = dx + dy * charW;
|
||||
currentInt = (int) (Math.floor(bit) / (HtmlFont.intBits));
|
||||
currentIntBitPosition = bit - (currentInt * HtmlFont.intBits);
|
||||
final int charIdx = charIndex * charIntCount + currentInt;
|
||||
if (charIdx >= 0 && charIdx < chars32.length) {
|
||||
bitData = (chars32[charIdx] >> currentIntBitPosition) & 1;
|
||||
if (bitData == 1) {
|
||||
imgElCtx.fillRect( dx, charIndex*charH+dy, 1, 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
if (d.getRenderer() instanceof HtmlRenderer) {
|
||||
((HtmlRenderer) d.getRenderer()).f = this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,292 +1,292 @@
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import org.teavm.jso.canvas.CanvasImageSource;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.teavm.jso.typedarrays.Uint8ClampedArray;
|
||||
import org.warp.picalculator.StaticVars;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public class HtmlRenderer implements Renderer {
|
||||
private static final boolean ENABLE_SUPERSAMPLING = false;
|
||||
private static final boolean ENABLE_TRANSPARENCY = true;
|
||||
private String currentColor = "#000000ff";
|
||||
private String clearColor = "#000000ff";
|
||||
HtmlFont f = null;
|
||||
HtmlSkin currentSkin = null;
|
||||
private final CanvasRenderingContext2D g;
|
||||
private final HtmlEngine e;
|
||||
public HtmlRenderer(HtmlEngine e, CanvasRenderingContext2D g) {
|
||||
this.g = g;
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
private String toHex(int c) {
|
||||
final int a = c >> 24 & 0xFF;
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
return String.format("#%02x%02x%02x%02x", r, gg, b, a);
|
||||
}
|
||||
|
||||
private String toHex8(int c) {
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
return String.format("#%02x%02x%02x", r, gg, b);
|
||||
}
|
||||
|
||||
private String toHex(int r, int g, int b) {
|
||||
return String.format("#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
|
||||
private String toHex(int r, int g, int b, int a) {
|
||||
return String.format("#%02x%02x%02x%02x", r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetClearColor() {
|
||||
return hexToInt(clearColor);
|
||||
}
|
||||
|
||||
private int hexToInt(String hex) {
|
||||
switch (hex.length()) {
|
||||
case 6:
|
||||
return (0xFF << 24) |
|
||||
(Integer.valueOf(hex.substring(0, 2), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2, 4), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4, 6), 16);
|
||||
case 6+1:
|
||||
return (0xFF << 24) |
|
||||
(Integer.valueOf(hex.substring(0+1, 2+1), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2+1, 4+1), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4+1, 6+1), 16);
|
||||
case 8:
|
||||
return (Integer.valueOf(hex.substring(6, 8), 16) << 24) |
|
||||
(Integer.valueOf(hex.substring(0, 2), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2, 4), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4, 6), 16);
|
||||
case 8+1:
|
||||
return (Integer.valueOf(hex.substring(6+1, 8+1), 16) << 24) |
|
||||
(Integer.valueOf(hex.substring(0+1, 2+1), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2+1, 4+1), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4+1, 6+1), 16);
|
||||
}
|
||||
return 0xFF000000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) x, (int) y, (int) (x + width), (int) (y + height), (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void glDrawSkin(int x0, int y0, int x1, int y1, int s0, int t0, int s1, int t1, 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;
|
||||
final boolean flippedY = (y1 - y0) / (t1 - t0) < 0;
|
||||
int oldColor = 0;
|
||||
int newColor;
|
||||
final int onex = s0 <= s1 ? 1 : -1;
|
||||
final int oney = t0 <= t1 ? 1 : -1;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (onex == -1) {
|
||||
final int s00 = s0;
|
||||
s0 = s1;
|
||||
s1 = s00;
|
||||
width = s1 - s0;
|
||||
}
|
||||
if (oney == -1) {
|
||||
final int t00 = t0;
|
||||
t0 = t1;
|
||||
t1 = t00;
|
||||
height = t1 - t0;
|
||||
}
|
||||
if (x0 >= size[0] || y0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 + width >= size[0]) {
|
||||
s1 = size[0] - x0 + s0;
|
||||
}
|
||||
if (y0 + height >= size[1]) {
|
||||
t1 = size[1] - y0 + t0;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
if (onex == -1) {
|
||||
width += x0;
|
||||
s1 += x0 + 1;
|
||||
} else {
|
||||
s0 -= x0;
|
||||
}
|
||||
x0 = 0;
|
||||
}
|
||||
if (y0 < 0) {
|
||||
if (oney == -1) {
|
||||
height += y0;
|
||||
t1 += y0 + 1;
|
||||
} else {
|
||||
t0 -= y0;
|
||||
}
|
||||
y0 = 0;
|
||||
}
|
||||
g.drawImage(currentSkin.getImgElement(), s0, t0, s1-s0, t1-t0, x0, y0, x1-x0, y1-y0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
x += StaticVars.screenPos[0];
|
||||
y += StaticVars.screenPos[1];
|
||||
g.setFillStyle(currentColor);
|
||||
g.fillRect( x, y, width, height );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
glDrawStringLeft(x - f.getStringWidth(text), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String textString) {
|
||||
x += StaticVars.screenPos[0];
|
||||
y += StaticVars.screenPos[1];
|
||||
|
||||
f.imgElCtx.setGlobalCompositeOperation("source-in");
|
||||
f.imgElCtx.setFillStyle(currentColor);
|
||||
f.imgElCtx.fillRect(0, 0, f.imgEl.getWidth(), f.imgEl.getHeight());
|
||||
|
||||
final int[] text = f.getCharIndexes(textString);
|
||||
final int[] screenSize = e.getSize();
|
||||
int cpos;
|
||||
final int l = text.length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
cpos = (i * (f.charW));
|
||||
final int charIndex = text[i];
|
||||
g.drawImage(f.imgEl, 0, charIndex*f.charH, f.charW, f.charH, x+cpos, y, f.charW, f.charH);
|
||||
}
|
||||
}
|
||||
|
||||
private int stackColors(int... color) {
|
||||
double a = 0;
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
for (final int newColor : color) {
|
||||
final double alpha = (newColor >> 24 & 0xFF) / 255d;
|
||||
a = a * (1d - alpha) + (newColor >> 24 & 0xFF) * alpha;
|
||||
r = r * (1d - alpha) + (newColor >> 16 & 0xFF) * alpha;
|
||||
g = g * (1d - alpha) + (newColor >> 8 & 0xFF) * alpha;
|
||||
b = b * (1d - alpha) + (newColor & 0xFF) * alpha;
|
||||
}
|
||||
return ((int) a) << 24 | ((int) r) << 16 | ((int) g) << 8 | ((int) b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
glDrawStringLeft(x - (f.getStringWidth(text) / 2), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1) {
|
||||
if (x1-x0 > 0 && y1-y0 > 0) {
|
||||
g.beginPath();
|
||||
g.moveTo(x0, y0);
|
||||
g.lineTo(x1, y1);
|
||||
g.stroke();
|
||||
} else {
|
||||
g.fillRect(x0, y0, (x1-x0)+1, (y1-y0)+1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
glDrawStringRight(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
glDrawStringLeft(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawStringCenter(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4i(int red, int green, int blue, int alpha) {
|
||||
g.setFillStyle(currentColor = toHex(red, green, blue, alpha));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
glColor4i((int) (red * 255d), (int) (green * 255d), (int) (blue * 255d), (int) (alpha * 255d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
g.setFillStyle(currentColor = toHex(r, gg, b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
glColor3i((int) (red * 255d), (int) (green * 255d), (int) (blue * 255d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor(int c) {
|
||||
final int a = c >> 24 & 0xFF;
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
g.setFillStyle(currentColor = toHex(r, gg, b, a));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4i(int red, int green, int blue, int alpha) {
|
||||
clearColor = toHex(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearColor = toHex((int)(red*255),
|
||||
(int)(green*255),
|
||||
(int)(blue*255),
|
||||
(int)(alpha*255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(int c) {
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
clearColor = toHex(r, gg, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int screenWidth, int screenHeight) {
|
||||
g.setFillStyle(clearColor);
|
||||
g.fillRect(0, 0, screenWidth, screenHeight);
|
||||
g.setFillStyle(currentColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont getCurrentFont() {
|
||||
return f;
|
||||
}
|
||||
}
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import org.teavm.jso.canvas.CanvasImageSource;
|
||||
import org.teavm.jso.canvas.CanvasRenderingContext2D;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.teavm.jso.typedarrays.Uint8ClampedArray;
|
||||
import org.warp.picalculator.StaticVars;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public class HtmlRenderer implements Renderer {
|
||||
private static final boolean ENABLE_SUPERSAMPLING = false;
|
||||
private static final boolean ENABLE_TRANSPARENCY = true;
|
||||
private String currentColor = "#000000ff";
|
||||
private String clearColor = "#000000ff";
|
||||
HtmlFont f = null;
|
||||
HtmlSkin currentSkin = null;
|
||||
private final CanvasRenderingContext2D g;
|
||||
private final HtmlEngine e;
|
||||
public HtmlRenderer(HtmlEngine e, CanvasRenderingContext2D g) {
|
||||
this.g = g;
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
private String toHex(int c) {
|
||||
final int a = c >> 24 & 0xFF;
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
return String.format("#%02x%02x%02x%02x", r, gg, b, a);
|
||||
}
|
||||
|
||||
private String toHex8(int c) {
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
return String.format("#%02x%02x%02x", r, gg, b);
|
||||
}
|
||||
|
||||
private String toHex(int r, int g, int b) {
|
||||
return String.format("#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
|
||||
private String toHex(int r, int g, int b, int a) {
|
||||
return String.format("#%02x%02x%02x%02x", r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetClearColor() {
|
||||
return hexToInt(clearColor);
|
||||
}
|
||||
|
||||
private int hexToInt(String hex) {
|
||||
switch (hex.length()) {
|
||||
case 6:
|
||||
return (0xFF << 24) |
|
||||
(Integer.valueOf(hex.substring(0, 2), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2, 4), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4, 6), 16);
|
||||
case 6+1:
|
||||
return (0xFF << 24) |
|
||||
(Integer.valueOf(hex.substring(0+1, 2+1), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2+1, 4+1), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4+1, 6+1), 16);
|
||||
case 8:
|
||||
return (Integer.valueOf(hex.substring(6, 8), 16) << 24) |
|
||||
(Integer.valueOf(hex.substring(0, 2), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2, 4), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4, 6), 16);
|
||||
case 8+1:
|
||||
return (Integer.valueOf(hex.substring(6+1, 8+1), 16) << 24) |
|
||||
(Integer.valueOf(hex.substring(0+1, 2+1), 16) << 16) |
|
||||
(Integer.valueOf(hex.substring(2+1, 4+1), 16) << 8) |
|
||||
Integer.valueOf(hex.substring(4+1, 6+1), 16);
|
||||
}
|
||||
return 0xFF000000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) x, (int) y, (int) (x + width), (int) (y + height), (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void glDrawSkin(int x0, int y0, int x1, int y1, int s0, int t0, int s1, int t1, 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;
|
||||
final boolean flippedY = (y1 - y0) / (t1 - t0) < 0;
|
||||
int oldColor = 0;
|
||||
int newColor;
|
||||
final int onex = s0 <= s1 ? 1 : -1;
|
||||
final int oney = t0 <= t1 ? 1 : -1;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (onex == -1) {
|
||||
final int s00 = s0;
|
||||
s0 = s1;
|
||||
s1 = s00;
|
||||
width = s1 - s0;
|
||||
}
|
||||
if (oney == -1) {
|
||||
final int t00 = t0;
|
||||
t0 = t1;
|
||||
t1 = t00;
|
||||
height = t1 - t0;
|
||||
}
|
||||
if (x0 >= size[0] || y0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 + width >= size[0]) {
|
||||
s1 = size[0] - x0 + s0;
|
||||
}
|
||||
if (y0 + height >= size[1]) {
|
||||
t1 = size[1] - y0 + t0;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
if (onex == -1) {
|
||||
width += x0;
|
||||
s1 += x0 + 1;
|
||||
} else {
|
||||
s0 -= x0;
|
||||
}
|
||||
x0 = 0;
|
||||
}
|
||||
if (y0 < 0) {
|
||||
if (oney == -1) {
|
||||
height += y0;
|
||||
t1 += y0 + 1;
|
||||
} else {
|
||||
t0 -= y0;
|
||||
}
|
||||
y0 = 0;
|
||||
}
|
||||
g.drawImage(currentSkin.getImgElement(), s0, t0, s1-s0, t1-t0, x0, y0, x1-x0, y1-y0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
x += StaticVars.screenPos[0];
|
||||
y += StaticVars.screenPos[1];
|
||||
g.setFillStyle(currentColor);
|
||||
g.fillRect( x, y, width, height );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
glDrawStringLeft(x - f.getStringWidth(text), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String textString) {
|
||||
x += StaticVars.screenPos[0];
|
||||
y += StaticVars.screenPos[1];
|
||||
|
||||
f.imgElCtx.setGlobalCompositeOperation("source-in");
|
||||
f.imgElCtx.setFillStyle(currentColor);
|
||||
f.imgElCtx.fillRect(0, 0, f.imgEl.getWidth(), f.imgEl.getHeight());
|
||||
|
||||
final int[] text = f.getCharIndexes(textString);
|
||||
final int[] screenSize = e.getSize();
|
||||
int cpos;
|
||||
final int l = text.length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
cpos = (i * (f.charW));
|
||||
final int charIndex = text[i];
|
||||
g.drawImage(f.imgEl, 0, charIndex*f.charH, f.charW, f.charH, x+cpos, y, f.charW, f.charH);
|
||||
}
|
||||
}
|
||||
|
||||
private int stackColors(int... color) {
|
||||
double a = 0;
|
||||
double r = 0;
|
||||
double g = 0;
|
||||
double b = 0;
|
||||
for (final int newColor : color) {
|
||||
final double alpha = (newColor >> 24 & 0xFF) / 255d;
|
||||
a = a * (1d - alpha) + (newColor >> 24 & 0xFF) * alpha;
|
||||
r = r * (1d - alpha) + (newColor >> 16 & 0xFF) * alpha;
|
||||
g = g * (1d - alpha) + (newColor >> 8 & 0xFF) * alpha;
|
||||
b = b * (1d - alpha) + (newColor & 0xFF) * alpha;
|
||||
}
|
||||
return ((int) a) << 24 | ((int) r) << 16 | ((int) g) << 8 | ((int) b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
glDrawStringLeft(x - (f.getStringWidth(text) / 2), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1) {
|
||||
if (x1-x0 > 0 && y1-y0 > 0) {
|
||||
g.beginPath();
|
||||
g.moveTo(x0, y0);
|
||||
g.lineTo(x1, y1);
|
||||
g.stroke();
|
||||
} else {
|
||||
g.fillRect(x0, y0, (x1-x0)+1, (y1-y0)+1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
glDrawStringRight(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
glDrawStringLeft(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawStringCenter(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4i(int red, int green, int blue, int alpha) {
|
||||
g.setFillStyle(currentColor = toHex(red, green, blue, alpha));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
glColor4i((int) (red * 255d), (int) (green * 255d), (int) (blue * 255d), (int) (alpha * 255d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
g.setFillStyle(currentColor = toHex(r, gg, b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
glColor3i((int) (red * 255d), (int) (green * 255d), (int) (blue * 255d));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor(int c) {
|
||||
final int a = c >> 24 & 0xFF;
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
g.setFillStyle(currentColor = toHex(r, gg, b, a));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4i(int red, int green, int blue, int alpha) {
|
||||
clearColor = toHex(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearColor = toHex((int)(red*255),
|
||||
(int)(green*255),
|
||||
(int)(blue*255),
|
||||
(int)(alpha*255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(int c) {
|
||||
final int r = c >> 16 & 0xFF;
|
||||
final int gg = c >> 8 & 0xFF;
|
||||
final int b = c & 0xFF;
|
||||
clearColor = toHex(r, gg, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int screenWidth, int screenHeight) {
|
||||
g.setFillStyle(clearColor);
|
||||
g.fillRect(0, 0, screenWidth, screenHeight);
|
||||
g.setFillStyle(currentColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HtmlFont getCurrentFont() {
|
||||
return f;
|
||||
}
|
||||
}
|
@ -1,86 +1,86 @@
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.warp.picalculator.deps.StorageUtils;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
import ar.com.hjg.pngj.PngReader;
|
||||
|
||||
public class HtmlSkin implements Skin {
|
||||
|
||||
private String url;
|
||||
|
||||
private int[] skinSize;
|
||||
|
||||
private boolean initd;
|
||||
|
||||
private HTMLImageElement imgEl;
|
||||
|
||||
public HtmlSkin(String file) throws IOException {
|
||||
load(file);
|
||||
}
|
||||
|
||||
public void use(GraphicEngine d) {
|
||||
if (d instanceof HtmlEngine) {
|
||||
if (!initd)
|
||||
initialize(d);
|
||||
((HtmlEngine) d).getRenderer().currentSkin = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(String file) throws IOException {
|
||||
if (!file.startsWith("/"))
|
||||
file = "/"+file;
|
||||
url = StorageUtils.basepath+file;
|
||||
try {
|
||||
PngReader r = new PngReader(StorageUtils.getResourceStream(file));
|
||||
skinSize = new int[] { r.imgInfo.cols, r.imgInfo.rows };
|
||||
r.close();
|
||||
} catch (URISyntaxException e) {
|
||||
IOException ex = new IOException();
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
HTMLDocument doc = Window.current().getDocument();
|
||||
imgEl = doc.createElement("img").cast();
|
||||
imgEl.setSrc(url);
|
||||
imgEl.setClassName("hidden");
|
||||
doc.getBody().appendChild(imgEl);
|
||||
initd = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkinWidth() {
|
||||
return skinSize[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkinHeight() {
|
||||
return skinSize[1];
|
||||
}
|
||||
|
||||
public final String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public final HTMLImageElement getImgElement() {
|
||||
return imgEl;
|
||||
}
|
||||
}
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.teavm.jso.JSObject;
|
||||
import org.teavm.jso.browser.Window;
|
||||
import org.teavm.jso.dom.html.HTMLDocument;
|
||||
import org.teavm.jso.dom.html.HTMLImageElement;
|
||||
import org.warp.picalculator.deps.StorageUtils;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
import ar.com.hjg.pngj.PngReader;
|
||||
|
||||
public class HtmlSkin implements Skin {
|
||||
|
||||
private String url;
|
||||
|
||||
private int[] skinSize;
|
||||
|
||||
private boolean initd;
|
||||
|
||||
private HTMLImageElement imgEl;
|
||||
|
||||
public HtmlSkin(String file) throws IOException {
|
||||
load(file);
|
||||
}
|
||||
|
||||
public void use(GraphicEngine d) {
|
||||
if (d instanceof HtmlEngine) {
|
||||
if (!initd)
|
||||
initialize(d);
|
||||
((HtmlEngine) d).getRenderer().currentSkin = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(String file) throws IOException {
|
||||
if (!file.startsWith("/"))
|
||||
file = "/"+file;
|
||||
url = StorageUtils.basepath+file;
|
||||
try {
|
||||
PngReader r = new PngReader(StorageUtils.getResourceStream(file));
|
||||
skinSize = new int[] { r.imgInfo.cols, r.imgInfo.rows };
|
||||
r.close();
|
||||
} catch (URISyntaxException e) {
|
||||
IOException ex = new IOException();
|
||||
ex.initCause(e);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
HTMLDocument doc = Window.current().getDocument();
|
||||
imgEl = doc.createElement("img").cast();
|
||||
imgEl.setSrc(url);
|
||||
imgEl.setClassName("hidden");
|
||||
doc.getBody().appendChild(imgEl);
|
||||
initd = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialized() {
|
||||
return initd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkinWidth() {
|
||||
return skinSize[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSkinHeight() {
|
||||
return skinSize[1];
|
||||
}
|
||||
|
||||
public final String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public final HTMLImageElement getImgElement() {
|
||||
return imgEl;
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
|
||||
public interface InputEvent extends Event {
|
||||
|
||||
@JSProperty
|
||||
String getValue();
|
||||
}
|
||||
package org.warp.picalculator.gui.graphicengine.html;
|
||||
|
||||
import org.teavm.jso.JSProperty;
|
||||
import org.teavm.jso.dom.events.Event;
|
||||
|
||||
public interface InputEvent extends Event {
|
||||
|
||||
@JSProperty
|
||||
String getValue();
|
||||
}
|
@ -153,7 +153,7 @@ public class BigComplex {
|
||||
* The branch is chosen such that the imaginary part of the result
|
||||
* has the
|
||||
* same sign as the imaginary part of this.
|
||||
* @see Tim Ahrendt, <a href="http://dx.doi.org/10.1145/236869.236924">Fast
|
||||
* @see Tim Ahrendt, <a href="https://doi.org/10.1145/236869.236924">Fast
|
||||
* High-precision computation of complex square roots</a>,
|
||||
* ISSAC 1996 p142-149.
|
||||
* @since 2008-10-27
|
||||
|
@ -580,7 +580,7 @@ public class BigIntegerMath {
|
||||
* @since 2009-08-06
|
||||
* @author Richard J. Mathar
|
||||
* @throws Error
|
||||
* @see <a href="http://dx.doi.org/10.1080/01630568908816313">P. L. Butzer
|
||||
* @see <a href="https://doi.org/10.1080/01630568908816313">P. L. Butzer
|
||||
* et al, Num. Funct. Anal. Opt. 10 (5)( 1989) 419-488</a>
|
||||
*/
|
||||
static public Rational centrlFactNumt(int n, int k) throws Error {
|
||||
@ -627,7 +627,7 @@ public class BigIntegerMath {
|
||||
* @return T(n,k)
|
||||
* @since 2009-08-06
|
||||
* @author Richard J. Mathar
|
||||
* @see <a href="http://dx.doi.org/10.1080/01630568908816313">P. L. Butzer
|
||||
* @see <a href="https://doi.org/10.1080/01630568908816313">P. L. Butzer
|
||||
* et al, Num. Funct. Anal. Opt. 10 (5)( 1989) 419-488</a>
|
||||
*/
|
||||
static public Rational centrlFactNumT(int n, int k) {
|
||||
|
@ -137,7 +137,7 @@ public class Wigner3j {
|
||||
* separated. Only as many as announced by the m1 parameter are
|
||||
* used; trailing numbers are ignored.
|
||||
* @see A. Bar-Shalom and M. Klapisch,
|
||||
* <a href="http://dx.doi.org/10.1016/0010-4655(88)90192-0">NJGRAF...
|
||||
* <a href="https://doi.org/10.1016/0010-4655(88)90192-0">NJGRAF...
|
||||
* </a>, Comp. Phys Comm. 50 (3) (1988) 375
|
||||
* @since 2011-02-13
|
||||
* @since 2012-02-15 Upgraded return value to BigSurdVec
|
||||
|
Loading…
Reference in New Issue
Block a user