Merge remote-tracking branch 'origin/master'
# Conflicts: # core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java
This commit is contained in:
commit
12329c5ffe
|
@ -0,0 +1,4 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
|
@ -1,7 +1,5 @@
|
|||
*.class
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
!/target/*.jar
|
||||
|
@ -9,7 +7,7 @@
|
|||
*.war
|
||||
*.jar
|
||||
*.ear
|
||||
*Thumbs.db
|
||||
Thumbs.db
|
||||
font_gputest1.rft
|
||||
font_gputest12.rft
|
||||
font_gputest2.rft
|
||||
|
@ -26,10 +24,11 @@ math-rules-cache.zip
|
|||
/backups/
|
||||
/Resources_and_Videos/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
/bin/
|
||||
|
||||
# Created by https://www.gitignore.io/api/git,java,maven,eclipse,intellij,intellij+all,intellij+iml
|
||||
# Edit at https://www.gitignore.io/?templates=git,java,maven,eclipse,intellij,intellij+all,intellij+iml
|
||||
|
||||
### Eclipse ###
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
|
@ -85,3 +84,262 @@ local.properties
|
|||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
### Eclipse Patch ###
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated
|
||||
|
||||
.sts4-cache/
|
||||
|
||||
### Git ###
|
||||
# Created by git for backups. To disable backups in Git:
|
||||
# $ git config --global mergetool.keepBackup false
|
||||
*.orig
|
||||
|
||||
# Created by git when using merge tools for conflicts
|
||||
*.BACKUP.*
|
||||
*.BASE.*
|
||||
*.LOCAL.*
|
||||
*.REMOTE.*
|
||||
*_BACKUP_*.txt
|
||||
*_BASE_*.txt
|
||||
*_LOCAL_*.txt
|
||||
*_REMOTE_*.txt
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Intellij Patch ###
|
||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
||||
|
||||
# *.iml
|
||||
# modules.xml
|
||||
# .idea/misc.xml
|
||||
# *.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/**/sonarlint/
|
||||
|
||||
# SonarQube Plugin
|
||||
.idea/**/sonarIssues.xml
|
||||
|
||||
# Markdown Navigator plugin
|
||||
.idea/**/markdown-navigator.xml
|
||||
.idea/**/markdown-navigator/
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
|
||||
# Generated files
|
||||
|
||||
# Sensitive or high-churn files
|
||||
|
||||
# Gradle
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
|
||||
# Mongo Explorer plugin
|
||||
|
||||
# File-based project format
|
||||
|
||||
# IntelliJ
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
|
||||
# JIRA plugin
|
||||
|
||||
# Cursive Clojure plugin
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
|
||||
# Editor-based Rest Client
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Intellij+iml ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
|
||||
# Generated files
|
||||
|
||||
# Sensitive or high-churn files
|
||||
|
||||
# Gradle
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
|
||||
# Mongo Explorer plugin
|
||||
|
||||
# File-based project format
|
||||
|
||||
# IntelliJ
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
|
||||
# JIRA plugin
|
||||
|
||||
# Cursive Clojure plugin
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
|
||||
# Editor-based Rest Client
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
|
||||
### Intellij+iml Patch ###
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
### Maven ###
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.flattened-pom.xml
|
||||
|
||||
# End of https://www.gitignore.io/api/git,java,maven,eclipse,intellij,intellij+all,intellij+iml
|
|
@ -1,6 +1,3 @@
|
|||
[submodule "Flow"]
|
||||
path = Flow
|
||||
url = https://github.com/Cavallium/Flow
|
||||
[submodule "bigdecimal-math"]
|
||||
path = bigdecimal-math
|
||||
url = https://github.com/Cavallium/bigdecimal-math
|
||||
|
|
1
Flow
1
Flow
|
@ -1 +0,0 @@
|
|||
Subproject commit 92db616ef508f16fe30e8e37d17d7d7a18f56f4a
|
|
@ -1 +1 @@
|
|||
Subproject commit 40d89e539223aaa9202326833a2c813bed3c6eef
|
||||
Subproject commit da70aa7ba3bcae0e2e76fde338c56696ff25ea96
|
|
@ -18,8 +18,9 @@
|
|||
<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/JavaSE-11">
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
|
|
15
core/pom.xml
15
core/pom.xml
|
@ -6,7 +6,7 @@
|
|||
<parent>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>warppi</artifactId>
|
||||
<version>0.9.0a3</version>
|
||||
<version>0.10.0-alpha</version>
|
||||
</parent>
|
||||
<artifactId>warppi-core</artifactId>
|
||||
|
||||
|
@ -14,20 +14,15 @@
|
|||
<description>WarpPI Calculator core project</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>warppi-flow</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>warppi-util</artifactId>
|
||||
<version>0.9.0a3</version>
|
||||
<version>0.10.0-alpha</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.cavallium</groupId>
|
||||
<artifactId>bigdecimal-math</artifactId>
|
||||
<version>0.9.0a3</version>
|
||||
<version>0.10.0-alpha</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>it.unimi.dsi</groupId>
|
||||
|
@ -46,8 +41,8 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -1,146 +0,0 @@
|
|||
package it.cavallium.warppi;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.boot.StartupArguments;
|
||||
import it.cavallium.warppi.device.HardwareDevice;
|
||||
import it.cavallium.warppi.device.HardwareTouchDevice;
|
||||
import it.cavallium.warppi.device.InputManager;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.flow.BehaviorSubject;
|
||||
import it.cavallium.warppi.flow.Observable;
|
||||
import it.cavallium.warppi.gui.DisplayManager;
|
||||
import it.cavallium.warppi.gui.HUD;
|
||||
import it.cavallium.warppi.gui.HardwareDisplay;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
import it.cavallium.warppi.util.ClassUtils;
|
||||
|
||||
public class Engine {
|
||||
public static final Engine INSTANCE = new Engine();
|
||||
private static Platform platform;
|
||||
private static boolean running = false;
|
||||
private static BehaviorSubject<LoadingStatus> loadPhase = BehaviorSubject.create();
|
||||
private final BehaviorSubject<Boolean> loaded = BehaviorSubject.create(false);
|
||||
private HardwareDevice hardwareDevice;
|
||||
|
||||
private Engine() {}
|
||||
|
||||
/**
|
||||
* Start an instance of the calculator.
|
||||
*
|
||||
* @param platform
|
||||
* Platform implementation
|
||||
* @param screen
|
||||
* Default screen to show at startup
|
||||
* @param disp
|
||||
* Hardware display
|
||||
* @param hud
|
||||
* Head-up display
|
||||
* @param args
|
||||
* Startup arguments
|
||||
* @throws InterruptedException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void start(final Platform platform, final Screen screen, final HardwareDisplay disp,
|
||||
final HardwareTouchDevice touchdevice, final HUD hud, final StartupArguments args)
|
||||
throws InterruptedException, IOException {
|
||||
if (Engine.running) {
|
||||
throw new RuntimeException("Already running!");
|
||||
} else {
|
||||
Engine.running = true;
|
||||
Engine.INSTANCE.startInstance(platform, screen, disp, touchdevice, hud, args);
|
||||
}
|
||||
}
|
||||
|
||||
private void startInstance(final Platform platform, final Screen screen, final HardwareDisplay disp,
|
||||
final HardwareTouchDevice touchdevice, final HUD hud, final StartupArguments args)
|
||||
throws InterruptedException, IOException {
|
||||
Engine.platform = platform;
|
||||
platform.getConsoleUtils().out().println("WarpPI Calculator");
|
||||
initializeEnvironment(args);
|
||||
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
currentThread.setPriority(Thread.MAX_PRIORITY);
|
||||
Engine.getPlatform().setThreadName(currentThread, "Main thread");
|
||||
|
||||
final DisplayManager dm = new DisplayManager(disp, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
|
||||
final Keyboard k = new Keyboard();
|
||||
final InputManager im = new InputManager(k, touchdevice);
|
||||
hardwareDevice = new HardwareDevice(dm, im);
|
||||
|
||||
hardwareDevice.setup(() -> Engine.loadPhase.onNext(new LoadingStatus()));
|
||||
}
|
||||
|
||||
private void onShutdown() {
|
||||
Engine.platform.getConsoleUtils().out().println(1, "Shutdown...");
|
||||
beforeShutdown();
|
||||
Engine.platform.getConsoleUtils().out().println(1, "");
|
||||
Engine.platform.getConsoleUtils().out().println(1, "Closed.");
|
||||
Engine.getPlatform().exit(0);
|
||||
}
|
||||
|
||||
private void initializeEnvironment(final StartupArguments args) throws IOException {
|
||||
ClassUtils.classLoader = this.getClass();
|
||||
StaticVars.startupArguments = args;
|
||||
StaticVars.debugWindow2x = args.isZoomed();
|
||||
if (args.isVerboseLoggingEnabled() || args.isDebugEnabled()) {
|
||||
StaticVars.outputLevel = ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE;
|
||||
}
|
||||
Engine.platform.getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, args);
|
||||
checkDeviceType();
|
||||
if (args.isRaspberryModeAllowed() == false) {
|
||||
Engine.getPlatform().setRunningOnRaspberry(false);
|
||||
}
|
||||
if (Engine.getPlatform().isRunningOnRaspberry()) {
|
||||
Engine.getPlatform().getGpio().wiringPiSetupPhys();
|
||||
Engine.getPlatform().getGpio().pinMode(12, Engine.getPlatform().getGpio().valuePwmOutput());
|
||||
} else {
|
||||
StaticVars.screenPos = new int[] { 0, 0 };
|
||||
if (Engine.getPlatform().isJavascript() == false) {
|
||||
Engine.getPlatform().getSettings().setDebugEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeviceType() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void beforeShutdown() {
|
||||
Keyboard.stopKeyboard();
|
||||
}
|
||||
|
||||
public Observable<Boolean> isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public Observable<LoadingStatus> getLoadPhase() {
|
||||
return Engine.loadPhase;
|
||||
}
|
||||
|
||||
public HardwareDevice getHardwareDevice() {
|
||||
return hardwareDevice;
|
||||
}
|
||||
|
||||
public static Platform getPlatform() {
|
||||
return Engine.platform;
|
||||
}
|
||||
|
||||
public static class LoadingStatus {
|
||||
protected LoadingStatus() {
|
||||
|
||||
}
|
||||
|
||||
public void done() {
|
||||
Engine.INSTANCE.loaded.onNext(true);
|
||||
Engine.INSTANCE.hardwareDevice.getDisplayManager().waitForExit();
|
||||
Engine.INSTANCE.onShutdown();
|
||||
}
|
||||
|
||||
public void failed() {
|
||||
Engine.INSTANCE.onShutdown();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,7 +9,12 @@ import java.net.URL;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.boot.StartupArguments;
|
||||
import it.cavallium.warppi.device.DeviceStateDevice;
|
||||
import it.cavallium.warppi.device.display.BacklightOutputDevice;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.KeyboardInputDevice;
|
||||
import it.cavallium.warppi.device.input.TouchInputDevice;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
|
||||
public interface Platform {
|
||||
|
@ -52,21 +57,29 @@ public interface Platform {
|
|||
|
||||
URLClassLoader newURLClassLoader(URL[] urls);
|
||||
|
||||
Map<String, GraphicEngine> getEnginesList();
|
||||
TouchInputDevice getTouchInputDevice();
|
||||
|
||||
KeyboardInputDevice getKeyboardInputDevice();
|
||||
|
||||
DisplayOutputDevice getDisplayOutputDevice();
|
||||
|
||||
GraphicEngine getEngine(String string) throws NullPointerException;
|
||||
BacklightOutputDevice getBacklightOutputDevice();
|
||||
|
||||
DeviceStateDevice getDeviceStateDevice();
|
||||
|
||||
void throwNewExceptionInInitializerError(String text);
|
||||
|
||||
String[] stacktraceToString(Error e);
|
||||
|
||||
void loadPlatformRules();
|
||||
|
||||
void zip(String targetPath, String destinationFilePath, String password);
|
||||
|
||||
void unzip(String targetZipFilePath, String destinationFolderPath, String password);
|
||||
|
||||
boolean compile(String[] command, PrintWriter printWriter, PrintWriter errors);
|
||||
/**
|
||||
* Determines the list of files containing DSL rules to load.
|
||||
*
|
||||
* @return a <code>List</code> of paths of files which contain DSL rules.
|
||||
* Each <code>String</code> in the returned <code>List</code> can be passed as an argument to
|
||||
* {@link StorageUtils#getResourceStream(String)} to access the corresponding file's contents.
|
||||
* @throws IOException if an IO error occurs while getting the list of rule file paths.
|
||||
*/
|
||||
List<String> getRuleFilePaths() throws IOException;
|
||||
|
||||
public interface Gpio {
|
||||
int valueOutput();
|
||||
|
@ -97,7 +110,7 @@ public interface Platform {
|
|||
|
||||
Object getBoardType();
|
||||
}
|
||||
|
||||
|
||||
public interface ConsoleUtils {
|
||||
int OUTPUTLEVEL_NODEBUG = 0;
|
||||
int OUTPUTLEVEL_DEBUG_MIN = 1;
|
||||
|
@ -204,4 +217,6 @@ public interface Platform {
|
|||
|
||||
}
|
||||
|
||||
void setArguments(StartupArguments args);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,19 +3,16 @@ package it.cavallium.warppi;
|
|||
import java.util.function.Function;
|
||||
|
||||
import it.cavallium.warppi.boot.StartupArguments;
|
||||
import it.cavallium.warppi.flow.BehaviorSubject;
|
||||
import it.cavallium.warppi.flow.Observable;
|
||||
import it.cavallium.warppi.util.EventSubmitter;
|
||||
|
||||
/*
|
||||
* TODO: Move everything to Engine.Settings
|
||||
*/
|
||||
public class StaticVars {
|
||||
public static final boolean zoomed = true;
|
||||
public static int[] screenPos = new int[] { 0, 0 };
|
||||
public static final int[] screenSize = new int[] { 480, 320 };
|
||||
public static int outputLevel = 0;
|
||||
public static boolean debugWindow2x = false;
|
||||
public static BehaviorSubject<Float> windowZoom = BehaviorSubject.create(2F);
|
||||
public static EventSubmitter<Float> windowZoom = new EventSubmitter<>(1F);
|
||||
public static Function<Float, Float> windowZoomFunction = (val) -> {
|
||||
if (StaticVars.debugWindow2x) {
|
||||
return val + 1;
|
||||
|
@ -23,7 +20,7 @@ public class StaticVars {
|
|||
return val;
|
||||
}
|
||||
};
|
||||
public static Observable<Float> windowZoom$ = StaticVars.windowZoom.map(StaticVars.windowZoomFunction);
|
||||
public static EventSubmitter<Float> windowZoom$ = StaticVars.windowZoom.map(StaticVars.windowZoomFunction);
|
||||
public static StartupArguments startupArguments;
|
||||
|
||||
private StaticVars() {
|
||||
|
|
|
@ -0,0 +1,143 @@
|
|||
package it.cavallium.warppi;
|
||||
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.boot.StartupArguments;
|
||||
import it.cavallium.warppi.device.Device;
|
||||
import it.cavallium.warppi.device.DeviceStateDevice;
|
||||
import it.cavallium.warppi.device.display.BacklightOutputDevice;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.InputManager;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.device.input.KeyboardInputDevice;
|
||||
import it.cavallium.warppi.device.input.TouchInputDevice;
|
||||
import it.cavallium.warppi.gui.DisplayManager;
|
||||
import it.cavallium.warppi.gui.HUD;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
import it.cavallium.warppi.util.ClassUtils;
|
||||
import it.cavallium.warppi.util.EventSubmitter;
|
||||
import it.cavallium.warppi.util.RunnableWithException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class WarpPI {
|
||||
public static final WarpPI INSTANCE = new WarpPI();
|
||||
private static Platform platform;
|
||||
private static boolean running = false;
|
||||
private final EventSubmitter<Boolean> loaded = EventSubmitter.create(false);
|
||||
private Device device;
|
||||
|
||||
private WarpPI() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an instance of the calculator.
|
||||
*
|
||||
* @param platform Platform implementation
|
||||
* @param screen Default screen to show at startup
|
||||
* @param hud Head-up display
|
||||
* @param args Startup arguments
|
||||
* @throws InterruptedException
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void start(final Platform platform, final Screen screen, final HUD hud, final StartupArguments args, final RunnableWithException onLoading) throws IOException {
|
||||
if (WarpPI.running) {
|
||||
throw new RuntimeException("Already running!");
|
||||
} else {
|
||||
WarpPI.running = true;
|
||||
WarpPI.INSTANCE.startInstance(platform, screen, hud, args, onLoading);
|
||||
}
|
||||
}
|
||||
|
||||
private void startInstance(final Platform platform, final Screen screen,
|
||||
final HUD hud, final StartupArguments args, final RunnableWithException onLoading)
|
||||
throws IOException {
|
||||
WarpPI.platform = platform;
|
||||
// Set arguments on platform before everything else
|
||||
platform.setArguments(args);
|
||||
|
||||
platform.getConsoleUtils().out().println("WarpPI Calculator");
|
||||
initializeEnvironment(args);
|
||||
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
currentThread.setPriority(Thread.MAX_PRIORITY);
|
||||
WarpPI.getPlatform().setThreadName(currentThread, "Main thread");
|
||||
|
||||
try {
|
||||
final DisplayOutputDevice display = platform.getDisplayOutputDevice();
|
||||
final BacklightOutputDevice backlight = platform.getBacklightOutputDevice();
|
||||
final DisplayManager dm = new DisplayManager(display, backlight, hud, screen, "WarpPI Calculator by Andrea Cavalli (@Cavallium)");
|
||||
final KeyboardInputDevice keyboard = platform.getKeyboardInputDevice();
|
||||
final TouchInputDevice touchscreen = platform.getTouchInputDevice();
|
||||
final DeviceStateDevice deviceState = platform.getDeviceStateDevice();
|
||||
final InputManager im = new InputManager(keyboard, touchscreen);
|
||||
device = new Device(dm, im, deviceState);
|
||||
device.setup();
|
||||
onLoading.run();
|
||||
this.loadingCompleted();
|
||||
} catch (Exception ex) {
|
||||
this.loadingFailed(ex);
|
||||
}
|
||||
this.onShutdown();
|
||||
}
|
||||
|
||||
private void onShutdown() {
|
||||
WarpPI.platform.getConsoleUtils().out().println(1, "Shutdown...");
|
||||
beforeShutdown();
|
||||
WarpPI.platform.getConsoleUtils().out().println(1, "");
|
||||
WarpPI.platform.getConsoleUtils().out().println(1, "Closed.");
|
||||
WarpPI.getPlatform().exit(0);
|
||||
}
|
||||
|
||||
private void initializeEnvironment(final StartupArguments args) throws IOException {
|
||||
ClassUtils.classLoader = this.getClass();
|
||||
StaticVars.startupArguments = args;
|
||||
StaticVars.debugWindow2x = args.isZoomed();
|
||||
if (args.isVerboseLoggingEnabled() || args.isDebugEnabled()) {
|
||||
StaticVars.outputLevel = ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE;
|
||||
}
|
||||
WarpPI.platform.getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, args);
|
||||
checkDeviceType();
|
||||
if (args.isRaspberryModeAllowed() == false) {
|
||||
WarpPI.getPlatform().setRunningOnRaspberry(false);
|
||||
}
|
||||
if (WarpPI.getPlatform().isRunningOnRaspberry()) {
|
||||
WarpPI.getPlatform().getGpio().wiringPiSetupPhys();
|
||||
WarpPI.getPlatform().getGpio().pinMode(12, WarpPI.getPlatform().getGpio().valuePwmOutput());
|
||||
} else {
|
||||
if (WarpPI.getPlatform().isJavascript() == false) {
|
||||
WarpPI.getPlatform().getSettings().setDebugEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDeviceType() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
public void beforeShutdown() {
|
||||
Keyboard.stopKeyboard();
|
||||
}
|
||||
|
||||
public EventSubmitter<Boolean> isLoaded() {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
public Device getHardwareDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
public static Platform getPlatform() {
|
||||
return WarpPI.platform;
|
||||
}
|
||||
|
||||
|
||||
private void loadingCompleted() {
|
||||
WarpPI.INSTANCE.loaded.submit(true);
|
||||
WarpPI.INSTANCE.device.getDeviceStateDevice().waitForExit();
|
||||
}
|
||||
|
||||
private void loadingFailed(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
|
@ -1,81 +1,77 @@
|
|||
package it.cavallium.warppi.boot;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.Engine.LoadingStatus;
|
||||
package it.cavallium.warppi.boot;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform;
|
||||
import it.cavallium.warppi.device.PIHardwareDisplay;
|
||||
import it.cavallium.warppi.device.PIHardwareTouchDevice;
|
||||
import it.cavallium.warppi.gui.CalculatorHUD;
|
||||
import it.cavallium.warppi.gui.screens.LoadingScreen;
|
||||
import it.cavallium.warppi.math.rules.RulesManager;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
|
||||
public class Boot {
|
||||
|
||||
public static void boot(final Platform platform, final String[] args) throws Exception {
|
||||
Engine.start(platform, new LoadingScreen(), new PIHardwareDisplay(), new PIHardwareTouchDevice(false, false, false), new CalculatorHUD(), Boot.parseStartupArguments(args));
|
||||
Engine.INSTANCE.getLoadPhase().subscribe(Boot::loadCalculator);
|
||||
}
|
||||
|
||||
private static void loadCalculator(final LoadingStatus loading) {
|
||||
try {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setBrightness(0.2f);
|
||||
RulesManager.initialize();
|
||||
RulesManager.warmUp();
|
||||
loading.done();
|
||||
} catch (InterruptedException | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
loading.failed();
|
||||
}
|
||||
|
||||
public static StartupArguments parseStartupArguments(final String[] a) {
|
||||
final StartupArgumentsImpl args = new StartupArgumentsImpl();
|
||||
Arrays.asList(a).stream().parallel().filter((x) -> x != null).map(String::toLowerCase).forEach(arg -> Boot.parseArgument(args, arg));
|
||||
return args;
|
||||
}
|
||||
|
||||
public static void parseArgument(final StartupArgumentsImpl args, final String arg) {
|
||||
switch (arg) {
|
||||
case "-zoomed":
|
||||
args.setZoomed(true);
|
||||
break;
|
||||
case "-verbose":
|
||||
args.setVerboseLoggingEnabled(true);
|
||||
break;
|
||||
case "-noraspi":
|
||||
args.setRaspberryModeAllowed(false);
|
||||
break;
|
||||
case "nogui":
|
||||
args.setNoGUIEngineForced(true);
|
||||
break;
|
||||
case "ms-dos":
|
||||
args.setMSDOSModeEnabled(true);
|
||||
break;
|
||||
case "html":
|
||||
args.setHTMLEngineForced(true);
|
||||
break;
|
||||
case "gpu":
|
||||
args.setGPUEngineForced(true);
|
||||
break;
|
||||
case "cpu":
|
||||
args.setCPUEngineForced(true);
|
||||
break;
|
||||
case "framebuffer":
|
||||
args.setFrameBufferEngineForced(true);
|
||||
break;
|
||||
case "-debug":
|
||||
args.setDebugEnabled(true);
|
||||
break;
|
||||
case "-uncached":
|
||||
args.setUncached(true);
|
||||
break;
|
||||
default:
|
||||
// Not using ConsoleUtils because it isn't initialized at this point.
|
||||
System.out.println("Unrecognized argument " + arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
import it.cavallium.warppi.gui.CalculatorHUD;
|
||||
import it.cavallium.warppi.gui.screens.LoadingScreen;
|
||||
import it.cavallium.warppi.math.rules.RulesManager;
|
||||
|
||||
public class Boot {
|
||||
|
||||
public static void boot(final Platform platform, final String[] args) throws Exception {
|
||||
WarpPI.start(
|
||||
platform,
|
||||
new LoadingScreen(),
|
||||
new CalculatorHUD(),
|
||||
Boot.parseStartupArguments(args),
|
||||
Boot::loadCalculator);
|
||||
}
|
||||
|
||||
private static void loadCalculator() throws Exception {
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setBrightness(0.2f);
|
||||
//TODO: plugins system: PluginsManager.initialize();
|
||||
RulesManager.initialize();
|
||||
RulesManager.warmUp();
|
||||
}
|
||||
|
||||
public static StartupArguments parseStartupArguments(final String[] a) {
|
||||
final StartupArgumentsImpl args = new StartupArgumentsImpl();
|
||||
Arrays.asList(a).stream().parallel().filter((x) -> x != null).map(String::toLowerCase).forEach(arg -> Boot.parseArgument(args, arg));
|
||||
return args;
|
||||
}
|
||||
|
||||
public static void parseArgument(final StartupArgumentsImpl args, final String arg) {
|
||||
switch (arg) {
|
||||
case "-zoomed":
|
||||
args.setZoomed(true);
|
||||
break;
|
||||
case "-verbose":
|
||||
args.setVerboseLoggingEnabled(true);
|
||||
break;
|
||||
case "-noraspi":
|
||||
args.setRaspberryModeAllowed(false);
|
||||
break;
|
||||
case "nogui":
|
||||
args.setNoGUIEngineForced(true);
|
||||
break;
|
||||
case "ms-dos":
|
||||
args.setMSDOSModeEnabled(true);
|
||||
break;
|
||||
case "html":
|
||||
args.setHTMLEngineForced(true);
|
||||
break;
|
||||
case "gpu":
|
||||
args.setGPUEngineForced(true);
|
||||
break;
|
||||
case "cpu":
|
||||
args.setCPUEngineForced(true);
|
||||
break;
|
||||
case "framebuffer":
|
||||
args.setFrameBufferEngineForced(true);
|
||||
break;
|
||||
case "-debug":
|
||||
args.setDebugEnabled(true);
|
||||
break;
|
||||
case "-uncached":
|
||||
args.setUncached(true);
|
||||
break;
|
||||
default:
|
||||
// Not using ConsoleUtils because it isn't initialized at this point.
|
||||
System.out.println("Unrecognized argument " + arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.io.ObjectInputStream;
|
|||
import java.io.ObjectOutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
|
||||
public class CacheFile {
|
||||
private String path;
|
||||
|
@ -22,7 +22,7 @@ public class CacheFile {
|
|||
path = UUID.randomUUID().toString() + ".ser";
|
||||
} while (new File(path).exists());
|
||||
try {
|
||||
File.createTempFile(Engine.getPlatform().getSettings().getCalculatorNameLowercase(), "");
|
||||
File.createTempFile(WarpPI.getPlatform().getSettings().getCalculatorNameLowercase(), "");
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.input.InputManager;
|
||||
import it.cavallium.warppi.gui.DisplayManager;
|
||||
|
||||
public class Device {
|
||||
private final DisplayManager displayManager;
|
||||
private final InputManager inputManager;
|
||||
private final DeviceStateDevice deviceState;
|
||||
|
||||
public Device(final DisplayManager m, final InputManager im, final DeviceStateDevice dm) {
|
||||
displayManager = m;
|
||||
inputManager = im;
|
||||
deviceState = dm;
|
||||
}
|
||||
|
||||
public DisplayManager getDisplayManager() {
|
||||
return displayManager;
|
||||
}
|
||||
|
||||
public InputManager getInputManager() {
|
||||
return inputManager;
|
||||
}
|
||||
|
||||
public DeviceStateDevice getDeviceStateDevice() {
|
||||
return deviceState;
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
displayManager.initialize();
|
||||
inputManager.initialize();
|
||||
deviceState.initialize();
|
||||
|
||||
inputManager.getTouchDevice().listenTouchEvents(displayManager.getTouchEventListener());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public interface DeviceStateDevice {
|
||||
|
||||
void initialize();
|
||||
|
||||
void waitForExit();
|
||||
|
||||
void powerOff();
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.gui.DisplayManager;
|
||||
|
||||
public class HardwareDevice {
|
||||
private final DisplayManager displayManager;
|
||||
private final InputManager inputManager;
|
||||
|
||||
public HardwareDevice(final DisplayManager m, final InputManager im) {
|
||||
displayManager = m;
|
||||
inputManager = im;
|
||||
}
|
||||
|
||||
public DisplayManager getDisplayManager() {
|
||||
return displayManager;
|
||||
}
|
||||
|
||||
public InputManager getInputManager() {
|
||||
return inputManager;
|
||||
}
|
||||
|
||||
public void setup(final Runnable r) {
|
||||
displayManager.initialize();
|
||||
inputManager.getKeyboard().startKeyboard();
|
||||
final Thread t = new Thread(r);
|
||||
Engine.getPlatform().setThreadDaemon(t, false);
|
||||
Engine.getPlatform().setThreadName(t, "Main thread (after setup)");
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import it.cavallium.warppi.event.TouchEventListener;
|
||||
import it.cavallium.warppi.event.TouchPoint;
|
||||
|
||||
public interface HardwareTouchDevice extends TouchEventListener {
|
||||
boolean getInvertedXY();
|
||||
|
||||
boolean getInvertedX();
|
||||
|
||||
boolean getInvertedY();
|
||||
|
||||
default void setInvertedXY() {}
|
||||
|
||||
default void setInvertedX() {}
|
||||
|
||||
default void setInvertedY() {}
|
||||
|
||||
TouchPoint makePoint(long id, float x, float y, int maxX, int maxY, float radiusX, float radiusY, float force,
|
||||
float rotationAngle);
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
public class InputManager {
|
||||
private final Keyboard keyboard;
|
||||
private final HardwareTouchDevice touchDevice;
|
||||
|
||||
public InputManager(final Keyboard k, final HardwareTouchDevice t) {
|
||||
keyboard = k;
|
||||
touchDevice = t;
|
||||
}
|
||||
|
||||
public Keyboard getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public HardwareTouchDevice getTouchDevice() {
|
||||
return touchDevice;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.gui.HardwareDisplay;
|
||||
|
||||
public class PIHardwareDisplay implements HardwareDisplay {
|
||||
|
||||
@Override
|
||||
public void initialize() {}
|
||||
|
||||
@Override
|
||||
public void shutdown() {}
|
||||
|
||||
@Override
|
||||
public void setBrightness(final double value) {
|
||||
if (Engine.getPlatform().isRunningOnRaspberry()) {
|
||||
Engine.getPlatform().getGpio().pwmWrite(12, (int) Math.ceil(value * 1024f));
|
||||
// SoftPwm.softPwmWrite(12, (int)(Math.ceil(brightness*10)));
|
||||
} else {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Brightness: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
package it.cavallium.warppi.device;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.event.TouchCancelEvent;
|
||||
import it.cavallium.warppi.event.TouchEndEvent;
|
||||
import it.cavallium.warppi.event.TouchMoveEvent;
|
||||
import it.cavallium.warppi.event.TouchPoint;
|
||||
import it.cavallium.warppi.event.TouchStartEvent;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
|
||||
public class PIHardwareTouchDevice implements HardwareTouchDevice {
|
||||
|
||||
private final boolean invertXY, invertX, invertY;
|
||||
|
||||
public PIHardwareTouchDevice(final boolean invertXY, final boolean invertX, final boolean invertY) {
|
||||
this.invertXY = invertXY;
|
||||
this.invertX = invertX;
|
||||
this.invertY = invertY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchStart(final TouchStartEvent e) {
|
||||
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
boolean refresh = false;
|
||||
if (scr != null && scr.initialized && scr.onTouchStart(e)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
//Default behavior
|
||||
}
|
||||
if (refresh) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().forceRefresh = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEnd(final TouchEndEvent e) {
|
||||
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
boolean refresh = false;
|
||||
if (scr != null && scr.initialized && scr.onTouchEnd(e)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
//Default behavior
|
||||
}
|
||||
if (refresh) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().forceRefresh = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchCancel(final TouchCancelEvent e) {
|
||||
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
boolean refresh = false;
|
||||
if (scr != null && scr.initialized && scr.onTouchCancel(e)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
//Default behavior
|
||||
}
|
||||
if (refresh) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().forceRefresh = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchMove(final TouchMoveEvent e) {
|
||||
final Screen scr = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
boolean refresh = false;
|
||||
if (scr != null && scr.initialized && scr.onTouchMove(e)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
//Default behavior
|
||||
}
|
||||
if (refresh) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().forceRefresh = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInvertedXY() {
|
||||
return invertXY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInvertedX() {
|
||||
return invertX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInvertedY() {
|
||||
return invertY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TouchPoint makePoint(final long id, float x, float y, final int screenWidth, final int screenHeight,
|
||||
final float radiusX, final float radiusY, final float force, final float rotationAngle) {
|
||||
if (getInvertedXY()) {
|
||||
final double oldX = x;
|
||||
final double oldY = y;
|
||||
x = (float) (oldY * screenWidth / screenHeight);
|
||||
y = (float) (oldX * screenHeight / screenWidth);
|
||||
}
|
||||
if (getInvertedX()) {
|
||||
x = screenWidth - x;
|
||||
}
|
||||
if (getInvertedY()) {
|
||||
y = screenHeight - y;
|
||||
}
|
||||
return new TouchPoint(id, x, y, radiusX, radiusY, force, rotationAngle);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package it.cavallium.warppi.device.chip;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
|
||||
public class ParallelToSerial {
|
||||
|
||||
|
@ -18,16 +18,16 @@ public class ParallelToSerial {
|
|||
|
||||
public boolean[] read() {
|
||||
final boolean[] data = new boolean[8];
|
||||
Engine.getPlatform().getGpio().digitalWrite(CLK_INH, Engine.getPlatform().getGpio().valueHigh());
|
||||
Engine.getPlatform().getGpio().digitalWrite(SH_LD, Engine.getPlatform().getGpio().valueLow());
|
||||
Engine.getPlatform().getGpio().delayMicroseconds(1);
|
||||
Engine.getPlatform().getGpio().digitalWrite(SH_LD, Engine.getPlatform().getGpio().valueHigh());
|
||||
Engine.getPlatform().getGpio().digitalWrite(CLK_INH, Engine.getPlatform().getGpio().valueLow());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(CLK_INH, WarpPI.getPlatform().getGpio().valueHigh());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(SH_LD, WarpPI.getPlatform().getGpio().valueLow());
|
||||
WarpPI.getPlatform().getGpio().delayMicroseconds(1);
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(SH_LD, WarpPI.getPlatform().getGpio().valueHigh());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(CLK_INH, WarpPI.getPlatform().getGpio().valueLow());
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
Engine.getPlatform().getGpio().digitalWrite(CLK, Engine.getPlatform().getGpio().valueHigh());
|
||||
Engine.getPlatform().getGpio().digitalWrite(CLK, Engine.getPlatform().getGpio().valueLow());
|
||||
data[i] = Engine.getPlatform().getGpio().digitalRead(QH) == Engine.getPlatform().getGpio().valueHigh() ? true : false;
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(CLK, WarpPI.getPlatform().getGpio().valueHigh());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(CLK, WarpPI.getPlatform().getGpio().valueLow());
|
||||
data[i] = WarpPI.getPlatform().getGpio().digitalRead(QH) == WarpPI.getPlatform().getGpio().valueHigh() ? true : false;
|
||||
}
|
||||
|
||||
return data;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package it.cavallium.warppi.device.chip;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
|
||||
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 {
|
||||
Engine.getPlatform().getGpio().digitalWrite(RCK, Engine.getPlatform().getGpio().valueLow());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(RCK, WarpPI.getPlatform().getGpio().valueLow());
|
||||
|
||||
for (int i = 7; i >= 0; i--) {
|
||||
Engine.getPlatform().getGpio().digitalWrite(SCK, Engine.getPlatform().getGpio().valueLow());
|
||||
Engine.getPlatform().getGpio().digitalWrite(SER, data[i]);
|
||||
Engine.getPlatform().getGpio().digitalWrite(SCK, Engine.getPlatform().getGpio().valueHigh());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(SCK, WarpPI.getPlatform().getGpio().valueLow());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(SER, data[i]);
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(SCK, WarpPI.getPlatform().getGpio().valueHigh());
|
||||
}
|
||||
|
||||
Engine.getPlatform().getGpio().digitalWrite(RCK, Engine.getPlatform().getGpio().valueHigh());
|
||||
WarpPI.getPlatform().getGpio().digitalWrite(RCK, WarpPI.getPlatform().getGpio().valueHigh());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package it.cavallium.warppi.device.display;
|
||||
|
||||
public interface BacklightOutputDevice {
|
||||
|
||||
/**
|
||||
* Set the brightness level
|
||||
* @param value Value from 0.0 to 1.0
|
||||
*/
|
||||
void setBrightness(double value);
|
||||
|
||||
/**
|
||||
* Turn on or off the backlight
|
||||
* @param value true is ON, false is OFF
|
||||
*/
|
||||
void setPower(boolean value);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package it.cavallium.warppi.device.display;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
|
||||
public interface DisplayOutputDevice {
|
||||
public GraphicEngine getGraphicEngine();
|
||||
public int[] getDisplaySize();
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package it.cavallium.warppi.device.display;
|
||||
|
||||
public class NoDisplaysAvailableException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package it.cavallium.warppi.device.display;
|
||||
|
||||
public class NullBacklightOutputDevice implements BacklightOutputDevice {
|
||||
|
||||
private double brightness;
|
||||
private boolean power;
|
||||
|
||||
@Override
|
||||
public void setBrightness(double value) {
|
||||
this.brightness = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPower(boolean value) {
|
||||
this.power = value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package it.cavallium.warppi.device.graphicengine;
|
||||
package it.cavallium.warppi.device.display;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -7,7 +7,7 @@ import java.net.URL;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.util.ClassUtils;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class RAWFont {
|
|||
loadFont("/font_" + name + ".rft");
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(1);
|
||||
WarpPI.getPlatform().exit(1);
|
||||
}
|
||||
chars32 = new int[(maxBound - minBound) * charIntCount];
|
||||
for (int charIndex = 0; charIndex < maxBound - minBound; charIndex++) {
|
||||
|
@ -110,7 +110,7 @@ public class RAWFont {
|
|||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println(string);
|
||||
Engine.getPlatform().exit(-1);
|
||||
WarpPI.getPlatform().exit(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
|
@ -0,0 +1,5 @@
|
|||
package it.cavallium.warppi.device.input;
|
||||
|
||||
public interface HardwareKeyboardDevice {
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package it.cavallium.warppi.device.input;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class InputManager {
|
||||
private final KeyboardInputDevice keyboard;
|
||||
private final TouchInputDevice touchDevice;
|
||||
|
||||
public InputManager(KeyboardInputDevice keyboard, TouchInputDevice touchscreen) {
|
||||
this.keyboard = Objects.requireNonNull(keyboard);
|
||||
this.touchDevice = Objects.requireNonNull(touchscreen);
|
||||
}
|
||||
|
||||
public KeyboardInputDevice getKeyboard() {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public TouchInputDevice getTouchDevice() {
|
||||
return touchDevice;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
this.keyboard.initialize();
|
||||
this.touchDevice.initialize();
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
package it.cavallium.warppi.device;
|
||||
package it.cavallium.warppi.device.input;
|
||||
|
||||
public interface KeyboardAWTValues {
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package it.cavallium.warppi.device.input;
|
||||
|
||||
public interface KeyboardInputDevice {
|
||||
|
||||
void initialize();
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package it.cavallium.warppi.device;
|
||||
package it.cavallium.warppi.device.input;
|
||||
|
||||
public interface KeyboardJogampValues {
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package it.cavallium.warppi.device.input;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import it.cavallium.warppi.event.TouchEvent;
|
||||
import it.cavallium.warppi.event.TouchPoint;
|
||||
|
||||
public class NullTouchInputDevice implements TouchInputDevice {
|
||||
|
||||
@Override
|
||||
public boolean getSwappedAxes() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInvertedX() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInvertedY() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listenTouchEvents(Consumer<TouchEvent> touchEventListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TouchPoint makePoint(long id, float x, float y, int maxX, int maxY, float radiusX, float radiusY,
|
||||
float force, float rotationAngle) {
|
||||
return new TouchPoint(id, maxX, maxY, radiusX, radiusY, force, rotationAngle);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package it.cavallium.warppi.device.input;
|
||||
|
||||
import java.util.concurrent.Flow.Subscriber;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import it.cavallium.warppi.event.TouchEvent;
|
||||
import it.cavallium.warppi.event.TouchEventListener;
|
||||
import it.cavallium.warppi.event.TouchPoint;
|
||||
|
||||
public interface TouchInputDevice {
|
||||
boolean getSwappedAxes();
|
||||
|
||||
boolean getInvertedX();
|
||||
|
||||
boolean getInvertedY();
|
||||
|
||||
default void setInvertedXY() {}
|
||||
|
||||
default void setInvertedX() {}
|
||||
|
||||
default void setInvertedY() {}
|
||||
|
||||
void listenTouchEvents(Consumer<TouchEvent> touchEventListener);
|
||||
|
||||
default TouchPoint makePoint(final long id, float x, float y, final int screenWidth, final int screenHeight,
|
||||
final float radiusX, final float radiusY, final float force, final float rotationAngle) {
|
||||
if (getSwappedAxes()) {
|
||||
final double oldX = x;
|
||||
final double oldY = y;
|
||||
x = (float) (oldY * screenWidth / screenHeight);
|
||||
y = (float) (oldX * screenHeight / screenWidth);
|
||||
}
|
||||
if (getInvertedX()) {
|
||||
x = screenWidth - x;
|
||||
}
|
||||
if (getInvertedY()) {
|
||||
y = screenHeight - y;
|
||||
}
|
||||
return new TouchPoint(id, x, y, radiusX, radiusY, force, rotationAngle);
|
||||
}
|
||||
|
||||
void initialize();
|
||||
}
|
|
@ -2,13 +2,16 @@ package it.cavallium.warppi.extra.mario;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
|
@ -45,33 +48,33 @@ public class MarioScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() {
|
||||
public void graphicInitialized(ScreenContext ctx) {
|
||||
try {
|
||||
if (MarioScreen.skin == null) {
|
||||
MarioScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioskin.png");
|
||||
MarioScreen.skin = d.display.getGraphicEngine().loadSkin("/marioskin.png");
|
||||
}
|
||||
if (MarioScreen.groundskin == null) {
|
||||
MarioScreen.groundskin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioground.png");
|
||||
MarioScreen.groundskin = d.display.getGraphicEngine().loadSkin("/marioground.png");
|
||||
}
|
||||
if (MarioScreen.gpuTest2 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest2 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest2");
|
||||
MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest2");
|
||||
} catch (final Exception ex) {}
|
||||
}
|
||||
if (MarioScreen.gpuTest1 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest12");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest12");
|
||||
MarioScreen.gpuTest12 = true;
|
||||
} catch (final Exception ex) {
|
||||
MarioScreen.gpuTest12 = false;
|
||||
try {
|
||||
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest1");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest", "gputest1");
|
||||
} catch (final Exception ex2) {}
|
||||
}
|
||||
}
|
||||
if (MarioScreen.gpuTest3 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest3 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("N:\\gputest\\font_gputest3.png");
|
||||
MarioScreen.gpuTest3 = d.display.getGraphicEngine().loadSkin("N:\\gputest\\font_gputest3.png");
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -85,30 +88,30 @@ public class MarioScreen extends Screen {
|
|||
public void initialized() {
|
||||
try {
|
||||
if (MarioScreen.skin == null) {
|
||||
MarioScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioskin.png");
|
||||
MarioScreen.skin = d.display.getGraphicEngine().loadSkin("/marioskin.png");
|
||||
}
|
||||
if (MarioScreen.groundskin == null) {
|
||||
MarioScreen.groundskin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/marioground.png");
|
||||
MarioScreen.groundskin = d.display.getGraphicEngine().loadSkin("/marioground.png");
|
||||
}
|
||||
if (MarioScreen.gpuTest2 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest2 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest2");
|
||||
MarioScreen.gpuTest2 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest2");
|
||||
} catch (final Exception ex) {}
|
||||
}
|
||||
if (MarioScreen.gpuTest1 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest12");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest12");
|
||||
MarioScreen.gpuTest12 = true;
|
||||
} catch (final Exception ex) {
|
||||
MarioScreen.gpuTest12 = false;
|
||||
try {
|
||||
MarioScreen.gpuTest1 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("N:\\gputest\\gputest1");
|
||||
MarioScreen.gpuTest1 = d.display.getGraphicEngine().loadFont("N:\\gputest\\gputest1");
|
||||
} catch (final Exception ex2) {}
|
||||
}
|
||||
}
|
||||
if (MarioScreen.gpuTest3 == null) {
|
||||
try {
|
||||
MarioScreen.gpuTest3 = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("N:\\gputest\\font_gputest3.png");
|
||||
MarioScreen.gpuTest3 = d.display.getGraphicEngine().loadSkin("N:\\gputest\\font_gputest3.png");
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
@ -166,7 +169,7 @@ public class MarioScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
if (!errored) {
|
||||
final boolean upPressed = false, downPressed = false, runPressed = false;
|
||||
g.gameTick(dt, upPressed, downPressed, leftPressed, rightPressed, jumpPressed, runPressed);
|
||||
|
@ -182,89 +185,90 @@ public class MarioScreen extends Screen {
|
|||
gpuCharTestt1Elapsed -= 1.5;
|
||||
}
|
||||
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xff000000);
|
||||
d.renderer.glClearColor(0xff000000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
if (errored) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(0, 20, "ERROR");
|
||||
d.renderer.glDrawStringLeft(0, 20, "ERROR");
|
||||
} else {
|
||||
if (MarioScreen.groundskin != null) {
|
||||
final double playerX = g.getPlayer().getX();
|
||||
final double playerY = g.getPlayer().getY();
|
||||
MarioScreen.groundskin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
MarioScreen.groundskin.use(d.display);
|
||||
final MarioWorld w = g.getCurrentWorld();
|
||||
final int width = w.getWidth();
|
||||
final int height = w.getHeight();
|
||||
final float screenX = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() / 2f - 8f;
|
||||
final float screenY = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2f - 8f;
|
||||
final float screenX = ctx.getWidth() / 2f - 8f;
|
||||
final float screenY = ctx.getHeight() / 2f - 8f;
|
||||
final float shiftX = -8 + 16 * (float) playerX;
|
||||
final float shiftY = -8 + 16 * (height - (float) playerY);
|
||||
int blue = -1;
|
||||
for (int ix = 0; ix < width; ix++) {
|
||||
for (int iy = 0; iy < height; iy++) {
|
||||
final double distX = Math.abs(playerX - ix);
|
||||
final double distY = Math.abs(playerY - iy - 1.5d);
|
||||
if (distX * distX + distY * distY / 2d < 25d) {
|
||||
final double distY = Math.abs(playerY - iy - 1.2d);
|
||||
if (distX * distX + distY * distY / 2d < 270d) {
|
||||
final byte b = w.getBlockIdAt(ix, iy);
|
||||
if (b == 0) {
|
||||
if (blue != 1) {
|
||||
blue = 1;
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xff9290ff);
|
||||
d.renderer.glColor(0xff9290ff);
|
||||
}
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillColor(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16);
|
||||
d.renderer.glFillColor(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16);
|
||||
} else {
|
||||
if (blue != 0) {
|
||||
blue = 0;
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xffffffff);
|
||||
d.renderer.glColor(0xffffffff);
|
||||
}
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16, 0, 0, 16, 16);
|
||||
d.renderer.glFillRect(screenX - shiftX + 16 * ix, screenY - shiftY + 16 * (height - iy), 16, 16, 0, 0, 16, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (blue != 0) {
|
||||
blue = 0;
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xffffffff);
|
||||
d.renderer.glColor(0xffffffff);
|
||||
}
|
||||
|
||||
//DRAW MARIO
|
||||
MarioScreen.skin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(screenX - (g.getPlayer().flipped ? 3 : 0), screenY, 35, 27, 35 * (g.getPlayer().marioSkinPos[0] + (g.getPlayer().flipped ? 2 : 1)), 27 * g.getPlayer().marioSkinPos[1], 35 * (g.getPlayer().flipped ? -1 : 1), 27);
|
||||
MarioScreen.skin.use(d.display);
|
||||
d.renderer.glFillRect(screenX - (g.getPlayer().flipped ? 3 : 0), screenY, 35, 27, 35 * (g.getPlayer().marioSkinPos[0] + (g.getPlayer().flipped ? 2 : 1)), 27 * g.getPlayer().marioSkinPos[1], 35 * (g.getPlayer().flipped ? -1 : 1), 27);
|
||||
// PIDisplay.renderer.glDrawSkin(getPosX() - 18, 25 + getPosY(), 35 * (marioSkinPos[0] + (flipped ? 2 : 1)), 27 * marioSkinPos[1], 35 * (marioSkinPos[0] + (flipped ? 1 : 2)), 27 * (marioSkinPos[1] + 1), true);
|
||||
}
|
||||
|
||||
// GPU PERFORMANCE TEST
|
||||
if (MarioScreen.gpuTest1 != null) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3f(1, 1, 1);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillColor(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() - (MarioScreen.gpuTest12 ? 512 : 256), Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), MarioScreen.gpuTest12 ? 512 : 256, MarioScreen.gpuTest12 ? 512 : 256);
|
||||
MarioScreen.gpuTest1.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3f(0, 0, 0);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth(), Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]);
|
||||
d.renderer.glColor3f(1, 1, 1);
|
||||
d.renderer.glFillColor(ctx.getWidth() - (MarioScreen.gpuTest12 ? 512 : 256), ctx.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), MarioScreen.gpuTest12 ? 512 : 256, MarioScreen.gpuTest12 ? 512 : 256);
|
||||
MarioScreen.gpuTest1.use(d.display);
|
||||
d.renderer.glColor3f(0, 0, 0);
|
||||
d.renderer.glDrawStringRight(ctx.getWidth(), ctx.getHeight() / 2 - (MarioScreen.gpuTest12 ? 256 : 128), gpuCharTest1[gpuCharTest1Num]);
|
||||
}
|
||||
if (MarioScreen.gpuTest3 != null) {
|
||||
MarioScreen.gpuTest3.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4f(1, 1, 1, 0.7f);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(0, StaticVars.screenSize[1] - 128, 224, 128, gpuTestNum * 224, 0, 224, 128);
|
||||
MarioScreen.gpuTest3.use(d.display);
|
||||
d.renderer.glColor4f(1, 1, 1, 0.7f);
|
||||
d.renderer.glFillRect(0, display.getDisplaySize()[1] - 128, 224, 128, gpuTestNum * 224, 0, 224, 128);
|
||||
}
|
||||
if (MarioScreen.gpuTest2 != null) {
|
||||
MarioScreen.gpuTest2.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFF000000);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "A");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFF800000);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "B");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFeea28e);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "C");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFee7255);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "D");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFeac0b0);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "E");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFf3d8ce);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "F");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor(0xFFffede7);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringRight(StaticVars.screenSize[0], Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G");
|
||||
MarioScreen.gpuTest2.use(d.display);
|
||||
d.renderer.glColor(0xFF000000);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "A");
|
||||
d.renderer.glColor(0xFF800000);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "B");
|
||||
d.renderer.glColor(0xFFeea28e);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "C");
|
||||
d.renderer.glColor(0xFFee7255);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "D");
|
||||
d.renderer.glColor(0xFFeac0b0);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "E");
|
||||
d.renderer.glColor(0xFFf3d8ce);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "F");
|
||||
d.renderer.glColor(0xFFffede7);
|
||||
d.renderer.glDrawStringRight(display.getDisplaySize()[0], ctx.getHeight() - MarioScreen.gpuTest2.getCharacterHeight(), "G");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,16 @@ package it.cavallium.warppi.extra.tetris;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
|
@ -30,7 +32,7 @@ public class TetrisScreen extends Screen {
|
|||
|
||||
private ButtonInfo backPressed = new ButtonInfo();
|
||||
|
||||
private GraphicEngine e;
|
||||
private DisplayOutputDevice e;
|
||||
|
||||
private Renderer r;
|
||||
|
||||
|
@ -43,16 +45,15 @@ public class TetrisScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public void initialized() {
|
||||
StaticVars.windowZoom.onNext(2f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() {
|
||||
public void graphicInitialized(ScreenContext ctx) {
|
||||
try {
|
||||
e = d.engine;
|
||||
e = d.display;
|
||||
r = d.renderer;
|
||||
if (TetrisScreen.skin == null) {
|
||||
TetrisScreen.skin = Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadSkin("/tetrisskin.png");
|
||||
TetrisScreen.skin = d.display.getGraphicEngine().loadSkin("/tetrisskin.png");
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -65,22 +66,23 @@ public class TetrisScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xff000000);
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
d.renderer.glClearColor(0xff000000);
|
||||
g.update(dt, leftPressed, rightPressed, downPressed, upPressed, okPressed, backPressed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
if (TetrisScreen.skin != null) {
|
||||
TetrisScreen.skin.use(e);
|
||||
}
|
||||
r.glColor3f(1, 1, 1);
|
||||
BlockColor[] renderedGrid = g.getRenderedGrid();
|
||||
int centerScreen = StaticVars.screenSize[0]/2;
|
||||
int centerScreen = ctx.getWidth()/2;
|
||||
int centerGrid = TetrisGame.WIDTH*6/2-1;
|
||||
final int leftOffset = centerScreen - centerGrid;
|
||||
final int topOffset = StaticVars.screenSize[1] - TetrisGame.HEIGHT*6-1;
|
||||
final int topOffset = ctx.getHeight() - TetrisGame.HEIGHT*6-1;
|
||||
for (int y = 0; y < TetrisGame.HEIGHT; y++) {
|
||||
for (int x = 0; x < TetrisGame.WIDTH; x++) {
|
||||
final int offset = x+y*TetrisGame.WIDTH;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
|
@ -31,7 +32,7 @@ public class CalculatorHUD extends HUD {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
@ -39,23 +40,25 @@ public class CalculatorHUD extends HUD {
|
|||
@Override
|
||||
public void renderTopmostBackground() {
|
||||
final Renderer r = d.renderer;
|
||||
final GraphicEngine engine = d.engine;
|
||||
final DisplayOutputDevice display = d.display;
|
||||
final GraphicEngine engine = display.getGraphicEngine();
|
||||
|
||||
r.glColor(0xFFc5c2af);
|
||||
r.glFillColor(0, 0, engine.getWidth(), 20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTopmost() {
|
||||
final Renderer r = d.renderer;
|
||||
final GraphicEngine engine = d.engine;
|
||||
public void renderTopmost(RenderContext ctx) {
|
||||
final Renderer r = ctx.getRenderer();
|
||||
final DisplayOutputDevice display = d.display;
|
||||
final GraphicEngine engine = display.getGraphicEngine();
|
||||
final Skin guiSkin = d.guiSkin;
|
||||
|
||||
//DRAW TOP
|
||||
r.glColor3i(0, 0, 0);
|
||||
r.glDrawLine(0, 20, engine.getWidth() - 1, 20);
|
||||
r.glColor3i(255, 255, 255);
|
||||
guiSkin.use(engine);
|
||||
guiSkin.use(display);
|
||||
if (Keyboard.shift) {
|
||||
r.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 2, 16 * 0, 16, 16);
|
||||
} else {
|
||||
|
@ -69,31 +72,31 @@ public class CalculatorHUD extends HUD {
|
|||
|
||||
int padding = 2;
|
||||
|
||||
final int brightness = (int) Math.ceil(Engine.INSTANCE.getHardwareDevice().getDisplayManager().getBrightness() * 9);
|
||||
final int brightness = (int) Math.ceil(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getBrightness() * 9);
|
||||
if (brightness <= 10) {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
|
||||
} else {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Brightness error");
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(1, "Brightness error");
|
||||
}
|
||||
|
||||
padding += 18 + 6;
|
||||
|
||||
final boolean canGoBack = Engine.INSTANCE.getHardwareDevice().getDisplayManager().canGoBack();
|
||||
final boolean canGoForward = Engine.INSTANCE.getHardwareDevice().getDisplayManager().canGoForward();
|
||||
final boolean canGoBack = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().canGoBack();
|
||||
final boolean canGoForward = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().canGoForward();
|
||||
|
||||
if (Engine.getPlatform().getSettings().isDebugEnabled()) {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
|
||||
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
|
||||
padding += 18 + 6;
|
||||
}
|
||||
|
||||
if (canGoBack && canGoForward) {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
|
||||
} else if (canGoBack) {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
|
||||
} else if (canGoForward) {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
|
||||
} else {
|
||||
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
|
||||
r.glFillRect(ctx.getWidth() - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
|
||||
}
|
||||
|
||||
padding += 18;
|
||||
|
@ -101,23 +104,23 @@ public class CalculatorHUD extends HUD {
|
|||
//DRAW BOTTOM
|
||||
r.glDrawStringLeft(2, 90, d.displayDebugString);
|
||||
|
||||
Utils.getFont(true, false).use(engine);
|
||||
Utils.getFont(true, false).use(display);
|
||||
r.glColor4i(255, 0, 0, 40);
|
||||
r.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 - 7 + 1, "WORK IN");
|
||||
r.glDrawStringLeft(1 + 1, ctx.getHeight() - 7 - 7 + 1, "WORK IN");
|
||||
r.glColor4i(255, 0, 0, 80);
|
||||
r.glDrawStringLeft(1, StaticVars.screenSize[1] - 7 - 7, "WORK IN");
|
||||
r.glDrawStringLeft(1, ctx.getHeight() - 7 - 7, "WORK IN");
|
||||
r.glColor4i(255, 0, 0, 40);
|
||||
r.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 + 1, "PROGRESS.");
|
||||
r.glDrawStringLeft(1 + 1, ctx.getHeight() - 7 + 1, "PROGRESS.");
|
||||
r.glColor4i(255, 0, 0, 80);
|
||||
r.glDrawStringLeft(1, StaticVars.screenSize[1] - 7, "PROGRESS.");
|
||||
r.glDrawStringLeft(1, ctx.getHeight() - 7, "PROGRESS.");
|
||||
|
||||
int currentDebugLine = 2;
|
||||
if (Engine.getPlatform().getSettings().isDebugEnabled()) {
|
||||
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
|
||||
ObjectArrayList<Screen> allSessions = new ObjectArrayList<>();
|
||||
for (Screen session : Engine.INSTANCE.getHardwareDevice().getDisplayManager().sessions) {
|
||||
for (Screen session : WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().sessions) {
|
||||
allSessions.add(0, session);
|
||||
}
|
||||
Screen curScreen = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
Screen curScreen = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
|
||||
if (curScreen.historyBehavior == HistoryBehavior.DONT_KEEP_IN_HISTORY) {
|
||||
allSessions.add(curScreen);
|
||||
}
|
||||
|
@ -126,7 +129,7 @@ public class CalculatorHUD extends HUD {
|
|||
if (session != null) {
|
||||
String title = session.getSessionTitle();
|
||||
if (title != null && title.length() > 0) {
|
||||
Utils.getFont(true).use(engine);
|
||||
Utils.getFont(true).use(display);
|
||||
if (session.historyBehavior == HistoryBehavior.DONT_KEEP_IN_HISTORY) {
|
||||
r.glColor(0xFF3333FF);
|
||||
} else if (session.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
|
@ -134,28 +137,48 @@ public class CalculatorHUD extends HUD {
|
|||
} else {
|
||||
r.glColor(0xFF990000);
|
||||
}
|
||||
r.glDrawStringLeft(0, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "[" + String.format("%1$03d", session.debugScreenID) + "]" + title.toUpperCase());
|
||||
if (session == Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen()) {
|
||||
r.glDrawStringLeft(0, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "[" + String.format("%1$03d", session.debugScreenID) + "] " + title.toUpperCase());
|
||||
if (session == WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getScreen()) {
|
||||
r.glColor(0xFF00CC00);
|
||||
} else {
|
||||
r.glColor(0xFF990000);
|
||||
}
|
||||
r.glDrawStringLeft(0, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), " " + title.toUpperCase());
|
||||
r.glDrawStringLeft(0, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), " " + title.toUpperCase());
|
||||
}
|
||||
currentDebugLine++;
|
||||
}
|
||||
}
|
||||
r.glColor(0xFF000000);
|
||||
r.glDrawStringLeft(5, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "DEBUG ENABLED");
|
||||
r.glDrawStringLeft(5, ctx.getHeight() - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "DEBUG ENABLED");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMarginLeft() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMarginTop() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMarginRight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMarginBottom() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBackground() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
@ -1,34 +1,30 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.Platform.Semaphore;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.flow.Observable;
|
||||
import it.cavallium.warppi.flow.Pair;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.gui.graphicengine.RenderingLoop;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
import it.cavallium.warppi.gui.graphicengine.impl.nogui.NoGuiEngine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.BacklightOutputDevice;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.event.*;
|
||||
import it.cavallium.warppi.gui.graphicengine.*;
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
import it.cavallium.warppi.util.Timer;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class DisplayManager implements RenderingLoop {
|
||||
private static final int tickDuration = 50;
|
||||
|
||||
private float brightness;
|
||||
|
||||
public final GraphicEngine engine;
|
||||
public final HardwareDisplay monitor;
|
||||
public final DisplayOutputDevice display;
|
||||
public final GraphicEngine graphicEngine;
|
||||
public final BacklightOutputDevice backlight;
|
||||
public final boolean supportsPauses;
|
||||
public Renderer renderer;
|
||||
|
||||
|
@ -51,24 +47,23 @@ public final class DisplayManager implements RenderingLoop {
|
|||
*/
|
||||
public boolean forceRefresh;
|
||||
|
||||
public DisplayManager(final HardwareDisplay monitor, final HUD hud, final Screen screen, final String title) {
|
||||
this.monitor = monitor;
|
||||
public DisplayManager(final DisplayOutputDevice display, final BacklightOutputDevice backlight, final HUD hud, final Screen screen, final String title) {
|
||||
this.display = display;
|
||||
this.graphicEngine = display.getGraphicEngine();
|
||||
this.backlight = backlight;
|
||||
this.hud = hud;
|
||||
initialTitle = title;
|
||||
initialScreen = screen;
|
||||
|
||||
screenChange = Engine.getPlatform().newSemaphore();
|
||||
engine = chooseGraphicEngine();
|
||||
supportsPauses = engine.doesRefreshPauses();
|
||||
screenChange = WarpPI.getPlatform().newSemaphore();
|
||||
supportsPauses = graphicEngine.doesRefreshPauses();
|
||||
|
||||
glyphsHeight = new int[] { 9, 6, 12, 9 };
|
||||
glyphsHeight = new int[]{9, 6, 12, 9};
|
||||
displayDebugString = "";
|
||||
errorMessages = new ObjectArrayList<>();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
monitor.initialize();
|
||||
|
||||
try {
|
||||
hud.d = this;
|
||||
hud.create();
|
||||
|
@ -77,18 +72,17 @@ public final class DisplayManager implements RenderingLoop {
|
|||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(0);
|
||||
WarpPI.getPlatform().exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
engine.create();
|
||||
renderer = engine.getRenderer();
|
||||
engine.setTitle(initialTitle);
|
||||
graphicEngine.create();
|
||||
renderer = graphicEngine.getRenderer();
|
||||
graphicEngine.setTitle(initialTitle);
|
||||
loop();
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
monitor.shutdown();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -111,54 +105,6 @@ public final class DisplayManager implements RenderingLoop {
|
|||
* GL_UNSIGNED_BYTE, skin); } catch (IOException ex) { ex.printStackTrace(); } }
|
||||
*/
|
||||
|
||||
private GraphicEngine chooseGraphicEngine() {
|
||||
GraphicEngine d;
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "framebuffer engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Using FB Graphic Engine");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "CPU engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Using CPU Graphic Engine");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "GPU engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Using GPU Graphic Engine");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "headless 24 bit engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
System.err.println(
|
||||
"Using Headless 24 bit Engine! This is a problem! No other graphic engines are available.");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "headless 256 colors engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
System.err.println("Using Headless 256 Engine! This is a problem! No other graphic engines are available.");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "headless 8 colors engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
System.err
|
||||
.println("Using Headless basic Engine! This is a problem! No other graphic engines are available.");
|
||||
return d;
|
||||
}
|
||||
d = Utils.getOrDefault(Engine.getPlatform().getEnginesList(), "HTML5 engine", null);
|
||||
if (d != null && d.isSupported()) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_NODEBUG,
|
||||
"Using Html Graphic Engine");
|
||||
return d;
|
||||
}
|
||||
d = new NoGuiEngine();
|
||||
if (d != null && d.isSupported()) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Using NoGui Graphic Engine");
|
||||
return d;
|
||||
}
|
||||
throw new UnsupportedOperationException("No graphic engines available.");
|
||||
}
|
||||
|
||||
public void closeScreen() {
|
||||
boolean isLastSession = sessions[1] == null;
|
||||
if (!isLastSession) {
|
||||
|
@ -193,10 +139,10 @@ public final class DisplayManager implements RenderingLoop {
|
|||
}
|
||||
if (mustBeAddedToHistory) {
|
||||
if (screen.historyBehavior == HistoryBehavior.NORMAL
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
if (currentSession > 0) {
|
||||
final int sl = sessions.length; // TODO: I don't know why if i don't add +5 or more some items
|
||||
// disappear
|
||||
// disappear
|
||||
List<Screen> newSessions = new LinkedList<>();
|
||||
int i = 0;
|
||||
for (Screen s : sessions) {
|
||||
|
@ -250,14 +196,14 @@ public final class DisplayManager implements RenderingLoop {
|
|||
screenChange.release();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(0);
|
||||
WarpPI.getPlatform().exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void replaceScreen(final Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.historyBehavior == HistoryBehavior.NORMAL
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
|| screen.historyBehavior == HistoryBehavior.ALWAYS_KEEP_IN_HISTORY) {
|
||||
sessions[currentSession] = screen;
|
||||
} else {
|
||||
currentSession = -1;
|
||||
|
@ -276,7 +222,7 @@ public final class DisplayManager implements RenderingLoop {
|
|||
screenChange.release();
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(0);
|
||||
WarpPI.getPlatform().exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -354,77 +300,87 @@ public final class DisplayManager implements RenderingLoop {
|
|||
}
|
||||
|
||||
private void load_skin() throws IOException {
|
||||
guiSkin = engine.loadSkin("/skin.png");
|
||||
guiSkin = graphicEngine.loadSkin("/skin.png");
|
||||
}
|
||||
|
||||
private void load_fonts() throws IOException {
|
||||
fonts = new BinaryFont[7];
|
||||
fonts[0] = engine.loadFont("smal");
|
||||
fonts[1] = engine.loadFont("smallest");
|
||||
fonts[2] = engine.loadFont("norm");
|
||||
fonts[3] = engine.loadFont("smal");
|
||||
fonts[0] = graphicEngine.loadFont("smal");
|
||||
fonts[1] = graphicEngine.loadFont("smallest");
|
||||
fonts[2] = graphicEngine.loadFont("norm");
|
||||
fonts[3] = graphicEngine.loadFont("smal");
|
||||
// 4
|
||||
// fonts[5] = engine.loadFont("square");
|
||||
}
|
||||
|
||||
private void draw_init() {
|
||||
if (engine.supportsFontRegistering()) {
|
||||
final List<BinaryFont> fontsIterator = engine.getRegisteredFonts();
|
||||
if (graphicEngine.supportsFontRegistering()) {
|
||||
final List<BinaryFont> fontsIterator = graphicEngine.getRegisteredFonts();
|
||||
for (final BinaryFont f : fontsIterator) {
|
||||
if (!f.isInitialized()) {
|
||||
f.initialize(engine);
|
||||
f.initialize(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!screen.graphicInitialized) {
|
||||
try {
|
||||
screen.initializeGraphic();
|
||||
var displaySize = display.getDisplaySize();
|
||||
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
|
||||
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
|
||||
var scrCtx = new ScreenContext(graphicEngine, scrWidth, scrHeight);
|
||||
screen.initializeGraphic(scrCtx);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
renderer.glClear(engine.getWidth(), engine.getHeight());
|
||||
renderer.glClear(graphicEngine.getWidth(), graphicEngine.getHeight());
|
||||
}
|
||||
|
||||
private void draw_world() {
|
||||
var displaySize = display.getDisplaySize();
|
||||
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
|
||||
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
|
||||
var scrCtx = new RenderContext(graphicEngine, renderer.getBoundedInstance(hud.getMarginLeft(), hud.getMarginTop(), scrWidth, scrHeight), scrWidth, scrHeight);
|
||||
var fullCtx = new RenderContext(graphicEngine, renderer, displaySize[0], displaySize[1]);
|
||||
|
||||
renderer.glColor3i(255, 255, 255);
|
||||
|
||||
if (error != null) {
|
||||
final BinaryFont fnt = Utils.getFont(false, false);
|
||||
if (fnt != null && fnt != engine.getRenderer().getCurrentFont()) {
|
||||
fnt.use(engine);
|
||||
if (fnt != null && fnt != graphicEngine.getRenderer().getCurrentFont()) {
|
||||
fnt.use(display);
|
||||
}
|
||||
renderer.glColor3i(129, 28, 22);
|
||||
renderer.glDrawStringRight(StaticVars.screenSize[0] - 2,
|
||||
StaticVars.screenSize[1] - (fnt.getCharacterHeight() + 2),
|
||||
Engine.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR");
|
||||
renderer.glDrawStringRight(display.getDisplaySize()[0] - 2,
|
||||
display.getDisplaySize()[1] - (fnt.getCharacterHeight() + 2),
|
||||
WarpPI.getPlatform().getSettings().getCalculatorNameUppercase() + " CALCULATOR");
|
||||
renderer.glColor3i(149, 32, 26);
|
||||
renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, 22, error);
|
||||
renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, 22, error);
|
||||
renderer.glColor3i(164, 34, 28);
|
||||
int i = 22;
|
||||
for (final String stackPart : errorStackTrace) {
|
||||
renderer.glDrawStringLeft(2, 22 + i, stackPart);
|
||||
i += 11;
|
||||
}
|
||||
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
|
||||
fonts[0].use(engine);
|
||||
if (fonts[0] != null && fonts[0] != graphicEngine.getRenderer().getCurrentFont()) {
|
||||
fonts[0].use(display);
|
||||
}
|
||||
renderer.glColor3i(129, 28, 22);
|
||||
renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, 11, "UNEXPECTED EXCEPTION");
|
||||
renderer.glDrawStringCenter(display.getDisplaySize()[0] / 2, 11, "UNEXPECTED EXCEPTION");
|
||||
} else {
|
||||
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
|
||||
fonts[0].use(engine);
|
||||
if (fonts[0] != null && fonts[0] != graphicEngine.getRenderer().getCurrentFont()) {
|
||||
fonts[0].use(display);
|
||||
}
|
||||
if (hud.visible)
|
||||
hud.renderBackground();
|
||||
screen.render();
|
||||
screen.render(scrCtx);
|
||||
if (hud.visible) {
|
||||
hud.render();
|
||||
hud.render(fullCtx);
|
||||
hud.renderTopmostBackground();
|
||||
}
|
||||
screen.renderTopmost();
|
||||
screen.renderTopmost(fullCtx);
|
||||
if (hud.visible)
|
||||
hud.renderTopmost();
|
||||
hud.renderTopmost(fullCtx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,8 +392,8 @@ public final class DisplayManager implements RenderingLoop {
|
|||
private long precTime = -1;
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if (supportsPauses == false || Keyboard.popRefreshRequest() || forceRefresh || screen.mustBeRefreshed()) {
|
||||
public void refresh(boolean force) {
|
||||
if (force || supportsPauses == false || Keyboard.popRefreshRequest() || forceRefresh || screen.mustBeRefreshed()) {
|
||||
forceRefresh = false;
|
||||
draw();
|
||||
}
|
||||
|
@ -456,45 +412,42 @@ public final class DisplayManager implements RenderingLoop {
|
|||
}
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(0);
|
||||
WarpPI.getPlatform().exit(0);
|
||||
}
|
||||
|
||||
final Observable<Long> workTimer = Observable.interval(DisplayManager.tickDuration);
|
||||
var displayRefreshManager = new DisplayRefreshManager(this::onRefresh);
|
||||
new Timer(DisplayManager.tickDuration, displayRefreshManager::onTick);
|
||||
graphicEngine.onResize().subscribe(displayRefreshManager::onResize);
|
||||
|
||||
final Observable<Integer[]> onResizeObservable = engine.onResize();
|
||||
Observable<Pair<Long, Integer[]>> refreshObservable;
|
||||
if (onResizeObservable == null) {
|
||||
refreshObservable = workTimer.map((l) -> Pair.of(l, null));
|
||||
} else {
|
||||
refreshObservable = Observable.combineChanged(workTimer, engine.onResize());
|
||||
}
|
||||
|
||||
refreshObservable.subscribe((pair) -> {
|
||||
double dt = 0;
|
||||
final long newtime = System.nanoTime();
|
||||
if (precTime == -1) {
|
||||
dt = DisplayManager.tickDuration;
|
||||
} else {
|
||||
dt = (newtime - precTime) / 1000d / 1000d;
|
||||
}
|
||||
precTime = newtime;
|
||||
|
||||
if (pair.getRight() != null) {
|
||||
final Integer[] windowSize = pair.getRight();
|
||||
StaticVars.screenSize[0] = windowSize[0];
|
||||
StaticVars.screenSize[1] = windowSize[1];
|
||||
}
|
||||
|
||||
screen.beforeRender((float) (dt / 1000d));
|
||||
});
|
||||
|
||||
engine.start(getDrawable());
|
||||
graphicEngine.start(getDrawable());
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
private void onRefresh(Integer[] windowSize) {
|
||||
double dt = 0;
|
||||
final long newtime = System.nanoTime();
|
||||
if (precTime == -1) {
|
||||
dt = DisplayManager.tickDuration;
|
||||
} else {
|
||||
dt = (newtime - precTime) / 1000d / 1000d;
|
||||
}
|
||||
precTime = newtime;
|
||||
|
||||
if (windowSize != null) {
|
||||
display.getDisplaySize()[0] = windowSize[0];
|
||||
display.getDisplaySize()[1] = windowSize[1];
|
||||
}
|
||||
|
||||
var displaySize = display.getDisplaySize();
|
||||
var scrWidth = displaySize[0] - hud.getMarginLeft() - hud.getMarginRight();
|
||||
var scrHeight = displaySize[1] - hud.getMarginTop() - hud.getMarginBottom();
|
||||
var scrCtx = new ScreenContext(graphicEngine, scrWidth, scrHeight);
|
||||
screen.beforeRender(scrCtx, (float) (dt / 1000d));
|
||||
}
|
||||
|
||||
public void changeBrightness(final float change) {
|
||||
setBrightness(brightness + change);
|
||||
}
|
||||
|
@ -502,7 +455,7 @@ public final class DisplayManager implements RenderingLoop {
|
|||
public void setBrightness(final float newval) {
|
||||
if (newval >= 0 && newval <= 1) {
|
||||
brightness = newval;
|
||||
monitor.setBrightness(brightness);
|
||||
backlight.setBrightness(brightness);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,7 +491,31 @@ public final class DisplayManager implements RenderingLoop {
|
|||
renderer.glFillRect(x, y, uvX2 - uvX, uvY2 - uvY, uvX, uvY, uvX2 - uvX, uvY2 - uvY);
|
||||
}
|
||||
|
||||
public void waitForExit() {
|
||||
engine.waitForExit();
|
||||
public Consumer<TouchEvent> getTouchEventListener() {
|
||||
return (TouchEvent t) -> {
|
||||
boolean refresh = false;
|
||||
if (screen != null && screen.initialized && executeTouchEventOnScreen(t, screen)) {
|
||||
refresh = true;
|
||||
} else {
|
||||
//Default behavior
|
||||
}
|
||||
if (refresh) {
|
||||
forceRefresh = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private boolean executeTouchEventOnScreen(TouchEvent t, Screen scr) {
|
||||
if (t instanceof TouchStartEvent) {
|
||||
return scr.onTouchStart((TouchStartEvent) t);
|
||||
} else if (t instanceof TouchMoveEvent) {
|
||||
return scr.onTouchMove((TouchMoveEvent) t);
|
||||
} else if (t instanceof TouchEndEvent) {
|
||||
return scr.onTouchEnd((TouchEndEvent) t);
|
||||
} else if (t instanceof TouchCancelEvent) {
|
||||
return scr.onTouchCancel((TouchCancelEvent) t);
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DisplayRefreshManager {
|
||||
private final Consumer<Integer[]> refreshConsumer;
|
||||
private volatile Integer[] size;
|
||||
|
||||
public DisplayRefreshManager(Consumer<Integer[]> refreshConsumer) {
|
||||
this.refreshConsumer = refreshConsumer;
|
||||
}
|
||||
|
||||
public void onTick() {
|
||||
refreshConsumer.accept(size);
|
||||
}
|
||||
|
||||
public void onResize(Integer[] newSize) {
|
||||
var oldSize = size;
|
||||
if (oldSize == null || !Arrays.equals(oldSize, newSize)) {
|
||||
size = newSize;
|
||||
refreshConsumer.accept(size);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
|
||||
|
@ -20,9 +20,9 @@ public class GUIErrorMessage {
|
|||
creationTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void draw(final GraphicEngine g, final Renderer r, final String msg) {
|
||||
final int scrW = g.getWidth();
|
||||
final int scrH = g.getHeight();
|
||||
public void draw(final DisplayOutputDevice g, final Renderer r, final String msg) {
|
||||
final int scrW = g.getGraphicEngine().getWidth();
|
||||
final int scrH = g.getGraphicEngine().getHeight();
|
||||
final int width = 200;
|
||||
final int height = 20;
|
||||
final int margin = 4;
|
||||
|
|
|
@ -5,13 +5,13 @@ public interface GraphicalInterface {
|
|||
|
||||
void initialize() throws InterruptedException;
|
||||
|
||||
void initializeGraphic() throws InterruptedException;
|
||||
void initializeGraphic(ScreenContext ctx) throws InterruptedException;
|
||||
|
||||
void render();
|
||||
void render(RenderContext ctx);
|
||||
|
||||
void renderTopmost();
|
||||
void renderTopmost(RenderContext ctx);
|
||||
|
||||
void beforeRender(float dt);
|
||||
void beforeRender(ScreenContext ctx, float dt);
|
||||
|
||||
boolean mustBeRefreshed();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import it.cavallium.warppi.gui.screens.Screen;
|
||||
|
||||
public abstract class HUD implements GraphicalInterface {
|
||||
public DisplayManager d;
|
||||
public boolean created = false;
|
||||
|
@ -18,7 +20,7 @@ public abstract class HUD implements GraphicalInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initializeGraphic() throws InterruptedException {
|
||||
public void initializeGraphic(ScreenContext ctx) throws InterruptedException {
|
||||
if (!graphicInitialized) {
|
||||
graphicInitialized = true;
|
||||
graphicInitialized();
|
||||
|
@ -42,15 +44,15 @@ public abstract class HUD implements GraphicalInterface {
|
|||
public abstract void renderBackground();
|
||||
|
||||
@Override
|
||||
public abstract void render();
|
||||
public abstract void render(RenderContext ctx);
|
||||
|
||||
public abstract void renderTopmostBackground();
|
||||
|
||||
@Override
|
||||
public abstract void renderTopmost();
|
||||
public abstract void renderTopmost(RenderContext ctx);
|
||||
|
||||
@Override
|
||||
public abstract void beforeRender(float dt);
|
||||
public abstract void beforeRender(ScreenContext ctx, float dt);
|
||||
|
||||
@Override
|
||||
public boolean mustBeRefreshed() {
|
||||
|
@ -65,4 +67,11 @@ public abstract class HUD implements GraphicalInterface {
|
|||
visible = true;
|
||||
}
|
||||
|
||||
public abstract int getMarginLeft();
|
||||
|
||||
public abstract int getMarginTop();
|
||||
|
||||
public abstract int getMarginRight();
|
||||
|
||||
public abstract int getMarginBottom();
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
public interface HardwareDisplay {
|
||||
void initialize();
|
||||
|
||||
void shutdown();
|
||||
|
||||
void setBrightness(double value);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
public class RenderContext extends ScreenContext {
|
||||
private final Renderer renderer;
|
||||
|
||||
public RenderContext(GraphicEngine graphicEngine, Renderer renderer, int width, int height) {
|
||||
super(graphicEngine, width, height);
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
public Renderer getRenderer() {
|
||||
return renderer;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package it.cavallium.warppi.gui;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
|
||||
public class ScreenContext {
|
||||
private final GraphicEngine graphicEngine;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public ScreenContext(GraphicEngine graphicEngine, int width, int height) {
|
||||
this.graphicEngine = graphicEngine;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public GraphicEngine getGraphicEngine() {
|
||||
return graphicEngine;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
}
|
|
@ -2,11 +2,11 @@ package it.cavallium.warppi.gui.expression;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.event.KeyboardEventListener;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockVariable;
|
||||
import it.cavallium.warppi.gui.expression.blocks.TreeContainer;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
public abstract class ExtraMenu<T extends Block> implements KeyboardEventListener {
|
||||
|
@ -32,7 +32,7 @@ public abstract class ExtraMenu<T extends Block> implements KeyboardEventListene
|
|||
protected int height;
|
||||
protected int[] location;
|
||||
|
||||
public abstract void draw(GraphicEngine ge, Renderer r, Caret caret);
|
||||
public abstract void draw(DisplayOutputDevice ge, Renderer r, Caret caret);
|
||||
|
||||
public abstract void open();
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.GraphicalElement;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.ExtraMenu;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
||||
|
@ -45,7 +45,7 @@ public abstract class Block implements TreeBlock, GraphicalElement {
|
|||
* Position relative to the window.
|
||||
* @param small
|
||||
*/
|
||||
public abstract void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret);
|
||||
public abstract void draw(DisplayOutputDevice ge, Renderer r, int x, int y, Caret caret);
|
||||
|
||||
public abstract boolean putBlock(Caret caret, Block newBlock);
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.parser.features.FeatureChar;
|
||||
|
@ -29,7 +29,7 @@ public class BlockChar extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
r.glDrawCharLeft(x, y, ch);
|
||||
|
|
|
@ -2,13 +2,13 @@ package it.cavallium.warppi.gui.expression.blocks;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.GraphicalElement;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.CaretState;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -182,7 +182,7 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
* @param caret
|
||||
* Position of the caret.
|
||||
*/
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
int paddingX = 1;
|
||||
|
||||
if (caret.getRemaining() == 0) {
|
||||
|
@ -377,6 +377,10 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
BlockContainer.initialized = true;
|
||||
}
|
||||
|
||||
public static boolean isInitialized() {
|
||||
return BlockContainer.initialized;
|
||||
}
|
||||
|
||||
public static BinaryFont getDefaultFont(final boolean small) {
|
||||
BlockContainer.checkInitialized();
|
||||
return BlockContainer.defFonts[small ? 1 : 0];
|
||||
|
@ -396,7 +400,7 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
return BlockContainer.defFontSizes[b ? 3 : 1];
|
||||
}
|
||||
|
||||
public static void drawCaret(final GraphicEngine ge, final Renderer r, final Caret caret, final boolean small,
|
||||
public static void drawCaret(final DisplayOutputDevice ge, final Renderer r, final Caret caret, final boolean small,
|
||||
final int x, final int y, final int height) {
|
||||
if (caret.getState() == CaretState.VISIBLE_ON) {
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
|
@ -424,7 +428,7 @@ public class BlockContainer implements TreeContainer, GraphicalElement {
|
|||
|
||||
private static void checkInitialized() {
|
||||
if (!BlockContainer.initialized) {
|
||||
Engine.getPlatform().throwNewExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
||||
WarpPI.getPlatform().throwNewExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -38,7 +38,7 @@ public class BlockDivision extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
containerUp.draw(ge, r, x + 1 + paddingLeftUpper, y, caret);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
public class BlockExponentialNotation extends BlockPower {
|
||||
|
@ -25,7 +25,7 @@ public class BlockExponentialNotation extends BlockPower {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
r.glDrawStringLeft(x, y + height - bh, "ℯ℮");
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -56,7 +56,7 @@ public class BlockLogarithm extends Block implements IParenthesis {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
if (prefix != null) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
||||
|
@ -52,7 +52,7 @@ public abstract class BlockParenthesisAbstract extends Block implements IParenth
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
if (prefix != null) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -26,7 +26,7 @@ public class BlockPower extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(true).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
containerExponent.draw(ge, r, x, y, caret);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -32,7 +32,7 @@ public class BlockPower2 extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(true).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
containerExponent.draw(ge, r, x, y, caret);
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -29,7 +29,7 @@ public class BlockSquareRoot extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
r.glDrawLine(x, y + height - 10 + 1, x, y + height - 10 + 2); // /
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package it.cavallium.warppi.gui.expression.blocks;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
|
@ -21,7 +21,7 @@ public class BlockUndefined extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
r.glDrawStringLeft(x, y, "UNDEFINED");
|
||||
|
|
|
@ -2,14 +2,14 @@ package it.cavallium.warppi.gui.expression.blocks;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.ExtraMenu;
|
||||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.functions.Variable.V_TYPE;
|
||||
|
@ -82,7 +82,7 @@ public class BlockVariable extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
||||
if (ic.variableTypeDirtyID != typeDirtyID) {
|
||||
retrieveValue();
|
||||
}
|
||||
|
@ -238,9 +238,9 @@ public class BlockVariable extends Block {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final Caret caret) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final Caret caret) {
|
||||
r.glColor3f(1.0f, 1.0f, 1.0f);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(ge);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(ge);
|
||||
int popupX = location[0];
|
||||
int popupY = location[1];
|
||||
if (popupX < 0) {
|
||||
|
@ -249,7 +249,7 @@ public class BlockVariable extends Block {
|
|||
if (popupY < 0) {
|
||||
popupY = 0;
|
||||
}
|
||||
final int[] screenSize = ge.getSize();
|
||||
final int[] screenSize = ge.getDisplaySize();
|
||||
if (popupX + width >= screenSize[0]) {
|
||||
popupX = screenSize[0] - width - 1;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package it.cavallium.warppi.gui.expression.containers;
|
|||
import it.cavallium.warppi.gui.expression.InputContext;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockNumericChar;
|
||||
|
||||
public class InlineInputContainer extends InputContainer {
|
||||
|
||||
|
@ -30,6 +31,21 @@ public class InlineInputContainer extends InputContainer {
|
|||
|
||||
@Override
|
||||
public Block parseChar(final char c) {
|
||||
return new BlockChar(c);
|
||||
switch (c) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '.':
|
||||
return new BlockNumericChar(c);
|
||||
default:
|
||||
return new BlockChar(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package it.cavallium.warppi.gui.expression.containers;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.event.KeyboardEventListener;
|
||||
import it.cavallium.warppi.gui.GraphicalElement;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
|
@ -10,7 +11,6 @@ import it.cavallium.warppi.gui.expression.blocks.Block;
|
|||
import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockReference;
|
||||
import it.cavallium.warppi.gui.expression.layouts.InputLayout;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
|
@ -211,7 +211,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||
* @param y
|
||||
* Position relative to the window.
|
||||
*/
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y) {
|
||||
caret.resetRemaining();
|
||||
root.draw(ge, r, x, y, caret);
|
||||
if (extra != null) {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package it.cavallium.warppi.gui.expression.containers;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.GraphicalElement;
|
||||
import it.cavallium.warppi.gui.expression.Caret;
|
||||
import it.cavallium.warppi.gui.expression.CaretState;
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
|
||||
import it.cavallium.warppi.gui.expression.layouts.OutputLayout;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -119,7 +119,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout
|
|||
* @param y
|
||||
* Position relative to the window.
|
||||
*/
|
||||
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y) {
|
||||
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y) {
|
||||
int offset = 0;
|
||||
for (final BlockContainer root : roots) {
|
||||
root.draw(ge, r, x, y + offset, caret);
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
package it.cavallium.warppi.gui.graphicengine;
|
||||
|
||||
import it.cavallium.warppi.util.EventSubscriber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import it.cavallium.warppi.flow.Observable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface GraphicEngine {
|
||||
|
||||
int[] getSize();
|
||||
|
||||
boolean isSupported();
|
||||
|
||||
boolean isInitialized();
|
||||
|
||||
void setTitle(String title);
|
||||
|
||||
void setResizable(boolean r);
|
||||
|
||||
void setDisplayMode(final int ww, final int wh);
|
||||
void setDisplayMode(int ww, int wh);
|
||||
|
||||
void create(Runnable object);
|
||||
|
||||
default void create() {
|
||||
create(null);
|
||||
};
|
||||
|
||||
void create(Runnable object);
|
||||
|
||||
Observable<Integer[]> onResize();
|
||||
EventSubscriber<Integer[]> onResize();
|
||||
|
||||
int getWidth();
|
||||
|
||||
|
@ -43,10 +46,6 @@ public interface GraphicEngine {
|
|||
|
||||
Skin loadSkin(String file) throws IOException;
|
||||
|
||||
void waitForExit();
|
||||
|
||||
boolean isSupported();
|
||||
|
||||
boolean doesRefreshPauses();
|
||||
|
||||
default boolean supportsFontRegistering() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package it.cavallium.warppi.gui.graphicengine;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.impl.common.ReboundedRenderer;
|
||||
|
||||
public interface Renderer {
|
||||
void glColor3i(int r, int gg, int b);
|
||||
|
||||
|
@ -42,4 +44,8 @@ public interface Renderer {
|
|||
void glClearSkin();
|
||||
|
||||
BinaryFont getCurrentFont();
|
||||
|
||||
default Renderer getBoundedInstance(int dx, int dy, int width, int height) {
|
||||
return new ReboundedRenderer(this, dx, dy, width, height);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
package it.cavallium.warppi.gui.graphicengine;
|
||||
|
||||
public interface RenderingLoop {
|
||||
void refresh();
|
||||
void refresh(boolean force);
|
||||
}
|
||||
|
|
|
@ -3,15 +3,17 @@ package it.cavallium.warppi.gui.graphicengine;
|
|||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
|
||||
public interface Skin {
|
||||
|
||||
void load(String file) throws IOException, URISyntaxException;
|
||||
|
||||
void initialize(GraphicEngine d);
|
||||
void initialize(DisplayOutputDevice d);
|
||||
|
||||
boolean isInitialized();
|
||||
|
||||
void use(GraphicEngine d);
|
||||
void use(DisplayOutputDevice d);
|
||||
|
||||
/**
|
||||
* May not be available before initialization
|
||||
|
|
|
@ -3,9 +3,9 @@ package it.cavallium.warppi.gui.graphicengine.impl.common;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform.ImageUtils.ImageReader;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
|
||||
public abstract class PngSkin implements Skin {
|
||||
|
@ -25,7 +25,7 @@ public abstract class PngSkin implements Skin {
|
|||
if (!file.startsWith("/")) {
|
||||
file = "/" + file;
|
||||
}
|
||||
final ImageReader r = Engine.getPlatform().getImageUtils().load(Engine.getPlatform().getStorageUtils().getResourceStream(file));
|
||||
final ImageReader r = WarpPI.getPlatform().getImageUtils().load(WarpPI.getPlatform().getStorageUtils().getResourceStream(file));
|
||||
if (r == null) {
|
||||
skinData = new int[0];
|
||||
skinSize = new int[] { 0, 0 };
|
||||
|
@ -37,7 +37,7 @@ public abstract class PngSkin implements Skin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final GraphicEngine d) {
|
||||
public void initialize(final DisplayOutputDevice d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import java.util.LinkedList;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
|
||||
public abstract class RFTFont implements BinaryFont {
|
||||
|
@ -62,7 +62,7 @@ public abstract class RFTFont implements BinaryFont {
|
|||
}
|
||||
|
||||
private void load(final String path, final boolean onlyRaw) throws IOException {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN + 1, "Loading font " + path);
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN + 1, "Loading font " + path);
|
||||
loadFont(path);
|
||||
if (!onlyRaw) {
|
||||
chars32 = new int[intervalsTotalSize * charIntCount];
|
||||
|
@ -94,14 +94,14 @@ public abstract class RFTFont implements BinaryFont {
|
|||
}
|
||||
}
|
||||
|
||||
Engine.getPlatform().gc();
|
||||
WarpPI.getPlatform().gc();
|
||||
}
|
||||
|
||||
private void loadFont(String string) throws IOException {
|
||||
if (!string.startsWith("/")) {
|
||||
string = "/" + string;
|
||||
}
|
||||
InputStream res = Engine.getPlatform().getStorageUtils().getResourceStream(string);
|
||||
InputStream res = WarpPI.getPlatform().getStorageUtils().getResourceStream(string);
|
||||
final int[] file = Utils.realBytes(Utils.convertStreamToByteArray(res, res.available()));
|
||||
final int filelength = file.length;
|
||||
if (filelength >= 16) {
|
||||
|
@ -140,7 +140,7 @@ public abstract class RFTFont implements BinaryFont {
|
|||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
System.out.println(string);
|
||||
Engine.getPlatform().exit(-1);
|
||||
WarpPI.getPlatform().exit(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -266,7 +266,7 @@ public abstract class RFTFont implements BinaryFont {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final GraphicEngine d) {}
|
||||
public void initialize(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(final String text) {
|
||||
|
@ -314,7 +314,7 @@ public abstract class RFTFont implements BinaryFont {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void use(final GraphicEngine d) {
|
||||
public void use(final DisplayOutputDevice d) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
package it.cavallium.warppi.gui.graphicengine.impl.common;
|
||||
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
public class ReboundedRenderer implements Renderer {
|
||||
private final Renderer renderer;
|
||||
private final int dx;
|
||||
private final int dy;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
public ReboundedRenderer(Renderer renderer, int dx, int dy, int width, int height) {
|
||||
this.renderer = renderer;
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
renderer.glColor3i(r, gg, b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor(int c) {
|
||||
renderer.glColor(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4i(int red, int green, int blue, int alpha) {
|
||||
renderer.glColor4i(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
renderer.glColor3f(red, green, blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
renderer.glColor4f(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4i(int red, int green, int blue, int alpha) {
|
||||
renderer.glClearColor4i(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
renderer.glClearColor4f(red, green, blue, alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetClearColor() {
|
||||
return renderer.glGetClearColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(int c) {
|
||||
renderer.glClearColor(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int screenWidth, int screenHeight) {
|
||||
renderer.glClear(screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1) {
|
||||
renderer.glDrawLine(this.dx + x0, this.dy + y0, this.dx + x1, this.dy + y1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
|
||||
renderer.glFillRect(this.dx + x, this.dy + y, width, height, uvX, uvY, uvWidth, uvHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
renderer.glFillColor(this.dx + x, this.dy + y, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
renderer.glDrawCharLeft(this.dx + x, this.dy + y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
renderer.glDrawCharCenter(this.dx + x, this.dy + y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
renderer.glDrawCharRight(this.dx + x, this.dy + y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String text) {
|
||||
renderer.glDrawStringLeft(this.dx + x, this.dy + y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
renderer.glDrawStringCenter(this.dx + x, this.dy + y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
renderer.glDrawStringRight(this.dx + x, this.dy + y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
renderer.glClearSkin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryFont getCurrentFont() {
|
||||
return renderer.getCurrentFont();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderer getBoundedInstance(int dx, int dy, int width, int height) {
|
||||
return renderer.getBoundedInstance(this.dx + dx, this.dy + dy, width, height);
|
||||
}
|
||||
}
|
|
@ -2,19 +2,20 @@ package it.cavallium.warppi.gui.graphicengine.impl.nogui;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform.Semaphore;
|
||||
import it.cavallium.warppi.flow.Observable;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.gui.graphicengine.BinaryFont;
|
||||
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
import it.cavallium.warppi.gui.graphicengine.RenderingLoop;
|
||||
import it.cavallium.warppi.gui.graphicengine.Skin;
|
||||
import it.cavallium.warppi.util.EventSubmitter;
|
||||
import it.cavallium.warppi.util.EventSubscriber;
|
||||
|
||||
public class NoGuiEngine implements GraphicEngine {
|
||||
|
||||
private boolean initialized;
|
||||
public Semaphore exitSemaphore = Engine.getPlatform().newSemaphore(0);
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
|
@ -44,7 +45,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<Integer[]> onResize() {
|
||||
public EventSubscriber<Integer[]> onResize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,6 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
@Override
|
||||
public void destroy() {
|
||||
initialized = false;
|
||||
exitSemaphore.release();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -140,6 +140,11 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
public BinaryFont getCurrentFont() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Renderer getBoundedInstance(int dx, int dy, int width, int height) {
|
||||
return getRenderer();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -147,7 +152,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
public BinaryFont loadFont(final String fontName) throws IOException {
|
||||
return new BinaryFont() {
|
||||
@Override
|
||||
public void use(final GraphicEngine d) {}
|
||||
public void use(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public void load(final String file) throws IOException {}
|
||||
|
@ -158,7 +163,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final GraphicEngine d) {}
|
||||
public void initialize(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(final String text) {
|
||||
|
@ -193,7 +198,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
public BinaryFont loadFont(final String path, final String fontName) throws IOException {
|
||||
return new BinaryFont() {
|
||||
@Override
|
||||
public void use(final GraphicEngine d) {}
|
||||
public void use(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public void load(final String file) throws IOException {}
|
||||
|
@ -204,7 +209,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final GraphicEngine d) {}
|
||||
public void initialize(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(final String text) {
|
||||
|
@ -239,7 +244,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
public Skin loadSkin(final String file) throws IOException {
|
||||
return new Skin() {
|
||||
@Override
|
||||
public void use(final GraphicEngine d) {}
|
||||
public void use(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public void load(final String file) throws IOException {}
|
||||
|
@ -250,7 +255,7 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(final GraphicEngine d) {}
|
||||
public void initialize(final DisplayOutputDevice d) {}
|
||||
|
||||
@Override
|
||||
public int getSkinWidth() {
|
||||
|
@ -266,13 +271,6 @@ public class NoGuiEngine implements GraphicEngine {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
return true;
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.functions.Variable.VariableValue;
|
||||
import it.cavallium.warppi.util.Utils;
|
||||
|
@ -28,29 +31,29 @@ public class ChooseVariableValueScreen extends Screen {
|
|||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Utils.getFont(false, true).use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
public void render(RenderContext ctx) {
|
||||
Utils.getFont(false, true).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
ctx.getRenderer().glColor4i(0, 0, 0, 64);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 - 20, "WORK IN PROGRESS.");
|
||||
|
||||
Utils.getFont(false, false).use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Utils.getFont(false, false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
ctx.getRenderer().glColor4i(0, 0, 0, 64);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class EmptyScreen extends Screen {
|
||||
|
||||
|
@ -20,16 +22,16 @@ public class EmptyScreen extends Screen {
|
|||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
public void render(RenderContext ctx) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
||||
|
||||
public class KeyboardDebugScreen extends Screen {
|
||||
|
@ -28,23 +30,23 @@ public class KeyboardDebugScreen extends Screen {
|
|||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final Renderer renderer = Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
public void render(RenderContext ctx) {
|
||||
final Renderer renderer = WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glDrawStringRight(StaticVars.screenSize[0] - 10, 30, "-" + keyevent.toUpperCase() + "-");
|
||||
renderer.glDrawStringRight(ctx.getWidth() - 10, 30, "-" + keyevent.toUpperCase() + "-");
|
||||
if (keyevent != "NONE") {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glDrawStringLeft(10, 30, "Key position");
|
||||
renderer.glDrawStringLeft(10, 45, "X: " + KeyboardDebugScreen.keyX + ", Y:" + KeyboardDebugScreen.keyY);
|
||||
renderer.glDrawStringLeft(10, 65, "Key value");
|
||||
renderer.glDrawStringLeft(10, 80, key);
|
||||
}
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (KeyboardDebugScreen.log[i] != null) {
|
||||
|
@ -56,10 +58,10 @@ public class KeyboardDebugScreen extends Screen {
|
|||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glFillColor(-80 + 100 + 200, 90, 5, 5);
|
||||
renderer.glFillColor(-80 + 100, 100, 200, 70);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
renderer.glDrawStringCenter(-80 + 100 + 200 / 2, 100 + 70 / 2 - renderer.getCurrentFont().getCharacterHeight() / 2, "FROM SERIAL");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (KeyboardDebugScreen.pinsA[i] == 1) {
|
||||
|
@ -102,10 +104,10 @@ public class KeyboardDebugScreen extends Screen {
|
|||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glFillColor(150 + 90, 200, 5, 5);
|
||||
renderer.glFillColor(150 + 100, 100, 200, 70);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[2].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
renderer.glDrawStringCenter(150 + 100 + 200 / 2, 100 + 70 / 2 - renderer.getCurrentFont().getCharacterHeight() / 2, "TO SERIAL");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().fonts[3].use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 15; i >= 8; i--) {
|
||||
if (KeyboardDebugScreen.pinsB[i] == 1) {
|
||||
|
@ -176,7 +178,7 @@ public class KeyboardDebugScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
if (System.currentTimeMillis() - beforetime >= 1000) {
|
||||
keyevent = "NONE";
|
||||
KeyboardDebugScreen.keyX = 0;
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.extra.mario.MarioScreen;
|
||||
import it.cavallium.warppi.gui.GraphicUtils;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class LoadingScreen extends Screen {
|
||||
|
||||
|
@ -21,7 +25,7 @@ public class LoadingScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public void created() throws InterruptedException {
|
||||
Engine.INSTANCE.isLoaded().subscribe((loaded) -> {
|
||||
WarpPI.INSTANCE.isLoaded().subscribe((loaded) -> {
|
||||
this.loaded = loaded;
|
||||
});
|
||||
endLoading = 0;
|
||||
|
@ -29,37 +33,43 @@ public class LoadingScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public void initialized() throws InterruptedException {
|
||||
previousZoomValue = StaticVars.windowZoomFunction.apply(StaticVars.windowZoom.getLastValue());
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().hide();
|
||||
StaticVars.windowZoom.onNext(1f);
|
||||
float lastZoomValue = StaticVars.windowZoom.getLastValue();
|
||||
previousZoomValue = StaticVars.windowZoomFunction.apply(lastZoomValue);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().hide();
|
||||
if (lastZoomValue != 1.0f) {
|
||||
StaticVars.windowZoom.submit(1f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
|
||||
|
||||
endLoading += dt;
|
||||
if (!ended && loaded && (Engine.getPlatform().getSettings().isDebugEnabled() || endLoading >= 3.5f)) {
|
||||
if (!ended && loaded && ((WarpPI.getPlatform().getSettings().isDebugEnabled() && endLoading >= 1.5f) || endLoading >= 3.5f)) {
|
||||
ended = true;
|
||||
StaticVars.windowZoom.onNext(previousZoomValue);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
|
||||
if (previousZoomValue != 1.0f) {
|
||||
StaticVars.windowZoom.submit(previousZoomValue);
|
||||
}
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
|
||||
}
|
||||
mustRefresh = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 255, 255);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(StaticVars.screenSize[0] / 2f - 80, StaticVars.screenSize[1] / 2f - 64, 160, 48, 0, 32, 160, 48);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(StaticVars.screenSize[0] / 2f - 24, StaticVars.screenSize[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(display);
|
||||
ctx.getRenderer().glColor3i(255, 255, 255);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 80, ctx.getHeight() / 2f - 64, 160, 48, 0, 32, 160, 48);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() / 2f - 24, ctx.getHeight() / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
|
||||
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(StaticVars.screenSize[0] - 224, StaticVars.screenSize[1] - 48, 224, 48, 0, 80, 224, 48);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glFillRect(StaticVars.screenSize[0] - 160 - 24 - 224, StaticVars.screenSize[1] - 48, 160, 48, 224, 80, 160, 48);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() - 224, ctx.getHeight() - 48, 224, 48, 0, 80, 224, 48);
|
||||
ctx.getRenderer().glFillRect(ctx.getWidth() - 160 - 24 - 224, ctx.getHeight() - 48, 160, 48, 224, 80, 160, 48);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,11 +3,13 @@ package it.cavallium.warppi.gui.screens;
|
|||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.Platform.ConsoleUtils;
|
||||
import it.cavallium.warppi.device.Keyboard;
|
||||
import it.cavallium.warppi.device.input.Keyboard;
|
||||
import it.cavallium.warppi.event.Key;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.event.KeyReleasedEvent;
|
||||
|
@ -43,6 +45,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|||
public class MathInputScreen extends Screen {
|
||||
|
||||
private static final BinaryFont fontBig = Utils.getFont(false);
|
||||
private final boolean isCloned;
|
||||
|
||||
public MathContext calc;
|
||||
public InputContext ic;
|
||||
|
@ -62,11 +65,11 @@ public class MathInputScreen extends Screen {
|
|||
public MathInputScreen() {
|
||||
super();
|
||||
historyBehavior = HistoryBehavior.NORMAL;
|
||||
isCloned = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a copy of this element
|
||||
* @param mathInputScreen
|
||||
*/
|
||||
private MathInputScreen(MathInputScreen old) {
|
||||
this.calc = new MathContext(old.calc);
|
||||
|
@ -80,6 +83,7 @@ public class MathInputScreen extends Screen {
|
|||
this.mustRefresh = old.mustRefresh;
|
||||
this.result = new NormalOutputContainer(old.result);
|
||||
this.userInput = new NormalInputContainer(old.userInput, this.ic);
|
||||
this.isCloned = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,16 +91,6 @@ public class MathInputScreen extends Screen {
|
|||
ic = new InputContext();
|
||||
calc = new MathContext();
|
||||
|
||||
try {
|
||||
BlockContainer.initializeFonts(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("norm"), Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.loadFont("smal"));
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
Engine.getPlatform().exit(1);
|
||||
}
|
||||
|
||||
userInput = new NormalInputContainer(ic);
|
||||
result = new NormalOutputContainer();
|
||||
|
||||
calc.init();
|
||||
}
|
||||
|
||||
|
@ -106,20 +100,34 @@ public class MathInputScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {
|
||||
/* Fine caricamento */
|
||||
try {
|
||||
if (!BlockContainer.isInitialized()) {
|
||||
BlockContainer.initializeFonts(ctx.getGraphicEngine().loadFont("norm"), ctx.getGraphicEngine().loadFont("smal"));
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
WarpPI.getPlatform().exit(1);
|
||||
}
|
||||
|
||||
if (!isCloned) {
|
||||
userInput = new NormalInputContainer(ic);
|
||||
result = new NormalOutputContainer();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager().error == null) {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xFFc5c2af);
|
||||
public void beforeRender(final ScreenContext ctx, final float dt) {
|
||||
if (WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error == null) {
|
||||
ctx.getGraphicEngine().getRenderer().glClearColor(0xFFc5c2af);
|
||||
} else {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glClearColor(0xFFDC3C32);
|
||||
}
|
||||
if (userInput.beforeRender(dt)) {
|
||||
mustRefresh = true;
|
||||
ctx.getGraphicEngine().getRenderer().glClearColor(0xFFDC3C32);
|
||||
}
|
||||
if (userInput != null)
|
||||
if (userInput.beforeRender(dt)) {
|
||||
mustRefresh = true;
|
||||
}
|
||||
if (computingResult) {
|
||||
computingElapsedTime += dt;
|
||||
computingAnimationElapsedTime += dt;
|
||||
|
@ -140,14 +148,14 @@ public class MathInputScreen extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final Renderer renderer = Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
|
||||
MathInputScreen.fontBig.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
public void render(RenderContext ctx) {
|
||||
final Renderer renderer = ctx.getRenderer();
|
||||
MathInputScreen.fontBig.use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
final int textColor = 0xFF000000;
|
||||
final int padding = 4;
|
||||
renderer.glColor(textColor);
|
||||
|
||||
userInput.draw(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine, renderer, padding, padding + 20);
|
||||
userInput.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, padding, padding);
|
||||
|
||||
if (computingResult) {
|
||||
renderer.glColor3f(1, 1, 1);
|
||||
|
@ -156,20 +164,20 @@ public class MathInputScreen extends Screen {
|
|||
final int size = 32;
|
||||
final int posY = computingAnimationIndex % 2;
|
||||
final int posX = (computingAnimationIndex - posY) / 2;
|
||||
renderer.glFillRect(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() - size - 4, Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - size - 4, size, size, leftX + size * posX, leftY + size * posY, size, size);
|
||||
renderer.glFillRect(ctx.getWidth() - size - 4, ctx.getHeight() - size - 4, size, size, leftX + size * posX, leftY + size * posY, size, size);
|
||||
if (computingBreakTipVisible) {
|
||||
Utils.getFont(false).use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
Utils.getFont(false).use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glColor3f(0.75f, 0, 0);
|
||||
renderer.glDrawStringRight(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() - 4 - size - 4, Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - size / 2 - renderer.getCurrentFont().getCharacterHeight() / 2 - 4, "Press (=) to stop");
|
||||
renderer.glDrawStringRight(ctx.getWidth() - 4 - size - 4, ctx.getHeight() - size / 2 - renderer.getCurrentFont().getCharacterHeight() / 2 - 4, "Press (=) to stop");
|
||||
}
|
||||
} else if (!result.isContentEmpty()) {
|
||||
result.draw(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine, renderer, Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getWidth() - result.getWidth() - 2, Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine.getHeight() - result.getHeight() - 2);
|
||||
result.draw(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display, renderer, ctx.getWidth() - result.getWidth() - 2, ctx.getHeight() - result.getHeight() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderTopmost() {
|
||||
final Renderer renderer = Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer;
|
||||
public void renderTopmost(RenderContext ctx) {
|
||||
final Renderer renderer = ctx.getRenderer();
|
||||
renderer.glColor3f(1, 1, 1);
|
||||
final int pos = 2;
|
||||
final int spacersNumb = 1;
|
||||
|
@ -179,7 +187,7 @@ public class MathInputScreen extends Screen {
|
|||
} else {
|
||||
skinN = 21;
|
||||
}
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().guiSkin.use(WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().display);
|
||||
renderer.glFillRect(2 + 18 * pos + 2 * spacersNumb, 2, 16, 16, 16 * skinN, 16 * 0, 16, 16);
|
||||
}
|
||||
|
||||
|
@ -195,7 +203,7 @@ public class MathInputScreen extends Screen {
|
|||
|
||||
@Override
|
||||
public boolean onKeyPressed(final KeyPressedEvent k) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "MathInputScreen", "Pressed key " + k.getKey().toString());
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "MathInputScreen", "Pressed key " + k.getKey().toString());
|
||||
try {
|
||||
switch (k.getKey()) {
|
||||
case OK:
|
||||
|
@ -347,9 +355,9 @@ public class MathInputScreen extends Screen {
|
|||
userInput.clear();
|
||||
result.clear();
|
||||
currentStep = 0;
|
||||
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager().error != null) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Resetting after error...");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().error = null;
|
||||
if (WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error != null) {
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(1, "Resetting after error...");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error = null;
|
||||
}
|
||||
return true;
|
||||
case SURD_MODE:
|
||||
|
@ -361,7 +369,7 @@ public class MathInputScreen extends Screen {
|
|||
}
|
||||
return true;
|
||||
case debug1:
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new EmptyScreen());
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new EmptyScreen());
|
||||
return true;
|
||||
case HISTORY_BACK:
|
||||
// if (Engine.INSTANCE.getHardwareDevice().getDisplayManager().canGoBack()) {
|
||||
|
@ -428,7 +436,7 @@ public class MathInputScreen extends Screen {
|
|||
@SuppressWarnings("unchecked")
|
||||
private void swapInputScreen() {
|
||||
MathInputScreen mis = new MathInputScreen(this);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(mis);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(mis);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
@ -517,10 +525,10 @@ public class MathInputScreen extends Screen {
|
|||
if (!step) {
|
||||
currentStep = 0;
|
||||
}
|
||||
if (Engine.INSTANCE.getHardwareDevice().getDisplayManager().error != null) {
|
||||
if (WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error != null) {
|
||||
//TODO: make the error management a global API rather than being relegated to this screen.
|
||||
Engine.getPlatform().getConsoleUtils().out().println(1, "Resetting after error...");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().error = null;
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(1, "Resetting after error...");
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error = null;
|
||||
calc.f = null;
|
||||
calc.f2 = null;
|
||||
calc.resultsCount = 0;
|
||||
|
@ -540,13 +548,21 @@ public class MathInputScreen extends Screen {
|
|||
calc.f2.clear();
|
||||
}
|
||||
calc.f.add(expr);
|
||||
Engine.getPlatform().getConsoleUtils().out().println(2, "INPUT: " + expr);
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(2, "INPUT: " + expr);
|
||||
final MathSolver ms = new MathSolver(expr);
|
||||
final ObjectArrayList<ObjectArrayList<Function>> resultSteps = ms.solveAllSteps();
|
||||
resultSteps.add(0, Utils.newArrayList(expr));
|
||||
int stepNumber = 0;
|
||||
for (ObjectArrayList<Function> resultStep : resultSteps) {
|
||||
stepNumber++;
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(0, "STEP " + stepNumber);
|
||||
for (Function function : resultStep) {
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(0, " :: " + function.toString());
|
||||
}
|
||||
}
|
||||
final ObjectArrayList<Function> resultExpressions = resultSteps.get(resultSteps.size() - 1);
|
||||
for (final Function rr : resultExpressions) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(0, "RESULT: " + rr.toString());
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(0, "RESULT: " + rr.toString());
|
||||
}
|
||||
final ObjectArrayList<ObjectArrayList<Block>> resultBlocks = MathParser.parseOutput(calc, resultExpressions);
|
||||
result.setContentAsMultipleGroups(resultBlocks);
|
||||
|
@ -559,22 +575,22 @@ public class MathInputScreen extends Screen {
|
|||
}
|
||||
}
|
||||
} catch (final InterruptedException ex) {
|
||||
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Computing thread stopped.");
|
||||
WarpPI.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Computing thread stopped.");
|
||||
} catch (final Exception ex) {
|
||||
if (Engine.getPlatform().getSettings().isDebugEnabled()) {
|
||||
if (WarpPI.getPlatform().getSettings().isDebugEnabled()) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
} catch (final Error e) {
|
||||
d.errorStackTrace = Engine.getPlatform().stacktraceToString(e);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().error = e.id.toString();
|
||||
d.errorStackTrace = WarpPI.getPlatform().stacktraceToString(e);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
computingResult = false;
|
||||
});
|
||||
Engine.getPlatform().setThreadName(computingThread, "Computing Thread");
|
||||
Engine.getPlatform().setThreadDaemon(computingThread);
|
||||
WarpPI.getPlatform().setThreadName(computingThread, "Computing Thread");
|
||||
WarpPI.getPlatform().setThreadDaemon(computingThread);
|
||||
computingThread.setPriority(Thread.NORM_PRIORITY + 3);
|
||||
computingThread.start();
|
||||
return true;
|
||||
|
@ -638,9 +654,9 @@ public class MathInputScreen extends Screen {
|
|||
boolean cancelled = false;
|
||||
for (final Function f : knownVarsInFunctions) {
|
||||
final ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0)));
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(cvs);
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(cvs);
|
||||
try {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().screenChange.acquire();
|
||||
WarpPI.INSTANCE.getHardwareDevice().getDisplayManager().screenChange.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
if (cvs.resultNumberValue == null) {
|
||||
cancelled = true;
|
||||
|
@ -661,9 +677,9 @@ public class MathInputScreen extends Screen {
|
|||
}
|
||||
}
|
||||
});
|
||||
Engine.getPlatform().setThreadName(ct, "Variables user-input queue thread");
|
||||
WarpPI.getPlatform().setThreadName(ct, "Variables user-input queue thread");
|
||||
ct.setPriority(Thread.MIN_PRIORITY);
|
||||
Engine.getPlatform().setThreadDaemon(ct);
|
||||
WarpPI.getPlatform().setThreadDaemon(ct);
|
||||
ct.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@ package it.cavallium.warppi.gui.screens;
|
|||
|
||||
import it.cavallium.warppi.event.KeyboardEventListener;
|
||||
import it.cavallium.warppi.event.TouchEventListener;
|
||||
import it.cavallium.warppi.gui.DisplayManager;
|
||||
import it.cavallium.warppi.gui.GraphicalInterface;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.*;
|
||||
|
||||
public abstract class Screen implements KeyboardEventListener, TouchEventListener, GraphicalInterface {
|
||||
public DisplayManager d;
|
||||
|
@ -21,10 +19,10 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initializeGraphic() throws InterruptedException {
|
||||
public void initializeGraphic(ScreenContext ctx) throws InterruptedException {
|
||||
if (!graphicInitialized) {
|
||||
graphicInitialized = true;
|
||||
graphicInitialized();
|
||||
graphicInitialized(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,18 +64,18 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene
|
|||
* Called before initialized()
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public abstract void graphicInitialized() throws InterruptedException;
|
||||
public abstract void graphicInitialized(ScreenContext ctx) throws InterruptedException;
|
||||
|
||||
@Override
|
||||
public abstract void render();
|
||||
public abstract void render(RenderContext ctx);
|
||||
|
||||
@Override
|
||||
public void renderTopmost() {
|
||||
public void renderTopmost(RenderContext ctx) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void beforeRender(float dt);
|
||||
public abstract void beforeRender(ScreenContext ctx, float dt);
|
||||
|
||||
@Override
|
||||
public abstract boolean mustBeRefreshed();
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package it.cavallium.warppi.gui.screens;
|
||||
|
||||
import it.cavallium.warppi.Engine;
|
||||
import it.cavallium.warppi.WarpPI;
|
||||
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
||||
import it.cavallium.warppi.StaticVars;
|
||||
import it.cavallium.warppi.event.KeyPressedEvent;
|
||||
import it.cavallium.warppi.gui.HistoryBehavior;
|
||||
import it.cavallium.warppi.gui.RenderContext;
|
||||
import it.cavallium.warppi.gui.ScreenContext;
|
||||
|
||||
public class SolveForXScreen extends Screen {
|
||||
|
||||
|
@ -24,20 +27,21 @@ public class SolveForXScreen extends Screen {
|
|||
public void initialized() throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void graphicInitialized() throws InterruptedException {}
|
||||
public void graphicInitialized(ScreenContext ctx) throws InterruptedException {}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(0, 0, 0, 64);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2 + 1, StaticVars.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor3i(255, 0, 0);
|
||||
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringCenter(StaticVars.screenSize[0] / 2, StaticVars.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
public void render(RenderContext ctx) {
|
||||
DisplayOutputDevice display = d.display;
|
||||
ctx.getRenderer().glColor4i(0, 0, 0, 64);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2 + 1, ctx.getHeight() / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
ctx.getRenderer().glColor3i(255, 0, 0);
|
||||
ctx.getRenderer().glDrawStringCenter(ctx.getWidth() / 2, ctx.getHeight() / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRender(final float dt) {
|
||||
public void beforeRender(ScreenContext ctx, final float dt) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package it.cavallium.warppi.math;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.math.functions.*;
|
||||
import it.cavallium.warppi.math.functions.Number;
|
||||
import it.cavallium.warppi.math.functions.equations.Equation;
|
||||
import it.cavallium.warppi.math.functions.equations.EquationsSystem;
|
||||
import it.cavallium.warppi.math.functions.equations.EquationsSystemPart;
|
||||
import it.cavallium.warppi.math.functions.trigonometry.*;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
@ -15,6 +21,16 @@ public interface Function {
|
|||
@Override
|
||||
String toString();
|
||||
|
||||
/**
|
||||
* Indicates whether some other object is a <code>Function</code> which is <em>identical</em> to this one.
|
||||
* <p>
|
||||
* Two functions which are not identical, but only equivalent (due to, for example, the commutative property) aren't
|
||||
* considered equal.
|
||||
*
|
||||
* @param o the other object to compare.
|
||||
* @return <code>true</code> if the other object is identical to this <code>Function</code>, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
@Override
|
||||
boolean equals(Object o);
|
||||
|
||||
|
@ -28,7 +44,7 @@ public interface Function {
|
|||
/**
|
||||
* Deep clone this function, also change mathContext.
|
||||
*
|
||||
* @param mathContext new mathContext
|
||||
* @param newMathContext new mathContext
|
||||
* @return A clone of this function.
|
||||
*/
|
||||
Function clone(MathContext newMathContext);
|
||||
|
@ -80,4 +96,49 @@ public interface Function {
|
|||
* @throws Error
|
||||
*/
|
||||
ObjectArrayList<Block> toBlock(MathContext context) throws Error;
|
||||
|
||||
/**
|
||||
* Accepts a {@code Function.Visitor<Argument, Result>} by calling the correct overload of <code>visit</code>.
|
||||
*
|
||||
* @param visitor The visitor to be accepted.
|
||||
* @param argument An additional argument to be passed to <code>visit</code>.
|
||||
* @param <Argument> The type of an additional argument to be passed to the <code>visit</code> method.
|
||||
* @param <Result> The return type of the <code>visit</code> method.
|
||||
* @return The value returned by <code>visit</code>.
|
||||
*/
|
||||
<Argument, Result> Result accept(Visitor<Argument, Result> visitor, Argument argument);
|
||||
|
||||
/**
|
||||
* Executes a different overload of a method for each <code>Function</code> implementation.
|
||||
*
|
||||
* @param <Argument> The type of an additional argument which can be passed to all <code>visit</code> method overloads.
|
||||
* If the argument is not required, this type parameter should be set to {@link Void}.
|
||||
* @param <Result> The return type of all <code>visit</code> method overloads.
|
||||
*/
|
||||
interface Visitor<Argument, Result> {
|
||||
Result visit(ArcCosine arcCosine, Argument argument);
|
||||
Result visit(ArcSine arcSine, Argument argument);
|
||||
Result visit(ArcTangent arcTangent, Argument argument);
|
||||
Result visit(Cosine cosine, Argument argument);
|
||||
Result visit(Division division, Argument argument);
|
||||
Result visit(Equation equation, Argument argument);
|
||||
Result visit(EquationsSystem equationsSystem, Argument argument);
|
||||
Result visit(EquationsSystemPart equationsSystemPart, Argument argument);
|
||||
Result visit(Expression expression, Argument argument);
|
||||
Result visit(Joke joke, Argument argument);
|
||||
Result visit(Logarithm logarithm, Argument argument);
|
||||
Result visit(Multiplication multiplication, Argument argument);
|
||||
Result visit(Negative negative, Argument argument);
|
||||
Result visit(Number number, Argument argument);
|
||||
Result visit(Power power, Argument argument);
|
||||
Result visit(Root root, Argument argument);
|
||||
Result visit(RootSquare rootSquare, Argument argument);
|
||||
Result visit(Sine sine, Argument argument);
|
||||
Result visit(Subtraction subtraction, Argument argument);
|
||||
Result visit(SumSubtraction sumSubtraction, Argument argument);
|
||||
Result visit(Sum sum, Argument argument);
|
||||
Result visit(Tangent tangent, Argument argument);
|
||||
Result visit(Undefined undefined, Argument argument);
|
||||
Result visit(Variable variable, Argument argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,14 +133,12 @@ public abstract class FunctionDynamic implements Function {
|
|||
|
||||
@Override
|
||||
public abstract FunctionDynamic clone();
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return functions.hashCode() + 883 * super.hashCode();
|
||||
return Arrays.hashCode(functions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return false;
|
||||
}
|
||||
public abstract boolean equals(Object o);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import it.cavallium.warppi.util.Errors;
|
|||
import it.cavallium.warppi.util.Utils;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class FunctionOperator implements Function {
|
||||
|
||||
/**
|
||||
|
@ -175,7 +177,7 @@ public abstract class FunctionOperator implements Function {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return parameter1.hashCode() + 7 * parameter2.hashCode() + 883 * super.hashCode();
|
||||
return Objects.hash(parameter1, parameter2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
|||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class FunctionSingle implements Function {
|
||||
|
||||
private boolean simplified;
|
||||
|
@ -64,7 +66,7 @@ public abstract class FunctionSingle implements Function {
|
|||
|
||||
/**
|
||||
*
|
||||
* @param var
|
||||
* @param value
|
||||
* Parameter.
|
||||
* @return A new instance of this function.
|
||||
*/
|
||||
|
@ -117,9 +119,14 @@ public abstract class FunctionSingle implements Function {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return parameter.hashCode() + 883 * super.hashCode();
|
||||
return Objects.hash(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + "(" + getParameter() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,4 +59,9 @@ public class Division extends FunctionOperator {
|
|||
result.add(bd);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
|
@ -582,6 +582,11 @@ public class Expression extends FunctionSingle {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "(";
|
||||
|
|
|
@ -61,4 +61,8 @@ public class Joke implements Function {
|
|||
throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,4 +55,8 @@ public class Logarithm extends FunctionOperator {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,9 @@ package it.cavallium.warppi.math.functions;
|
|||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockNumericChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockParenthesis;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
import it.cavallium.warppi.math.*;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -24,11 +22,7 @@ public class Multiplication extends FunctionOperator {
|
|||
public boolean equals(final Object o) {
|
||||
if (o instanceof Multiplication) {
|
||||
final FunctionOperator f = (FunctionOperator) o;
|
||||
if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) {
|
||||
return true;
|
||||
} else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) {
|
||||
return true;
|
||||
}
|
||||
return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -71,7 +65,7 @@ public class Multiplication extends FunctionOperator {
|
|||
} else {
|
||||
result.addAll(sub1);
|
||||
}
|
||||
if (nearLeft instanceof BlockChar && nearRight instanceof BlockChar && !(par2 instanceof Negative) && !(par1 instanceof Number && par2 instanceof Number) && !(par1 instanceof Number && par2 instanceof Multiplication && ((Multiplication)par2).getParameter1() instanceof Number)) {
|
||||
if (nearLeft instanceof BlockChar && nearRight instanceof BlockChar && !(nearLeft instanceof BlockNumericChar && nearRight instanceof BlockNumericChar) && !(par2 instanceof Negative) && !(par1 instanceof Number && par2 instanceof Number) && !(par1 instanceof Number && par2 instanceof Multiplication && ((Multiplication)par2).getParameter1() instanceof Number)) {
|
||||
|
||||
} else {
|
||||
result.add(new BlockChar(MathematicalSymbols.MULTIPLICATION));
|
||||
|
@ -87,6 +81,11 @@ public class Multiplication extends FunctionOperator {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
public boolean isNegative() {
|
||||
return parameter1.equals(new Number(getMathContext(), -1)) || parameter2.equals(new Number(getMathContext(), -1));
|
||||
}
|
||||
|
@ -104,4 +103,4 @@ public class Multiplication extends FunctionOperator {
|
|||
public static Multiplication newNegative(final MathContext context, final Function value2) {
|
||||
return new Multiplication(context, new Number(context, -1), value2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,7 @@ package it.cavallium.warppi.math.functions;
|
|||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockParenthesis;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionSingle;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
import it.cavallium.warppi.math.*;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -52,4 +49,9 @@ public class Negative extends FunctionSingle {
|
|||
return blocks;
|
||||
// throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,9 @@ import java.math.BigDecimal;
|
|||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.blocks.*;
|
||||
import org.nevec.rjm.BigDecimalMath;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockExponentialNotation;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockPower;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.rules.Rule;
|
||||
|
@ -256,10 +252,10 @@ public class Number implements Function {
|
|||
final BlockPower bp = new BlockExponentialNotation();
|
||||
final BlockContainer bpec = bp.getExponentContainer();
|
||||
for (final char c : numberParts[0].toCharArray()) {
|
||||
result.add(new BlockChar(c));
|
||||
result.add(new BlockNumericChar(c));
|
||||
}
|
||||
for (final char c : numberParts[1].toCharArray()) {
|
||||
bpec.appendBlockUnsafe(new BlockChar(c));
|
||||
bpec.appendBlockUnsafe(new BlockNumericChar(c));
|
||||
} ;
|
||||
bpec.recomputeDimensions();
|
||||
bp.recomputeDimensions();
|
||||
|
@ -267,12 +263,17 @@ public class Number implements Function {
|
|||
return result;
|
||||
} else {
|
||||
for (final char c : numberString.toCharArray()) {
|
||||
result.add(new BlockChar(c));
|
||||
result.add(new BlockNumericChar(c));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function setParameter(final int index, final Function var) throws IndexOutOfBoundsException {
|
||||
throw new IndexOutOfBoundsException();
|
||||
|
|
|
@ -50,4 +50,9 @@ public class Power extends FunctionOperator {
|
|||
result.add(bp);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,4 +39,8 @@ public class Root extends FunctionOperator {
|
|||
throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,33 +5,37 @@ import it.cavallium.warppi.gui.expression.blocks.BlockContainer;
|
|||
import it.cavallium.warppi.gui.expression.blocks.BlockSquareRoot;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.FunctionSingle;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public class RootSquare extends FunctionOperator {
|
||||
public class RootSquare extends FunctionSingle {
|
||||
|
||||
public RootSquare(final MathContext root, final Function value2) {
|
||||
super(root, new Number(root, 2), value2);
|
||||
private final Number degree;
|
||||
|
||||
public RootSquare(final MathContext root, final Function value) {
|
||||
super(root, value);
|
||||
this.degree = new Number(root, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (o instanceof Root) {
|
||||
final FunctionOperator f = (FunctionOperator) o;
|
||||
return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2());
|
||||
if (o instanceof RootSquare) {
|
||||
final RootSquare f = (RootSquare) o;
|
||||
return parameter.equals(f.getParameter());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RootSquare clone() {
|
||||
return new RootSquare(mathContext, parameter2 == null ? null : parameter2.clone());
|
||||
return new RootSquare(mathContext, parameter == null ? null : parameter.clone());
|
||||
}
|
||||
|
||||
@Override
|
||||
public RootSquare clone(MathContext c) {
|
||||
return new RootSquare(c, parameter2 == null ? null : parameter2.clone(c));
|
||||
return new RootSquare(c, parameter == null ? null : parameter.clone(c));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +43,7 @@ public class RootSquare extends FunctionOperator {
|
|||
final ObjectArrayList<Block> result = new ObjectArrayList<>();
|
||||
final BlockSquareRoot bsqr = new BlockSquareRoot();
|
||||
final BlockContainer bsqrc = bsqr.getNumberContainer();
|
||||
for (final Block b : getParameter2().toBlock(context)) {
|
||||
for (final Block b : getParameter().toBlock(context)) {
|
||||
bsqrc.appendBlockUnsafe(b);
|
||||
}
|
||||
bsqrc.recomputeDimensions();
|
||||
|
@ -48,4 +52,12 @@ public class RootSquare extends FunctionOperator {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
public Number getDegree() {
|
||||
return degree;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ package it.cavallium.warppi.math.functions;
|
|||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
import it.cavallium.warppi.math.*;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -43,4 +40,8 @@ public class Subtraction extends FunctionOperator {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
|
@ -2,10 +2,7 @@ package it.cavallium.warppi.math.functions;
|
|||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
import it.cavallium.warppi.math.*;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -19,11 +16,7 @@ public class Sum extends FunctionOperator {
|
|||
public boolean equals(final Object o) {
|
||||
if (o instanceof Sum) {
|
||||
final FunctionOperator f = (FunctionOperator) o;
|
||||
if (parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2())) {
|
||||
return true;
|
||||
} else if (parameter1.equals(f.getParameter2()) && parameter2.equals(f.getParameter1())) {
|
||||
return true;
|
||||
}
|
||||
return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -47,4 +40,8 @@ public class Sum extends FunctionOperator {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,7 @@ package it.cavallium.warppi.math.functions;
|
|||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionOperator;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.math.MathematicalSymbols;
|
||||
import it.cavallium.warppi.math.*;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -43,4 +40,8 @@ public class SumSubtraction extends FunctionOperator {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public class Undefined implements Function {
|
|||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
return false;
|
||||
return o instanceof Undefined;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,6 +58,11 @@ public class Undefined implements Function {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "UNDEFINED";
|
||||
|
|
|
@ -8,6 +8,8 @@ import it.cavallium.warppi.math.rules.Rule;
|
|||
import it.cavallium.warppi.util.Error;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Variable implements Function {
|
||||
|
||||
protected char var;
|
||||
|
@ -84,7 +86,7 @@ public class Variable implements Function {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
return Objects.hash(var, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -131,4 +133,9 @@ public class Variable implements Function {
|
|||
result.add(new BlockChar(getChar()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ public class Equation extends FunctionOperator {
|
|||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
// TODO Auto-generated method stub
|
||||
if (o instanceof Equation) {
|
||||
final FunctionOperator f = (FunctionOperator) o;
|
||||
return parameter1.equals(f.getParameter1()) && parameter2.equals(f.getParameter2());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -68,4 +71,8 @@ public class Equation extends FunctionOperator {
|
|||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,26 @@ public class EquationsSystem extends FunctionDynamic {
|
|||
super(root, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (!(o instanceof EquationsSystem)) {
|
||||
return false;
|
||||
}
|
||||
final FunctionDynamic f = (FunctionDynamic) o;
|
||||
|
||||
if (functions.length != f.getParametersLength()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < functions.length; i++) {
|
||||
if (!functions[i].equals(f.getParameter(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EquationsSystem clone() {
|
||||
Function[] newFuncs = functions.clone();
|
||||
|
@ -46,4 +66,8 @@ public class EquationsSystem extends FunctionDynamic {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package it.cavallium.warppi.math.functions.equations;
|
||||
|
||||
import it.cavallium.warppi.gui.expression.blocks.Block;
|
||||
import it.cavallium.warppi.math.Function;
|
||||
import it.cavallium.warppi.math.FunctionSingle;
|
||||
import it.cavallium.warppi.math.MathContext;
|
||||
import it.cavallium.warppi.util.Error;
|
||||
|
@ -34,4 +35,8 @@ public class EquationsSystemPart extends FunctionSingle {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,10 @@ public class ArcCosine extends FunctionSingle {
|
|||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
// TODO Auto-generated method stub
|
||||
if (o instanceof ArcCosine) {
|
||||
final FunctionSingle f = (FunctionSingle) o;
|
||||
return parameter.equals(f.getParameter());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -38,4 +41,9 @@ public class ArcCosine extends FunctionSingle {
|
|||
throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + getClass().getSimpleName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <Argument, Result> Result accept(final Function.Visitor<Argument, Result> visitor, final Argument argument) {
|
||||
return visitor.visit(this, argument);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue