Merge remote-tracking branch 'origin/new-math-rules'

Conflicts:
	.gitignore
	src/main/java/org/warp/picalculator/device/Keyboard.java
	src/main/java/org/warp/picalculator/gui/graphicengine/cpu/SwingWindow.java
	src/main/java/org/warp/picalculator/gui/screens/MarioScreen.java
This commit is contained in:
Andrea Cavalli 2018-06-09 19:53:46 +02:00
commit e9967062fd
255 changed files with 10720 additions and 4309 deletions

View File

@ -1,17 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-9.0.1">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
@ -19,6 +8,7 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -28,5 +18,17 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/jar-specific/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

19
.gitignore vendored
View File

@ -4,18 +4,25 @@
.mtj.tmp/
# Package Files #
*.jar
!/target/*.jar
*.war
*.jar
*.ear
Thumbs.db
font_easter.png
font_easter.rft
font_fu32.rft
*Thumbs.db
font_gputest1.rft
font_gputest12.rft
font_gputest2.rft
font_gputest3.png
font_gputest4.png
font_gputest4.xcf
manager2/
VBO_Example.java
/target/
!/target/*.jar
/backups/
/Resources_and_Videos/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/bin/
/bin/

View File

@ -17,13 +17,13 @@
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>

View File

@ -1,4 +1,8 @@
eclipse.preferences.version=1
encoding//src/jar-specific/java=UTF-8
encoding//src/js-specific/java=UTF-8
encoding//src/main/java=UTF-8
encoding//src/main/java/org/warp/picalculator/gui/expression/blocks/BlockParenthesis.java=UTF-8
encoding//src/main/java/org/warp/picalculator/math/MathematicalSymbols.java=UTF-8
encoding/<project>=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8

View File

@ -1,14 +1,6 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.javaFormatter=org.eclipse.jdt.core.defaultJavaFormatter

View File

@ -1,4 +1,4 @@
activeProfiles=
activeProfiles=jarprofile
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

Binary file not shown.

View File

@ -1,5 +1,5 @@
# WarpPI Calculator
Step-by-step algebraic calculator for Raspberry PI.
Step-by-step algebra calculator for Raspberry PI.
**This project is experimental and strictly related to my calculator, designed to run on an embedded hardware.
It works but many fundamental features aren't complete.**<br>

BIN
libs/raspi2fb Normal file

Binary file not shown.

BIN
math-rules-cache.zip Normal file

Binary file not shown.

207
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.warp.picalculator</groupId>
@ -7,7 +8,16 @@
<version>1.0-SNAPSHOT</version>
<name>WarpPI Calculator</name>
<url>http://warp.ovh</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<src.dir>src/main/java</src.dir>
</properties>
<repositories>
<repository>
<id>teavm-dev</id>
<url>https://dl.bintray.com/konsoletyper/teavm</url>
</repository>
<repository>
<id>oss-snapshots-repo</id>
<name>Sonatype OSS Maven Repository</name>
@ -18,51 +28,171 @@
</snapshots>
</repository>
</repositories>
<profiles>
<profile>
<id>jarprofile</id>
<properties>
<src.dir>jar-specific</src.dir>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<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>
<dependency>
<groupId>ar.com.hjg</groupId>
<artifactId>pngj</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jsprofile</id>
<properties>
<src.dir>js-specific</src.dir>
</properties>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
<exclude>org/warp/picalculator/gui/graphicengine/cpu/*</exclude>
<exclude>org/warp/picalculator/gui/graphicengine/gpu/*</exclude>
<exclude>org/warp/picalculator/gui/graphicengine/headless24bit/*</exclude>
<exclude>org/warp/picalculator/gui/graphicengine/headless256/*</exclude>
<exclude>org/warp/picalculator/gui/graphicengine/headless8/*</exclude>
<exclude>org/warp/picalculator/gui/graphicengine/framebuffer/*</exclude>
</excludes>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>0.5.1</version>
<dependencies>
<!-- This dependency is required by TeaVM to emulate subset of Java
class library -->
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>0.5.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<mainClass>org.warp.picalculator.Main</mainClass>
<mainPageIncluded>true</mainPageIncluded>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!--<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
<version>4.12</version> <scope>test</scope> </dependency> -->
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>7.2.0</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all-main</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<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>ar.com.hjg</groupId>
<artifactId>pngj</artifactId>
<version>2.1.0</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<finalName>WarpPICalculator</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>
${basedir}/src/main/java
</source>
<source>
${basedir}/src/${src.dir}/java
</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<!-- download source code in Eclipse, best practice -->
<plugin>
@ -75,14 +205,12 @@
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
@ -115,7 +243,6 @@
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId>

View File

@ -0,0 +1,110 @@
package org.warp.picalculator;
import java.io.PrintStream;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.warp.picalculator.math.MathematicalSymbols;
public class ConsoleUtils {
public static final class AdvancedOutputStream extends StringWriter {
private void print(PrintStream stream, String str) {
stream.print(fixString(str));
}
private void println(PrintStream stream, String str) {
stream.println(fixString(str));
}
private void println(PrintStream stream) {
stream.println();
}
private String fixString(String str) {
return str.replace("" + MathematicalSymbols.NTH_ROOT, "root").replace("" + MathematicalSymbols.SQUARE_ROOT, "sqrt").replace("" + MathematicalSymbols.POWER, "powerOf").replace("" + MathematicalSymbols.POWER_OF_TWO, "powerOfTwo").replace("" + MathematicalSymbols.SINE, "sine").replace("" + MathematicalSymbols.COSINE, "cosine").replace("" + MathematicalSymbols.TANGENT, "tangent").replace("" + MathematicalSymbols.ARC_SINE, "asin").replace("" + MathematicalSymbols.ARC_COSINE, "acos").replace("" + MathematicalSymbols.ARC_TANGENT, "atan").replace("" + MathematicalSymbols.UNDEFINED, "undefined").replace("" + MathematicalSymbols.PI, "PI").replace("" + MathematicalSymbols.EULER_NUMBER, "EULER_NUMBER").replace("" + MathematicalSymbols.X, "X").replace("" + MathematicalSymbols.Y, "Y");
}
public void println(String str) {
println(0, str);
}
public void println(int level) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out);
} else {
println(System.out);
}
}
}
public void println(int level, String str) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + str);
} else {
println(System.out, "[" + time + "]" + str);
}
}
}
public void print(int level, String str) {
if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) {
print(System.out, str);
} else {
print(System.out, str);
}
}
}
public void println(int level, String prefix, String str) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "][" + prefix + "]" + str);
} else {
println(System.out, "[" + time + "][" + prefix + "]" + str);
}
}
}
public void println(int level, String... parts) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
String output = "";
for (int i = 0; i < parts.length; i++) {
if (i + 1 == parts.length) {
output += parts[i];
} else {
output += "[" + parts[i] + "]";
}
}
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + output);
} else {
println(System.out, "[" + time + "]" + output);
}
}
}
private String getTimeString() {
return LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss.SSS"));
}
int before = 0;
boolean due = false;
}
public static ConsoleUtils.AdvancedOutputStream out = new ConsoleUtils.AdvancedOutputStream();
public static final int OUTPUTLEVEL_NODEBUG = 0;
public static final int OUTPUTLEVEL_DEBUG_MIN = 1;
public static final int OUTPUTLEVEL_DEBUG_VERBOSE = 4;
}

View File

@ -0,0 +1,32 @@
package org.warp.picalculator;
import java.io.PrintWriter;
import java.io.StringWriter;
public final class PlatformUtils {
public static final boolean isJavascript = false;
public static String osName = System.getProperty("os.name").toLowerCase();
public static void setThreadName(Thread t, String string) {
t.setName(string);
}
public static void setDaemon(Thread kt) {
kt.setDaemon(true);
}
public static void setDaemon(Thread kt, boolean val) {
kt.setDaemon(val);
}
public static void throwNewExceptionInInitializerError(String string) {
throw new ExceptionInInitializerError(string);
}
public static String[] stacktraceToString(Error e) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
}
}

View File

@ -0,0 +1,49 @@
package org.warp.picalculator;
import java.io.File;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;
public class ZipUtils {
public static void zip(String targetPath, String destinationFilePath, String password) {
try {
final ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (password.length() > 0) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword(password);
}
final ZipFile zipFile = new ZipFile(destinationFilePath);
final File targetFile = new File(targetPath);
if (targetFile.isFile()) {
zipFile.addFile(targetFile, parameters);
} else if (targetFile.isDirectory()) {
zipFile.addFolder(targetFile, parameters);
}
} catch (final Exception e) {
e.printStackTrace();
}
}
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password) {
try {
final ZipFile zipFile = new ZipFile(targetZipFilePath);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destinationFolderPath);
} catch (final Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,14 @@
package org.warp.picalculator.deps;
import java.util.concurrent.atomic.AtomicInteger;
public class DAtomicInteger extends AtomicInteger {
public DAtomicInteger() {
super();
}
public DAtomicInteger(int i) {
super(i);
}
private static final long serialVersionUID = 2910383978241062566L;
}

View File

@ -0,0 +1,27 @@
package org.warp.picalculator.deps;
import org.warp.picalculator.ClassUtils;
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();
}
public static GraphicEngine newHeadless24bitEngine() {
return new org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitEngine();
}
public static GraphicEngine newHeadless256Engine() {
return new org.warp.picalculator.gui.graphicengine.headless256.Headless256Engine();
}
public static GraphicEngine newHeadless8Engine() {
return new org.warp.picalculator.gui.graphicengine.headless8.Headless8Engine();
}
public static GraphicEngine newCPUEngine() {
return new CPUEngine();
}
public static GraphicEngine newFBEngine() {
return new FBEngine();
}
}

View File

@ -0,0 +1,47 @@
package org.warp.picalculator.deps;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DGpio {
public static final int OUTPUT = com.pi4j.wiringpi.Gpio.OUTPUT;
public static final int PWM_OUTPUT = com.pi4j.wiringpi.Gpio.PWM_OUTPUT;
public static final int INPUT = com.pi4j.wiringpi.Gpio.INPUT;
public static final int HIGH = com.pi4j.wiringpi.Gpio.HIGH;
public static final int LOW = com.pi4j.wiringpi.Gpio.LOW;
public static final Object UnknownBoardType = com.pi4j.system.SystemInfo.BoardType.UNKNOWN;
public static void wiringPiSetupPhys() {
com.pi4j.wiringpi.Gpio.wiringPiSetupPhys();
}
public static void pinMode(int i, int type) {
com.pi4j.wiringpi.Gpio.pinMode(i, type);
}
public static void digitalWrite(int pin, int val) {
com.pi4j.wiringpi.Gpio.digitalWrite(pin, val);
}
public static void digitalWrite(int pin, boolean val) {
com.pi4j.wiringpi.Gpio.digitalWrite(pin, val);
}
public static void pwmWrite(int pin, int val) {
com.pi4j.wiringpi.Gpio.pwmWrite(pin, val);
}
public static void delayMicroseconds(int t) {
com.pi4j.wiringpi.Gpio.delayMicroseconds(t);
}
public static int digitalRead(int pin) {
return com.pi4j.wiringpi.Gpio.digitalRead(pin);
}
public static Object getBoardType() {
return ClassUtils.invokeStaticMethod("com.pi4j.system.SystemInfo.getBoardType");
}
}

View File

@ -0,0 +1,13 @@
package org.warp.picalculator.deps;
import java.io.PrintWriter;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DJDTCompiler {
public static boolean compile(String[] strings, PrintWriter printWriter, PrintWriter printWriter2) {
return org.eclipse.jdt.internal.compiler.batch.Main.compile(strings, printWriter, printWriter2, null);
}
}

View File

@ -0,0 +1,7 @@
package org.warp.picalculator.deps;
public class DSystem {
public static final void exit(int val) {
System.exit(val);
}
}

View File

@ -0,0 +1,16 @@
package org.warp.picalculator.deps;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class StorageUtils {
public static final boolean exists(Path f) {
return Files.exists(f);
}
public static Path get(String path) {
return Paths.get(path);
}
}

View File

@ -0,0 +1,568 @@
package org.warp.picalculator.deps.jogamp;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DJogamp {
//
// Unicode: Non printable controls: [0x00 - 0x1F]
//
/**
* This value, {@value}, is used to indicate that the keyCode is unknown.
*/
public static final short VK_UNDEFINED = (short) 0x0;
static final short VK_FREE01 = (short) 0x01;
/** Constant for the HOME function key. ASCII: Start Of Text. */
public static final short VK_HOME = (short) 0x02;
/** Constant for the END function key. ASCII: End Of Text. */
public static final short VK_END = (short) 0x03;
/** Constant for the END function key. ASCII: End Of Transmission. */
public static final short VK_FINAL = (short) 0x04;
/** Constant for the PRINT function key. ASCII: Enquiry. */
public static final short VK_PRINTSCREEN = (short) 0x05;
static final short VK_FREE06 = (short) 0x06;
static final short VK_FREE07 = (short) 0x07;
/** Constant for the BACK SPACE key "\b", matching ASCII. Printable! */
public static final short VK_BACK_SPACE = (short) 0x08;
/** Constant for the HORIZ TAB key "\t", matching ASCII. Printable! */
public static final short VK_TAB = (short) 0x09;
/** LINE_FEED "\n", matching ASCII, n/a on keyboard. */
static final short VK_FREE0A = (short) 0x0A;
/** Constant for the PAGE DOWN function key. ASCII: Vertical Tabulation. */
public static final short VK_PAGE_DOWN = (short) 0x0B;
/** Constant for the CLEAR key, i.e. FORM FEED, matching ASCII. */
public static final short VK_CLEAR = (short) 0x0C;
/** Constant for the ENTER key, i.e. CARRIAGE RETURN, matching ASCII. Printable! */
public static final short VK_ENTER = (short) 0x0D;
static final short VK_FREE0E = (short) 0x0E;
/** Constant for the CTRL function key. ASCII: shift-in. */
public static final short VK_SHIFT = (short) 0x0F;
/** Constant for the PAGE UP function key. ASCII: Data Link Escape. */
public static final short VK_PAGE_UP = (short) 0x10;
/** Constant for the CTRL function key. ASCII: device-ctrl-one. */
public static final short VK_CONTROL = (short) 0x11;
/** Constant for the left ALT function key. ASCII: device-ctrl-two. */
public static final short VK_ALT = (short) 0x12;
/** Constant for the ALT_GRAPH function key, i.e. right ALT key. ASCII: device-ctrl-three. */
public static final short VK_ALT_GRAPH = (short) 0x13;
/** Constant for the CAPS LOCK function key. ASCII: device-ctrl-four. */
public static final short VK_CAPS_LOCK = (short) 0x14;
static final short VK_FREE15 = (short) 0x15;
/** Constant for the PAUSE function key. ASCII: sync-idle. */
public static final short VK_PAUSE = (short) 0x16;
/** <b>scroll lock</b> key. ASCII: End Of Transmission Block. */
public static final short VK_SCROLL_LOCK = (short) 0x17;
/** Constant for the CANCEL function key. ASCII: Cancel. */
public static final short VK_CANCEL = (short) 0x18;
static final short VK_FREE19 = (short) 0x19;
/** Constant for the INSERT function key. ASCII: Substitute. */
public static final short VK_INSERT = (short) 0x1A;
/** Constant for the ESCAPE function key. ASCII: Escape. */
public static final short VK_ESCAPE = (short) 0x1B;
/** Constant for the Convert function key, Japanese "henkan". ASCII: File Separator. */
public static final short VK_CONVERT = (short) 0x1C;
/** Constant for the Don't Convert function key, Japanese "muhenkan". ASCII: Group Separator.*/
public static final short VK_NONCONVERT = (short) 0x1D;
/** Constant for the Accept or Commit function key, Japanese "kakutei". ASCII: Record Separator.*/
public static final short VK_ACCEPT = (short) 0x1E;
/** Constant for the Mode Change (?). ASCII: Unit Separator.*/
public static final short VK_MODECHANGE = (short) 0x1F;
//
// Unicode: Printable [0x20 - 0x7E]
// NOTE: Collision of 'a' - 'x' [0x61 .. 0x78], used for keyCode/keySym Fn function keys
//
/** Constant for the SPACE function key. ASCII: SPACE. */
public static final short VK_SPACE = (short) 0x20;
/** Constant for the "!" key. */
public static final short VK_EXCLAMATION_MARK = (short) 0x21;
/** Constant for the """ key. */
public static final short VK_QUOTEDBL = (short) 0x22;
/** Constant for the "#" key. */
public static final short VK_NUMBER_SIGN = (short) 0x23;
/** Constant for the "$" key. */
public static final short VK_DOLLAR = (short) 0x24;
/** Constant for the "%" key. */
public static final short VK_PERCENT = (short) 0x25;
/** Constant for the "&" key. */
public static final short VK_AMPERSAND = (short) 0x26;
/** Constant for the "'" key. */
public static final short VK_QUOTE = (short) 0x27;
/** Constant for the "(" key. */
public static final short VK_LEFT_PARENTHESIS = (short) 0x28;
/** Constant for the ")" key. */
public static final short VK_RIGHT_PARENTHESIS = (short) 0x29;
/** Constant for the "*" key */
public static final short VK_ASTERISK = (short) 0x2A;
/** Constant for the "+" key. */
public static final short VK_PLUS = (short) 0x2B;
/** Constant for the comma key, "," */
public static final short VK_COMMA = (short) 0x2C;
/** Constant for the minus key, "-" */
public static final short VK_MINUS = (short) 0x2D;
/** Constant for the period key, "." */
public static final short VK_PERIOD = (short) 0x2E;
/** Constant for the forward slash key, "/" */
public static final short VK_SLASH = (short) 0x2F;
/** VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39] */
public static final short VK_0 = (short) 0x30;
/** See {@link #VK_0}. */
public static final short VK_1 = (short) 0x31;
/** See {@link #VK_0}. */
public static final short VK_2 = (short) 0x32;
/** See {@link #VK_0}. */
public static final short VK_3 = (short) 0x33;
/** See {@link #VK_0}. */
public static final short VK_4 = (short) 0x34;
/** See {@link #VK_0}. */
public static final short VK_5 = (short) 0x35;
/** See {@link #VK_0}. */
public static final short VK_6 = (short) 0x36;
/** See {@link #VK_0}. */
public static final short VK_7 = (short) 0x37;
/** See {@link #VK_0}. */
public static final short VK_8 = (short) 0x38;
/** See {@link #VK_0}. */
public static final short VK_9 = (short) 0x39;
/** Constant for the ":" key. */
public static final short VK_COLON = (short) 0x3A;
/** Constant for the semicolon key, ";" */
public static final short VK_SEMICOLON = (short) 0x3B;
/** Constant for the equals key, "<" */
public static final short VK_LESS = (short) 0x3C;
/** Constant for the equals key, "=" */
public static final short VK_EQUALS = (short) 0x3D;
/** Constant for the equals key, ">" */
public static final short VK_GREATER = (short) 0x3E;
/** Constant for the equals key, "?" */
public static final short VK_QUESTIONMARK = (short) 0x3F;
/** Constant for the equals key, "@" */
public static final short VK_AT = (short) 0x40;
/** VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A) */
public static final short VK_A = (short) 0x41;
/** See {@link #VK_A}. */
public static final short VK_B = (short) 0x42;
/** See {@link #VK_A}. */
public static final short VK_C = (short) 0x43;
/** See {@link #VK_A}. */
public static final short VK_D = (short) 0x44;
/** See {@link #VK_A}. */
public static final short VK_E = (short) 0x45;
/** See {@link #VK_A}. */
public static final short VK_F = (short) 0x46;
/** See {@link #VK_A}. */
public static final short VK_G = (short) 0x47;
/** See {@link #VK_A}. */
public static final short VK_H = (short) 0x48;
/** See {@link #VK_A}. */
public static final short VK_I = (short) 0x49;
/** See {@link #VK_A}. */
public static final short VK_J = (short) 0x4A;
/** See {@link #VK_A}. */
public static final short VK_K = (short) 0x4B;
/** See {@link #VK_A}. */
public static final short VK_L = (short) 0x4C;
/** See {@link #VK_A}. */
public static final short VK_M = (short) 0x4D;
/** See {@link #VK_A}. */
public static final short VK_N = (short) 0x4E;
/** See {@link #VK_A}. */
public static final short VK_O = (short) 0x4F;
/** See {@link #VK_A}. */
public static final short VK_P = (short) 0x50;
/** See {@link #VK_A}. */
public static final short VK_Q = (short) 0x51;
/** See {@link #VK_A}. */
public static final short VK_R = (short) 0x52;
/** See {@link #VK_A}. */
public static final short VK_S = (short) 0x53;
/** See {@link #VK_A}. */
public static final short VK_T = (short) 0x54;
/** See {@link #VK_A}. */
public static final short VK_U = (short) 0x55;
/** See {@link #VK_A}. */
public static final short VK_V = (short) 0x56;
/** See {@link #VK_A}. */
public static final short VK_W = (short) 0x57;
/** See {@link #VK_A}. */
public static final short VK_X = (short) 0x58;
/** See {@link #VK_A}. */
public static final short VK_Y = (short) 0x59;
/** See {@link #VK_A}. */
public static final short VK_Z = (short) 0x5A;
/** Constant for the open bracket key, "[" */
public static final short VK_OPEN_BRACKET = (short) 0x5B;
/**Constant for the back slash key, "\" */
public static final short VK_BACK_SLASH = (short) 0x5C;
/** Constant for the close bracket key, "]" */
public static final short VK_CLOSE_BRACKET = (short) 0x5D;
/** Constant for the "^" key. */
public static final short VK_CIRCUMFLEX = (short) 0x5E;
/** Constant for the "_" key */
public static final short VK_UNDERSCORE = (short) 0x5F;
/** Constant for the "`" key */
public static final short VK_BACK_QUOTE = (short) 0x60;
/** Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym. */
/**
* Constant for the F<i>n</i> function keys.
* <p>
* F1..F24, i.e. F<i>n</i>, are mapped from on <code>0x60+n</code> -> <code>[0x61 .. 0x78]</code>.
* </p>
* <p>
* <b>Warning:</b> The F<i>n</i> function keys <b>do collide</b> with unicode characters small 'a' thru 'x'!<br/>
* See <a href="#unicodeCollision">Unicode Collision</a> for details.
* </p>
*/
public static final short VK_F1 = (short) ( 0x60+ 1 );
/** Constant for the F2 function key. See {@link #VK_F1}. */
public static final short VK_F2 = (short) ( 0x60+ 2 );
/** Constant for the F3 function key. See {@link #VK_F1}. */
public static final short VK_F3 = (short) ( 0x60+ 3 );
/** Constant for the F4 function key. See {@link #VK_F1}. */
public static final short VK_F4 = (short) ( 0x60+ 4 );
/** Constant for the F5 function key. See {@link #VK_F1}. */
public static final short VK_F5 = (short) ( 0x60+ 5 );
/** Constant for the F6 function key. See {@link #VK_F1}. */
public static final short VK_F6 = (short) ( 0x60+ 6 );
/** Constant for the F7 function key. See {@link #VK_F1}. */
public static final short VK_F7 = (short) ( 0x60+ 7 );
/** Constant for the F8 function key. See {@link #VK_F1}. */
public static final short VK_F8 = (short) ( 0x60+ 8 );
/** Constant for the F9 function key. See {@link #VK_F1}. */
public static final short VK_F9 = (short) ( 0x60+ 9 );
/** Constant for the F11 function key. See {@link #VK_F1}. */
public static final short VK_F10 = (short) ( 0x60+10 );
/** Constant for the F11 function key. See {@link #VK_F1}. */
public static final short VK_F11 = (short) ( 0x60+11 );
/** Constant for the F12 function key. See {@link #VK_F1}.*/
public static final short VK_F12 = (short) ( 0x60+12 );
/** Constant for the F13 function key. See {@link #VK_F1}. */
public static final short VK_F13 = (short) ( 0x60+13 );
/** Constant for the F14 function key. See {@link #VK_F1}. */
public static final short VK_F14 = (short) ( 0x60+14 );
/** Constant for the F15 function key. See {@link #VK_F1}. */
public static final short VK_F15 = (short) ( 0x60+15 );
/** Constant for the F16 function key. See {@link #VK_F1}. */
public static final short VK_F16 = (short) ( 0x60+16 );
/** Constant for the F17 function key. See {@link #VK_F1}. */
public static final short VK_F17 = (short) ( 0x60+17 );
/** Constant for the F18 function key. See {@link #VK_F1}. */
public static final short VK_F18 = (short) ( 0x60+18 );
/** Constant for the F19 function key. See {@link #VK_F1}. */
public static final short VK_F19 = (short) ( 0x60+19 );
/** Constant for the F20 function key. See {@link #VK_F1}. */
public static final short VK_F20 = (short) ( 0x60+20 );
/** Constant for the F21 function key. See {@link #VK_F1}. */
public static final short VK_F21 = (short) ( 0x60+21 );
/** Constant for the F22 function key. See {@link #VK_F1}. */
public static final short VK_F22 = (short) ( 0x60+22 );
/** Constant for the F23 function key. See {@link #VK_F1}. */
public static final short VK_F23 = (short) ( 0x60+23 );
/** Constant for the F24 function key. See {@link #VK_F1}. */
public static final short VK_F24 = (short) ( 0x60+24 );
/** Constant for the "{" key */
public static final short VK_LEFT_BRACE = (short) 0x7B;
/** Constant for the "|" key */
public static final short VK_PIPE = (short) 0x7C;
/** Constant for the "}" key */
public static final short VK_RIGHT_BRACE = (short) 0x7D;
/** Constant for the "~" key, matching ASCII */
public static final short VK_TILDE = (short) 0x7E;
//
// Unicode: Non printable controls: [0x7F - 0x9F]
//
// Numpad keys [0x7F - 0x8E] are printable
//
/** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
public static final short VK_SEPARATOR = (short) 0x7F;
/** Numeric keypad VK_NUMPAD0 thru VK_NUMPAD9 are mapped to UTF control (0x80 - 0x89). Non printable UTF control. */
public static final short VK_NUMPAD0 = (short) 0x80;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD1 = (short) 0x81;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD2 = (short) 0x82;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD3 = (short) 0x83;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD4 = (short) 0x84;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD5 = (short) 0x85;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD6 = (short) 0x86;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD7 = (short) 0x87;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD8 = (short) 0x88;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD9 = (short) 0x89;
/** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
public static final short VK_DECIMAL = (short) 0x8A;
/** Numeric keypad <b>add</b> key. Non printable UTF control. */
public static final short VK_ADD = (short) 0x8B;
/** Numeric keypad <b>subtract</b> key. Non printable UTF control. */
public static final short VK_SUBTRACT = (short) 0x8C;
/** Numeric keypad <b>multiply</b> key. Non printable UTF control. */
public static final short VK_MULTIPLY = (short) 0x8D;
/** Numeric keypad <b>divide</b> key. Non printable UTF control. */
public static final short VK_DIVIDE = (short) 0x8E;
/** Constant for the DEL key, matching ASCII. Non printable UTF control. */
public static final short VK_DELETE = (short) 0x93;
/** Numeric keypad <b>num lock</b> key. Non printable UTF control. */
public static final short VK_NUM_LOCK = (short) 0x94;
/** Constant for the cursor- or numerical-pad <b>left</b> arrow key. Non printable UTF control. */
public static final short VK_LEFT = (short) 0x95;
/** Constant for the cursor- or numerical-pad <b>up</b> arrow key. Non printable UTF control. */
public static final short VK_UP = (short) 0x96;
/** Constant for the cursor- or numerical-pad <b>right</b> arrow key. Non printable UTF control. */
public static final short VK_RIGHT = (short) 0x97;
/** Constant for the cursor- or numerical pad <b>down</b> arrow key. Non printable UTF control. */
public static final short VK_DOWN = (short) 0x98;
/** Constant for the Context Menu key. Non printable UTF control. */
public static final short VK_CONTEXT_MENU = (short) 0x99;
/**
* Constant for the MS "Windows" function key.
* It is used for both the left and right version of the key.
*/
public static final short VK_WINDOWS = (short) 0x9A;
/** Constant for the Meta function key. */
public static final short VK_META = (short) 0x9B;
/** Constant for the Help function key. */
public static final short VK_HELP = (short) 0x9C;
/** Constant for the Compose function key. */
public static final short VK_COMPOSE = (short) 0x9D;
/** Constant for the Begin function key. */
public static final short VK_BEGIN = (short) 0x9E;
/** Constant for the Stop function key. */
public static final short VK_STOP = (short) 0x9F;
//
// Unicode: Printable [0x00A0 - 0xDFFF]
//
/** Constant for the inverted exclamation mark key. */
public static final short VK_INVERTED_EXCLAMATION_MARK = (short) 0xA1;
/** Constant for the Euro currency sign key. */
public static final short VK_EURO_SIGN = (short) 0x20AC;
//
// Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable)
//
/* for Sun keyboards */
public static final short VK_CUT = (short) 0xF879;
public static final short VK_COPY = (short) 0xF87A;
public static final short VK_PASTE = (short) 0xF87B;
public static final short VK_UNDO = (short) 0xF87C;
public static final short VK_AGAIN = (short) 0xF87D;
public static final short VK_FIND = (short) 0xF87E;
public static final short VK_PROPS = (short) 0xF87F;
/* for input method support on Asian Keyboards */
/**
* Constant for the input method on/off key.
*/
/* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
public static final short VK_INPUT_METHOD_ON_OFF = (short) 0xF890;
/**
* Constant for the Code Input function key.
*/
/* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
public static final short VK_CODE_INPUT = (short) 0xF891;
/**
* Constant for the Roman Characters function key.
*/
/* Japanese PC 106 keyboard: roumaji */
public static final short VK_ROMAN_CHARACTERS = (short) 0xF892;
/**
* Constant for the All Candidates function key.
*/
/* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
public static final short VK_ALL_CANDIDATES = (short) 0xF893;
/**
* Constant for the Previous Candidate function key.
*/
/* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
public static final short VK_PREVIOUS_CANDIDATE = (short) 0xF894;
/**
* Constant for the Alphanumeric function key.
*/
/* Japanese PC 106 keyboard: eisuu */
public static final short VK_ALPHANUMERIC = (short) 0xF895;
/**
* Constant for the Katakana function key.
*/
/* Japanese PC 106 keyboard: katakana */
public static final short VK_KATAKANA = (short) 0xF896;
/**
* Constant for the Hiragana function key.
*/
/* Japanese PC 106 keyboard: hiragana */
public static final short VK_HIRAGANA = (short) 0xF897;
/**
* Constant for the Full-Width Characters function key.
*/
/* Japanese PC 106 keyboard: zenkaku */
public static final short VK_FULL_WIDTH = (short) 0xF898;
/**
* Constant for the Half-Width Characters function key.
*/
/* Japanese PC 106 keyboard: hankaku */
public static final short VK_HALF_WIDTH = (short) 0xF89A;
/**
* Constant for the Japanese-Katakana function key.
* This key switches to a Japanese input method and selects its Katakana input mode.
*/
/* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
public static final short VK_JAPANESE_KATAKANA = (short) 0xF89B;
/**
* Constant for the Japanese-Hiragana function key.
* This key switches to a Japanese input method and selects its Hiragana input mode.
*/
/* Japanese Macintosh keyboard */
public static final short VK_JAPANESE_HIRAGANA = (short) 0xF89C;
/**
* Constant for the Japanese-Roman function key.
* This key switches to a Japanese input method and selects its Roman-Direct input mode.
*/
/* Japanese Macintosh keyboard */
public static final short VK_JAPANESE_ROMAN = (short) 0xF89D;
/**
* Constant for the locking Kana function key.
* This key locks the keyboard into a Kana layout.
*/
/* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
public static final short VK_KANA_LOCK = (short) 0xF89F;
/**
* Constant for Keyboard became invisible, e.g. Android's soft keyboard Back button hit while keyboard is visible.
*/
public static final short VK_KEYBOARD_INVISIBLE = (short) 0xF8FF;
}

View File

@ -0,0 +1,110 @@
package org.warp.picalculator;
import java.io.PrintStream;
import java.io.StringWriter;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.warp.picalculator.math.MathematicalSymbols;
public class ConsoleUtils {
public static final class AdvancedOutputStream {
private void print(PrintStream stream, String str) {
stream.print(fixString(str));
}
private void println(PrintStream stream, String str) {
stream.println(fixString(str));
}
private void println(PrintStream stream) {
stream.println();
}
private String fixString(String str) {
return str.replace("" + MathematicalSymbols.NTH_ROOT, "root").replace("" + MathematicalSymbols.SQUARE_ROOT, "sqrt").replace("" + MathematicalSymbols.POWER, "powerOf").replace("" + MathematicalSymbols.POWER_OF_TWO, "powerOfTwo").replace("" + MathematicalSymbols.SINE, "sine").replace("" + MathematicalSymbols.COSINE, "cosine").replace("" + MathematicalSymbols.TANGENT, "tangent").replace("" + MathematicalSymbols.ARC_SINE, "asin").replace("" + MathematicalSymbols.ARC_COSINE, "acos").replace("" + MathematicalSymbols.ARC_TANGENT, "atan").replace("" + MathematicalSymbols.UNDEFINED, "undefined").replace("" + MathematicalSymbols.PI, "PI").replace("" + MathematicalSymbols.EULER_NUMBER, "EULER_NUMBER").replace("" + MathematicalSymbols.X, "X").replace("" + MathematicalSymbols.Y, "Y");
}
public void println(String str) {
println(0, str);
}
public void println(int level) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out);
} else {
println(System.out);
}
}
}
public void println(int level, String str) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + str);
} else {
println(System.out, "[" + time + "]" + str);
}
}
}
public void print(int level, String str) {
if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) {
print(System.out, str);
} else {
print(System.out, str);
}
}
}
public void println(int level, String prefix, String str) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "][" + prefix + "]" + str);
} else {
println(System.out, "[" + time + "][" + prefix + "]" + str);
}
}
}
public void println(int level, String... parts) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
String output = "";
for (int i = 0; i < parts.length; i++) {
if (i + 1 == parts.length) {
output += parts[i];
} else {
output += "[" + parts[i] + "]";
}
}
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + output);
} else {
println(System.out, "[" + time + "]" + output);
}
}
}
private String getTimeString() {
return System.currentTimeMillis()+"";
}
int before = 0;
boolean due = false;
}
public static ConsoleUtils.AdvancedOutputStream out = new ConsoleUtils.AdvancedOutputStream();
public static final int OUTPUTLEVEL_NODEBUG = 0;
public static final int OUTPUTLEVEL_DEBUG_MIN = 1;
public static final int OUTPUTLEVEL_DEBUG_VERBOSE = 4;
}

View File

@ -0,0 +1,28 @@
package org.warp.picalculator;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.warp.picalculator.gui.expression.blocks.Block;
public final class PlatformUtils {
public static final boolean isJavascript = true;
public static String osName = "JavaScript";
public static void setThreadName(Thread t, String string) {
}
public static void setDaemon(Thread kt) {
}
public static void setDaemon(Thread kt, boolean val) {
}
public static void throwNewExceptionInInitializerError(String string) {
throw new NullPointerException(string);
}
public static String[] stacktraceToString(Error e) {
return e.getMessage().toUpperCase().replace("\r", "").split("\n");
}
}

View File

@ -0,0 +1,11 @@
package org.warp.picalculator;
public class ZipUtils {
public static void zip(String targetPath, String destinationFilePath, String password) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
}

View File

@ -0,0 +1,339 @@
/*
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
/*
*
*
*
*
*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package org.warp.picalculator.deps;
import java.util.function.IntUnaryOperator;
import java.util.function.IntBinaryOperator;
import sun.misc.Unsafe;
/**
* An {@code int} value that may be updated atomically. See the
* {@link java.util.concurrent.atomic} package specification for
* description of the properties of atomic variables. An
* {@code AtomicInteger} is used in applications such as atomically
* incremented counters, and cannot be used as a replacement for an
* {@link java.lang.Integer}. However, this class does extend
* {@code Number} to allow uniform access by tools and utilities that
* deal with numerically-based classes.
*
* @since 1.5
* @author Doug Lea
*/
public class DAtomicInteger extends Number implements java.io.Serializable {
private static final long serialVersionUID = 6214790243416807050L;
private volatile int value;
/**
* Creates a new AtomicInteger with the given initial value.
*
* @param initialValue the initial value
*/
public DAtomicInteger(int initialValue) {
value = initialValue;
}
/**
* Creates a new AtomicInteger with initial value {@code 0}.
*/
public DAtomicInteger() {
}
/**
* Gets the current value.
*
* @return the current value
*/
public final int get() {
return value;
}
/**
* Sets to the given value.
*
* @param newValue the new value
*/
public final void set(int newValue) {
value = newValue;
}
/**
* Eventually sets to the given value.
*
* @param newValue the new value
* @since 1.6
*/
public final void lazySet(int newValue) {
value = newValue;
}
/**
* Atomically sets to the given value and returns the old value.
*
* @param newValue the new value
* @return the previous value
*/
public final int getAndSet(int newValue) {
int oldV = value;
value = newValue;
return oldV;
}
/**
* Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value.
*
* @param expect the expected value
* @param update the new value
* @return {@code true} if successful. False return indicates that
* the actual value was not equal to the expected value.
*/
public final boolean compareAndSet(int expect, int update) {
boolean equal = (value == expect);
value = update;
return equal;
}
/**
* Atomically sets the value to the given updated value
* if the current value {@code ==} the expected value.
*
* <p><a href="package-summary.html#weakCompareAndSet">May fail
* spuriously and does not provide ordering guarantees</a>, so is
* only rarely an appropriate alternative to {@code compareAndSet}.
*
* @param expect the expected value
* @param update the new value
* @return {@code true} if successful
*/
public final boolean weakCompareAndSet(int expect, int update) {
return compareAndSet(expect, update);
}
/**
* Atomically increments by one the current value.
*
* @return the previous value
*/
public final int getAndIncrement() {
int oldV = value;
value++;
return oldV;
}
/**
* Atomically decrements by one the current value.
*
* @return the previous value
*/
public final int getAndDecrement() {
int oldV = value;
value--;
return oldV;
}
/**
* Atomically adds the given value to the current value.
*
* @param delta the value to add
* @return the previous value
*/
public final int getAndAdd(int delta) {
int oldV = value;
value+=delta;
return oldV;
}
/**
* Atomically increments by one the current value.
*
* @return the updated value
*/
public final int incrementAndGet() {
value++;
return value;
}
/**
* Atomically decrements by one the current value.
*
* @return the updated value
*/
public final int decrementAndGet() {
value--;
return value;
}
/**
* Atomically adds the given value to the current value.
*
* @param delta the value to add
* @return the updated value
*/
public final int addAndGet(int delta) {
value+=delta;
return value;
}
/**
* Atomically updates the current value with the results of
* applying the given function, returning the previous value. The
* function should be side-effect-free, since it may be re-applied
* when attempted updates fail due to contention among threads.
*
* @param updateFunction a side-effect-free function
* @return the previous value
* @since 1.8
*/
public final int getAndUpdate(IntUnaryOperator updateFunction) {
int prev, next;
do {
prev = get();
next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next));
return prev;
}
/**
* Atomically updates the current value with the results of
* applying the given function, returning the updated value. The
* function should be side-effect-free, since it may be re-applied
* when attempted updates fail due to contention among threads.
*
* @param updateFunction a side-effect-free function
* @return the updated value
* @since 1.8
*/
public final int updateAndGet(IntUnaryOperator updateFunction) {
int prev, next;
do {
prev = get();
next = updateFunction.applyAsInt(prev);
} while (!compareAndSet(prev, next));
return next;
}
/**
* Atomically updates the current value with the results of
* applying the given function to the current and given values,
* returning the previous value. The function should be
* side-effect-free, since it may be re-applied when attempted
* updates fail due to contention among threads. The function
* is applied with the current value as its first argument,
* and the given update as the second argument.
*
* @param x the update value
* @param accumulatorFunction a side-effect-free function of two arguments
* @return the previous value
* @since 1.8
*/
public final int getAndAccumulate(int x,
IntBinaryOperator accumulatorFunction) {
int prev, next;
do {
prev = get();
next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return prev;
}
/**
* Atomically updates the current value with the results of
* applying the given function to the current and given values,
* returning the updated value. The function should be
* side-effect-free, since it may be re-applied when attempted
* updates fail due to contention among threads. The function
* is applied with the current value as its first argument,
* and the given update as the second argument.
*
* @param x the update value
* @param accumulatorFunction a side-effect-free function of two arguments
* @return the updated value
* @since 1.8
*/
public final int accumulateAndGet(int x,
IntBinaryOperator accumulatorFunction) {
int prev, next;
do {
prev = get();
next = accumulatorFunction.applyAsInt(prev, x);
} while (!compareAndSet(prev, next));
return next;
}
/**
* Returns the String representation of the current value.
* @return the String representation of the current value
*/
public String toString() {
return Integer.toString(get());
}
/**
* Returns the value of this {@code AtomicInteger} as an {@code int}.
*/
public int intValue() {
return get();
}
/**
* Returns the value of this {@code AtomicInteger} as a {@code long}
* after a widening primitive conversion.
* @jls 5.1.2 Widening Primitive Conversions
*/
public long longValue() {
return (long)get();
}
/**
* Returns the value of this {@code AtomicInteger} as a {@code float}
* after a widening primitive conversion.
* @jls 5.1.2 Widening Primitive Conversions
*/
public float floatValue() {
return (float)get();
}
/**
* Returns the value of this {@code AtomicInteger} as a {@code double}
* after a widening primitive conversion.
* @jls 5.1.2 Widening Primitive Conversions
*/
public double doubleValue() {
return (double)get();
}
}

View File

@ -0,0 +1,25 @@
package org.warp.picalculator.deps;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
public class DEngine {
public static GraphicEngine newCPUEngine() {
return null;
}
public static GraphicEngine newGPUEngine() {
return null;
}
public static GraphicEngine newHeadless24bitEngine() {
return null;
}
public static GraphicEngine newHeadless256Engine() {
return null;
}
public static GraphicEngine newHeadless8Engine() {
return null;
}
public static GraphicEngine newFBEngine() {
return null;
}
}

View File

@ -0,0 +1,45 @@
package org.warp.picalculator.deps;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DGpio {
public static final int OUTPUT = 0;
public static final int PWM_OUTPUT = 1;
public static final int INPUT = 2;
public static final int HIGH = 3;
public static final int LOW = 4;
public static final Object UnknownBoardType = new Object();
public static void wiringPiSetupPhys() {
}
public static void pinMode(int i, int type) {
}
public static void digitalWrite(int pin, int val) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static void digitalWrite(int pin, boolean val) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static void pwmWrite(int pin, int val) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static void delayMicroseconds(int t) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static int digitalRead(int pin) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
public static Object getBoardType() {
return new Object();
}
}

View File

@ -0,0 +1,13 @@
package org.warp.picalculator.deps;
import java.io.PrintWriter;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DJDTCompiler {
public static boolean compile(String[] strings, PrintWriter printWriter, PrintWriter printWriter2) {
throw new java.lang.UnsupportedOperationException("Not implemented.");
}
}

View File

@ -0,0 +1,7 @@
package org.warp.picalculator.deps;
public class DSystem {
public static final void exit(int code) {
System.err.println("====================PROGRAM END====================");
}
}

View File

@ -0,0 +1,14 @@
package org.warp.picalculator.deps;
import java.io.File;
import java.nio.file.Path;
public class StorageUtils {
public static final boolean exists(Path f) {
return f.toFile().exists();
}
public static Path get(String path) {
return new File(path).toPath();
}
}

View File

@ -0,0 +1,568 @@
package org.warp.picalculator.deps.jogamp;
import org.warp.picalculator.ClassUtils;
import org.warp.picalculator.ClassUtils.Var;
public class DJogamp {
//
// Unicode: Non printable controls: [0x00 - 0x1F]
//
/**
* This value, {@value}, is used to indicate that the keyCode is unknown.
*/
public static final short VK_UNDEFINED = (short) 0x0;
static final short VK_FREE01 = (short) 0x01;
/** Constant for the HOME function key. ASCII: Start Of Text. */
public static final short VK_HOME = (short) 0x02;
/** Constant for the END function key. ASCII: End Of Text. */
public static final short VK_END = (short) 0x03;
/** Constant for the END function key. ASCII: End Of Transmission. */
public static final short VK_FINAL = (short) 0x04;
/** Constant for the PRINT function key. ASCII: Enquiry. */
public static final short VK_PRINTSCREEN = (short) 0x05;
static final short VK_FREE06 = (short) 0x06;
static final short VK_FREE07 = (short) 0x07;
/** Constant for the BACK SPACE key "\b", matching ASCII. Printable! */
public static final short VK_BACK_SPACE = (short) 0x08;
/** Constant for the HORIZ TAB key "\t", matching ASCII. Printable! */
public static final short VK_TAB = (short) 0x09;
/** LINE_FEED "\n", matching ASCII, n/a on keyboard. */
static final short VK_FREE0A = (short) 0x0A;
/** Constant for the PAGE DOWN function key. ASCII: Vertical Tabulation. */
public static final short VK_PAGE_DOWN = (short) 0x0B;
/** Constant for the CLEAR key, i.e. FORM FEED, matching ASCII. */
public static final short VK_CLEAR = (short) 0x0C;
/** Constant for the ENTER key, i.e. CARRIAGE RETURN, matching ASCII. Printable! */
public static final short VK_ENTER = (short) 0x0D;
static final short VK_FREE0E = (short) 0x0E;
/** Constant for the CTRL function key. ASCII: shift-in. */
public static final short VK_SHIFT = (short) 0x0F;
/** Constant for the PAGE UP function key. ASCII: Data Link Escape. */
public static final short VK_PAGE_UP = (short) 0x10;
/** Constant for the CTRL function key. ASCII: device-ctrl-one. */
public static final short VK_CONTROL = (short) 0x11;
/** Constant for the left ALT function key. ASCII: device-ctrl-two. */
public static final short VK_ALT = (short) 0x12;
/** Constant for the ALT_GRAPH function key, i.e. right ALT key. ASCII: device-ctrl-three. */
public static final short VK_ALT_GRAPH = (short) 0x13;
/** Constant for the CAPS LOCK function key. ASCII: device-ctrl-four. */
public static final short VK_CAPS_LOCK = (short) 0x14;
static final short VK_FREE15 = (short) 0x15;
/** Constant for the PAUSE function key. ASCII: sync-idle. */
public static final short VK_PAUSE = (short) 0x16;
/** <b>scroll lock</b> key. ASCII: End Of Transmission Block. */
public static final short VK_SCROLL_LOCK = (short) 0x17;
/** Constant for the CANCEL function key. ASCII: Cancel. */
public static final short VK_CANCEL = (short) 0x18;
static final short VK_FREE19 = (short) 0x19;
/** Constant for the INSERT function key. ASCII: Substitute. */
public static final short VK_INSERT = (short) 0x1A;
/** Constant for the ESCAPE function key. ASCII: Escape. */
public static final short VK_ESCAPE = (short) 0x1B;
/** Constant for the Convert function key, Japanese "henkan". ASCII: File Separator. */
public static final short VK_CONVERT = (short) 0x1C;
/** Constant for the Don't Convert function key, Japanese "muhenkan". ASCII: Group Separator.*/
public static final short VK_NONCONVERT = (short) 0x1D;
/** Constant for the Accept or Commit function key, Japanese "kakutei". ASCII: Record Separator.*/
public static final short VK_ACCEPT = (short) 0x1E;
/** Constant for the Mode Change (?). ASCII: Unit Separator.*/
public static final short VK_MODECHANGE = (short) 0x1F;
//
// Unicode: Printable [0x20 - 0x7E]
// NOTE: Collision of 'a' - 'x' [0x61 .. 0x78], used for keyCode/keySym Fn function keys
//
/** Constant for the SPACE function key. ASCII: SPACE. */
public static final short VK_SPACE = (short) 0x20;
/** Constant for the "!" key. */
public static final short VK_EXCLAMATION_MARK = (short) 0x21;
/** Constant for the """ key. */
public static final short VK_QUOTEDBL = (short) 0x22;
/** Constant for the "#" key. */
public static final short VK_NUMBER_SIGN = (short) 0x23;
/** Constant for the "$" key. */
public static final short VK_DOLLAR = (short) 0x24;
/** Constant for the "%" key. */
public static final short VK_PERCENT = (short) 0x25;
/** Constant for the "&" key. */
public static final short VK_AMPERSAND = (short) 0x26;
/** Constant for the "'" key. */
public static final short VK_QUOTE = (short) 0x27;
/** Constant for the "(" key. */
public static final short VK_LEFT_PARENTHESIS = (short) 0x28;
/** Constant for the ")" key. */
public static final short VK_RIGHT_PARENTHESIS = (short) 0x29;
/** Constant for the "*" key */
public static final short VK_ASTERISK = (short) 0x2A;
/** Constant for the "+" key. */
public static final short VK_PLUS = (short) 0x2B;
/** Constant for the comma key, "," */
public static final short VK_COMMA = (short) 0x2C;
/** Constant for the minus key, "-" */
public static final short VK_MINUS = (short) 0x2D;
/** Constant for the period key, "." */
public static final short VK_PERIOD = (short) 0x2E;
/** Constant for the forward slash key, "/" */
public static final short VK_SLASH = (short) 0x2F;
/** VK_0 thru VK_9 are the same as UTF16/ASCII '0' thru '9' [0x30 - 0x39] */
public static final short VK_0 = (short) 0x30;
/** See {@link #VK_0}. */
public static final short VK_1 = (short) 0x31;
/** See {@link #VK_0}. */
public static final short VK_2 = (short) 0x32;
/** See {@link #VK_0}. */
public static final short VK_3 = (short) 0x33;
/** See {@link #VK_0}. */
public static final short VK_4 = (short) 0x34;
/** See {@link #VK_0}. */
public static final short VK_5 = (short) 0x35;
/** See {@link #VK_0}. */
public static final short VK_6 = (short) 0x36;
/** See {@link #VK_0}. */
public static final short VK_7 = (short) 0x37;
/** See {@link #VK_0}. */
public static final short VK_8 = (short) 0x38;
/** See {@link #VK_0}. */
public static final short VK_9 = (short) 0x39;
/** Constant for the ":" key. */
public static final short VK_COLON = (short) 0x3A;
/** Constant for the semicolon key, ";" */
public static final short VK_SEMICOLON = (short) 0x3B;
/** Constant for the equals key, "<" */
public static final short VK_LESS = (short) 0x3C;
/** Constant for the equals key, "=" */
public static final short VK_EQUALS = (short) 0x3D;
/** Constant for the equals key, ">" */
public static final short VK_GREATER = (short) 0x3E;
/** Constant for the equals key, "?" */
public static final short VK_QUESTIONMARK = (short) 0x3F;
/** Constant for the equals key, "@" */
public static final short VK_AT = (short) 0x40;
/** VK_A thru VK_Z are the same as Capital UTF16/ASCII 'A' thru 'Z' (0x41 - 0x5A) */
public static final short VK_A = (short) 0x41;
/** See {@link #VK_A}. */
public static final short VK_B = (short) 0x42;
/** See {@link #VK_A}. */
public static final short VK_C = (short) 0x43;
/** See {@link #VK_A}. */
public static final short VK_D = (short) 0x44;
/** See {@link #VK_A}. */
public static final short VK_E = (short) 0x45;
/** See {@link #VK_A}. */
public static final short VK_F = (short) 0x46;
/** See {@link #VK_A}. */
public static final short VK_G = (short) 0x47;
/** See {@link #VK_A}. */
public static final short VK_H = (short) 0x48;
/** See {@link #VK_A}. */
public static final short VK_I = (short) 0x49;
/** See {@link #VK_A}. */
public static final short VK_J = (short) 0x4A;
/** See {@link #VK_A}. */
public static final short VK_K = (short) 0x4B;
/** See {@link #VK_A}. */
public static final short VK_L = (short) 0x4C;
/** See {@link #VK_A}. */
public static final short VK_M = (short) 0x4D;
/** See {@link #VK_A}. */
public static final short VK_N = (short) 0x4E;
/** See {@link #VK_A}. */
public static final short VK_O = (short) 0x4F;
/** See {@link #VK_A}. */
public static final short VK_P = (short) 0x50;
/** See {@link #VK_A}. */
public static final short VK_Q = (short) 0x51;
/** See {@link #VK_A}. */
public static final short VK_R = (short) 0x52;
/** See {@link #VK_A}. */
public static final short VK_S = (short) 0x53;
/** See {@link #VK_A}. */
public static final short VK_T = (short) 0x54;
/** See {@link #VK_A}. */
public static final short VK_U = (short) 0x55;
/** See {@link #VK_A}. */
public static final short VK_V = (short) 0x56;
/** See {@link #VK_A}. */
public static final short VK_W = (short) 0x57;
/** See {@link #VK_A}. */
public static final short VK_X = (short) 0x58;
/** See {@link #VK_A}. */
public static final short VK_Y = (short) 0x59;
/** See {@link #VK_A}. */
public static final short VK_Z = (short) 0x5A;
/** Constant for the open bracket key, "[" */
public static final short VK_OPEN_BRACKET = (short) 0x5B;
/**Constant for the back slash key, "\" */
public static final short VK_BACK_SLASH = (short) 0x5C;
/** Constant for the close bracket key, "]" */
public static final short VK_CLOSE_BRACKET = (short) 0x5D;
/** Constant for the "^" key. */
public static final short VK_CIRCUMFLEX = (short) 0x5E;
/** Constant for the "_" key */
public static final short VK_UNDERSCORE = (short) 0x5F;
/** Constant for the "`" key */
public static final short VK_BACK_QUOTE = (short) 0x60;
/** Small UTF/ASCII 'a' thru 'z' (0x61 - 0x7a) - Not used for keyCode / keySym. */
/**
* Constant for the F<i>n</i> function keys.
* <p>
* F1..F24, i.e. F<i>n</i>, are mapped from on <code>0x60+n</code> -> <code>[0x61 .. 0x78]</code>.
* </p>
* <p>
* <b>Warning:</b> The F<i>n</i> function keys <b>do collide</b> with unicode characters small 'a' thru 'x'!<br/>
* See <a href="#unicodeCollision">Unicode Collision</a> for details.
* </p>
*/
public static final short VK_F1 = (short) ( 0x60+ 1 );
/** Constant for the F2 function key. See {@link #VK_F1}. */
public static final short VK_F2 = (short) ( 0x60+ 2 );
/** Constant for the F3 function key. See {@link #VK_F1}. */
public static final short VK_F3 = (short) ( 0x60+ 3 );
/** Constant for the F4 function key. See {@link #VK_F1}. */
public static final short VK_F4 = (short) ( 0x60+ 4 );
/** Constant for the F5 function key. See {@link #VK_F1}. */
public static final short VK_F5 = (short) ( 0x60+ 5 );
/** Constant for the F6 function key. See {@link #VK_F1}. */
public static final short VK_F6 = (short) ( 0x60+ 6 );
/** Constant for the F7 function key. See {@link #VK_F1}. */
public static final short VK_F7 = (short) ( 0x60+ 7 );
/** Constant for the F8 function key. See {@link #VK_F1}. */
public static final short VK_F8 = (short) ( 0x60+ 8 );
/** Constant for the F9 function key. See {@link #VK_F1}. */
public static final short VK_F9 = (short) ( 0x60+ 9 );
/** Constant for the F11 function key. See {@link #VK_F1}. */
public static final short VK_F10 = (short) ( 0x60+10 );
/** Constant for the F11 function key. See {@link #VK_F1}. */
public static final short VK_F11 = (short) ( 0x60+11 );
/** Constant for the F12 function key. See {@link #VK_F1}.*/
public static final short VK_F12 = (short) ( 0x60+12 );
/** Constant for the F13 function key. See {@link #VK_F1}. */
public static final short VK_F13 = (short) ( 0x60+13 );
/** Constant for the F14 function key. See {@link #VK_F1}. */
public static final short VK_F14 = (short) ( 0x60+14 );
/** Constant for the F15 function key. See {@link #VK_F1}. */
public static final short VK_F15 = (short) ( 0x60+15 );
/** Constant for the F16 function key. See {@link #VK_F1}. */
public static final short VK_F16 = (short) ( 0x60+16 );
/** Constant for the F17 function key. See {@link #VK_F1}. */
public static final short VK_F17 = (short) ( 0x60+17 );
/** Constant for the F18 function key. See {@link #VK_F1}. */
public static final short VK_F18 = (short) ( 0x60+18 );
/** Constant for the F19 function key. See {@link #VK_F1}. */
public static final short VK_F19 = (short) ( 0x60+19 );
/** Constant for the F20 function key. See {@link #VK_F1}. */
public static final short VK_F20 = (short) ( 0x60+20 );
/** Constant for the F21 function key. See {@link #VK_F1}. */
public static final short VK_F21 = (short) ( 0x60+21 );
/** Constant for the F22 function key. See {@link #VK_F1}. */
public static final short VK_F22 = (short) ( 0x60+22 );
/** Constant for the F23 function key. See {@link #VK_F1}. */
public static final short VK_F23 = (short) ( 0x60+23 );
/** Constant for the F24 function key. See {@link #VK_F1}. */
public static final short VK_F24 = (short) ( 0x60+24 );
/** Constant for the "{" key */
public static final short VK_LEFT_BRACE = (short) 0x7B;
/** Constant for the "|" key */
public static final short VK_PIPE = (short) 0x7C;
/** Constant for the "}" key */
public static final short VK_RIGHT_BRACE = (short) 0x7D;
/** Constant for the "~" key, matching ASCII */
public static final short VK_TILDE = (short) 0x7E;
//
// Unicode: Non printable controls: [0x7F - 0x9F]
//
// Numpad keys [0x7F - 0x8E] are printable
//
/** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
public static final short VK_SEPARATOR = (short) 0x7F;
/** Numeric keypad VK_NUMPAD0 thru VK_NUMPAD9 are mapped to UTF control (0x80 - 0x89). Non printable UTF control. */
public static final short VK_NUMPAD0 = (short) 0x80;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD1 = (short) 0x81;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD2 = (short) 0x82;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD3 = (short) 0x83;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD4 = (short) 0x84;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD5 = (short) 0x85;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD6 = (short) 0x86;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD7 = (short) 0x87;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD8 = (short) 0x88;
/** See {@link #VK_NUMPAD0}. */
public static final short VK_NUMPAD9 = (short) 0x89;
/** Numeric keypad <b>decimal separator</b> key. Non printable UTF control. */
public static final short VK_DECIMAL = (short) 0x8A;
/** Numeric keypad <b>add</b> key. Non printable UTF control. */
public static final short VK_ADD = (short) 0x8B;
/** Numeric keypad <b>subtract</b> key. Non printable UTF control. */
public static final short VK_SUBTRACT = (short) 0x8C;
/** Numeric keypad <b>multiply</b> key. Non printable UTF control. */
public static final short VK_MULTIPLY = (short) 0x8D;
/** Numeric keypad <b>divide</b> key. Non printable UTF control. */
public static final short VK_DIVIDE = (short) 0x8E;
/** Constant for the DEL key, matching ASCII. Non printable UTF control. */
public static final short VK_DELETE = (short) 0x93;
/** Numeric keypad <b>num lock</b> key. Non printable UTF control. */
public static final short VK_NUM_LOCK = (short) 0x94;
/** Constant for the cursor- or numerical-pad <b>left</b> arrow key. Non printable UTF control. */
public static final short VK_LEFT = (short) 0x95;
/** Constant for the cursor- or numerical-pad <b>up</b> arrow key. Non printable UTF control. */
public static final short VK_UP = (short) 0x96;
/** Constant for the cursor- or numerical-pad <b>right</b> arrow key. Non printable UTF control. */
public static final short VK_RIGHT = (short) 0x97;
/** Constant for the cursor- or numerical pad <b>down</b> arrow key. Non printable UTF control. */
public static final short VK_DOWN = (short) 0x98;
/** Constant for the Context Menu key. Non printable UTF control. */
public static final short VK_CONTEXT_MENU = (short) 0x99;
/**
* Constant for the MS "Windows" function key.
* It is used for both the left and right version of the key.
*/
public static final short VK_WINDOWS = (short) 0x9A;
/** Constant for the Meta function key. */
public static final short VK_META = (short) 0x9B;
/** Constant for the Help function key. */
public static final short VK_HELP = (short) 0x9C;
/** Constant for the Compose function key. */
public static final short VK_COMPOSE = (short) 0x9D;
/** Constant for the Begin function key. */
public static final short VK_BEGIN = (short) 0x9E;
/** Constant for the Stop function key. */
public static final short VK_STOP = (short) 0x9F;
//
// Unicode: Printable [0x00A0 - 0xDFFF]
//
/** Constant for the inverted exclamation mark key. */
public static final short VK_INVERTED_EXCLAMATION_MARK = (short) 0xA1;
/** Constant for the Euro currency sign key. */
public static final short VK_EURO_SIGN = (short) 0x20AC;
//
// Unicode: Private 0xE000 - 0xF8FF (Marked Non-Printable)
//
/* for Sun keyboards */
public static final short VK_CUT = (short) 0xF879;
public static final short VK_COPY = (short) 0xF87A;
public static final short VK_PASTE = (short) 0xF87B;
public static final short VK_UNDO = (short) 0xF87C;
public static final short VK_AGAIN = (short) 0xF87D;
public static final short VK_FIND = (short) 0xF87E;
public static final short VK_PROPS = (short) 0xF87F;
/* for input method support on Asian Keyboards */
/**
* Constant for the input method on/off key.
*/
/* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
public static final short VK_INPUT_METHOD_ON_OFF = (short) 0xF890;
/**
* Constant for the Code Input function key.
*/
/* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
public static final short VK_CODE_INPUT = (short) 0xF891;
/**
* Constant for the Roman Characters function key.
*/
/* Japanese PC 106 keyboard: roumaji */
public static final short VK_ROMAN_CHARACTERS = (short) 0xF892;
/**
* Constant for the All Candidates function key.
*/
/* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
public static final short VK_ALL_CANDIDATES = (short) 0xF893;
/**
* Constant for the Previous Candidate function key.
*/
/* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
public static final short VK_PREVIOUS_CANDIDATE = (short) 0xF894;
/**
* Constant for the Alphanumeric function key.
*/
/* Japanese PC 106 keyboard: eisuu */
public static final short VK_ALPHANUMERIC = (short) 0xF895;
/**
* Constant for the Katakana function key.
*/
/* Japanese PC 106 keyboard: katakana */
public static final short VK_KATAKANA = (short) 0xF896;
/**
* Constant for the Hiragana function key.
*/
/* Japanese PC 106 keyboard: hiragana */
public static final short VK_HIRAGANA = (short) 0xF897;
/**
* Constant for the Full-Width Characters function key.
*/
/* Japanese PC 106 keyboard: zenkaku */
public static final short VK_FULL_WIDTH = (short) 0xF898;
/**
* Constant for the Half-Width Characters function key.
*/
/* Japanese PC 106 keyboard: hankaku */
public static final short VK_HALF_WIDTH = (short) 0xF89A;
/**
* Constant for the Japanese-Katakana function key.
* This key switches to a Japanese input method and selects its Katakana input mode.
*/
/* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
public static final short VK_JAPANESE_KATAKANA = (short) 0xF89B;
/**
* Constant for the Japanese-Hiragana function key.
* This key switches to a Japanese input method and selects its Hiragana input mode.
*/
/* Japanese Macintosh keyboard */
public static final short VK_JAPANESE_HIRAGANA = (short) 0xF89C;
/**
* Constant for the Japanese-Roman function key.
* This key switches to a Japanese input method and selects its Roman-Direct input mode.
*/
/* Japanese Macintosh keyboard */
public static final short VK_JAPANESE_ROMAN = (short) 0xF89D;
/**
* Constant for the locking Kana function key.
* This key locks the keyboard into a Kana layout.
*/
/* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
public static final short VK_KANA_LOCK = (short) 0xF89F;
/**
* Constant for Keyboard became invisible, e.g. Android's soft keyboard Back button hit while keyboard is visible.
*/
public static final short VK_KEYBOARD_INVISIBLE = (short) 0xF8FF;
}

View File

@ -31,7 +31,8 @@ import java.nio.file.ProviderNotFoundException;
import java.nio.file.StandardCopyOption;
/**
* A simple library class which helps with loading dynamic libraries stored in the
* A simple library class which helps with loading dynamic libraries stored in
* the
* JAR archive. These libraries usualy contain implementation of some methods in
* native code (using JNI - Java Native Interface).
*
@ -40,106 +41,112 @@ import java.nio.file.StandardCopyOption;
*
*/
public class NativeUtils {
/**
* The minimum length a prefix for a file has to have according to {@link File#createTempFile(String, String)}}.
*/
private static final int MIN_PREFIX_LENGTH = 3;
/**
* Temporary directory which will contain the DLLs.
*/
private static File temporaryDir;
/**
* The minimum length a prefix for a file has to have according to
* {@link File#createTempFile(String, String)}}.
*/
private static final int MIN_PREFIX_LENGTH = 3;
/**
* Private constructor - this class will never be instanced
*/
private NativeUtils() {
}
/**
* Temporary directory which will contain the DLLs.
*/
private static File temporaryDir;
/**
* Loads library from current JAR archive
*
* The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after
* exiting.
* Method uses String as filename because the pathname is "abstract", not system-dependent.
*
* @param path The path of file inside JAR as absolute path (beginning with '/'), e.g. /package/File.ext
* @throws IOException If temporary file creation or read/write operation fails
* @throws IllegalArgumentException If source file (param path) does not exist
* @throws IllegalArgumentException If the path is not absolute or if the filename is shorter than three characters
* (restriction of {@link File#createTempFile(java.lang.String, java.lang.String)}).
* @throws FileNotFoundException If the file could not be found inside the JAR.
*/
public static void loadLibraryFromJar(String path) throws IOException {
if (!path.startsWith("/")) {
throw new IllegalArgumentException("The path has to be absolute (start with '/').");
}
// Obtain filename from path
String[] parts = path.split("/");
String filename = (parts.length > 1) ? parts[parts.length - 1] : null;
// Check if the filename is okay
if (filename == null || filename.length() < MIN_PREFIX_LENGTH) {
throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
}
// Prepare temporary file
if (temporaryDir == null) {
temporaryDir = createTempDirectory("nativeutils");
temporaryDir.deleteOnExit();
}
/**
* Private constructor - this class will never be instanced
*/
private NativeUtils() {}
File temp = new File(temporaryDir, filename);
/**
* Loads library from current JAR archive
*
* The file from JAR is copied into system temporary directory and then
* loaded. The temporary file is deleted after
* exiting.
* Method uses String as filename because the pathname is "abstract", not
* system-dependent.
*
* @param path
* The path of file inside JAR as absolute path (beginning with
* '/'), e.g. /package/File.ext
* @throws IOException
* If temporary file creation or read/write operation fails
* @throws IllegalArgumentException
* If source file (param path) does not exist
* @throws IllegalArgumentException
* If the path is not absolute or if the filename is shorter
* than three characters
* (restriction of
* {@link File#createTempFile(java.lang.String, java.lang.String)}).
* @throws FileNotFoundException
* If the file could not be found inside the JAR.
*/
public static void loadLibraryFromJar(String path) throws IOException {
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
temp.delete();
throw e;
} catch (NullPointerException e) {
temp.delete();
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
}
if (!path.startsWith("/")) {
throw new IllegalArgumentException("The path has to be absolute (start with '/').");
}
try {
System.load(temp.getAbsolutePath());
} finally {
if (isPosixCompliant()) {
// Assume POSIX compliant file system, can be deleted after loading
temp.delete();
} else {
// Assume non-POSIX, and don't delete until last file descriptor closed
temp.deleteOnExit();
}
}
}
// Obtain filename from path
final String[] parts = path.split("/");
final String filename = (parts.length > 1) ? parts[parts.length - 1] : null;
private static boolean isPosixCompliant() {
try {
if (FileSystems.getDefault()
.supportedFileAttributeViews()
.contains("posix")) {
return true;
}
return false;
} catch (FileSystemNotFoundException
| ProviderNotFoundException
| SecurityException e) {
return false;
}
}
private static File createTempDirectory(String prefix) throws IOException
{
String tempDir = System.getProperty("java.io.tmpdir");
File generatedDir = new File(tempDir, prefix + System.nanoTime());
if (!generatedDir.mkdir())
throw new IOException("Failed to create temp directory " + generatedDir.getName());
return generatedDir;
}
// Check if the filename is okay
if (filename == null || filename.length() < MIN_PREFIX_LENGTH) {
throw new IllegalArgumentException("The filename has to be at least 3 characters long.");
}
// Prepare temporary file
if (temporaryDir == null) {
temporaryDir = createTempDirectory("nativeutils");
temporaryDir.deleteOnExit();
}
final File temp = new File(temporaryDir, filename);
try (InputStream is = NativeUtils.class.getResourceAsStream(path)) {
Files.copy(is, temp.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (final IOException e) {
temp.delete();
throw e;
} catch (final NullPointerException e) {
temp.delete();
throw new FileNotFoundException("File " + path + " was not found inside JAR.");
}
try {
System.load(temp.getAbsolutePath());
} finally {
if (isPosixCompliant()) {
// Assume POSIX compliant file system, can be deleted after loading
temp.delete();
} else {
// Assume non-POSIX, and don't delete until last file descriptor closed
temp.deleteOnExit();
}
}
}
private static boolean isPosixCompliant() {
try {
if (FileSystems.getDefault().supportedFileAttributeViews().contains("posix")) {
return true;
}
return false;
} catch (FileSystemNotFoundException | ProviderNotFoundException | SecurityException e) {
return false;
}
}
private static File createTempDirectory(String prefix) throws IOException {
final String tempDir = System.getProperty("java.io.tmpdir");
final File generatedDir = new File(tempDir, prefix + System.nanoTime());
if (!generatedDir.mkdir()) {
throw new IOException("Failed to create temp directory " + generatedDir.getName());
}
return generatedDir;
}
}

View File

@ -3,13 +3,13 @@ package org.nevec.rjm;
import java.math.MathContext;
import java.math.RoundingMode;
import org.warp.picalculator.Utils;
import org.warp.picalculator.ConsoleUtils;
public final class SafeMathContext {
public static MathContext newMathContext(int precision) {
if (precision <= 0) {
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
ConsoleUtils.out.print(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
precision = 1;
}
return new MathContext(precision);
@ -17,7 +17,7 @@ public final class SafeMathContext {
public static MathContext newMathContext(int precision, RoundingMode roundingMode) {
if (precision <= 0) {
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
ConsoleUtils.out.print(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
precision = 1;
}
return new MathContext(precision, roundingMode);

View File

@ -0,0 +1,244 @@
package org.warp.picalculator;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ClassUtils {
public static Class<?> classLoader;
public static Object invokeStaticMethod(String path, Var<?>... vars) {
return invokeMethod(path, null, vars);
}
@SuppressWarnings("rawtypes")
public static Object invokeMethod(String path, Object instance, Var<?>... vars) {
Class[] classes = new Class[vars.length];
Object[] objects = new Object[vars.length];
String[] blob = path.split("\\.");
String className = String.join(".", Arrays.copyOfRange(blob, 0, blob.length-1));
String methodName = blob[blob.length-1];
int index = 0;
for (Var<?> v : vars) {
classes[index] = v.getType();
objects[index] = v.getVar();
index++;
}
try {
return classLoader.getClassLoader().loadClass(className).getMethod(methodName, classes).invoke(instance, objects);
} catch (InvocationTargetException ex) {
NullPointerException exc = new NullPointerException();
exc.addSuppressed(ex);
throw exc;
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
}
@SuppressWarnings("rawtypes")
public static Object newClassInstance(String className, Var<?>... vars) {
Class[] classes = new Class[vars.length];
Object[] objects = new Object[vars.length];
int index = 0;
for (Var<?> v : vars) {
classes[index] = v.getType();
objects[index] = v.getVar();
index++;
}
try {
return classLoader.getClassLoader().loadClass(className).getDeclaredConstructor(classes).newInstance(objects);
} catch (InvocationTargetException ex) {
NullPointerException exc = new NullPointerException();
exc.addSuppressed(ex);
throw exc;
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
}
@SuppressWarnings("unchecked")
public static <T> T getStaticField(String path, Class<T> type) {
try {
String[] blob = path.split("\\.");
String className = String.join(".", Arrays.copyOfRange(blob, 0, blob.length-1));
String var = blob[blob.length-1];
return (T) classLoader.getClassLoader().loadClass(className).getField(var).get(null);
} catch (ClassNotFoundException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
}
public static <T> Var<T> getStaticFieldVar(String path, Class<T> type) {
T obj = getStaticField(path, type);
return new Var<T>(obj, type);
}
public static int getEnumIndex(String className, String value) {
try {
Object[] enumConstants = classLoader.getClassLoader().loadClass(className).getEnumConstants();
int index = 0;
for (Object o : enumConstants) {
if (o.toString().equals(value)) {
return index;
}
index++;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
return -1;
}
public static Object getEnumObject(String className, String value) {
try {
Object[] enumConstants = classLoader.getClassLoader().loadClass(className).getEnumConstants();
for (Object o : enumConstants) {
if (o.toString().equals(value)) {
return o;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
return new Object();
}
public static class Var<E> {
private final E var;
private final Class<E> type;
public Var(E var, Class<E> type) {
this.var = var;
this.type = type;
}
public synchronized final E getVar() {
return var;
}
public synchronized final Class<E> getType() {
return type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((var == null) ? 0 : var.hashCode());
return result;
}
@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Var other = (Var) obj;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (var == null) {
if (other.var != null)
return false;
} else if (!var.equals(other.var))
return false;
return true;
}
@Override
public String toString() {
return "Var [var=" + var + ", type=" + type + "]";
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Integer> newVar(int i) {
return new Var(i, int.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Short> newVar(short i) {
return new Var(i, short.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Byte> newVar(byte i) {
return new Var(i, byte.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Boolean> newVar(boolean i) {
return new Var(i, boolean.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Character> newVar(char i) {
return new Var(i, char.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Long> newVar(long i) {
return new Var(i, long.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Float> newVar(float i) {
return new Var(i, float.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<Double> newVar(double i) {
return new Var(i, double.class);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Var<String> newVar(String i) {
return new Var(i, String.class);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E> Var<E> newVar(E[] i, Class<E> type) {
return new Var(i, getArrayClass(type));
}
@SuppressWarnings("unchecked")
private static <T> Class<? extends T[]> getArrayClass(Class<T> clazz) {
return (Class<? extends T[]>) Array.newInstance(clazz, 0).getClass();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Var<?> newVarFromClass(Object classObj, String className) {
try {
return new Var(classObj, classLoader.getClassLoader().loadClass(className));
} catch (ClassNotFoundException | IllegalArgumentException e) {
e.printStackTrace();
NullPointerException exc = new NullPointerException();
exc.addSuppressed(e);
throw exc;
}
}
}
}

View File

@ -1,10 +1,14 @@
package org.warp.picalculator;
import java.io.IOException;
import org.warp.picalculator.device.PIHardwareDisplay;
import org.warp.picalculator.gui.CalculatorHUD;
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
public class KeyboardTest {
public static void main(String[] args) throws InterruptedException {
new Main(new KeyboardDebugScreen(), args);
public static void main(String[] args) throws InterruptedException, Error, IOException {
new Main(new KeyboardDebugScreen(), new PIHardwareDisplay(), new CalculatorHUD(), args);
}
}

View File

@ -1,52 +1,62 @@
package org.warp.picalculator;
import java.io.IOException;
import org.warp.picalculator.deps.DGpio;
import org.warp.picalculator.deps.DSystem;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.PIHardwareDisplay;
import org.warp.picalculator.gui.CalculatorHUD;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.HUD;
import org.warp.picalculator.gui.HardwareDisplay;
import org.warp.picalculator.gui.screens.LoadingScreen;
import org.warp.picalculator.gui.screens.Screen;
import com.pi4j.system.SystemInfo.BoardType;
import com.pi4j.wiringpi.Gpio;
import org.warp.picalculator.math.rules.RulesManager;
public class Main {
public static Main instance;
public static String[] args;
public Main(String[] args) throws InterruptedException {
this(new LoadingScreen(), args);
public Main(String[] args) throws InterruptedException, Error, IOException {
this(new LoadingScreen(), new PIHardwareDisplay(), new CalculatorHUD(), args);
}
public Main(Screen screen, String[] args) {
public Main(Screen screen, HardwareDisplay disp, HUD hud, String[] args) throws InterruptedException, Error, IOException {
System.out.println("WarpPI Calculator");
instance = this;
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
Thread.currentThread().setName("Main thread");
Main.args = args;
ClassUtils.classLoader = this.getClass();
beforeStart();
new DisplayManager(screen);
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
PlatformUtils.setThreadName(Thread.currentThread(), "Main thread");
new DisplayManager(disp, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
afterStart();
if (screen instanceof LoadingScreen) {
((LoadingScreen) screen).loaded = true;
}
DisplayManager.INSTANCE.waitForExit();
Utils.out.println(1, "Shutdown...");
ConsoleUtils.out.println(1, "Shutdown...");
beforeShutdown();
Utils.out.println(1, "");
Utils.out.println(1, "Closed.");
System.exit(0);
ConsoleUtils.out.println(1, "");
ConsoleUtils.out.println(1, "Closed.");
DSystem.exit(0);
}
public void beforeStart() {
public void beforeStart() throws IOException {
boolean isRaspi = false;
try {
isRaspi = com.pi4j.system.SystemInfo.getBoardType() != BoardType.UNKNOWN;
} catch (Exception e) {}
isRaspi = DGpio.getBoardType() != DGpio.UnknownBoardType;
} catch (final Exception e) {}
if (Utils.isRunningOnRaspberry() && !Utils.isInArray("-noraspi", args) && isRaspi) {
Gpio.wiringPiSetupPhys();
Gpio.pinMode(12, Gpio.PWM_OUTPUT);
DGpio.wiringPiSetupPhys();
DGpio.pinMode(12, DGpio.PWM_OUTPUT);
} else {
StaticVars.screenPos = new int[] { 0, 0 };
StaticVars.debugOn = true;
}
Utils.debugThirdScreen = StaticVars.debugOn & false;
for (String arg : args) {
for (final String arg : args) {
if (arg.contains("2x")) {
StaticVars.debugWindow2x = true;
}
@ -74,6 +84,15 @@ public class Main {
if (arg.contains("fb")) {
Utils.forceEngine = "fb";
}
if (arg.contains("nogui")) {
Utils.forceEngine = "nogui";
}
if (arg.contains("verbose") || arg.contains("debug")) {
StaticVars.outputLevel = ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE;
}
if (arg.contains("uncached")) {
Utils.debugCache = true;
}
if (arg.contains("ms-dos")) {
Utils.headlessOverride = true;
Utils.msDosMode = true;
@ -82,15 +101,17 @@ public class Main {
Keyboard.startKeyboard();
}
public void afterStart() {
public void afterStart() throws InterruptedException, Error {
DisplayManager.INSTANCE.setBrightness(0.2f);
RulesManager.initialize();
RulesManager.warmUp();
}
public void beforeShutdown() {
Keyboard.stopKeyboard();
}
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) throws InterruptedException, Error, IOException {
/*
* TEST: Comparing BigIntegerMath.divisors() vs programmingpraxis' Number.getFactors() function
*

View File

@ -1,13 +1,12 @@
package org.warp.picalculator;
import java.nio.ByteBuffer;
public class MmapByteBuffer {
private int fd;
private int address;
private int length;
private ByteBuffer buffer;
private final int fd;
private final int address;
private final int length;
private final ByteBuffer buffer;
public MmapByteBuffer(int fd, int address, int length, ByteBuffer buffer) {
this.fd = fd;
@ -19,15 +18,15 @@ public class MmapByteBuffer {
public int getFd() {
return fd;
}
public int getAddress() {
return address;
}
public int getLength() {
return length;
}
public ByteBuffer getBuffer() {
return buffer;
}

View File

@ -0,0 +1,30 @@
package org.warp.picalculator;
import java.math.BigInteger;
import java.util.Iterator;
import java.util.LinkedList;
public class ScriptUtils {
public static boolean instanceOf(Object a, Class<?> b) {
return b.isInstance(a);
}
public static LinkedList<BigInteger> mcm(LinkedList<BigInteger> factors1, LinkedList<BigInteger> factors2) {
final LinkedList<BigInteger> mcm = new LinkedList<>();
final Iterator<BigInteger> i1 = factors1.iterator();
while (i1.hasNext()) {
final BigInteger int1 = i1.next();
final Iterator<BigInteger> i2 = factors2.iterator();
while (i2.hasNext()) {
final BigInteger int2 = i2.next();
if (int1.equals(int2)) {
i1.remove();
i2.remove();
mcm.add(int1);
break;
}
}
}
return mcm;
}
}

View File

@ -10,10 +10,19 @@ public class StaticVars {
public static int[] screenPos = new int[] { 0, 0 };
public static final int[] screenSize = new int[] { 480, 320 };
public static boolean debugOn;
public static int outputLevel = 5;
public static int outputLevel = 0;
public static boolean debugWindow2x = false;
public static float windowZoom = 2;
private StaticVars() {
}
public static float getCurrentZoomValue() {
if (StaticVars.debugOn & StaticVars.debugWindow2x) {
return 2;
} else {
return StaticVars.windowZoom;
}
}
}

View File

@ -2,8 +2,10 @@ package org.warp.picalculator;
import java.io.IOException;
import org.warp.picalculator.deps.DEngine;
import org.warp.picalculator.deps.DSystem;
import org.warp.picalculator.device.Key;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.KeyboardEventListener;
import org.warp.picalculator.gui.expression.InputContext;
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
@ -13,7 +15,6 @@ 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.gpu.GPUEngine;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.functions.Expression;
@ -21,7 +22,7 @@ import org.warp.picalculator.math.parser.MathParser;
public class TestGPU {
public static final GraphicEngine d = new GPUEngine();
public static final GraphicEngine d = DEngine.newGPUEngine();
public static void main(String[] args) throws IOException, Error {
StaticVars.debugOn = true;
@ -32,86 +33,91 @@ public class TestGPU {
Keyboard.setAdditionalKeyboardListener(new KeyboardEventListener() {
@Override
public boolean keyPressed(Key k) {
switch (k) {
case LEFT:
c.moveLeft();
return true;
case RIGHT:
c.moveRight();
return true;
case NUM0:
c.typeChar('0');
return true;
case NUM1:
c.typeChar('1');
return true;
case NUM2:
c.typeChar('2');
return true;
case NUM3:
c.typeChar('3');
return true;
case NUM4:
c.typeChar('4');
return true;
case NUM5:
c.typeChar('5');
return true;
case NUM6:
c.typeChar('6');
return true;
case NUM7:
c.typeChar('7');
return true;
case NUM8:
c.typeChar('8');
return true;
case NUM9:
c.typeChar('9');
return true;
case PLUS:
c.typeChar(MathematicalSymbols.SUM);
return true;
case MINUS:
c.typeChar(MathematicalSymbols.SUBTRACTION);
return true;
case MULTIPLY:
c.typeChar(MathematicalSymbols.MULTIPLICATION);
return true;
case DIVIDE:
c.typeChar(MathematicalSymbols.DIVISION);
return true;
case SQRT:
c.typeChar(MathematicalSymbols.SQUARE_ROOT);
return true;
case PARENTHESIS_OPEN:
case SINE:
c.typeChar(MathematicalSymbols.PARENTHESIS_OPEN);
return true;
case PARENTHESIS_CLOSE:
case debug_DEG:
c.moveRight();
return true;
case DELETE:
c.del();
return true;
case RESET:
c.clear();
return true;
case POWER:
d.destroy();
System.exit(0);
return true;
case EQUAL:
Expression expr;
try {
expr = MathParser.parseInput(new MathContext(), c);
System.out.println("Parsed input:" + expr.toString());
} catch (final Error e) {
e.printStackTrace();
}
default:
break;
try {
switch (k) {
case LEFT:
c.moveLeft();
return true;
case RIGHT:
c.moveRight();
return true;
case NUM0:
c.typeChar('0');
return true;
case NUM1:
c.typeChar('1');
return true;
case NUM2:
c.typeChar('2');
return true;
case NUM3:
c.typeChar('3');
return true;
case NUM4:
c.typeChar('4');
return true;
case NUM5:
c.typeChar('5');
return true;
case NUM6:
c.typeChar('6');
return true;
case NUM7:
c.typeChar('7');
return true;
case NUM8:
c.typeChar('8');
return true;
case NUM9:
c.typeChar('9');
return true;
case PLUS:
c.typeChar(MathematicalSymbols.SUM);
return true;
case MINUS:
c.typeChar(MathematicalSymbols.SUBTRACTION);
return true;
case MULTIPLY:
c.typeChar(MathematicalSymbols.MULTIPLICATION);
return true;
case DIVIDE:
c.typeChar(MathematicalSymbols.DIVISION);
return true;
case SQRT:
c.typeChar(MathematicalSymbols.SQUARE_ROOT);
return true;
case PARENTHESIS_OPEN:
case SINE:
c.typeChar(MathematicalSymbols.PARENTHESIS_OPEN);
return true;
case PARENTHESIS_CLOSE:
case debug_DEG:
c.moveRight();
return true;
case DELETE:
c.del();
return true;
case RESET:
c.clear();
return true;
case POWEROFF:
d.destroy();
DSystem.exit(0);
return true;
case EQUAL:
Expression expr;
try {
expr = MathParser.parseInput(new MathContext(), c);
System.out.println("Parsed input:" + expr.toString());
} catch (final Error e) {
e.printStackTrace();
}
default:
break;
}
return false;
} catch (final Exception ex) {
ex.printStackTrace();
}
return false;
@ -180,7 +186,7 @@ public class TestGPU {
}
if (!StaticVars.debugOn) {
d.destroy();
System.exit(0);
DSystem.exit(0);
}
}).start();

View File

@ -1,18 +1,12 @@
package org.warp.picalculator;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import org.warp.picalculator.MmapByteBuffer;
public class TestJNI {
public TestJNI() {
}
static {
System.load("/boot/libpicalc.so");
}
@ -24,7 +18,7 @@ public class TestJNI {
public MmapByteBuffer retrieveBuffer() {
return getDisplayBuffer();
}
public void deleteBuffer() {
disposeDisplayBuffer();
}

View File

@ -7,7 +7,6 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.ref.WeakReference;
@ -16,9 +15,18 @@ import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Iterator;
import java.util.LinkedList;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
import org.nevec.rjm.BigDecimalMath;
import org.nevec.rjm.Rational;
@ -45,61 +53,17 @@ public class Utils {
public static final int scale = 24;
public static final int displayScale = 8;
public static final BigInteger maxFactor = BigInteger.valueOf(1000000L);
public static final int scaleMode = BigDecimal.ROUND_HALF_UP;
public static final RoundingMode scaleMode2 = RoundingMode.HALF_UP;
public static AdvancedOutputStream out = new AdvancedOutputStream();
public static final int OUTPUTLEVEL_NODEBUG = 0;
public static final int OUTPUTLEVEL_DEBUG_MIN = 1;
public static final int OUTPUTLEVEL_DEBUG_MAX = 4;
public static boolean debugThirdScreen;
public static boolean headlessOverride = false;
private static String OS = System.getProperty("os.name").toLowerCase();
public static String forceEngine;
public static boolean msDosMode;
public static final class AdvancedOutputStream extends StringWriter {
public void println(String str) {
println(0, str);
}
public void println(int level) {
if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) {
System.out.println();
} else {
System.err.println();
}
}
}
public void println(int level, String str) {
if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) {
System.out.println(str);
} else {
System.err.println(str);
}
}
}
public void print(int level, String str) {
if (StaticVars.outputLevel >= level) {
if (StaticVars.outputLevel == 0) {
System.out.print(str);
} else {
System.err.print(str);
}
}
}
int before = 0;
boolean due = false;
}
public static boolean debugCache;
public static boolean newtMode = true;
public static boolean isInArray(String ch, String[] a) {
boolean contains = false;
@ -538,15 +502,6 @@ public class Utils {
return realbytes;
}
public static boolean allSolved(List<Function> expressions) throws Error, InterruptedException {
for (final Function itm : expressions) {
if (itm.isSimplified() == false) {
return false;
}
}
return true;
}
public static Function[][] joinFunctionsResults(List<Function> l1, List<Function> l2) {
final int size1 = l1.size();
final int size2 = l2.size();
@ -698,7 +653,7 @@ public class Utils {
}
public static boolean isRunningOnRaspberry() {
if (System.getProperty("os.name").equals("Linux")) {
if (PlatformUtils.osName.equals("Linux")) {
final File file = new File("/etc", "os-release");
try (FileInputStream fis = new FileInputStream(file); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis))) {
String string;
@ -717,26 +672,7 @@ public class Utils {
}
public static boolean isWindows() {
return (OS.indexOf("win") >= 0);
}
public static LinkedList<BigInteger> mcm(LinkedList<BigInteger> factors1, LinkedList<BigInteger> factors2) {
LinkedList<BigInteger> mcm = new LinkedList<>();
Iterator<BigInteger> i1 = factors1.iterator();
while(i1.hasNext()) {
BigInteger int1 = i1.next();
Iterator<BigInteger> i2 = factors2.iterator();
while(i2.hasNext()) {
BigInteger int2 = i2.next();
if (int1.equals(int2)) {
i1.remove();
i2.remove();
mcm.add(int1);
break;
}
}
}
return mcm;
return (PlatformUtils.osName.indexOf("win") >= 0);
}
public static void gc() {
@ -747,4 +683,78 @@ public class Utils {
System.gc();
}
}
public static <T> ObjectArrayList<T> newArrayList(T o) {
final ObjectArrayList<T> t = new ObjectArrayList<>();
t.add(o);
return t;
}
public static Path getResource(String string) throws IOException, URISyntaxException {
final URL res = Main.instance.getClass().getResource(string);
final boolean isResource = res != null;
if (isResource) {
try {
final URI uri = res.toURI();
if (res.getProtocol().equalsIgnoreCase("jar")) {
try {
FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (final FileSystemAlreadyExistsException e) {
FileSystems.getFileSystem(uri);
}
final Path myFolderPath = Paths.get(uri);
return myFolderPath;
} else {
return Paths.get(uri);
}
} catch (final java.lang.IllegalArgumentException e) {
throw e;
}
} else {
return Paths.get(string.substring(1));
}
}
public static InputStream getResourceStreamSafe(String string) throws IOException, URISyntaxException {
try {
return getResourceStream(string);
} catch (final Exception ex) {
return null;
}
}
public static InputStream getResourceStream(String string) throws IOException, URISyntaxException {
final URL res = Main.instance.getClass().getResource(string);
final boolean isResource = res != null;
if (isResource) {
try {
final URI uri = res.toURI();
if (res.getProtocol().equalsIgnoreCase("jar")) {
try {
FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (final FileSystemAlreadyExistsException e) {
FileSystems.getFileSystem(uri);
}
final Path myFolderPath = Paths.get(uri);
return Files.newInputStream(myFolderPath);
} else {
return Files.newInputStream(Paths.get(uri));
}
} catch (final java.lang.IllegalArgumentException e) {
throw e;
}
} else {
return Files.newInputStream(Paths.get(string.substring(1)));
}
}
public static String read(InputStream input) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
return buffer.lines().collect(Collectors.joining("\n"));
}
}
public static Path getJarDirectory() {
return Paths.get("").toAbsolutePath();
}
}

View File

@ -24,7 +24,7 @@ public class CacheFile {
} while (Files.exists(Paths.get(path)));
try {
Files.createTempFile(StaticVars.calculatorNameLOWER, "");
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
}
@ -33,7 +33,7 @@ public class CacheFile {
if (lastOOS == null) {
try {
return new ObjectOutputStream(new FileOutputStream(path));
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
return lastOOS;
}
@ -46,7 +46,7 @@ public class CacheFile {
if (lastOIS == null) {
try {
return new ObjectInputStream(new FileInputStream(path));
} catch (IOException e) {
} catch (final IOException e) {
return lastOIS;
}
} else {
@ -72,7 +72,7 @@ public class CacheFile {
lastFIS.close();
lastFIS = null;
}
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
}
@ -81,7 +81,7 @@ public class CacheFile {
closeStreams();
try {
Files.deleteIfExists(Paths.get(path));
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
}

View File

@ -0,0 +1,5 @@
package org.warp.picalculator.device;
public enum Key {
POWEROFF, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, LETTER_Z, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI, SETTINGS, F1, F2, F3, F4, BACK, ZOOM_MODE, LOGARITHM, EULER_NUMBER
}

View File

@ -2,8 +2,9 @@ package org.warp.picalculator.device;
import java.awt.event.KeyEvent;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.PlatformUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.chip.ParallelToSerial;
import org.warp.picalculator.device.chip.SerialToParallel;
import org.warp.picalculator.gui.DisplayManager;
@ -12,7 +13,8 @@ import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
import org.warp.picalculator.gui.screens.MarioScreen;
import org.warp.picalculator.gui.screens.Screen;
import com.pi4j.wiringpi.Gpio;
import org.warp.picalculator.deps.DGpio;
import org.warp.picalculator.deps.jogamp.DJogamp;
public class Keyboard {
public static volatile boolean alpha = false;
@ -31,6 +33,7 @@ public class Keyboard {
private static volatile boolean[][] precedentStates = new boolean[8][8];
public static volatile boolean[][] debugKeysDown = new boolean[8][8];
public static volatile int debugKeyCode = -1;
public static volatile int debugKeyCodeRelease = -1;
private static volatile boolean refreshRequest = false;
@ -45,23 +48,27 @@ public class Keyboard {
debugKeyPressed(debugKeyCode);
debugKeyCode = -1;
}
if (debugKeyCodeRelease != -1) {
debugKeyReleased(debugKeyCodeRelease);
debugKeyCodeRelease = -1;
}
Thread.sleep(50);
}
} catch (final InterruptedException e) {}
} else {
Gpio.pinMode(CLK_INH_pin, Gpio.OUTPUT);
Gpio.pinMode(RCK_pin, Gpio.OUTPUT);
Gpio.pinMode(SER_pin, Gpio.OUTPUT);
Gpio.pinMode(SH_LD_pin, Gpio.OUTPUT);
Gpio.pinMode(SCK_and_CLK_pin, Gpio.OUTPUT);
Gpio.pinMode(QH_pin, Gpio.INPUT);
DGpio.pinMode(CLK_INH_pin, DGpio.OUTPUT);
DGpio.pinMode(RCK_pin, DGpio.OUTPUT);
DGpio.pinMode(SER_pin, DGpio.OUTPUT);
DGpio.pinMode(SH_LD_pin, DGpio.OUTPUT);
DGpio.pinMode(SCK_and_CLK_pin, DGpio.OUTPUT);
DGpio.pinMode(QH_pin, DGpio.INPUT);
Gpio.digitalWrite(CLK_INH_pin, false);
Gpio.digitalWrite(RCK_pin, false);
Gpio.digitalWrite(SER_pin, false);
Gpio.digitalWrite(SH_LD_pin, false);
Gpio.digitalWrite(SCK_and_CLK_pin, false);
Gpio.digitalWrite(QH_pin, false);
DGpio.digitalWrite(CLK_INH_pin, false);
DGpio.digitalWrite(RCK_pin, false);
DGpio.digitalWrite(SER_pin, false);
DGpio.digitalWrite(SH_LD_pin, false);
DGpio.digitalWrite(SCK_and_CLK_pin, false);
DGpio.digitalWrite(QH_pin, false);
final SerialToParallel chip1 = new SerialToParallel(RCK_pin, SCK_and_CLK_pin /*SCK*/, SER_pin);
final ParallelToSerial chip2 = new ParallelToSerial(SH_LD_pin, CLK_INH_pin, QH_pin, SCK_and_CLK_pin/*CLK*/);
@ -92,16 +99,16 @@ public class Keyboard {
}
}
});
kt.setName("Keyboard thread");
PlatformUtils.setThreadName(kt, "Keyboard thread");
kt.setPriority(Thread.NORM_PRIORITY + 1);
kt.setDaemon(true);
PlatformUtils.setDaemon(kt);
kt.start();
}
private synchronized static void debugKeyPressed(int keyCode) {
switch (keyCode) {
case KeyEvent.VK_ESCAPE:
Keyboard.keyPressed(Key.POWER);
Keyboard.keyPressed(Key.POWEROFF);
break;
case KeyEvent.VK_S:
if (Keyboard.shift) {
@ -165,6 +172,15 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_E:
if (Keyboard.shift) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.EULER_NUMBER);
}
break;
case KeyEvent.VK_Y:
if (Keyboard.alpha) {
Keyboard.keyPressed(Key.LETTER_Y);
@ -178,10 +194,19 @@ public class Keyboard {
} else if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE);
} else {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.ZOOM_MODE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_ENTER:
case KeyEvent.VK_L:
if (Keyboard.shift) {
Keyboard.keyPressed(Key.LOGARITHM);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.LOGARITHM);
}
break;
case DJogamp.VK_ENTER:
case KeyEvent.VK_ENTER:
if (Keyboard.shift) {
Keyboard.keyPressed(Key.STEP);
@ -281,7 +306,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_ADD:
case DJogamp.VK_ADD:
case KeyEvent.VK_ADD:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.PLUS);
@ -291,7 +316,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_SUBTRACT:
case DJogamp.VK_SUBTRACT:
case KeyEvent.VK_SUBTRACT:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.MINUS);
@ -299,7 +324,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_MULTIPLY:
case DJogamp.VK_MULTIPLY:
case KeyEvent.VK_MULTIPLY:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.MULTIPLY);
@ -307,7 +332,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_DIVIDE:
case DJogamp.VK_DIVIDE:
case KeyEvent.VK_DIVIDE:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.DIVIDE);
@ -322,7 +347,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_DELETE:
case DJogamp.VK_DELETE:
case KeyEvent.VK_DELETE:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.RESET);
@ -330,7 +355,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_LEFT:
case DJogamp.VK_LEFT:
case KeyEvent.VK_LEFT:
//LEFT
row = 2;
@ -342,7 +367,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_RIGHT:
case DJogamp.VK_RIGHT:
case KeyEvent.VK_RIGHT:
//RIGHT
row = 2;
@ -354,7 +379,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_UP:
case DJogamp.VK_UP:
case KeyEvent.VK_UP:
//UP
row = 1;
@ -366,7 +391,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_DOWN:
case DJogamp.VK_DOWN:
case KeyEvent.VK_DOWN:
//DOWN
row = 3;
@ -389,7 +414,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD4:
case DJogamp.VK_NUMPAD4:
case KeyEvent.VK_NUMPAD4:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.HISTORY_BACK);
@ -397,7 +422,7 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD6:
case DJogamp.VK_NUMPAD6:
case KeyEvent.VK_NUMPAD6:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.HISTORY_FORWARD);
@ -412,32 +437,77 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case com.jogamp.newt.event.KeyEvent.VK_SHIFT:
case DJogamp.VK_SHIFT:
case KeyEvent.VK_SHIFT:
Keyboard.keyPressed(Key.SHIFT);
break;
case KeyEvent.VK_A:
Keyboard.keyPressed(Key.ALPHA);
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD1:
case DJogamp.VK_NUMPAD1:
case KeyEvent.VK_NUMPAD1:
Keyboard.keyPressed(Key.SQRT);
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD2:
case DJogamp.VK_NUMPAD2:
case KeyEvent.VK_NUMPAD2:
Keyboard.keyPressed(Key.ROOT);
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD3:
case DJogamp.VK_NUMPAD3:
case KeyEvent.VK_NUMPAD3:
Keyboard.keyPressed(Key.POWER_OF_2);
break;
case com.jogamp.newt.event.KeyEvent.VK_NUMPAD5:
case DJogamp.VK_NUMPAD5:
case KeyEvent.VK_NUMPAD5:
Keyboard.keyPressed(Key.POWER_OF_x);
break;
}
}
private synchronized static void debugKeyReleased(int keyCode) {
switch (keyCode) {
case KeyEvent.VK_ENTER:
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case DJogamp.VK_LEFT:
case KeyEvent.VK_LEFT:
//LEFT
row = 2;
col = 3;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case DJogamp.VK_RIGHT:
case KeyEvent.VK_RIGHT:
//RIGHT
row = 2;
col = 5;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
System.out.println("RELEASE");
break;
case DJogamp.VK_UP:
case KeyEvent.VK_UP:
//UP
row = 1;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case DJogamp.VK_DOWN:
case KeyEvent.VK_DOWN:
//DOWN
row = 3;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
case (short) 12:
//DOWN
row = 2;
col = 4;
Keyboard.debugKeysDown[row - 1][col - 1] = false;
break;
}
}
public static boolean isKeyDown(int row, int col) {
if (StaticVars.debugOn == false) {
return precedentStates[row - 1][col - 1];
@ -455,89 +525,80 @@ public class Keyboard {
}
static final Key[][][] keyMap = /* [ROW, COLUMN, (0:normal 1:shift 2:alpha)] */
{
{ /* ROW 0 */
{Key.SHIFT, Key.SHIFT, Key.SHIFT}, /* 0,0 */
{Key.ALPHA, Key.ALPHA, Key.ALPHA}, /* 0,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 0,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 0,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 0,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 0,5 */
{Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.NONE}, /* 0,6 */
{Key.SIMPLIFY, Key.STEP, Key.NONE} /* 0,7 */
},
{ /* ROW 1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 1,6 */
{Key.NONE, Key.PI, Key.DRG_CYCLE} /* 1,7 */
},
{ /* ROW 2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,0 */
{Key.SQRT, Key.NONE, Key.LETTER_Y}, /* 2,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 2,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 2,7 */
},
{ /* ROW 3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 3,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 3,7 */
},
{ /* ROW 4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 4,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 4,7 */
},
{ /* ROW 5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 5,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 5,7 */
},
{ /* ROW 6 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 6,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 6,7 */
},
{ /* ROW 7 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,0 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,1 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,2 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,3 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,4 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,5 */
{Key.NONE, Key.NONE, Key.NONE}, /* 7,6 */
{Key.NONE, Key.NONE, Key.NONE} /* 7,7 */
}
};
{ { /* ROW 0 */
{ Key.SHIFT, Key.SHIFT, Key.SHIFT }, /* 0,0 */
{ Key.ALPHA, Key.ALPHA, Key.ALPHA }, /* 0,1 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,2 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,3 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 0,4 */
{ Key.SETTINGS, Key.NONE, Key.NONE }, /* 0,5 */
{ Key.BRIGHTNESS_CYCLE, Key.BRIGHTNESS_CYCLE_REVERSE, Key.ZOOM_MODE }, /* 0,6 */
{ Key.SIMPLIFY, Key.STEP, Key.NONE } /* 0,7 */
}, { /* ROW 1 */
{ Key.F4, Key.F4, Key.F4 }, /* 1,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 1,1 */
{ Key.LEFT, Key.NONE, Key.NONE }, /* 1,2 */
{ Key.OK, Key.NONE, Key.NONE }, /* 1,3 */
{ Key.RIGHT, Key.NONE, Key.NONE }, /* 1,4 */
{ Key.HISTORY_BACK, Key.NONE, Key.NONE }, /* 1,5 */
{ Key.HISTORY_FORWARD, Key.NONE, Key.NONE }, /* 1,6 */
{ Key.NONE, Key.PI, Key.DRG_CYCLE } /* 1,7 */
}, { /* ROW 2 */
{ Key.F3, Key.F4, Key.F4 }, /* 2,0 */
{ Key.SQRT, Key.ROOT, Key.NONE }, /* 2,1 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 2,2 */
{ Key.DOWN, Key.NONE, Key.NONE }, /* 2,3 */
{ Key.BACK, Key.NONE, Key.NONE }, /* 2,4 */
{ Key.HISTORY_BACK, Key.NONE, Key.NONE }, /* 2,5 */
{ Key.HISTORY_FORWARD, Key.NONE, Key.NONE }, /* 2,6 */
{ Key.NONE, Key.NONE, Key.LETTER_Z } /* 2,7 */
}, { /* ROW 3 */
{ Key.F2, Key.F2, Key.F2 }, /* 3,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,1 */
{ Key.POWER_OF_x, Key.NONE, Key.NONE }, /* 3,2 */
{ Key.POWER_OF_2, Key.NONE, Key.NONE }, /* 3,3 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 3,6 */
{ Key.DOT, Key.NONE, Key.LETTER_Y } /* 3,7 */
}, { /* ROW 4 */
{ Key.F1, Key.F1, Key.F1 }, /* 4,0 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,1 */
{ Key.PARENTHESIS_OPEN, Key.NONE, Key.NONE }, /* 4,2 */
{ Key.PARENTHESIS_CLOSE, Key.NONE, Key.NONE }, /* 4,3 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,4 */
{ Key.SURD_MODE, Key.NONE, Key.NONE }, /* 4,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 4,6 */
{ Key.NUM0, Key.NONE, Key.LETTER_X } /* 4,7 */
}, { /* ROW 5 */
{ Key.NUM7, Key.NONE, Key.NONE }, /* 5,0 */
{ Key.NUM8, Key.NONE, Key.NONE }, /* 5,1 */
{ Key.NUM9, Key.NONE, Key.NONE }, /* 5,2 */
{ Key.DELETE, Key.NONE, Key.NONE }, /* 5,3 */
{ Key.RESET, Key.NONE, Key.NONE }, /* 5,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 5,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 5,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 5,7 */
}, { /* ROW 6 */
{ Key.NUM4, Key.NONE, Key.NONE }, /* 6,0 */
{ Key.NUM5, Key.NONE, Key.NONE }, /* 6,1 */
{ Key.NUM6, Key.NONE, Key.NONE }, /* 6,2 */
{ Key.MULTIPLY, Key.NONE, Key.NONE }, /* 6,3 */
{ Key.DIVIDE, Key.NONE, Key.NONE }, /* 6,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 6,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 6,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 6,7 */
}, { /* ROW 7 */
{ Key.NUM1, Key.NONE, Key.NONE }, /* 7,0 */
{ Key.NUM2, Key.NONE, Key.NONE }, /* 7,1 */
{ Key.NUM3, Key.NONE, Key.NONE }, /* 7,2 */
{ Key.PLUS, Key.PLUS_MINUS, Key.NONE }, /* 7,3 */
{ Key.MINUS, Key.NONE, Key.NONE }, /* 7,4 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 7,5 */
{ Key.NONE, Key.NONE, Key.NONE }, /* 7,6 */
{ Key.NONE, Key.NONE, Key.NONE } /* 7,7 */
} };
static synchronized void keyPressedRaw(int row, int col) {
// KeyboardDebugScreen.keyX = row;
// KeyboardDebugScreen.keyY = col;
@ -546,7 +607,7 @@ public class Keyboard {
keyPressed(k);
} else {
if (false) {
} else {
keyPressed(Key.NONE);
}
@ -555,12 +616,12 @@ public class Keyboard {
public static void stopKeyboard() {
if (StaticVars.debugOn == false) {
Gpio.digitalWrite(33, false);
Gpio.digitalWrite(35, false);
Gpio.digitalWrite(36, false);
Gpio.digitalWrite(37, false);
Gpio.digitalWrite(38, false);
Gpio.digitalWrite(40, false);
DGpio.digitalWrite(33, false);
DGpio.digitalWrite(35, false);
DGpio.digitalWrite(36, false);
DGpio.digitalWrite(37, false);
DGpio.digitalWrite(38, false);
DGpio.digitalWrite(40, false);
}
}
@ -586,7 +647,7 @@ public class Keyboard {
refresh = true;
} else {
switch (k) {
case POWER:
case POWEROFF:
DisplayManager.INSTANCE.engine.destroy();
break;
case NONE:
@ -603,6 +664,10 @@ public class Keyboard {
DisplayManager.INSTANCE.cycleBrightness(true);
refresh = true;
break;
case ZOOM_MODE:
StaticVars.windowZoom = (StaticVars.windowZoom % 3) + 1;
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
refresh = true;
case HISTORY_BACK:
DisplayManager.INSTANCE.goBack();
refresh = true;
@ -640,7 +705,7 @@ public class Keyboard {
refreshRequest = true;
}
} else if (!done) {
Utils.out.println(1, "Key " + k.toString() + " ignored.");
ConsoleUtils.out.println(1, "Key " + k.toString() + " ignored.");
}
}
@ -670,7 +735,7 @@ public class Keyboard {
refreshRequest = true;
}
} else if (!done) {
Utils.out.println(1, "Key " + k.toString() + " ignored.");
ConsoleUtils.out.println(1, "Key " + k.toString() + " ignored.");
}
}
@ -678,10 +743,6 @@ public class Keyboard {
additionalListener = l;
}
public static enum Key {
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI
}
public static boolean popRefreshRequest() {
if (refreshRequest) {
refreshRequest = false;
@ -695,49 +756,79 @@ public class Keyboard {
/*
-coord-
NORMAL
SHIFT
ALPHA
-------
|0,0---|0,1---|------|0,3---|------|------|0,6---|
|SHIFT |ALPHA |------| ^ |------|------|+BRIGH|
|SHIFT |ALPHA |------| |------|------|-BRIGH|
|SHIFT |ALPHA |------| |------|------| |
|1,0---|1,1---|1,2---|1,3---|1,4---|1,5---|1,6---|
| = | | < | OK | > | Back | Fwd |
| | | | | | | |
| | | | | | | |
|2,0---|2,1---|------|2,3---|------|2,5---|2,6---|
| | SQRT |------| v |------| | |
| | ROOT |------| |------| | |
| | |------| |------| | |
|3,0---|3,1---|3,2---|3,3---|3,4---|3,5---|3,6---|
| | | POW 2| POW x| | | |
| | | | | | | |
| | | | | | | |
|4,0---|4,1---|4,2---|4,3---|4,4---|4,5---|4,6---|
| | | | | |S<=>D | |
| | | | | | | |
| | | | | | | |
|5,0---|5,1---|5,2---|5,3---|5,4---|5,5---|5,6---|
| 7 | 8 | 9 | DEL | RESET |
| | | | | |
| | | | | |
|6,0---|6,1---|6,2---|6,3---|6,4-----------------|
| 4 | 5 | 6 | * | / |
| | | | | |
| | | | | |
|7,0---|7,1---|7,2---|7,3---|7,4-----------------|
| 1 | 2 | 3 | + | - |
| | | | | |
| | | | | |
|4,7---|3,7---|2,7---|1,7---|0,7-----------------|
| 0 | . | | | SIMPLIFY |
| | | |PI | STEP |
| X | Y | Z |DRGCYCL|SOLVE FOR [x] |
|------|------|------|------|--------------------|
Keyboard:
Example button:
|ROW,COLUMN----|
| NORMAL STATE |
| SHIFT STATE |
| ALPHA STATE |
|--------------|
Physical keyboard:
|0,0-----|0,1-----|########|0,3-----|########|0,5-----|0,6-----|
| SHIFT | ALPHA |########| ^ |########|SETTINGS|+BRIGHT |
| NORMAL | ALPHA |########| |########| |-BRIGHT |
| SHIFT | NORMAL |########| |########| |ZOOMMODE|
|1,0-----|1,1-----|1,2-----|1,3-----|1,4-----|1,5-----|1,6-----|
| F_4 | | < | OK | > | Back | Fwd |
| F_4 | | | | | | |
| F_4 | | | | | | |
|2,0-----|2,1-----|--------|2,3-----|--------|2,5-----|2,6-----|
| F_3 | SQRT |########| v | BACK | | |
| F_3 | ROOT |########| | | | |
| F_3 | |########| | | | |
|3,0-----|3,1-----|3,2-----|3,3-----|3,4-----|3,5-----|3,6-----|
| F_2 | | POW x | POW 2 | | | |
| F_2 | | | | | | |
| F_2 | | | | | | |
|4,0-----|4,1-----|4,2-----|4,3-----|4,4-----|4,5-----|4,6-----|
| F_1 | | ( | ) | | S<=>D | |
| F_1 | | | | | | |
| F_1 | | | | | | |
|5,0-----|5,1-----|5,2-----|5,3-----|5,4-----|5,5-----|5,6-----|
| 7 | 8 | 9 | DEL | RESET |
| | | | | |
| | | | | |
|6,0-----|6,1-----|6,2-----|6,3-----|6,4-----------------------|
| 4 | 5 | 6 | * | / |
| | | | | |
| | | | | |
|7,0-----|7,1-----|7,2-----|7,3-----|7,4-----------------------|
| 1 | 2 | 3 | + | - |
| | | | | |
| | | | | |
|4,7-----|3,7-----|2,7-----|1,7-----|0,7-----------------------|
| 0 | . | | | SIMPLIFY |
| | | |PI | STEP |
| X | Y | Z |DRG CYCL| |
|--------|--------|--------|--------|--------------------------|
SCREEN F_n:
MathInputScreen:
Default:
[F_1] Normal: Solve for X Shift: Solve for _ Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Variables & constants Shift: Alpha:
[F_4] Normal: Functions f(x) Shift: Alpha:
Variable popup:
[F_1] Normal(if constant):Set value Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
MarioScreen
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
ChooseVariableValueScreen
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
SolveForXScreen
[F_1] Normal: Shift: Alpha:
[F_2] Normal: Shift: Alpha:
[F_3] Normal: Shift: Alpha:
[F_4] Normal: Shift: Alpha:
*/

View File

@ -1,7 +1,5 @@
package org.warp.picalculator.device;
import org.warp.picalculator.device.Keyboard.Key;
public interface KeyboardEventListener {
public abstract boolean keyPressed(Key k);

View File

@ -0,0 +1,26 @@
package org.warp.picalculator.device;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.deps.DGpio;
import org.warp.picalculator.gui.HardwareDisplay;
public class PIHardwareDisplay implements HardwareDisplay {
@Override
public void initialize() {}
@Override
public void shutdown() {}
@Override
public void setBrightness(double value) {
if (StaticVars.debugOn == false) {
DGpio.pwmWrite(12, (int) Math.ceil(value * 1024f));
// SoftPwm.softPwmWrite(12, (int)(Math.ceil(brightness*10)));
} else {
ConsoleUtils.out.println(1, "Brightness: " + value);
}
}
}

View File

@ -1,6 +1,6 @@
package org.warp.picalculator.device.chip;
import com.pi4j.wiringpi.Gpio;
import org.warp.picalculator.deps.DGpio;
public class ParallelToSerial {
@ -18,16 +18,16 @@ public class ParallelToSerial {
public boolean[] read() {
final boolean[] data = new boolean[8];
Gpio.digitalWrite(CLK_INH, Gpio.HIGH);
Gpio.digitalWrite(SH_LD, Gpio.LOW);
Gpio.delayMicroseconds(1);
Gpio.digitalWrite(SH_LD, Gpio.HIGH);
Gpio.digitalWrite(CLK_INH, Gpio.LOW);
DGpio.digitalWrite(CLK_INH, DGpio.HIGH);
DGpio.digitalWrite(SH_LD, DGpio.LOW);
DGpio.delayMicroseconds(1);
DGpio.digitalWrite(SH_LD, DGpio.HIGH);
DGpio.digitalWrite(CLK_INH, DGpio.LOW);
for (int i = 7; i >= 0; i--) {
Gpio.digitalWrite(CLK, Gpio.HIGH);
Gpio.digitalWrite(CLK, Gpio.LOW);
data[i] = Gpio.digitalRead(QH) == Gpio.HIGH ? true : false;
DGpio.digitalWrite(CLK, DGpio.HIGH);
DGpio.digitalWrite(CLK, DGpio.LOW);
data[i] = DGpio.digitalRead(QH) == DGpio.HIGH ? true : false;
}
return data;

View File

@ -1,6 +1,6 @@
package org.warp.picalculator.device.chip;
import com.pi4j.wiringpi.Gpio;
import org.warp.picalculator.deps.DGpio;
public class SerialToParallel {
private final int RCK; //Storage register clock pin (latch pin)
@ -17,15 +17,15 @@ public class SerialToParallel {
if (data.length != 8) {
return;
} else {
Gpio.digitalWrite(RCK, Gpio.LOW);
DGpio.digitalWrite(RCK, DGpio.LOW);
for (int i = 7; i >= 0; i--) {
Gpio.digitalWrite(SCK, Gpio.LOW);
Gpio.digitalWrite(SER, data[i]);
Gpio.digitalWrite(SCK, Gpio.HIGH);
DGpio.digitalWrite(SCK, DGpio.LOW);
DGpio.digitalWrite(SER, data[i]);
DGpio.digitalWrite(SCK, DGpio.HIGH);
}
Gpio.digitalWrite(RCK, Gpio.HIGH);
DGpio.digitalWrite(RCK, DGpio.HIGH);
}
}
}

View File

@ -13,6 +13,7 @@ import javax.imageio.ImageIO;
import org.warp.picalculator.Main;
import org.warp.picalculator.Utils;
import org.warp.picalculator.deps.DSystem;
/**
*
@ -35,7 +36,7 @@ public class RAWFont {
loadFont("/font_" + name + ".rft");
} catch (final IOException e) {
e.printStackTrace();
System.exit(1);
DSystem.exit(1);
}
chars32 = new int[(maxBound - minBound) * charIntCount];
for (int charIndex = 0; charIndex < maxBound - minBound; charIndex++) {
@ -113,7 +114,7 @@ public class RAWFont {
} catch (final Exception ex) {
ex.printStackTrace();
System.out.println(string);
System.exit(-1);
DSystem.exit(-1);
}
}
} else {

View File

@ -0,0 +1,32 @@
package org.warp.picalculator.extra.mario;
public class MarioBlock {
private final int x, y;
private final byte id;
public MarioBlock(int x, int y, byte b) {
this.x = x;
this.y = y;
id = b;
}
public boolean isSolid() {
return MarioBlock.isSolid(id);
}
public byte getID() {
return id;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public static boolean isSolid(byte id) {
return id != 0b0;
}
}

View File

@ -0,0 +1,9 @@
package org.warp.picalculator.extra.mario;
public class MarioEnemy extends MarioEntity {
public MarioEnemy(double x, double y, double forceX, double forceY, boolean onGround, boolean subjectToGravity) {
super(x, y, forceX, forceY, onGround, subjectToGravity);
}
}

View File

@ -0,0 +1,85 @@
package org.warp.picalculator.extra.mario;
public class MarioEntity {
protected double x;
protected double y;
public double forceX;
public double forceY;
public boolean collisionUp;
public boolean collisionDown;
public boolean collisionLeft;
public boolean collisionRight;
public boolean subjectToGravity;
public MarioEntity(double x, double y, double forceX, double forceY, boolean onGround, boolean subjectToGravity) {
this.x = x;
this.y = y;
this.forceX = forceX;
this.forceY = forceY;
collisionDown = onGround;
this.subjectToGravity = subjectToGravity;
}
public void setPosition(double x, double y) {
this.x = x;
this.y = y;
}
public void setPosition(double x, double y, boolean onGround) {
this.x = x;
this.y = y;
collisionDown = onGround;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public boolean isOnGround() {
return collisionDown;
}
public void setOnGround(boolean onGround) {
collisionDown = onGround;
}
public void gameTick(double dt) {
x = computeFutureDX(dt);
y = computeFutureDY(dt);
forceX = computeFutureForceDX(dt);
forceY = computeFutureForceDY(dt);
}
public double computeFutureDX(double dt) {
return (x + dt * forceX) - x;
}
public double computeFutureDY(double dt) {
final double forceY = this.forceY;
double y = this.y;
if (!collisionDown) {
y += dt * forceY;
}
return y - this.y;
}
public double computeFutureForceDX(double dt) {
double forceX = this.forceX;
forceX *= 0.75;
return forceX - this.forceX;
}
public double computeFutureForceDY(double dt) {
double forceY = this.forceY;
if (subjectToGravity && !collisionDown) {
forceY -= dt * 1569.6 / 16f;
} else {
forceY *= 0.75;
}
return forceY - this.forceY;
}
}

View File

@ -0,0 +1,5 @@
package org.warp.picalculator.extra.mario;
public class MarioEvent {
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,68 @@
package org.warp.picalculator.extra.mario;
public class MarioWorld {
private final int[] spawnPoint;
private final int width;
private final int height;
private final byte[][] data;
private final MarioEvent[] events;
private final MarioEntity[] entities;
/**
* @param width
* @param height
* @param data
* @param events
* @param marioEnemies
*/
public MarioWorld(int[] spawnPoint, int width, int height, byte[][] data, MarioEvent[] events, MarioEntity[] entities) {
this.spawnPoint = spawnPoint;
this.width = width;
this.height = height;
this.data = data;
this.events = events;
this.entities = entities;
}
public byte getBlockIdAt(int x, int y) {
final int idy = (height - 1 - y);
if (idy < 0 || idy >= data.length) {
return 0b0;
}
final int idx = x;
if (idx < 0 || idx >= data[0].length) {
return 0b0;
}
return data[idy][idx];
}
public MarioBlock getBlockAt(int x, int y) {
return new MarioBlock(x, y, getBlockIdAt(x, y));
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public void reset() {
}
public double getSpawnPointX() {
return spawnPoint[0];
}
public double getSpawnPointY() {
return spawnPoint[1];
}
public MarioEntity[] getEntities() {
return entities;
}
}

View File

@ -0,0 +1,137 @@
package org.warp.picalculator.extra.mario;
public class PlayerEntity extends MarioEntity {
private final int life;
public float walkAnimation = 0;
public float jumptime = 0;
public boolean walking = false;
public boolean running = false;
public boolean jumping = false;
public boolean flipped = false;
public int[] marioSkinPos = new int[] { 0, 0 };
private double controllerDX;
private double controllerDY;
public PlayerEntity(double x, double y, int life) {
super(x, y, 0, 0, true, true);
this.life = life;
}
@Override
public void gameTick(double dt) {
walkAnimation += dt;
x += computeFutureDX(dt);
y += computeFutureDY(dt);
forceX += computeFutureForceDX(dt);
forceY += computeFutureForceDY(dt);
if (controllerDX == 0) {
walking = false;
walkAnimation = 0;
} else {
if (controllerDX > 0) { //RIGHT
walking = true;
flipped = false;
}
if (controllerDX < 0) { //LEFT
walking = true;
flipped = true;
}
}
if (controllerDY > 0) { //JUMP
if (collisionUp) {
jumptime = Float.MAX_VALUE;
jumping = false;
}
jumptime += dt;
if (jumptime <= 0.5f && !jumping && collisionDown) {
jumping = true;
collisionDown = false;
} else if (jumptime <= 0.5f) {} else {
jumping = false;
}
} else {
jumping = false;
if (collisionDown) {
jumptime = 0;
} else {
jumptime = Float.MAX_VALUE;
}
}
if (!walking & !running & !jumping) {
marioSkinPos[0] = 0;
marioSkinPos[1] = 0;
} else if (collisionDown & walking & !running & !jumping && walkAnimation >= 0.08) {
while (walkAnimation > 0.08) {
walkAnimation -= 0.08;
if (marioSkinPos[0] == 1 & marioSkinPos[1] == 0) {
marioSkinPos[0] += 2;
} else if (marioSkinPos[0] == 3 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else if (marioSkinPos[0] == 2 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else {
marioSkinPos[0] = 1;
marioSkinPos[1] = 0;
}
}
} else if (jumping) {
marioSkinPos[0] = 5;
marioSkinPos[1] = 1;
}
}
@Override
public double computeFutureDX(double dt) {
return super.computeFutureDX(dt);
}
public double computeFuturedDY(double dt) {
return super.computeFutureDY(dt);
}
@Override
public double computeFutureForceDX(double dt) {
double forceX = this.forceX;
if (controllerDX == 0) {} else {
if (controllerDX > 0) { //RIGHT
if (forceX < 500f / 16f) {
forceX += dt * 500f / 16f;
}
}
if (controllerDX < 0) { //LEFT
if (forceX > -500f / 16f) {
forceX -= dt * 500f / 16f;
}
}
}
return (forceX + super.computeFutureForceDX(dt)) - this.forceX;
}
@Override
public double computeFutureForceDY(double dt) {
float jumptime = this.jumptime;
double forceY = this.forceY;
if (controllerDY > 0) { //JUMP
if (collisionUp) {
jumptime = Float.MAX_VALUE;
}
jumptime += dt;
if (jumptime <= 0.5f && !jumping && collisionDown) {
forceY = dt * (4 * 1569.6f) / 16f;
} else if (jumptime <= 0.5f) {
forceY = dt * (4 * 1569.6f) / 16f;
}
}
return (forceY + super.computeFutureForceDY(dt)) - this.forceY;
}
public void move(float dt, double dX, double dY) {
walkAnimation += dt;
controllerDX = dX;
controllerDY = dY;
}
}

View File

@ -0,0 +1,5 @@
package org.warp.picalculator.extra.mario;
public class PositionEvent extends MarioEvent {
}

View File

@ -0,0 +1,138 @@
package org.warp.picalculator.gui;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.Skin;
public class CalculatorHUD extends HUD {
@Override
public void created() throws InterruptedException {
// TODO Auto-generated method stub
}
@Override
public void initialized() throws InterruptedException {
// TODO Auto-generated method stub
}
@Override
public void render() {
// TODO Auto-generated method stub
}
@Override
public void renderTopmostBackground() {
final Renderer renderer = d.renderer;
final GraphicEngine engine = d.engine;
final Skin guiSkin = d.guiSkin;
renderer.glColor(0xFFc5c2af);
renderer.glFillColor(0, 0, engine.getWidth(), 20);
}
@Override
public void renderTopmost() {
final Renderer renderer = d.renderer;
final GraphicEngine engine = d.engine;
final Skin guiSkin = d.guiSkin;
//DRAW TOP
renderer.glColor3i(0, 0, 0);
renderer.glDrawLine(0, 20, engine.getWidth() - 1, 20);
renderer.glColor3i(255, 255, 255);
guiSkin.use(engine);
if (Keyboard.shift) {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 2, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 3, 16 * 0, 16, 16);
}
if (Keyboard.alpha) {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 0, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 1, 16 * 0, 16, 16);
}
/*
if (Calculator.angleMode == AngleMode.DEG) {
drawSkinPart(8 + 18 * 2, 2, 16 * 4, 16 * 0, 16 + 16 * 4, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
} else if (Calculator.angleMode == AngleMode.RAD) {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 6, 16 * 0, 16 + 16 * 6, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
} else if (Calculator.angleMode == AngleMode.GRA) {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 8, 16 * 0, 16 + 16 * 8, 16 + 16 * 0);
} else {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
}*/
int padding = 2;
final int brightness = (int) (Math.ceil(DisplayManager.INSTANCE.getBrightness() * 9));
if (brightness <= 10) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
} else {
ConsoleUtils.out.println(1, "Brightness error");
}
padding += 18 + 6;
final boolean canGoBack = DisplayManager.INSTANCE.canGoBack();
final boolean canGoForward = DisplayManager.INSTANCE.canGoForward();
if (StaticVars.haxMode) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
padding += 18 + 6;
}
if (canGoBack && canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
} else if (canGoBack) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
} else if (canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
} else {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
}
padding += 18;
//DRAW BOTTOM
d.renderer.glDrawStringLeft(2, 90, d.displayDebugString);
Utils.getFont(true, false).use(DisplayManager.INSTANCE.engine);
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 - 7 + 1, "WORK IN");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7 - 7, "WORK IN");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 + 1, "PROGRESS.");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7, "PROGRESS.");
}
@Override
public void beforeRender(float dt) {
// TODO Auto-generated method stub
}
@Override
public void renderBackground() {
// TODO Auto-generated method stub
}
}

View File

@ -1,27 +1,25 @@
package org.warp.picalculator.gui;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Semaphore;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.PlatformUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.deps.DEngine;
import org.warp.picalculator.deps.DSystem;
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.CPUEngine;
import org.warp.picalculator.gui.graphicengine.framebuffer.FBEngine;
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitEngine;
import org.warp.picalculator.gui.graphicengine.headless256.Headless256Engine;
import org.warp.picalculator.gui.graphicengine.headless8.Headless8Engine;
import org.warp.picalculator.gui.graphicengine.nogui.NoGuiEngine;
import org.warp.picalculator.gui.screens.Screen;
import com.pi4j.wiringpi.Gpio;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public final class DisplayManager implements RenderingLoop {
@ -29,6 +27,7 @@ public final class DisplayManager implements RenderingLoop {
private float brightness;
public final GraphicEngine engine;
public final HardwareDisplay monitor;
public final boolean supportsPauses;
public Renderer renderer;
@ -40,19 +39,45 @@ public final class DisplayManager implements RenderingLoop {
public final int[] glyphsHeight;
private Screen screen;
private final HUD hud;
public Semaphore screenChange = new Semaphore(0);
public String displayDebugString;
public ObjectArrayList<GUIErrorMessage> errorMessages;
public DisplayManager(Screen screen) {
public DisplayManager(HardwareDisplay monitor, HUD hud, Screen screen, String title) {
INSTANCE = this;
engine = chooseGraphicEngine();
supportsPauses = engine.doesRefreshPauses();
this.monitor = monitor;
this.hud = hud;
monitor.initialize();
glyphsHeight = new int[] { 9, 6, 12, 9 };
displayDebugString = "";
errorMessages = new ObjectArrayList<>();
try {
hud.d = this;
hud.create();
if (!hud.initialized) {
hud.initialize();
}
} catch (final Exception e) {
e.printStackTrace();
DSystem.exit(0);
}
setScreen(screen);
loop();
try {
engine.create();
renderer = engine.getRenderer();
engine.setTitle(title);
loop();
} catch (final Exception ex) {
ex.printStackTrace();
}
monitor.shutdown();
}
/*
* private void load_skin() {
@ -85,34 +110,39 @@ public final class DisplayManager implements RenderingLoop {
private GraphicEngine chooseGraphicEngine() {
GraphicEngine d;
d = new NoGuiEngine();
if (d.isSupported()) {
ConsoleUtils.out.println(1, "Using NoGui Graphic Engine");
return d;
}
if (!StaticVars.debugOn) {
d = new FBEngine();
d = DEngine.newFBEngine();
if (d.isSupported()) {
Utils.out.println(1, "Using FB Graphic Engine");
ConsoleUtils.out.println(1, "Using FB Graphic Engine");
return d;
}
}
d = new GPUEngine();
d = DEngine.newGPUEngine();
if (d.isSupported()) {
Utils.out.println(1, "Using GPU Graphic Engine");
ConsoleUtils.out.println(1, "Using GPU Graphic Engine");
return d;
}
d = new CPUEngine();
d = DEngine.newCPUEngine();
if (d.isSupported()) {
Utils.out.println(1, "Using CPU Graphic Engine");
ConsoleUtils.out.println(1, "Using CPU Graphic Engine");
return d;
}
d = new Headless24bitEngine();
d = DEngine.newHeadless24bitEngine();
if (d.isSupported()) {
System.err.println("Using Headless 24 bit Engine! This is a problem! No other graphic engines are available.");
return d;
}
d = new Headless256Engine();
d = DEngine.newHeadless256Engine();
if (d.isSupported()) {
System.err.println("Using Headless 256 Engine! This is a problem! No other graphic engines are available.");
return d;
}
d = new Headless8Engine();
d = DEngine.newHeadless8Engine();
if (d.isSupported()) {
System.err.println("Using Headless basic Engine! This is a problem! No other graphic engines are available.");
return d;
@ -123,6 +153,10 @@ public final class DisplayManager implements RenderingLoop {
public void setScreen(Screen screen) {
if (screen.initialized == false) {
if (screen.canBeInHistory) {
if (DisplayManager.INSTANCE.currentSession > 0) {
final int sl = DisplayManager.INSTANCE.sessions.length + 5; //TODO: I don't know why if i don't add +5 or more some items disappear
DisplayManager.INSTANCE.sessions = Arrays.copyOfRange(DisplayManager.INSTANCE.sessions, DisplayManager.INSTANCE.currentSession, sl);
}
DisplayManager.INSTANCE.currentSession = 0;
for (int i = DisplayManager.INSTANCE.sessions.length - 1; i >= 1; i--) {
DisplayManager.INSTANCE.sessions[i] = DisplayManager.INSTANCE.sessions[i - 1];
@ -142,7 +176,7 @@ public final class DisplayManager implements RenderingLoop {
}
} catch (final Exception e) {
e.printStackTrace();
System.exit(0);
DSystem.exit(0);
}
}
@ -167,7 +201,7 @@ public final class DisplayManager implements RenderingLoop {
}
} catch (final Exception e) {
e.printStackTrace();
System.exit(0);
DSystem.exit(0);
}
}
@ -236,7 +270,11 @@ public final class DisplayManager implements RenderingLoop {
}
public Screen getScreen() {
return DisplayManager.INSTANCE.screen;
return screen;
}
public HUD getHUD() {
return hud;
}
private void load_skin() throws IOException {
@ -255,8 +293,8 @@ public final class DisplayManager implements RenderingLoop {
private void draw_init() {
if (engine.supportsFontRegistering()) {
List<BinaryFont> fontsIterator = engine.getRegisteredFonts();
for (BinaryFont f : fontsIterator) {
final List<BinaryFont> fontsIterator = engine.getRegisteredFonts();
for (final BinaryFont f : fontsIterator) {
if (!f.isInitialized()) {
f.initialize(engine);
}
@ -265,100 +303,14 @@ public final class DisplayManager implements RenderingLoop {
renderer.glClear(engine.getWidth(), engine.getHeight());
}
private void draw_status() {
renderer.glColor(0xFFc5c2af);
renderer.glFillColor(0, 0, engine.getWidth(), 20);
renderer.glColor3i(0, 0, 0);
renderer.glDrawLine(0, 20, engine.getWidth() - 1, 20);
renderer.glColor3i(255, 255, 255);
guiSkin.use(engine);
if (Keyboard.shift) {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 2, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 3, 16 * 0, 16, 16);
}
if (Keyboard.alpha) {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 0, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 1, 16 * 0, 16, 16);
}
/*
if (Calculator.angleMode == AngleMode.DEG) {
drawSkinPart(8 + 18 * 2, 2, 16 * 4, 16 * 0, 16 + 16 * 4, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
} else if (Calculator.angleMode == AngleMode.RAD) {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 6, 16 * 0, 16 + 16 * 6, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
} else if (Calculator.angleMode == AngleMode.GRA) {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 8, 16 * 0, 16 + 16 * 8, 16 + 16 * 0);
} else {
drawSkinPart(8 + 18 * 2, 2, 16 * 5, 16 * 0, 16 + 16 * 5, 16 + 16 * 0);
drawSkinPart(8 + 18 * 3, 2, 16 * 7, 16 * 0, 16 + 16 * 7, 16 + 16 * 0);
drawSkinPart(8 + 18 * 4, 2, 16 * 9, 16 * 0, 16 + 16 * 9, 16 + 16 * 0);
}*/
int padding = 2;
final int brightness = (int) (Math.ceil(DisplayManager.INSTANCE.brightness * 9));
if (brightness <= 10) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
} else {
Utils.out.println(1, "Brightness error");
}
padding += 18 + 6;
final boolean canGoBack = canGoBack();
final boolean canGoForward = canGoForward();
if (StaticVars.haxMode) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
padding += 18 + 6;
}
if (canGoBack && canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
} else if (canGoBack) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
} else if (canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
} else {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
}
padding += 18;
screen.renderStatusbar();
}
private void draw_screen() {
screen.render();
}
private void draw_bottom() {
renderer.glDrawStringLeft(2, 90, displayDebugString);
Utils.getFont(true, false).use(DisplayManager.INSTANCE.engine);
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 - 7 + 1, "WORK IN");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7 - 7, "WORK IN");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 + 1, "PROGRESS.");
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7, "PROGRESS.");
}
private void draw_world() {
renderer.glColor3i(255, 255, 255);
if (error != null) {
BinaryFont fnt = Utils.getFont(false, false);
fnt.use(engine);
final BinaryFont fnt = Utils.getFont(false, false);
if (fnt != null && fnt != engine.getRenderer().getCurrentFont()) {
fnt.use(engine);
}
renderer.glColor3i(129, 28, 22);
renderer.glDrawStringRight(StaticVars.screenSize[0] - 2, StaticVars.screenSize[1] - (fnt.getCharacterHeight() + 2), StaticVars.calculatorNameUPPER + " CALCULATOR");
renderer.glColor3i(149, 32, 26);
@ -369,14 +321,21 @@ public final class DisplayManager implements RenderingLoop {
renderer.glDrawStringLeft(2, 22 + i, stackPart);
i += 11;
}
fonts[0].use(engine);
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
fonts[0].use(engine);
}
renderer.glColor3i(129, 28, 22);
renderer.glDrawStringCenter((StaticVars.screenSize[0] / 2), 11, "UNEXPECTED EXCEPTION");
} else {
fonts[0].use(engine);
draw_screen();
draw_status();
draw_bottom();
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
fonts[0].use(engine);
}
hud.renderBackground();
screen.render();
hud.render();
hud.renderTopmostBackground();
screen.renderTopmost();
hud.renderTopmost();
}
}
@ -404,9 +363,6 @@ public final class DisplayManager implements RenderingLoop {
public void loop() {
try {
engine.create();
renderer = engine.getRenderer();
load_skin();
load_fonts();
@ -414,7 +370,7 @@ public final class DisplayManager implements RenderingLoop {
screen.initialize();
} catch (final Exception e) {
e.printStackTrace();
System.exit(0);
DSystem.exit(0);
}
//Working thread
@ -491,8 +447,8 @@ public final class DisplayManager implements RenderingLoop {
e.printStackTrace();
}
});
workThread.setDaemon(true);
workThread.setName("Work thread");
PlatformUtils.setDaemon(workThread);
PlatformUtils.setThreadName(workThread, "Work thread");
workThread.start();
engine.start(getDrawable());
@ -508,12 +464,7 @@ public final class DisplayManager implements RenderingLoop {
public void setBrightness(float newval) {
if (newval >= 0 && newval <= 1) {
brightness = newval;
if (StaticVars.debugOn == false) {
Gpio.pwmWrite(12, (int) Math.ceil(brightness * 1024f));
// SoftPwm.softPwmWrite(12, (int)(Math.ceil(brightness*10)));
} else {
Utils.out.println(1, "Brightness: " + newval);
}
monitor.setBrightness(brightness);
}
}

View File

@ -0,0 +1,15 @@
package org.warp.picalculator.gui;
public interface GraphicalInterface {
public void create() throws InterruptedException;
public void initialize() throws InterruptedException;
public void render();
public void renderTopmost();
public void beforeRender(float dt);
public boolean mustBeRefreshed();
}

View File

@ -0,0 +1,48 @@
package org.warp.picalculator.gui;
public abstract class HUD implements GraphicalInterface {
public DisplayManager d;
public boolean created = false;
public boolean initialized = false;
public HUD() {}
@Override
public void initialize() throws InterruptedException {
if (!initialized) {
initialized = true;
initialized();
}
}
@Override
public void create() throws InterruptedException {
if (!created) {
created = true;
created();
}
}
public abstract void created() throws InterruptedException;
public abstract void initialized() throws InterruptedException;
public abstract void renderBackground();
@Override
public abstract void render();
public abstract void renderTopmostBackground();
@Override
public abstract void renderTopmost();
@Override
public abstract void beforeRender(float dt);
@Override
public boolean mustBeRefreshed() {
return true;
}
}

View File

@ -0,0 +1,9 @@
package org.warp.picalculator.gui;
public interface HardwareDisplay {
public void initialize();
public void shutdown();
public void setBrightness(double value);
}

View File

@ -5,8 +5,8 @@ public class Caret {
private int pos;
private int remaining;
private CaretState state;
private int[] lastSize;
private int[] lastLocation;
private final int[] lastSize;
private final int[] lastLocation;
public Caret(CaretState state, int pos) {
this(state, pos, new int[] { 0, 0 }, new int[] { 2, 5 });

View File

@ -30,8 +30,8 @@ public abstract class ExtraMenu<T extends Block> implements Serializable, Keyboa
public abstract void close();
public boolean beforeRender(float delta, Caret caret) {
int[] l = caret.getLastLocation();
int[] cs = caret.getLastSize();
final int[] l = caret.getLastLocation();
final int[] cs = caret.getLastSize();
location[0] = l[0] - block.getWidth() / 2 - width / 2;
location[1] = l[1] + cs[1];
return false;

View File

@ -11,8 +11,9 @@ public class InputContext {
public BlockVariable variableTypeDirtyID = null;
public InputContext() {
this.variableTypes = new HashMap<>();
this.variableTypes.put(MathematicalSymbols.PI, V_TYPE.CONSTANT);
variableTypes = new HashMap<>();
variableTypes.put(MathematicalSymbols.PI, V_TYPE.CONSTANT);
variableTypes.put(MathematicalSymbols.EULER_NUMBER, V_TYPE.CONSTANT);
}
public InputContext(HashMap<Character, V_TYPE> variableTypes) {

View File

@ -32,7 +32,7 @@ public abstract class Block implements GraphicalElement {
public abstract boolean delBlock(Caret caret);
public abstract Block getBlock(Caret caret);
public abstract BlockReference<?> getBlock(Caret caret);
@Override
public abstract void recomputeDimensions();

View File

@ -34,7 +34,7 @@ public class BlockChar extends Block {
}
@Override
public Block getBlock(Caret caret) {
public BlockReference<?> getBlock(Caret caret) {
return null;
}

View File

@ -2,6 +2,8 @@ package org.warp.picalculator.gui.expression.blocks;
import org.warp.picalculator.Error;
import org.warp.picalculator.Errors;
import org.warp.picalculator.PlatformUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.gui.GraphicalElement;
import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.expression.CaretState;
@ -69,6 +71,11 @@ public class BlockContainer implements GraphicalElement {
}
public void addBlock(int position, Block b) {
addBlockUnsafe(position, b);
recomputeDimensions();
}
public void addBlockUnsafe(int position, Block b) {
if (b.isSmall() != small) {
b.setSmall(small);
}
@ -77,7 +84,6 @@ public class BlockContainer implements GraphicalElement {
} else {
content.add(position, b);
}
recomputeDimensions();
}
public void appendBlock(Block b) {
@ -93,17 +99,26 @@ public class BlockContainer implements GraphicalElement {
}
public void removeBlock(Block b) {
content.remove(b);
removeBlockUnsafe(b);
recomputeDimensions();
}
public void removeBlockUnsafe(Block b) {
content.remove(b);
}
public void removeAt(int i) {
content.remove(i);
recomputeDimensions();
}
public Block getBlockAt(int i) {
return content.get(i);
public BlockReference<?> getBlockAt(int i) {
final Block b = content.get(i);
return new BlockReference<>(b, i, this);
}
public int getSize() {
return content.size();
}
public void clear() {
@ -202,8 +217,8 @@ public class BlockContainer implements GraphicalElement {
return removed;
}
public Block getBlock(Caret caret) {
Block block = null;
public BlockReference<?> getBlock(Caret caret) {
BlockReference<?> block = null;
int pos = 0;
for (final Block b : content) {
@ -323,11 +338,11 @@ public class BlockContainer implements GraphicalElement {
public void setSmall(boolean small) {
this.small = small;
if (this.autoMinimums) {
this.minWidth = BlockContainer.getDefaultCharWidth(small);
this.minHeight = BlockContainer.getDefaultCharHeight(small);
if (autoMinimums) {
minWidth = BlockContainer.getDefaultCharWidth(small);
minHeight = BlockContainer.getDefaultCharHeight(small);
}
for (Block b : this.content) {
for (final Block b : content) {
b.setSmall(small);
}
recomputeDimensions();
@ -339,7 +354,7 @@ public class BlockContainer implements GraphicalElement {
private static void checkInitialized() {
if (!initialized) {
throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
PlatformUtils.throwNewExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
}
}
@ -352,13 +367,14 @@ public class BlockContainer implements GraphicalElement {
}
public Function toFunction(MathContext context) throws Error {
ObjectArrayList<Block> blocks = getContent();
final ObjectArrayList<Block> blocks = getContent();
final ObjectArrayList<Feature> blockFeatures = new ObjectArrayList<>();
for (final Block block : blocks) {
final Feature blockFeature = block.toFeature(context);
if (blockFeature == null)
if (blockFeature == null) {
throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known Block");
}
blockFeatures.add(blockFeature);
}

View File

@ -57,8 +57,8 @@ public class BlockDivision extends Block {
}
@Override
public Block getBlock(Caret caret) {
Block bl = null;
public BlockReference<?> getBlock(Caret caret) {
BlockReference<?> bl = null;
bl = containerUp.getBlock(caret);
if (bl != null) {
return bl;

View File

@ -21,6 +21,6 @@ public class BlockExponentialNotation extends BlockPower {
super.recomputeDimensions();
bw = (int) (BlockContainer.getDefaultCharWidth(small) * 1.5);
bh = BlockContainer.getDefaultCharHeight(small);
this.width += bw;
width += bw;
}
}

View File

@ -0,0 +1,163 @@
package org.warp.picalculator.gui.expression.blocks;
import org.warp.picalculator.Error;
import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.math.Function;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.parser.features.FeatureLogarithm;
import org.warp.picalculator.math.parser.features.interfaces.Feature;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class BlockLogarithm extends Block {
private final BlockContainer containerBase;
private final BlockContainer containerNumber;
private final String prefix = "log";
private int prw;
private int bw;
private int bh;
private int bl;
private int chw;
private int chh;
private int schh;
private int nmbh;
private int toph;
public BlockLogarithm() {
containerBase = new BlockContainer(true);
containerNumber = new BlockContainer(false);
recomputeDimensions();
}
public BlockLogarithm(ObjectArrayList<Block> blocks) {
containerBase = new BlockContainer(true);
containerNumber = new BlockContainer(false, blocks);
recomputeDimensions();
}
@Override
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
BlockContainer.getDefaultFont(small).use(ge);
r.glColor(BlockContainer.getDefaultColor());
if (prefix != null) {
r.glDrawStringLeft(x + 1, y + line - chh / 2, prefix);
}
r.glDrawCharLeft(x + bw + prw, y + toph, '╭');
r.glDrawCharLeft(x + bw + prw, y + toph + nmbh - chh, '╰');
if (small) {
r.glFillColor(x + bw + prw + 1, y + toph + 5, 1, nmbh - 4 * 2);
r.glFillColor(x + width - 3, y + toph + 5, 1, nmbh - 4 * 2);
} else {
r.glFillColor(x + bw + prw + 3, y + toph + 6, 2, nmbh - 6 * 2);
r.glFillColor(x + width - 5, y + toph + 6, 2, nmbh - 6 * 2);
}
r.glDrawCharLeft(x + width - chw, y + toph, '╮');
r.glDrawCharLeft(x + width - chw, y + toph + nmbh - chh, '╯');
r.glColor(BlockContainer.getDefaultColor());
containerBase.draw(ge, r, x + prw, y + line + chh / 2 - bl, caret);
r.glColor(BlockContainer.getDefaultColor());
containerNumber.draw(ge, r, x + bw + prw + chw, y + toph, caret);
}
@Override
public boolean putBlock(Caret caret, Block newBlock) {
boolean added = false;
added = added | containerBase.putBlock(caret, newBlock);
added = added | containerNumber.putBlock(caret, newBlock);
if (added) {
recomputeDimensions();
}
return added;
}
@Override
public boolean delBlock(Caret caret) {
boolean removed = false;
removed = removed | containerBase.delBlock(caret);
removed = removed | containerNumber.delBlock(caret);
if (removed) {
recomputeDimensions();
}
return removed;
}
@Override
public BlockReference<?> getBlock(Caret caret) {
BlockReference<?> bl = null;
bl = containerBase.getBlock(caret);
if (bl != null) {
return bl;
}
bl = containerNumber.getBlock(caret);
return bl;
}
@Override
public void recomputeDimensions() {
if (prefix == null) {
prw = 0;
} else {
prw = 1 + BlockContainer.getDefaultCharWidth(small) * prefix.length();
}
bw = containerBase.getWidth();
bh = containerBase.getHeight();
bl = containerBase.getLine();
chw = BlockContainer.getDefaultCharWidth(small);
chh = BlockContainer.getDefaultCharHeight(small);
schh = BlockContainer.getDefaultCharHeight(true);
width = prw + bw + chw + containerNumber.getWidth() + chw + 3;
nmbh = containerNumber.getHeight();
final int nl = containerNumber.getLine();
if (bl > nmbh) {
toph = bl - nmbh;
line = toph + nl;
if (bl + (bh - bl) > toph + nmbh) {
height = bl + (bh - bl);
} else {
height = toph + nmbh;
}
} else {
System.out.println("b");
toph = 0;
line = toph + nl;
if (nmbh + bh - bl > toph + nmbh) {
height = nmbh + (bh - bl);
} else {
height = toph + nmbh;
}
}
}
@Override
public void setSmall(boolean small) {
this.small = small;
containerBase.setSmall(small);
containerNumber.setSmall(small);
recomputeDimensions();
}
public BlockContainer getBaseContainer() {
return containerBase;
}
public BlockContainer getNumberContainer() {
return containerNumber;
}
@Override
public int computeCaretMaxBound() {
return containerBase.computeCaretMaxBound() + containerNumber.computeCaretMaxBound();
}
@Override
public Feature toFeature(MathContext context) throws Error {
final Function base = getBaseContainer().toFunction(context);
final Function number = getNumberContainer().toFunction(context);
return new FeatureLogarithm(base, number);
}
}

View File

@ -0,0 +1,9 @@
package org.warp.picalculator.gui.expression.blocks;
public class BlockNumericChar extends BlockChar {
public BlockNumericChar(char ch) {
super(ch);
}
}

View File

@ -27,13 +27,13 @@ public abstract class BlockParenthesisAbstract extends Block {
public BlockParenthesisAbstract() {
containerNumber = new BlockContainer(false);
this.prefix = null;
prefix = null;
recomputeDimensions();
}
public BlockParenthesisAbstract(ObjectArrayList<Block> blocks) {
containerNumber = new BlockContainer(false, blocks);
this.prefix = null;
prefix = null;
recomputeDimensions();
}
@ -79,7 +79,7 @@ public abstract class BlockParenthesisAbstract extends Block {
}
@Override
public Block getBlock(Caret caret) {
public BlockReference<?> getBlock(Caret caret) {
return containerNumber.getBlock(caret);
}
@ -113,6 +113,7 @@ public abstract class BlockParenthesisAbstract extends Block {
return containerNumber.computeCaretMaxBound();
}
@Override
public abstract Feature toFeature(MathContext context) throws Error;
}

View File

@ -46,7 +46,7 @@ public class BlockPower extends Block {
}
@Override
public Block getBlock(Caret caret) {
public BlockReference<?> getBlock(Caret caret) {
return containerExponent.getBlock(caret);
}

View File

@ -0,0 +1,53 @@
package org.warp.picalculator.gui.expression.blocks;
public class BlockReference<T extends Block> {
private final T block;
private final BlockContainer container;
private final int blockPosition;
public BlockReference(T block, int blockPosition, BlockContainer container) {
this.block = block;
this.blockPosition = blockPosition;
this.container = container;
}
public T get() {
return block;
}
public BlockContainer getContainer() {
return container;
}
public int getIndex() {
return blockPosition;
}
public BlockReference<?> getNextBlock() {
return getBlockAtSafe(this.blockPosition + 1);
}
public boolean hasNextBlock() {
return isInsideBounds(this.blockPosition + 1);
}
public BlockReference<?> getPreviousBlock() {
return getBlockAtSafe(this.blockPosition - 1);
}
public boolean hasPreviousBlock() {
return isInsideBounds(this.blockPosition - 1);
}
private BlockReference<?> getBlockAtSafe(int i) {
if (isInsideBounds(i)) {
return container.getBlockAt(i);
}
return null;
}
private boolean isInsideBounds(int i) {
return i < container.getSize() && i >= 0;
}
}

View File

@ -56,7 +56,7 @@ public class BlockSquareRoot extends Block {
}
@Override
public Block getBlock(Caret caret) {
public BlockReference<?> getBlock(Caret caret) {
return containerNumber.getBlock(caret);
}

View File

@ -0,0 +1,62 @@
package org.warp.picalculator.gui.expression.blocks;
import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.math.MathContext;
import org.warp.picalculator.math.MathematicalSymbols;
import org.warp.picalculator.math.parser.features.FeatureChar;
import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class BlockUndefined extends Block {
public BlockUndefined() {
recomputeDimensions();
}
@Override
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
BlockContainer.getDefaultFont(small).use(ge);
r.glColor(BlockContainer.getDefaultColor());
r.glDrawStringLeft(x, y, "UNDEFINED");
}
@Override
public boolean putBlock(Caret caret, Block newBlock) {
return false;
}
@Override
public boolean delBlock(Caret caret) {
return false;
}
@Override
public BlockReference<?> getBlock(Caret caret) {
return null;
}
@Override
public void recomputeDimensions() {
width = BlockContainer.getDefaultFont(small).getStringWidth("UNDEFINED");
height = BlockContainer.getDefaultCharHeight(small);
line = height / 2;
}
@Override
public void setSmall(boolean small) {
this.small = small;
recomputeDimensions();
}
@Override
public int computeCaretMaxBound() {
return 0;
}
@Override
public Feature toFeature(MathContext context) {
return new FeatureChar(MathematicalSymbols.UNDEFINED);
}
}

View File

@ -1,7 +1,7 @@
package org.warp.picalculator.gui.expression.blocks;
import org.warp.picalculator.Error;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.device.Key;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.expression.ExtraMenu;
@ -16,7 +16,7 @@ import org.warp.picalculator.math.parser.features.interfaces.Feature;
public class BlockVariable extends Block {
private InputContext ic;
private final InputContext ic;
private final char ch;
private final VariableMenu menu;
private V_TYPE type;
@ -32,17 +32,20 @@ public class BlockVariable extends Block {
public BlockVariable(InputContext ic, char ch, boolean typeLocked) {
this.ic = ic;
this.ch = ch;
this.type = V_TYPE.VARIABLE;
this.color = 0xFF304ffe;
this.typeDirtyID = this;
type = V_TYPE.VARIABLE;
color = 0xFF304ffe;
typeDirtyID = this;
this.typeLocked = typeLocked;
this.menu = typeLocked ? null : new VariableMenu(this);
menu = typeLocked ? null : new VariableMenu(this);
retrieveValue();
recomputeDimensions();
}
private void retrieveValue() {
type = ic.variableTypes.getOrDefault(ch, V_TYPE.VARIABLE);
type = ic.variableTypes.get(ch);
if (type == null) {
type = V_TYPE.VARIABLE;
}
typeDirtyID = ic.variableTypeDirtyID;
if (menu != null) {
menu.mustRefreshMenu = true;
@ -100,7 +103,7 @@ public class BlockVariable extends Block {
}
@Override
public Block getBlock(Caret caret) {
public BlockReference<?> getBlock(Caret caret) {
return null;
}
@ -205,7 +208,7 @@ public class BlockVariable extends Block {
if (mustRefreshMenu) {
mustRefreshMenu = false;
text = block.type.toString();
BinaryFont f = BlockContainer.getDefaultFont(true);
final BinaryFont f = BlockContainer.getDefaultFont(true);
width = 7 + f.getStringWidth(text) + 7;
height = 2 + f.getCharacterHeight() + 2;
@ -227,7 +230,7 @@ public class BlockVariable extends Block {
if (popupY < 0) {
popupY = 0;
}
int[] screenSize = ge.getSize();
final int[] screenSize = ge.getSize();
if (popupX + width >= screenSize[0]) {
popupX = screenSize[0] - width - 1;
}

View File

@ -11,6 +11,7 @@ import org.warp.picalculator.gui.expression.ExtraMenu;
import org.warp.picalculator.gui.expression.InputContext;
import org.warp.picalculator.gui.expression.blocks.Block;
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
import org.warp.picalculator.gui.expression.blocks.BlockReference;
import org.warp.picalculator.gui.expression.layouts.InputLayout;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
@ -58,6 +59,10 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
public void typeChar(char c) {
final Block b = parseChar(c);
typeBlock(b);
}
public void typeBlock(Block b) {
if (b != null) {
caret.resetRemaining();
if (root.putBlock(caret, b)) {
@ -89,9 +94,9 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
closeExtra();
}
public Block getSelectedBlock() {
public BlockReference<?> getSelectedBlock() {
caret.resetRemaining();
Block selectedBlock = root.getBlock(caret);
final BlockReference<?> selectedBlock = root.getBlock(caret);
return selectedBlock;
}
@ -225,9 +230,9 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
public void toggleExtra() {
if (extra == null) {
Block selectedBlock = getSelectedBlock();
final BlockReference<?> selectedBlock = getSelectedBlock();
if (selectedBlock != null) {
extra = selectedBlock.getExtraMenu();
extra = selectedBlock.get().getExtraMenu();
extra.open();
}
} else {

View File

@ -3,10 +3,14 @@ package org.warp.picalculator.gui.expression.containers;
import org.warp.picalculator.gui.expression.InputContext;
import org.warp.picalculator.gui.expression.blocks.Block;
import org.warp.picalculator.gui.expression.blocks.BlockChar;
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
import org.warp.picalculator.gui.expression.blocks.BlockDivision;
import org.warp.picalculator.gui.expression.blocks.BlockNumericChar;
import org.warp.picalculator.gui.expression.blocks.BlockParenthesis;
import org.warp.picalculator.gui.expression.blocks.BlockPower;
import org.warp.picalculator.gui.expression.blocks.BlockReference;
import org.warp.picalculator.gui.expression.blocks.BlockSine;
import org.warp.picalculator.gui.expression.blocks.BlockLogarithm;
import org.warp.picalculator.gui.expression.blocks.BlockSquareRoot;
import org.warp.picalculator.gui.expression.blocks.BlockVariable;
import org.warp.picalculator.math.MathematicalSymbols;
@ -53,6 +57,7 @@ public class NormalInputContainer extends InputContainer {
case MathematicalSymbols.SUM:
case MathematicalSymbols.SUM_SUBTRACTION:
case MathematicalSymbols.SUBTRACTION:
return new BlockChar(c);
case '0':
case '1':
case '2':
@ -63,13 +68,18 @@ public class NormalInputContainer extends InputContainer {
case '7':
case '8':
case '9':
return new BlockChar(c);
case '.':
return new BlockNumericChar(c);
case MathematicalSymbols.SINE:
return new BlockSine();
case MathematicalSymbols.LOGARITHM:
return new BlockLogarithm();
case MathematicalSymbols.PI:
return new BlockVariable(inputContext, c, true);
case MathematicalSymbols.EULER_NUMBER:
return new BlockVariable(inputContext, c, true);
default:
for (char v : MathematicalSymbols.variables) {
for (final char v : MathematicalSymbols.variables) {
if (c == v) {
return new BlockVariable(inputContext, c);
}
@ -81,8 +91,47 @@ public class NormalInputContainer extends InputContainer {
@Override
public void typeChar(char c) {
super.typeChar(c);
if (c == MathematicalSymbols.PARENTHESIS_CLOSE) {
this.moveRight();
switch (c) {
case MathematicalSymbols.PARENTHESIS_CLOSE:
moveRight();
case MathematicalSymbols.DIVISION:
@SuppressWarnings("unchecked") final
BlockReference<BlockDivision> ref = (BlockReference<BlockDivision>) getSelectedBlock();
final BlockContainer parentContainer = ref.getContainer();
BlockReference<?> currentBlock = ref;
boolean groupedBefore = false;
int before = 0;
while (true) {
currentBlock = currentBlock.getPreviousBlock();
if (currentBlock == null) {
break;
}
final Block b = currentBlock.get();
if (b instanceof BlockNumericChar || b instanceof BlockVariable) {
if (!groupedBefore) {
groupedBefore = true;
}
before++;
} else {
break;
}
}
if (groupedBefore) {
moveLeft();
for (int i = 0; i < before; i++) {
final BlockReference<?> b = getSelectedBlock();
del();
moveRight();
typeBlock(b.get());
moveLeft();
moveLeft();
}
for (int i = 0; i < before + 1; i++) {
moveRight();
}
moveRight();// Move to the divisor
}
}
}
}

View File

@ -7,6 +7,7 @@ import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.expression.CaretState;
import org.warp.picalculator.gui.expression.blocks.Block;
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
import org.warp.picalculator.gui.expression.layouts.OutputLayout;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
@ -34,8 +35,8 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
public void setContentAsSingleGroup(ObjectArrayList<Block> blocks) {
roots.clear();
BlockContainer bcnt = new BlockContainer();
for (Block block : blocks) {
final BlockContainer bcnt = new BlockContainer();
for (final Block block : blocks) {
bcnt.appendBlockUnsafe(block);
}
roots.add(bcnt);
@ -44,9 +45,9 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
public void setContentAsMultipleGroups(ObjectArrayList<ObjectArrayList<Block>> roots) {
this.roots.clear();
for (ObjectArrayList<Block> blocks : roots) {
BlockContainer bcnt = new BlockContainer();
for (Block block : blocks) {
for (final ObjectArrayList<Block> blocks : roots) {
final BlockContainer bcnt = new BlockContainer();
for (final Block block : blocks) {
bcnt.appendBlockUnsafe(block);
}
this.roots.add(bcnt);
@ -55,18 +56,18 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
}
public void setContentAsMultipleElements(ObjectArrayList<Block> elems) {
this.roots.clear();
for (Block block : elems) {
BlockContainer bcnt = new BlockContainer();
roots.clear();
for (final Block block : elems) {
final BlockContainer bcnt = new BlockContainer();
bcnt.appendBlockUnsafe(block);
this.roots.add(bcnt);
roots.add(bcnt);
}
recomputeDimensions();
}
@Override
public void recomputeDimensions() {
for (BlockContainer root : roots) {
for (final BlockContainer root : roots) {
root.recomputeDimensions();
}
}
@ -74,10 +75,11 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
@Override
public int getWidth() {
int maxw = 0;
for (BlockContainer root : roots) {
int w = root.getWidth();
if (w > maxw)
for (final BlockContainer root : roots) {
final int w = root.getWidth();
if (w > maxw) {
maxw = w;
}
}
return maxw;
}
@ -85,7 +87,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
@Override
public int getHeight() {
int h = 0;
for (BlockContainer root : roots) {
for (final BlockContainer root : roots) {
h += root.getHeight() + 2;
}
if (h > 0) {
@ -122,7 +124,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
*/
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
int offset = 0;
for (BlockContainer root : roots) {
for (final BlockContainer root : roots) {
root.draw(ge, r, x, y + offset, caret);
offset += root.getHeight() + 2;
}
@ -135,8 +137,8 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
}
public boolean isContentEmpty() {
for (BlockContainer root : roots) {
ObjectArrayList<Block> cnt = root.getContent();
for (final BlockContainer root : roots) {
final ObjectArrayList<Block> cnt = root.getContent();
if (cnt != null && !cnt.isEmpty()) {
return false;
}

View File

@ -1,3 +0,0 @@
package org.warp.picalculator.gui.expression.containers;
public interface OutputLayout {}

View File

@ -0,0 +1,3 @@
package org.warp.picalculator.gui.expression.layouts;
public interface OutputLayout {}

View File

@ -36,7 +36,7 @@ public interface GraphicEngine {
public Renderer getRenderer();
public BinaryFont loadFont(String fontName) throws IOException;
public BinaryFont loadFont(String path, String fontName) throws IOException;
public Skin loadSkin(String file) throws IOException;

View File

@ -11,4 +11,8 @@ public interface Skin {
public boolean isInitialized();
public void use(GraphicEngine d);
public int getSkinWidth();
public int getSkinHeight();
}

View File

@ -38,7 +38,7 @@ public class CPUEngine implements GraphicEngine {
public void setDisplayMode(final int ww, final int wh) {
INSTANCE.setSize(ww, wh);
r.size = new int[] { ww, wh };
r.canvas2d = new int[ww * wh];
CPURenderer.canvas2d = new int[ww * wh];
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
}
@ -55,15 +55,22 @@ public class CPUEngine implements GraphicEngine {
setDisplayMode(StaticVars.screenSize[0], StaticVars.screenSize[1]);
INSTANCE.setVisible(true);
initialized = true;
if (onInitialized != null)
if (onInitialized != null) {
onInitialized.run();
}
}
@Override
public boolean wasResized() {
if (INSTANCE.wasResized) {
r.size = new int[] { INSTANCE.getWidth(), INSTANCE.getHeight() };
r.canvas2d = new int[r.size[0] * r.size[1]];
if (r.size[0] <= 0) {
r.size[0] = 1;
}
if (r.size[1] <= 0) {
r.size[1] = 1;
}
CPURenderer.canvas2d = new int[r.size[0] * r.size[1]];
g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
return true;
@ -178,13 +185,14 @@ public class CPUEngine implements GraphicEngine {
public void waitForExit() {
try {
exitSemaphore.acquire();
} catch (InterruptedException e) {}
} catch (final InterruptedException e) {}
}
@Override
public boolean isSupported() {
if (Utils.forceEngine != null && Utils.forceEngine != "cpu")
if (Utils.forceEngine != null && Utils.forceEngine != "cpu") {
return false;
}
return (Utils.headlessOverride || GraphicsEnvironment.isHeadless()) == false;
}

View File

@ -11,6 +11,7 @@ import java.util.logging.Logger;
import javax.imageio.ImageIO;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
@ -25,7 +26,7 @@ public class CPUFont implements BinaryFont {
public int charH;
public int charS;
public int charIntCount;
public LinkedList<Integer[]> intervals;
public int[] intervals;
public int intervalsTotalSize = 0;
public static final int intBits = 31;
private final boolean isResource;
@ -38,11 +39,11 @@ public class CPUFont implements BinaryFont {
isResource = true;
load("/font_" + fontName + ".rft", onlyRaw);
}
public CPUFont(String path, String fontName) throws IOException {
this(path, fontName, false);
}
CPUFont(String path, String fontName, boolean onlyRaw) throws IOException {
isResource = false;
load(path + "/font_" + fontName + ".rft", onlyRaw);
@ -60,9 +61,9 @@ public class CPUFont implements BinaryFont {
public void load(String path) throws IOException {
load(path, false);
}
private void load(String path, boolean onlyRaw) throws IOException {
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MIN, "Loading font " + path);
ConsoleUtils.out.println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Loading font " + path);
loadFont(path);
if (!onlyRaw) {
chars32 = new int[(intervalsTotalSize) * charIntCount];
@ -110,7 +111,7 @@ public class CPUFont implements BinaryFont {
minBound = file[0x9] << 24 | file[0xA] << 16 | file[0xB] << 8 | file[0xC];
maxBound = file[0xE] << 24 | file[0xF] << 16 | file[0x10] << 8 | file[0x11];
if (maxBound <= minBound) {
maxBound = 9900; //TODO remove it: temp fix
maxBound = 66000; //TODO remove it: temp fix
}
rawchars = new boolean[maxBound - minBound][];
int index = 0x12;
@ -167,44 +168,52 @@ public class CPUFont implements BinaryFont {
}
private void findIntervals() {
intervals = new LinkedList<Integer[]>();
final LinkedList<int[]> intervals = new LinkedList<>();
int beginIndex = -1;
int endIndex = 0;
int intervalSize = 0;
int holeSize = 0;
final int holeSize = 0;
for (int i = 0; i < rawchars.length; i++) {
if (rawchars[i] != null) {
beginIndex = i;
int firstNull = 0;
while(i+firstNull < rawchars.length && rawchars[i+firstNull] != null) {
while (i + firstNull < rawchars.length && rawchars[i + firstNull] != null) {
firstNull++;
}
endIndex = beginIndex + firstNull - 1;
i = endIndex;
if (endIndex >= 0) {
intervalSize = endIndex - beginIndex + 1;
intervals.add(new Integer[] {beginIndex, endIndex, intervalSize});
intervals.add(new int[] { beginIndex, endIndex, intervalSize });
intervalsTotalSize += intervalSize;
}
beginIndex = -1;
}
}
int lastIndex = 0;
boolean[][] newrawchars = new boolean[intervalsTotalSize][];
for (Integer[] interval: intervals) {
final boolean[][] newrawchars = new boolean[intervalsTotalSize][];
for (final int[] interval : intervals) {
if (rawchars.length - (interval[0]) - interval[2] < 0) {
System.err.println(interval[0] + "-" + interval[1] + "(" + interval[2] + ")");
System.err.println(rawchars.length - (interval[0]) - interval[2]);
throw new ArrayIndexOutOfBoundsException();
}
if (newrawchars.length - (lastIndex-1) - interval[2] < 0) {
System.err.println(newrawchars.length - (lastIndex-1) - interval[2]);
if (newrawchars.length - (lastIndex - 1) - interval[2] < 0) {
System.err.println(newrawchars.length - (lastIndex - 1) - interval[2]);
throw new ArrayIndexOutOfBoundsException();
}
System.arraycopy(rawchars, interval[0], newrawchars, lastIndex, interval[2]);
lastIndex += interval[2];
}
rawchars = newrawchars;
final int intervalsSize = intervals.size();
this.intervals = new int[intervalsSize * 3];
for (int i = 0; i < intervalsSize; i++) {
final int[] interval = intervals.get(i);
this.intervals[i * 3 + 0] = interval[0];
this.intervals[i * 3 + 1] = interval[1];
this.intervals[i * 3 + 2] = interval[2];
}
}
@SuppressWarnings("unused")
@ -224,41 +233,41 @@ public class CPUFont implements BinaryFont {
final int[] indexes = new int[l];
final char[] chars = txt.toCharArray();
for (int i = 0; i < l; i++) {
int originalIndex = (chars[i] & 0xFFFF) - minBound;
final int originalIndex = (chars[i] & 0xFFFF) - minBound;
indexes[i] = compressIndex(originalIndex);
}
return indexes;
}
public int getCharIndex(char c) {
int originalIndex = c & 0xFFFF;
final int originalIndex = c & 0xFFFF;
return compressIndex(originalIndex);
}
private int compressIndex(int originalIndex) {
int compressedIndex = 0;
for (Integer[] interval : intervals) {
if (interval[0] > originalIndex) {
for (int i = 0; i < intervals.length; i += 3) {
if (intervals[i] > originalIndex) {
break;
} else if (originalIndex <= interval[1]) {
compressedIndex+=(originalIndex-interval[0]);
} else if (originalIndex <= intervals[i + 1]) {
compressedIndex += (originalIndex - intervals[i]);
break;
} else {
compressedIndex+=interval[2];
compressedIndex += intervals[i + 2];
}
}
return compressedIndex;
}
private int decompressIndex(int compressedIndex) {
int originalIndex = 0;
final int originalIndex = 0;
int i = 0;
for (Integer[] interval : intervals) {
i+=interval[2];
for (int intvl = 0; intvl < intervals.length; intvl += 3) {
i += intervals[intvl + 2];
if (i == compressedIndex) {
return interval[1];
return intervals[intvl + 1];
} else if (i > compressedIndex) {
return interval[1] - (i - compressedIndex);
return intervals[intvl + 1] - (i - compressedIndex);
}
}
return originalIndex;
@ -299,4 +308,14 @@ public class CPUFont implements BinaryFont {
return true;
}
@Override
public int getSkinWidth() {
return -1;
}
@Override
public int getSkinHeight() {
return -1;
}
}

View File

@ -48,14 +48,21 @@ public class CPURenderer implements Renderer {
public void glClear(int screenWidth, int screenHeight) {
for (int x = 0; x < screenWidth; x++) {
for (int y = 0; y < screenHeight; y++) {
canvas2d[x + y * size[0]] = clearcolor;
final int index = x + y * size[0];
if (index >= 0 && index < canvas2d.length) {
canvas2d[index] = clearcolor;
}
}
}
}
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
private void glDrawSkin(int x0, int y0, int x1, int y1, int s0, int t0, int s1, int t1, boolean transparent) {
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;
int newColor;
final int onex = s0 <= s1 ? 1 : -1;
@ -101,16 +108,33 @@ public class CPURenderer implements Renderer {
}
y0 = 0;
}
int pixelX;
int pixelY;
for (int texx = 0; texx < s1 - s0; texx++) {
for (int texy = 0; texy < t1 - t0; texy++) {
pixelX = (x0 + texx * onex + width);
pixelY = (y0 + texy * oney + height);
if (pixelX - (pixelX % size[0]) == 0) {
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
for (double pixelX = 0; pixelX < x1 - x0; pixelX++) {
for (double pixelY = 0; pixelY < y1 - y0; pixelY++) {
final int index = (int) (x0 + pixelX + (y0 + pixelY) * size[0]);
if (index >= 0 && index < canvas2d.length && pixelX < size[0]) {
final int texx = (int) (pixelX / incrementX);
final int texy = (int) (pixelY / incrementY);
int expX = 0;
int expY = 0;
if (incrementX < 1) {
expX = (int) Math.round(1d / incrementX / 2d);
}
if (incrementY < 1) {
expY = (int) Math.round(1d / incrementY / 2d);
}
final int[] newColors = new int[(1 + expX * 2) * (1 + expY * 2)];
for (int expXi = -expX; expXi <= expX; expXi++) {
for (int expYi = -expY; expYi <= expY; expYi++) {
final int skinIndex = (int) (s0 + (texx * (flippedX ? -1d : 1d) + (flippedX ? -(s0 - s1) - 1 : 0) + expXi) + (t0 + (texy * (flippedY ? -1d : 1d) + (flippedY ? -(t0 - t1) - 1 : 0) + expYi)) * currentSkin.skinSize[0]);
final int idx = (expXi + expX) + (expYi + expY) * (1 + expY * 2);
if (idx >= 0 && idx < newColors.length) {
newColors[idx] = getSkinColorAt(currentSkin.skinData, skinIndex);
}
}
}
newColor = joinColors(newColors);
if (transparent) {
oldColor = canvas2d[pixelX + pixelY * size[0]];
oldColor = canvas2d[index];
final float a2 = (newColor >> 24 & 0xFF) / 255f;
final float a1 = 1f - a2;
final int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
@ -118,12 +142,55 @@ public class CPURenderer implements Renderer {
final int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
newColor = 0xFF000000 | r << 16 | g << 8 | b;
}
canvas2d[pixelX + pixelY * size[0]] = newColor;
canvas2d[index] = stackColors(canvas2d[index], newColor);
}
}
}
}
private int joinColors(int[] newColors) {
int a = 0;
int r = 0;
int g = 0;
int b = 0;
for (final int newColor : newColors) {
a += newColor >> 24 & 0xFF;
r += newColor >> 16 & 0xFF;
g += newColor >> 8 & 0xFF;
b += newColor & 0xFF;
}
return (a / newColors.length) << 24 | (r / newColors.length) << 16 | (g / newColors.length) << 8 | (b / newColors.length);
}
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);
}
private int getSkinColorAt(int[] skinData, int skinIndex) {
int newColor = 0;
if (skinIndex >= 0 && skinIndex < skinData.length) {
newColor = skinData[skinIndex];
final int a = (int) ((newColor >> 24 & 0xFF) * ((double) (color >> 24 & 0xFF) / (double) 0xFF));
final int r = (int) ((newColor >> 16 & 0xFF) * ((double) (color >> 16 & 0xFF) / (double) 0xFF));
final int g = (int) ((newColor >> 8 & 0xFF) * ((double) (color >> 8 & 0xFF) / (double) 0xFF));
final int b = (int) ((newColor & 0xFF) * ((double) (color & 0xFF) / (double) 0xFF));
newColor = a << 24 | r << 16 | g << 8 | b;
}
return newColor;
}
@Override
public void glDrawLine(float x0, float y0, float x1, float y1) {
x0 += StaticVars.screenPos[0];
@ -140,13 +207,13 @@ public class CPURenderer implements Renderer {
if (iy0 == iy1) {
for (int x = 0; x <= ix1 - ix0; x++) {
if ((ix0 + x < size[0]) & (iy0 < size[1])) {
canvas2d[ix0 + x + iy0 * size[0]] = color;
canvas2d[ix0 + x + iy0 * size[0]] = stackColors(canvas2d[ix0 + x + iy0 * size[0]], color);
}
}
} else if (ix0 == ix1) {
for (int y = 0; y <= iy1 - iy0; y++) {
if ((ix0 < size[0]) & (iy0 + y < size[1])) {
canvas2d[ix0 + (iy0 + y) * size[0]] = color;
canvas2d[ix0 + (iy0 + y) * size[0]] = stackColors(canvas2d[ix0 + (iy0 + y) * size[0]], color);
}
}
} else {
@ -154,7 +221,7 @@ public class CPURenderer implements Renderer {
for (int texx = 0; texx <= ix1 - ix0; texx++) {
if (ix0 + texx < size[0] && iy0 + (m * texx) < size[1]) {
if ((ix0 + texx < size[0]) & ((iy0 + (m * texx)) < size[1])) {
canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = color;
canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = stackColors(canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]], color);
}
}
}
@ -165,7 +232,7 @@ public class CPURenderer implements Renderer {
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) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
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);
}
@ -203,7 +270,10 @@ public class CPURenderer implements Renderer {
final int sizeW = size[0];
for (int px = x0; px < x1; px++) {
for (int py = y0; py < y1; py++) {
canvas2d[(px) + (py) * sizeW] = color;
final int idx = (px) + (py) * sizeW;
if (px < sizeW && idx >= 0 && idx < canvas2d.length) {
canvas2d[idx] = stackColors(canvas2d[idx], color);
}
}
}
}
@ -238,10 +308,13 @@ public class CPURenderer implements Renderer {
final int bit = dx + dy * currentFont.charW;
currentInt = (int) (Math.floor(bit) / (CPUFont.intBits));
currentIntBitPosition = bit - (currentInt * CPUFont.intBits);
bitData = (currentFont.chars32[charIndex * currentFont.charIntCount + currentInt] >> currentIntBitPosition) & 1;
screenPos = ix + cpos + dx + (iy + dy) * screenSize[0];
if (bitData == 1 & screenLength > screenPos & screenPos >= 0) {
screen[screenPos] = color;
final int charIdx = charIndex * currentFont.charIntCount + currentInt;
if (charIdx >= 0 && charIdx < currentFont.chars32.length) {
bitData = (currentFont.chars32[charIdx] >> currentIntBitPosition) & 1;
screenPos = ix + cpos + dx + (iy + dy) * screenSize[0];
if (bitData == 1 & screenLength > screenPos & screenPos >= 0) {
screen[screenPos] = stackColors(screen[screenPos], color);
}
}
}
}

View File

@ -23,8 +23,13 @@ public class CPUSkin implements Skin {
@Override
public void load(String file) throws IOException {
final BufferedImage img = ImageIO.read(isResource ? this.getClass().getResource("/" + file) : new File(file).toURI().toURL());
skinData = getMatrixOfImage(img);
skinSize = new int[] { img.getWidth(), img.getHeight() };
if (img == null) {
skinData = new int[0];
skinSize = new int[] { 0, 0 };
} else {
skinData = getMatrixOfImage(img);
skinSize = new int[] { img.getWidth(), img.getHeight() };
}
}
public static int[] getMatrixOfImage(BufferedImage bufferedImage) {
@ -58,4 +63,14 @@ public class CPUSkin implements Skin {
return true;
}
@Override
public int getSkinWidth() {
return skinSize[0];
}
@Override
public int getSkinHeight() {
return skinSize[1];
}
}

View File

@ -18,7 +18,6 @@ import javax.swing.JPanel;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
@ -40,8 +39,10 @@ public class SwingWindow extends JFrame {
// Transparent 16 x 16 pixel cursor image.
final BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (StaticVars.debugOn & StaticVars.debugWindow2x) {
mult = 2;
}
if (StaticVars.debugOn) {
if (StaticVars.debugWindow2x) mult = 2;
if (Utils.debugThirdScreen) {
this.setLocation(2880, 900);
setResizable(false);
@ -57,7 +58,7 @@ public class SwingWindow extends JFrame {
setResizable(false);
}
setTitle("WarpPI Calculator by Andrea Cavalli (XDrake99)");
setTitle("WarpPI Calculator by Andrea Cavalli (@Cavallium)");
addComponentListener(new ComponentListener() {
@Override
@ -88,7 +89,7 @@ public class SwingWindow extends JFrame {
@Override
public void keyReleased(KeyEvent arg0) {
Keyboard.debugKeyCodeRelease = arg0.getKeyCode();
}
@Override
@ -101,10 +102,10 @@ public class SwingWindow extends JFrame {
@Override
public void setSize(int width, int height) {
c.setSize(new Dimension(width*mult, height*mult));
c.setPreferredSize(new Dimension(width*mult, height*mult));
super.getContentPane().setSize(new Dimension(width*mult, height*mult));
super.getContentPane().setPreferredSize(new Dimension(width*mult, height*mult));
c.setSize(new Dimension(width * mult, height * mult));
c.setPreferredSize(new Dimension(width * mult, height * mult));
super.getContentPane().setSize(new Dimension(width * mult, height * mult));
super.getContentPane().setPreferredSize(new Dimension(width * mult, height * mult));
super.pack();
}
@ -115,12 +116,12 @@ public class SwingWindow extends JFrame {
@Override
public int getWidth() {
return c.getWidth()/mult;
return c.getWidth() / mult;
}
@Override
public int getHeight() {
return c.getHeight()/mult;
return c.getHeight() / mult;
}
public void setRenderingLoop(RenderingLoop renderingLoop) {
@ -128,12 +129,12 @@ public class SwingWindow extends JFrame {
}
public void centerWindow() {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - super.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - super.getHeight()) / 2);
super.setLocation(x, y);
final Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
final int x = (int) ((dimension.getWidth() - super.getWidth()) / 2);
final int y = (int) ((dimension.getHeight() - super.getHeight()) / 2);
super.setLocation(x, y);
}
// private static ObjectArrayList<Double> mediaValori = new ObjectArrayList<Double>();
public class CustomCanvas extends JPanel {
@ -152,8 +153,8 @@ public class SwingWindow extends JFrame {
final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData();
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
CPURenderer.canvas2d = a;
g.clearRect(0, 0, display.r.size[0]*mult, display.r.size[1]*mult);
g.drawImage(display.g, 0, 0, display.r.size[0]*mult, display.r.size[1]*mult, null);
g.clearRect(0, 0, display.r.size[0] * mult, display.r.size[1] * mult);
g.drawImage(display.g, 0, 0, display.r.size[0] * mult, display.r.size[1] * mult, null);
// long time2 = System.nanoTime();
// double timeDelta = ((double)(time2-time1))/1000000000d;
// double mediaAttuale = timeDelta;

View File

@ -1,11 +1,9 @@
package org.warp.picalculator.gui.graphicengine.framebuffer;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.concurrent.Semaphore;
import org.warp.picalculator.MmapByteBuffer;
@ -19,8 +17,6 @@ import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
import org.warp.picalculator.gui.graphicengine.cpu.CPUSkin;
import sun.nio.ch.DirectBuffer;
public class FBEngine implements GraphicEngine {
private static final int FB_DISPLAY_WIDTH = 320;
@ -28,8 +24,8 @@ public class FBEngine implements GraphicEngine {
private static final int FB_DISPLAY_BPP = 32;
private static final int WIDTH = 480;
private static final int HEIGHT = 320;
private static final int[] SIZE = new int[] {WIDTH, HEIGHT};
private TestJNI jni = new TestJNI();
private static final int[] SIZE = new int[] { WIDTH, HEIGHT };
private final TestJNI jni = new TestJNI();
public FBRenderer r;
private MappedByteBuffer fb;
MmapByteBuffer realFb;
@ -37,8 +33,7 @@ public class FBEngine implements GraphicEngine {
public volatile boolean initialized = false;
public Semaphore exitSemaphore = new Semaphore(0);
private boolean resizedTrigger = false;
@Override
public int[] getSize() {
return SIZE;
@ -50,29 +45,27 @@ public class FBEngine implements GraphicEngine {
}
@Override
public void setTitle(String title) {
}
public void setTitle(String title) {}
@Override
public void setResizable(boolean r) {
}
public void setResizable(boolean r) {}
@Override
public void setDisplayMode(int ww, int wh) {
}
public void setDisplayMode(int ww, int wh) {}
@Override
public void create(Runnable onInitialized) {
resizedTrigger = true;
realFb = jni.retrieveBuffer();
final long fbLen = realFb.getLength();
fb = (MappedByteBuffer) MappedByteBuffer.allocateDirect((int) fbLen);
fb = (MappedByteBuffer) ByteBuffer.allocateDirect((int) fbLen);
r = new FBRenderer(this, fb);
initialized = true;
if (onInitialized != null)
if (onInitialized != null) {
onInitialized.run();
}
}
@Override
@ -99,7 +92,7 @@ public class FBEngine implements GraphicEngine {
public void destroy() {
try {
fbFileRW.close();
} catch (IOException e) {
} catch (final IOException e) {
e.printStackTrace();
}
}
@ -134,7 +127,7 @@ public class FBEngine implements GraphicEngine {
}
private int _________________TMP = 0;
@Override
public void repaint() {
if (_________________TMP % 100 == 0) {
@ -144,10 +137,10 @@ public class FBEngine implements GraphicEngine {
_________________TMP++;
realFb.getBuffer().clear();
realFb.getBuffer().put(fb);
for (int i = 0; i < fb.capacity()/2; i++) {
realFb.getBuffer().put(i, (byte) (0xFF));
for (int i = 0; i < fb.capacity() / 2; i++) {
realFb.getBuffer().put(i, (byte) (_________________TMP < 50 ? 0xFF : 0xF0));
}
for (int i = fb.capacity()/2; i < fb.capacity(); i++) {
for (int i = fb.capacity() / 2; i < fb.capacity(); i++) {
realFb.getBuffer().put(i, (byte) (0x18));
}
}
@ -176,16 +169,18 @@ public class FBEngine implements GraphicEngine {
public void waitForExit() {
try {
exitSemaphore.acquire();
} catch (InterruptedException e) {}
} catch (final InterruptedException e) {}
}
@Override
public boolean isSupported() {
if (Utils.forceEngine != null && Utils.forceEngine != "fb")
if (Utils.forceEngine != null && Utils.forceEngine != "fb") {
return false;
}
if (Utils.headlessOverride) {
return false;
}
/*
File fbFile = new File("/dev/fb1");
try {
fbFileRW = new RandomAccessFile(fbFile, "rw");
@ -196,6 +191,7 @@ public class FBEngine implements GraphicEngine {
System.err.println("Cannot read framebuffer fb1.");
ex.printStackTrace();
}
*/
return false;
}
@ -203,5 +199,5 @@ public class FBEngine implements GraphicEngine {
public boolean doesRefreshPauses() {
return true;
}
}

View File

@ -7,49 +7,48 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
public class FBRenderer implements Renderer {
public FBRenderer(FBEngine fbEngine, MappedByteBuffer fb) {
}
public FBRenderer(FBEngine fbEngine, MappedByteBuffer fb) {}
@Override
public void glColor3i(int r, int gg, int b) {
// TODO Auto-generated method stub
}
@Override
public void glColor(int c) {
// TODO Auto-generated method stub
}
@Override
public void glColor4i(int red, int green, int blue, int alpha) {
// TODO Auto-generated method stub
}
@Override
public void glColor3f(float red, float green, float blue) {
// TODO Auto-generated method stub
}
@Override
public void glColor4f(float red, float green, float blue, float alpha) {
// TODO Auto-generated method stub
}
@Override
public void glClearColor4i(int red, int green, int blue, int alpha) {
// TODO Auto-generated method stub
}
@Override
public void glClearColor4f(float red, float green, float blue, float alpha) {
// TODO Auto-generated method stub
}
@Override
@ -61,74 +60,74 @@ public class FBRenderer implements Renderer {
@Override
public void glClearColor(int c) {
// TODO Auto-generated method stub
}
@Override
public void glClear(int screenWidth, int screenHeight) {
// TODO Auto-generated method stub
}
@Override
public void glDrawLine(float x0, float y0, float x1, float y1) {
// TODO Auto-generated method stub
}
@Override
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
float uvHeight) {
// TODO Auto-generated method stub
}
@Override
public void glFillColor(float x, float y, float width, float height) {
// TODO Auto-generated method stub
}
@Override
public void glDrawCharLeft(int x, int y, char ch) {
// TODO Auto-generated method stub
}
@Override
public void glDrawCharCenter(int x, int y, char ch) {
// TODO Auto-generated method stub
}
@Override
public void glDrawCharRight(int x, int y, char ch) {
// TODO Auto-generated method stub
}
@Override
public void glDrawStringLeft(float x, float y, String text) {
// TODO Auto-generated method stub
}
@Override
public void glDrawStringCenter(float x, float y, String text) {
// TODO Auto-generated method stub
}
@Override
public void glDrawStringRight(float x, float y, String text) {
// TODO Auto-generated method stub
}
@Override
public void glClearSkin() {
// TODO Auto-generated method stub
}
@Override

View File

@ -1,12 +1,10 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
@ -18,6 +16,7 @@ import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.texture.Texture;
public class GPUEngine implements GraphicEngine {
@ -26,10 +25,12 @@ public class GPUEngine implements GraphicEngine {
private NEWTWindow wnd;
private RenderingLoop d;
private GPURenderer r;
private Map<String, GPUFont> fontCache = new HashMap<String, GPUFont>();
private final Map<String, GPUFont> fontCache = new HashMap<>();
int[] size = new int[] { StaticVars.screenSize[0], StaticVars.screenSize[1] };
private final CopyOnWriteArrayList<BinaryFont> registeredFonts = new CopyOnWriteArrayList<BinaryFont>();
private Semaphore exitSemaphore = new Semaphore(0);
private final CopyOnWriteArrayList<BinaryFont> registeredFonts = new CopyOnWriteArrayList<>();
private final Semaphore exitSemaphore = new Semaphore(0);
protected LinkedList<Texture> registeredTextures;
protected LinkedList<Texture> unregisteredTextures;
@Override
public int[] getSize() {
@ -60,7 +61,7 @@ public class GPUEngine implements GraphicEngine {
public void setDisplayMode(int ww, int wh) {
size[0] = ww;
size[1] = wh;
wnd.window.setSize((StaticVars.debugOn & StaticVars.debugWindow2x) ? ww * 2 : ww, (StaticVars.debugOn & StaticVars.debugWindow2x) ? wh * 2 : wh);
wnd.window.setSize(ww, wh);
}
@Override
@ -71,6 +72,8 @@ public class GPUEngine implements GraphicEngine {
@Override
public void create(Runnable onInitialized) {
created = true;
registeredTextures = new LinkedList<>();
unregisteredTextures = new LinkedList<>();
r = new GPURenderer();
wnd = new NEWTWindow(this);
wnd.create();
@ -123,24 +126,24 @@ public class GPUEngine implements GraphicEngine {
@Override
public BinaryFont loadFont(String name) throws IOException {
for (Entry<String, GPUFont> entry : fontCache.entrySet()) {
for (final Entry<String, GPUFont> entry : fontCache.entrySet()) {
if (entry.getKey().equals(name)) {
return entry.getValue();
}
}
GPUFont font = new GPUFont(this, name);
final GPUFont font = new GPUFont(this, name);
fontCache.put(name, font);
return font;
}
@Override
public BinaryFont loadFont(String path, String name) throws IOException {
for (Entry<String, GPUFont> entry : fontCache.entrySet()) {
for (final Entry<String, GPUFont> entry : fontCache.entrySet()) {
if (entry.getKey().equals(name)) {
return entry.getValue();
}
}
GPUFont font = new GPUFont(this, path, name);
final GPUFont font = new GPUFont(this, path, name);
fontCache.put(name, font);
return font;
}
@ -154,22 +157,24 @@ public class GPUEngine implements GraphicEngine {
public void waitForExit() {
try {
exitSemaphore.acquire();
} catch (InterruptedException e) {}
} catch (final InterruptedException e) {}
}
@Override
public boolean isSupported() {
if (Utils.forceEngine != null && Utils.forceEngine != "gpu")
if (Utils.forceEngine != null && Utils.forceEngine != "gpu") {
return false;
if (Utils.headlessOverride)
}
if (Utils.headlessOverride) {
return false;
}
boolean available = false;
boolean errored = false;
try {
available = GLProfile.isAvailable(GLProfile.GL2ES2);
} catch (Exception ex) {
} catch (final Exception ex) {
errored = true;
System.err.println("OpenGL Error: "+ex.getMessage());
System.err.println("OpenGL Error: " + ex.getMessage());
}
if (!available && !errored) {
System.err.println(GLProfile.glAvailabilityToString());
@ -196,4 +201,8 @@ public class GPUEngine implements GraphicEngine {
return registeredFonts;
}
}
public void registerTexture(Texture t) {
unregisteredTextures.addLast(t);
}
}

View File

@ -1,15 +1,9 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.LinkedList;
import javax.imageio.ImageIO;
import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
@ -18,14 +12,10 @@ import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.util.texture.Texture;
import ar.com.hjg.pngj.IImageLine;
import ar.com.hjg.pngj.ImageInfo;
import ar.com.hjg.pngj.ImageLineHelper;
import ar.com.hjg.pngj.ImageLineInt;
import ar.com.hjg.pngj.PngReader;
import ar.com.hjg.pngj.PngWriter;
import ar.com.hjg.pngj.chunks.ChunkCopyBehaviour;
import ar.com.hjg.pngj.chunks.PngChunkTextVar;
public class GPUFont implements BinaryFont {
@ -36,7 +26,7 @@ public class GPUFont implements BinaryFont {
public int charH;
public int minCharIndex;
public int maxCharIndex;
public LinkedList<Integer[]> intervals;
public int[] intervals;
public int intervalsTotalSize = 0;
public int memoryWidth;
public int memoryHeight;
@ -46,14 +36,14 @@ public class GPUFont implements BinaryFont {
private File tmpFont;
GPUFont(GraphicEngine g, String name) throws IOException {
this((GPUEngine) g, null, name);
this(g, null, name);
}
public GPUFont(GraphicEngine g, String path, String name) throws IOException {
load(path, name);
((GPUEngine) g).registerFont(this);
}
@Override
public void load(String name) throws IOException {
load(null, name);
@ -83,78 +73,79 @@ public class GPUFont implements BinaryFont {
public int[] getCharIndexes(String txt) {
final int[] indexes = new int[txt.length()];
int i = 0;
for (char c : txt.toCharArray()) {
for (final char c : txt.toCharArray()) {
indexes[i] = compressIndex((c & 0xFFFF) - minCharIndex);
i++;
}
return indexes;
}
public int getCharIndex(char c) {
int originalIndex = c & 0xFFFF;
final int originalIndex = c & 0xFFFF;
return compressIndex(originalIndex);
}
private int compressIndex(int originalIndex) {
int compressedIndex = 0;
for (Integer[] interval : intervals) {
if (interval[0] > originalIndex) {
for (int i = 0; i < intervals.length; i += 3) {
if (intervals[i] > originalIndex) {
break;
} else if (originalIndex <= interval[1]) {
compressedIndex+=(originalIndex-interval[0]);
} else if (originalIndex <= intervals[i + 1]) {
compressedIndex += (originalIndex - intervals[i]);
break;
} else {
compressedIndex+=interval[2];
compressedIndex += intervals[i + 2];
}
}
return compressedIndex;
}
private int decompressIndex(int compressedIndex) {
int originalIndex = 0;
final int originalIndex = 0;
int i = 0;
for (Integer[] interval : intervals) {
i+=interval[2];
for (final int intvl = 0; i < intervals.length; i += 3) {
i += intervals[intvl + 2];
if (i >= compressedIndex) {
return interval[1] - (i - compressedIndex);
return intervals[intvl + 1] - (i - compressedIndex);
}
}
return originalIndex;
}
private void pregenTexture(boolean[][] chars) throws IOException {
final int totalChars = this.intervalsTotalSize;
final int totalChars = intervalsTotalSize;
int w = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charW)));
int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
int maxIndexW = (int) Math.floor(((double) w) / ((double) charW)) - 1;
int maxIndexH = (int) Math.floor(((double) h) / ((double) charH)) - 1;
if (w > h) {
System.out.println("w > h");
h = powerOf2((int) (Math.ceil((((double)totalChars)/((double)(maxIndexW))) * charH)));
h = powerOf2((int) (Math.ceil((((double) totalChars) / ((double) (maxIndexW))) * charH)));
maxIndexH = (int) Math.floor(((double) h) / ((double) charH)) - 1;
} else {
System.out.println("w <= h");
w = powerOf2((int) (Math.ceil((((double)totalChars)/((double)(maxIndexH))) * charW)));
w = powerOf2((int) (Math.ceil((((double) totalChars) / ((double) (maxIndexH))) * charW)));
maxIndexW = (int) Math.floor(((double) w) / ((double) charW)) - 1;
}
// final int h = powerOf2((int) (Math.ceil(Math.sqrt(totalChars) * charH)));
System.out.println(((int)Math.ceil(Math.sqrt(totalChars) * charW)) + " * " + ((int)Math.ceil(Math.sqrt(totalChars) * charH)) + " --> " + w + " * " + h);
File f = Files.createTempFile("texture-font-", ".png").toFile();
System.out.println(((int) Math.ceil(Math.sqrt(totalChars) * charW)) + " * " + ((int) Math.ceil(Math.sqrt(totalChars) * charH)) + " --> " + w + " * " + h);
final File f = Files.createTempFile("texture-font-", ".png").toFile();
f.deleteOnExit();
final FileOutputStream outputStream = new FileOutputStream(f);
final ImageInfo imi = new ImageInfo(w, h, 8, true); // 8 bits per channel, alpha
// open image for writing to a output stream
final PngWriter png = new PngWriter(outputStream, imi);
for (int y = 0; y < png.imgInfo.rows; y++) {
ImageLineInt iline = new ImageLineInt(imi);
int[] xValues = new int[imi.cols];
final ImageLineInt iline = new ImageLineInt(imi);
final int[] xValues = new int[imi.cols];
for (int indexX = 0; indexX <= maxIndexW; indexX++) {// this line will be written to all rows
final int charY = (y % charH);
final int indexY = (y - charY)/charH;
final int i = indexY * (maxIndexW+1) + indexX - this.minCharIndex;
final int indexY = (y - charY) / charH;
final int i = indexY * (maxIndexW + 1) + indexX - minCharIndex;
boolean[] currentChar;
if (i < totalChars && (currentChar=chars[i]) != null) {
if (i < totalChars && (currentChar = chars[i]) != null) {
for (int charX = 0; charX < charW; charX++) {
if (i >= 0 & i < totalChars && currentChar != null && currentChar[charX + charY * charW]) {
xValues[indexX * charW + charX] = 0xFFFFFFFF;
@ -172,7 +163,7 @@ public class GPUFont implements BinaryFont {
chars = null;
png.end();
Utils.gc();
try {
memoryWidth = w;
memoryHeight = h;
@ -182,7 +173,7 @@ public class GPUFont implements BinaryFont {
outputStream.flush();
outputStream.close();
Utils.gc();
this.tmpFont = f;
tmpFont = f;
} catch (GLException | IOException e) {
e.printStackTrace();
}
@ -198,7 +189,7 @@ public class GPUFont implements BinaryFont {
}
private int powerOf2(int i) {
return i >1 ? Integer.highestOneBit(i-1)<<1 : 1;
return i > 1 ? Integer.highestOneBit(i - 1) << 1 : 1;
}
@Override
@ -242,4 +233,14 @@ public class GPUFont implements BinaryFont {
public boolean isInitialized() {
return initialized;
}
@Override
public int getSkinWidth() {
return memoryWidth;
}
@Override
public int getSkinHeight() {
return memoryHeight;
}
}

View File

@ -1,17 +1,12 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
import org.warp.picalculator.StaticVars;
@ -31,13 +26,17 @@ public class GPURenderer implements Renderer {
public static GL2ES1 gl;
private static final int ELEMENT_VERTICES_COUNT = 6;
private static final int ELEMENTS_MAX_COUNT_PER_BUFFER = StaticVars.enableVBO ? 128 : 1;
private static final int ELEMENT_VERTICES_COUNT = 6, vertSize = 3, texSize = 2, colSize = 4, vertBuffer = 0,
texBuffer = 1, colBuffer = 2, vertMax = vertSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER,
texMax = texSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER,
colMax = colSize * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER;
private int[] handlers;
private final DeallocationHelper deallocationHelper = new DeallocationHelper();
FloatBuffer fbVertices;
FloatBuffer txVertices;
FloatBuffer colVertices;
FloatBuffer fbTextures;
FloatBuffer fbColors;
int fbElements;
float[] currentColor = new float[24];
@ -156,8 +155,8 @@ public class GPURenderer implements Renderer {
final float[] tex_vertices = { uvX, uvY, uvX + uvWidth, uvY, uvX, uvY + uvHeight, uvX, uvY + uvHeight, uvX + uvWidth, uvY, uvX + uvWidth, uvY + uvHeight };
fbElements++;
fbVertices.put(vertices);
txVertices.put(tex_vertices);
colVertices.put(currentColor);
fbTextures.put(tex_vertices);
fbColors.put(currentColor);
}
@Override
@ -182,8 +181,8 @@ public class GPURenderer implements Renderer {
final float[] tex_vertices = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, };
fbElements++;
fbVertices.put(vertices);
txVertices.put(tex_vertices);
colVertices.put(currentColor);
fbTextures.put(tex_vertices);
fbColors.put(currentColor);
}
@Override
@ -249,23 +248,24 @@ public class GPURenderer implements Renderer {
File f;
if (isResource) {
f = Files.createTempFile("texture-", ".png").toFile();
f.deleteOnExit();
ImageIO.write(img, "png", f);
} else {
f = new File(file);
}
int imgW = img.getWidth();
int imgH = img.getHeight();
final int imgW = img.getWidth();
final int imgH = img.getHeight();
img = null;
Utils.gc();
return new OpenedTextureData(imgW, imgH, f, isResource);
}
public static class OpenedTextureData {
public final int w;
public final int h;
public final File f;
public final boolean deleteOnExit;
/**
* @param w
* @param h
@ -278,16 +278,18 @@ public class GPURenderer implements Renderer {
this.f = f;
this.deleteOnExit = deleteOnExit;
}
}
static Texture importTexture(File f, boolean deleteOnExit) throws GLException, IOException {
final Texture tex = TextureIO.newTexture(f, false);
if (deleteOnExit && f.exists()) {
try {
if (StaticVars.debugOn) throw new IOException("Delete on exit!");
if (StaticVars.debugOn) {
throw new IOException("Delete on exit!");
}
f.delete();
}catch (Exception ex) {
} catch (final Exception ex) {
f.deleteOnExit();
}
}
@ -297,13 +299,49 @@ public class GPURenderer implements Renderer {
return tex;
}
public void startDrawCycle(boolean first) {
public void initDrawCycle() {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
if (fbVertices == null) {
fbVertices = Buffers.newDirectFloatBuffer(3 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
txVertices = Buffers.newDirectFloatBuffer(2 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
colVertices = Buffers.newDirectFloatBuffer(4 * ELEMENT_VERTICES_COUNT * ELEMENTS_MAX_COUNT_PER_BUFFER);
fbVertices = Buffers.newDirectFloatBuffer(vertMax);
fbTextures = Buffers.newDirectFloatBuffer(texMax);
fbColors = Buffers.newDirectFloatBuffer(colMax);
handlers = new int[3];
gl.glGenBuffers(3, handlers, 0);
}
if (first || fbVertices == null || cycleEnded) {
startDrawSegment(false);
if (textureChange) {
changeTexture();
}
}
public void endDrawCycle() {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
if (textureChange) {
if (fbElements > 0) {
endDrawSegment();
}
changeTexture();
} else {
if (fbElements > 0) {
endDrawSegment();
}
}
}
private void changeTexture() {
precTexEnabled = currentTexEnabled;
precTex = currentTex;
if (currentTexEnabled) {
gl.glEnable(GL.GL_TEXTURE_2D);
currentTex.bind(gl);
} else {
gl.glDisable(GL.GL_TEXTURE_2D);
}
firstBufferTexDataCall = true;
}
public void startDrawSegment(boolean continuation) {
if (!continuation || cycleEnded) {
fbElements = 0;
}
cycleEnded = false;
@ -313,58 +351,63 @@ public class GPURenderer implements Renderer {
private Texture precTex;
private boolean cycleEnded = true;
public void updateDrawCycle() {
updateDrawCycle(false, false);
}
public void updateDrawCycle(boolean first, boolean last) {
public void doDrawSegment() {
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
final boolean changeRequired = last || fbElements >= ELEMENTS_MAX_COUNT_PER_BUFFER;
if (first) {
startDrawCycle(true);
}
final boolean changeRequired = fbElements >= ELEMENTS_MAX_COUNT_PER_BUFFER;
if (textureChange) {
if (!first && fbElements > 0) {
endDrawCycle();
if (!last) {
startDrawCycle(true);
}
if (fbElements > 0) {
endDrawSegment();
startDrawSegment(false);
}
precTexEnabled = currentTexEnabled;
precTex = currentTex;
if (currentTexEnabled) {
gl.glEnable(GL.GL_TEXTURE_2D);
currentTex.bind(gl);
} else {
gl.glDisable(GL.GL_TEXTURE_2D);
}
} else if (!first) {
changeTexture();
} else {
if (fbElements > 0 && changeRequired) {
endDrawCycle();
if (!last) {
startDrawCycle(false);
}
endDrawSegment();
startDrawSegment(true);
}
}
}
public void endDrawCycle() {
fbVertices.limit(fbVertices.position());
txVertices.limit(txVertices.position());
colVertices.limit(colVertices.position());
fbVertices.rewind();
txVertices.rewind();
colVertices.rewind();
boolean firstBufferDataCall = true;
boolean firstBufferTexDataCall = true;
gl.glVertexPointer(3, GL.GL_FLOAT, 0, fbVertices);
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, txVertices);
gl.glColorPointer(4, GL.GL_FLOAT, 0, colVertices);
fbVertices.limit(fbVertices.capacity());
txVertices.limit(txVertices.capacity());
colVertices.limit(colVertices.capacity());
public void endDrawSegment() {
fbVertices.flip();
fbTextures.flip();
fbColors.flip();
// gl.glVertexPointer(vertSize, GL.GL_FLOAT, 0, fbVertices);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[vertBuffer]);
if (firstBufferTexDataCall) {
gl.glBufferData(GL.GL_ARRAY_BUFFER, fbVertices.limit() * Buffers.SIZEOF_FLOAT, fbVertices, GL.GL_STATIC_DRAW);
} else {
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, fbVertices.limit() * Buffers.SIZEOF_FLOAT, fbVertices);
}
gl.glVertexPointer(vertSize, GL.GL_FLOAT, 0, 0l);
// gl.glTexCoordPointer(texSize, GL.GL_FLOAT, 0, fbTextures);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[texBuffer]);
if (firstBufferTexDataCall) {
gl.glBufferData(GL.GL_ARRAY_BUFFER, fbTextures.limit() * Buffers.SIZEOF_FLOAT, fbTextures, GL.GL_STATIC_DRAW);
} else {
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, fbTextures.limit() * Buffers.SIZEOF_FLOAT, fbTextures);
}
gl.glTexCoordPointer(texSize, GL.GL_FLOAT, 0, 0l);
// gl.glColorPointer(colSize, GL.GL_FLOAT, 0, fbColors);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, handlers[colBuffer]);
if (firstBufferTexDataCall) {
gl.glBufferData(GL.GL_ARRAY_BUFFER, fbColors.limit() * Buffers.SIZEOF_FLOAT, fbColors, GL.GL_STATIC_DRAW);
} else {
gl.glBufferSubData(GL.GL_ARRAY_BUFFER, 0, fbColors.limit() * Buffers.SIZEOF_FLOAT, fbColors);
}
gl.glColorPointer(colSize, GL.GL_FLOAT, 0, 0l);
fbVertices.limit(vertMax);
fbTextures.limit(texMax);
fbColors.limit(colMax);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, fbElements * ELEMENT_VERTICES_COUNT);
//gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements * ELEMENT_VERTICES_COUNT);
firstBufferDataCall = false;
firstBufferTexDataCall = false;
cycleEnded = true;
// deleteBuffer(fbVertices);
@ -385,18 +428,18 @@ public class GPURenderer implements Renderer {
public void glClearSkin() {
if (currentTex != null) {
currentTex = null;
updateDrawCycle();
doDrawSegment();
}
}
void disableTexture() {
currentTexEnabled = false;
updateDrawCycle();
doDrawSegment();
}
void enableTexture() {
currentTexEnabled = true;
updateDrawCycle();
doDrawSegment();
}
void useTexture(Texture t, float w, float h) {
@ -405,4 +448,4 @@ public class GPURenderer implements Renderer {
currentTexHeight = h;
enableTexture();
}
}
}

View File

@ -1,7 +1,5 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -10,7 +8,6 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.gpu.GPURenderer.OpenedTextureData;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2ES1;
import com.jogamp.opengl.GLException;
import com.jogamp.opengl.util.texture.Texture;
@ -24,14 +21,14 @@ public class GPUSkin implements Skin {
private String texturePath;
private boolean initialized = false;
private boolean isResource;
GPUSkin(GraphicEngine d, String file) throws IOException {
load(file);
}
@Override
public void load(String file) throws IOException {
boolean isResource = !Files.exists(Paths.get(file));
final boolean isResource = !Files.exists(Paths.get(file));
if (isResource && (this.getClass().getClassLoader().getResource(file)) == null) {
throw new IOException("File '" + file + "' not found!");
}
@ -47,7 +44,7 @@ public class GPUSkin implements Skin {
t = GPURenderer.importTexture(i.f, i.deleteOnExit);
w = i.w;
h = i.h;
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
((GPUEngine) d).registerTexture(t);
initialized = true;
} catch (GLException | IOException e) {
e.printStackTrace();
@ -69,4 +66,14 @@ public class GPUSkin implements Skin {
return initialized;
}
@Override
public int getSkinWidth() {
return w;
}
@Override
public int getSkinHeight() {
return h;
}
}

View File

@ -29,8 +29,8 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.device.Key;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.DisplayManager;
import com.jogamp.newt.event.KeyEvent;
@ -49,22 +49,26 @@ import com.jogamp.opengl.fixedfunc.GLLightingFunc;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.fixedfunc.GLPointerFunc;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.texture.Texture;
/**
*
* @author Xerxes Rånby (xranby)
* @author Andrea Cavalli (XDRake99)
* @author Andrea Cavalli (@Cavallium)
*/
class NEWTWindow implements GLEventListener {
private final GPUEngine disp;
private final GPURenderer renderer;
public float windowZoom;
public int[] realWindowSize;
public Runnable onInitialized;
public NEWTWindow(GPUEngine disp) {
this.disp = disp;
renderer = disp.getRenderer();
realWindowSize = new int[] { 1, 1 };
}
public GLWindow window;
@ -82,12 +86,14 @@ class NEWTWindow implements GLEventListener {
final GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2ES1));
System.out.println("Loaded OpenGL");
// We may at this point tweak the caps and request a translucent drawable
caps.setHardwareAccelerated(true);
caps.setBackgroundOpaque(true); //transparency window
caps.setSampleBuffers(false);
// caps.setSampleBuffers(true);
// caps.setNumSamples(4);
final GLWindow glWindow = GLWindow.create(caps);
window = glWindow;
glWindow.setTitle("WarpPI Calculator by Andrea Cavalli (XDrake99)");
glWindow.setTitle("WarpPI Calculator by Andrea Cavalli (@Cavallium)");
glWindow.addWindowListener(new WindowListener() {
@ -142,7 +148,7 @@ class NEWTWindow implements GLEventListener {
public void keyReleased(KeyEvent arg0) {
switch (arg0.getKeyCode()) {
case KeyEvent.VK_ESCAPE:
Keyboard.keyReleased(Key.POWER);
Keyboard.keyReleased(Key.POWEROFF);
break;
case KeyEvent.VK_D:
Keyboard.keyReleased(Key.debug_DEG);
@ -173,7 +179,7 @@ class NEWTWindow implements GLEventListener {
} else if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyReleased(Key.BRIGHTNESS_CYCLE);
} else {
Keyboard.keyReleased(Key.NONE);
Keyboard.keyReleased(Key.ZOOM_MODE);
}
break;
case KeyEvent.VK_ENTER:
@ -283,8 +289,13 @@ class NEWTWindow implements GLEventListener {
public void init(GLAutoDrawable drawable) {
final GL2ES1 gl = drawable.getGL().getGL2ES1();
//Vsync
gl.setSwapInterval(2);
if (StaticVars.debugOn) {
//Vsync
gl.setSwapInterval(1);
} else {
//Vsync
gl.setSwapInterval(2);
}
//Textures
gl.glEnable(GL.GL_TEXTURE_2D);
@ -294,6 +305,9 @@ class NEWTWindow implements GLEventListener {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GLLightingFunc.GL_FLAT);
//Multisampling
//gl.glEnable(GL.GL_MULTISAMPLE);
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
@ -313,22 +327,40 @@ class NEWTWindow implements GLEventListener {
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
disp.size[0] = (StaticVars.debugOn & StaticVars.debugWindow2x) ? width / 2 : width;
disp.size[1] = (StaticVars.debugOn & StaticVars.debugWindow2x) ? height / 2 : height;
realWindowSize[0] = width;
realWindowSize[1] = height;
disp.size[0] = width;
disp.size[1] = height;
final GL2ES1 gl = glad.getGL().getGL2ES1();
if (width == 0) {
width = 1;
}
if (height == 0) {
height = 1;
onZoomChanged(gl, true);
}
private void onZoomChanged(GL2ES1 gl, boolean sizeChanged) {
final float precWindowZoom = windowZoom;
windowZoom = StaticVars.getCurrentZoomValue();
if (((precWindowZoom % ((int) precWindowZoom)) != 0f) != ((windowZoom % ((int) windowZoom)) != 0f)) {
final boolean linear = (windowZoom % ((int) windowZoom)) != 0f;
for (final Texture t : disp.registeredTextures) {
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, linear ? GL.GL_LINEAR : GL.GL_NEAREST);
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
}
}
final int width = realWindowSize[0];
final int height = realWindowSize[1];
disp.size[0] = (int) (realWindowSize[0] / windowZoom);
disp.size[1] = (int) (realWindowSize[1] / windowZoom);
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, (StaticVars.debugOn & StaticVars.debugWindow2x) ? width / 2 : width, (StaticVars.debugOn & StaticVars.debugWindow2x) ? height / 2 : height, 0.0, -1, 1);
gl.glOrtho(0.0, disp.size[0], disp.size[1], 0.0, -1, 1);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
@ -339,16 +371,31 @@ class NEWTWindow implements GLEventListener {
final GL2ES1 gl = glad.getGL().getGL2ES1();
GPURenderer.gl = gl;
if (windowZoom != StaticVars.getCurrentZoomValue()) {
onZoomChanged(gl, false);
}
Boolean linear = null;
while (!disp.unregisteredTextures.isEmpty()) {
if (linear == null) {
linear = (windowZoom % ((int) windowZoom)) != 0f;
}
final Texture t = disp.unregisteredTextures.pop();
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
disp.registeredTextures.addLast(t);
}
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
renderer.updateDrawCycle(true, false);
renderer.initDrawCycle();
disp.repaint();
renderer.updateDrawCycle(false, true);
renderer.endDrawCycle();
GPURenderer.gl = null;

View File

@ -7,14 +7,14 @@ import org.fusesource.jansi.AnsiConsole;
import org.fusesource.jansi.internal.WindowsSupport;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.Key;
import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
public class Headless24bitEngine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private Headless24bitRenderer r = new Headless24bitRenderer();
private final Headless24bitRenderer r = new Headless24bitRenderer();
private boolean stopped = true;
private RenderingLoop renderLoop;
public static final int C_MUL_X = 4;//8;
@ -67,7 +67,7 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
if (Utils.isWindows() && !Utils.msDosMode) {
win = true;
WindowsSupport.setConsoleMode(0x0200);
Thread t = new Thread(() -> {
final Thread t = new Thread(() -> {
int ch = -1;
while (true) {
if (precKey != null) {
@ -132,8 +132,9 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
t.start();
}
stopped = false;
if (onInitialized != null)
if (onInitialized != null) {
onInitialized.run();
}
}
@Override
@ -158,7 +159,7 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
@Override
public void start(RenderingLoop d) {
this.renderLoop = d;
renderLoop = d;
final Thread th = new Thread(() -> {
try {
double extratime = 0;
@ -215,10 +216,10 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
}
}
int[] newpix = new int[3];
for (int i = 0; i < pixs.length; i++) {
newpix[0] += pixs[i][0];
newpix[1] += pixs[i][1];
newpix[2] += pixs[i][2];
for (final int[] pix : pixs) {
newpix[0] += pix[0];
newpix[1] += pix[1];
newpix[2] += pix[2];
}
newpix[0] /= pixs.length;
newpix[1] /= pixs.length;
@ -233,10 +234,10 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
}
}
newpix = new int[3];
for (int i = 0; i < pixs.length; i++) {
newpix[0] += pixs[i][0];
newpix[1] += pixs[i][1];
newpix[2] += pixs[i][2];
for (final int[] pix : pixs) {
newpix[0] += pix[0];
newpix[1] += pix[1];
newpix[2] += pix[2];
}
newpix[0] /= pixs.length;
newpix[1] /= pixs.length;
@ -318,8 +319,9 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
@Override
public boolean isSupported() {
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-24bit"))
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-24bit")) {
return false;
}
return true;
}

View File

@ -44,4 +44,14 @@ public class Headless24bitFont implements BinaryFont {
return true;
}
@Override
public int getSkinWidth() {
return 0;
}
@Override
public int getSkinHeight() {
return 0;
}
}

Some files were not shown because too many files have changed in this diff Show More