This commit is contained in:
Andrea Cavalli 2018-08-29 00:07:45 +02:00
parent 8a7e4f29f3
commit 97422ba06a
27 changed files with 505 additions and 304 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

10
pom.xml
View File

@ -225,6 +225,16 @@
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.1</version>
</dependency>
<!-- <dependency> <groupId>ar.com.hjg</groupId> <artifactId>pngj</artifactId>
<version>2.1.0</version> </dependency> -->
</dependencies>

View File

@ -28,7 +28,7 @@ public class ConsoleUtils {
return str.replace("" + MathematicalSymbols.NTH_ROOT, "root").replace("" + MathematicalSymbols.SQUARE_ROOT, "sqrt").replace("" + MathematicalSymbols.POWER, "powerOf").replace("" + MathematicalSymbols.POWER_OF_TWO, "powerOfTwo").replace("" + MathematicalSymbols.SINE, "sine").replace("" + MathematicalSymbols.COSINE, "cosine").replace("" + MathematicalSymbols.TANGENT, "tangent").replace("" + MathematicalSymbols.ARC_SINE, "asin").replace("" + MathematicalSymbols.ARC_COSINE, "acos").replace("" + MathematicalSymbols.ARC_TANGENT, "atan").replace("" + MathematicalSymbols.UNDEFINED, "undefined").replace("" + MathematicalSymbols.PI, "PI").replace("" + MathematicalSymbols.EULER_NUMBER, "EULER_NUMBER").replace("" + MathematicalSymbols.X, "X").replace("" + MathematicalSymbols.Y, "Y");
}
public void println(String str) {
public void println(Object str) {
println(0, str);
}
@ -43,13 +43,13 @@ public class ConsoleUtils {
}
}
public void println(int level, String str) {
public void println(int level, Object str) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + str);
println(System.out, "[" + time + "] " + str);
} else {
println(System.out, "[" + time + "]" + str);
println(System.out, "[" + time + "] " + str);
}
}
}
@ -68,9 +68,9 @@ public class ConsoleUtils {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "][" + prefix + "]" + str);
println(System.out, "[" + time + "][" + prefix + "] " + str);
} else {
println(System.out, "[" + time + "][" + prefix + "]" + str);
println(System.out, "[" + time + "][" + prefix + "] " + str);
}
}
}
@ -78,18 +78,24 @@ public class ConsoleUtils {
public void println(int level, String... parts) {
if (StaticVars.outputLevel >= level) {
final String time = getTimeString();
String output = "";
StringBuilder output = new StringBuilder();
for (int i = 0; i < parts.length; i++) {
if (i + 1 == parts.length) {
output += parts[i];
output.append(' ');
output.append(parts[i]);
} else {
output += "[" + parts[i] + "]";
output.append('[');
output.append(parts[i]);
output.append(']');
}
}
output.insert(0, '[');
output.insert(1, time);
output.insert(time.length() + 1, ']');
if (StaticVars.outputLevel == 0) {
println(System.out, "[" + time + "]" + output);
println(System.out, output.toString());
} else {
println(System.out, "[" + time + "]" + output);
println(System.out, output.toString());
}
}
}

View File

@ -60,6 +60,12 @@ public class PICalculator {
instance = this;
ClassUtils.classLoader = this.getClass();
StaticVars.startupArguments = args;
Utils.debugThirdScreen = StaticVars.debugOn & false;
StaticVars.debugWindow2x = args.isZoomed();
if (args.isVerboseLoggingEnabled() || args.isDebugEnabled()) {
StaticVars.outputLevel = ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE;
}
ConsoleUtils.out.println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, args);
checkDeviceType();
if (Utils.isRunningOnRaspberry() && args.isRaspberryModeAllowed()) {
DGpio.wiringPiSetupPhys();
@ -68,11 +74,6 @@ public class PICalculator {
StaticVars.screenPos = new int[] { 0, 0 };
StaticVars.debugOn = true;
}
Utils.debugThirdScreen = StaticVars.debugOn & false;
StaticVars.debugWindow2x = args.isZoomed();
if (args.isVerboseLoggingEnabled() || args.isDebugEnabled()) {
StaticVars.outputLevel = ConsoleUtils.OUTPUTLEVEL_DEBUG_VERBOSE;
}
}
private void checkDeviceType() {

View File

@ -1,7 +1,14 @@
package org.warp.picalculator;
import java.util.Iterator;
import java.util.concurrent.CompletableFuture;
import org.warp.picalculator.boot.StartupArguments;
import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;
public class StaticVars {
public static final boolean enableVBO = true;
public static final String calculatorName = "WarpPI";
@ -14,18 +21,18 @@ public class StaticVars {
public static boolean debugOn;
public static int outputLevel = 0;
public static boolean debugWindow2x = false;
public static float windowZoom = 2;
public static BehaviorSubject<Float> windowZoom = BehaviorSubject.createDefault(2F);
public static Observable<Float> windowZoom$ = windowZoom.map((val) -> {
if (StaticVars.debugOn & StaticVars.debugWindow2x) {
return val + 1;
} else {
return val;
}
});
public static Iterator<Float> windowZoomValue = windowZoom$.blockingMostRecent(2F).iterator();
public static StartupArguments startupArguments;
private StaticVars() {
}
public static float getCurrentZoomValue() {
if (StaticVars.debugOn & StaticVars.debugWindow2x) {
return 2;
} else {
return StaticVars.windowZoom;
}
}
}

View File

@ -18,59 +18,61 @@ public class Main {
public static StartupArguments parseStartupArguments(final String[] a) {
final StartupArgumentsImpl args = new StartupArgumentsImpl();
Arrays.asList(a).stream().parallel().map(String::toLowerCase).forEach(arg -> {
switch (arg) {
case "2x":
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 "headless-8":
args.setHeadless8EngineForced(true);
break;
case "headless-256":
args.setHeadless256EngineForced(true);
break;
case "headless-24bit":
args.setHeadless24bitEngineForced(true);
break;
case "headless":
args.setHeadlessEngineForced(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:
ConsoleUtils.out.print(ConsoleUtils.OUTPUTLEVEL_NODEBUG, "Unrecognized argument " + arg);
break;
}
});
Arrays.asList(a).stream().parallel().map(String::toLowerCase).forEach(arg -> parseArgument(args, arg));
args.setHeadlessEngineForced(args.isHeadlessEngineForced() || args.isHeadless8EngineForced() || args.isHeadless256EngineForced() || args.isHeadless24bitEngineForced());
return args;
}
public static void parseArgument(StartupArgumentsImpl args, 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 "headless-8":
args.setHeadless8EngineForced(true);
break;
case "headless-256":
args.setHeadless256EngineForced(true);
break;
case "headless-24bit":
args.setHeadless24bitEngineForced(true);
break;
case "-headless":
args.setHeadlessEngineForced(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:
ConsoleUtils.out.println("Unrecognized argument " + arg);
break;
}
}
}

View File

@ -162,4 +162,10 @@ public class StartupArgumentsImpl implements StartupArguments {
this.isUncached = isUncached;
}
@Override
public String toString() {
return "StartupArguments = {\n\t\"isRaspberryModeAllowed\": \"" + isRaspberryModeAllowed + "\",\n\tisZoomed\": \"" + isZoomed + "\",\n\tisHeadlessEngineForced\": \"" + isHeadlessEngineForced + "\",\n\tisHeadless8EngineForced\": \"" + isHeadless8EngineForced + "\",\n\tisHeadless256EngineForced\": \"" + isHeadless256EngineForced + "\",\n\tisHeadless24bitEngineForced\": \"" + isHeadless24bitEngineForced + "\",\n\tisCPUEngineForced\": \"" + isCPUEngineForced + "\",\n\tisGPUEngineForced\": \"" + isGPUEngineForced + "\",\n\tisFrameBufferEngineForced\": \"" + isFrameBufferEngineForced + "\",\n\tisNoGUIEngineForced\": \"" + isNoGUIEngineForced + "\",\n\tisHTMLEngineForced\": \"" + isHTMLEngineForced + "\",\n\tisMSDOSModeEnabled\": \"" + isMSDOSModeEnabled + "\",\n\tisVerboseLoggingEnabled\": \"" + isVerboseLoggingEnabled + "\",\n\tisDebugEnabled\": \"" + isDebugEnabled + "\",\n\tisUncached\": \"" + isUncached + "\"\n}";
}
}

View File

@ -118,7 +118,7 @@ public class Keyboard {
if (Keyboard.shift) {
Keyboard.keyPressed(Key.ARCSINE);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_S);
} else {
Keyboard.keyPressed(Key.SINE);
}
@ -127,7 +127,7 @@ public class Keyboard {
if (Keyboard.shift) {
Keyboard.keyPressed(Key.ARCCOSINE);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_C);
} else {
Keyboard.keyPressed(Key.COSINE);
}
@ -136,7 +136,7 @@ public class Keyboard {
if (Keyboard.shift) {
Keyboard.keyPressed(Key.ARCTANGENT);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_T);
} else {
Keyboard.keyPressed(Key.TANGENT);
}
@ -144,6 +144,8 @@ public class Keyboard {
case KeyEvent.VK_D:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.debug_DEG);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.LETTER_D);
} else {
Keyboard.keyPressed(Key.NONE);
}
@ -151,6 +153,8 @@ public class Keyboard {
case KeyEvent.VK_R:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.debug_RAD);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.LETTER_R);
} else {
Keyboard.keyPressed(Key.NONE);
}
@ -158,6 +162,8 @@ public class Keyboard {
case KeyEvent.VK_G:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.debug_GRA);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.LETTER_G);
} else {
Keyboard.keyPressed(Key.NONE);
}
@ -170,17 +176,19 @@ public class Keyboard {
}
break;
case KeyEvent.VK_P:
if (Keyboard.alpha) {
Keyboard.keyPressed(Key.PI);
} else {
if (Keyboard.shift) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.LETTER_P);
} else {
Keyboard.keyPressed(Key.PI);
}
break;
case KeyEvent.VK_E:
if (Keyboard.shift) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_E);
} else {
Keyboard.keyPressed(Key.EULER_NUMBER);
}
@ -198,14 +206,14 @@ public class Keyboard {
} else if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.BRIGHTNESS_CYCLE);
} else {
Keyboard.keyPressed(Key.ZOOM_MODE);
Keyboard.keyPressed(Key.LETTER_B);
}
break;
case KeyEvent.VK_L:
if (Keyboard.shift) {
Keyboard.keyPressed(Key.LOGARITHM);
} else if (Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_L);
} else {
Keyboard.keyPressed(Key.LOGARITHM);
}
@ -307,7 +315,7 @@ public class Keyboard {
} else if (Keyboard.shift) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
Keyboard.keyPressed(Key.LETTER_M);
}
break;
case DJogamp.VK_ADD:
@ -345,11 +353,7 @@ public class Keyboard {
}
break;
case KeyEvent.VK_BACK_SPACE:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.DELETE);
} else {
Keyboard.keyPressed(Key.NONE);
}
Keyboard.keyPressed(Key.DELETE);
break;
case DJogamp.VK_DELETE:
case KeyEvent.VK_DELETE:
@ -441,11 +445,154 @@ public class Keyboard {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_A:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_A);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_F:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_F);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_H:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_H);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_I:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_I);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_J:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_J);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_K:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_K);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_N:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_N);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_O:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_O);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_Q:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_Q);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_U:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_U);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_V:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_V);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_W:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_W);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case KeyEvent.VK_Z:
if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.NONE);
} else if (Keyboard.alpha && !Keyboard.shift) {
Keyboard.keyPressed(Key.LETTER_Z);
} else if (Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.ZOOM_MODE);
} else {
Keyboard.keyPressed(Key.NONE);
}
break;
case DJogamp.VK_SHIFT:
case KeyEvent.VK_SHIFT:
Keyboard.keyPressed(Key.SHIFT);
break;
case KeyEvent.VK_A:
case KeyEvent.VK_CONTROL:
Keyboard.keyPressed(Key.ALPHA);
break;
case DJogamp.VK_NUMPAD1:
@ -656,9 +803,6 @@ public class Keyboard {
break;
case NONE:
break;
case LETTER_X:
letterPressed('X');
break;
case BRIGHTNESS_CYCLE:
HardwareDevice.INSTANCE.getDisplayManager().cycleBrightness(false);
refresh = true;
@ -669,7 +813,9 @@ public class Keyboard {
refresh = true;
break;
case ZOOM_MODE:
StaticVars.windowZoom = (StaticVars.windowZoom % 3) + 1;
float newZoom = (StaticVars.windowZoom.blockingLatest().iterator().next().floatValue() % 3) + 1;
StaticVars.windowZoom.onNext(newZoom);
ConsoleUtils.out.println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Keyboard", "Zoom: " + newZoom);
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
refresh = true;
case HISTORY_BACK:
@ -717,10 +863,6 @@ public class Keyboard {
}
}
private static void letterPressed(char L) {
}
public synchronized static void keyReleased(Key k) {
boolean done = false;
if (additionalListener != null) {

View File

@ -1,5 +1,16 @@
package org.warp.picalculator.event;
public enum Key {
POWEROFF, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, LETTER_Z, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI, SETTINGS, F1, F2, F3, F4, BACK, ZOOM_MODE, LOGARITHM, EULER_NUMBER
POWEROFF, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK,
HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, STEP, SIMPLIFY, BRIGHTNESS_CYCLE,
BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5,
NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS,
MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT,
RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT,
ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE,
ARCTANGENT, PI, SETTINGS, F1, F2, F3, F4, BACK, ZOOM_MODE, LOGARITHM,
EULER_NUMBER, LETTER_A, LETTER_B, LETTER_C, LETTER_D, LETTER_E, LETTER_F,
LETTER_G, LETTER_H, LETTER_I, LETTER_J, LETTER_K, LETTER_L, LETTER_M,
LETTER_N, LETTER_O, LETTER_P, LETTER_Q, LETTER_R, LETTER_S, LETTER_T,
LETTER_U, LETTER_V, LETTER_W, LETTER_X, LETTER_Y, LETTER_Z,
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.PlatformUtils;
@ -29,9 +30,14 @@ import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.nogui.NoGuiEngine;
import org.warp.picalculator.gui.screens.Screen;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap.Entry;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public final class DisplayManager implements RenderingLoop {
private static final int tickDuration = 50;
private HardwareDevice device;
private float brightness;
@ -379,13 +385,6 @@ public final class DisplayManager implements RenderingLoop {
}
private void checkDisplayResized() {
if (engine.wasResized()) {
StaticVars.screenSize[0] = engine.getWidth();
StaticVars.screenSize[1] = engine.getHeight();
}
};
public void loop() {
try {
load_skin();
@ -401,84 +400,24 @@ public final class DisplayManager implements RenderingLoop {
e.printStackTrace();
DSystem.exit(0);
}
//Working thread
final Thread workThread = new Thread(() -> {
try {
while (true) {
float dt = 0;
final long newtime = System.nanoTime();
if (precTime == -1) {
dt = 0;
} else {
dt = (float) ((newtime - precTime) / 1000000000d);
}
precTime = newtime;
/*
* Calcoli
*/
checkDisplayResized();
screen.beforeRender(dt);
Thread.sleep(50);
// for (int i = 0; i < 10; i++) {
// System.out.println("============");
// OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
// for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
// method.setAccessible(true);
// if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) {
// Object value;
// try {
// value = method.invoke(operatingSystemMXBean);
// } catch (Exception e) {
// value = e;
// } // try
// boolean percent = false;
// boolean mb = false;
// String displayName = method.getName();
// String displayValue = value.toString();
// if (displayName.endsWith("CpuLoad")) {
// percent = true;
// }
// if (displayName.endsWith("MemorySize")) {
// mb = true;
// }
// ObjectArrayList<String> arr = new ObjectArrayList<>();
// arr.add("getFreePhysicalMemorySize");
// arr.add("getProcessCpuLoad");
// arr.add("getSystemCpuLoad");
// arr.add("getTotalPhysicalMemorySize");
// if (arr.contains(displayName)) {
// if (percent) {
// try {
// System.out.println(displayName + " = " + (((int)(Float.parseFloat(displayValue) * 10000f))/100f) + "%");
// }catch(Exception ex) {
// System.out.println(displayName + " = " + displayValue);
// }
// } else if (mb) {
// try {
// System.out.println(displayName + " = " + (Long.parseLong(displayValue) / 1024L / 1024L) + " MB");
// }catch(Exception ex) {
// System.out.println(displayName + " = " + displayValue);
// }
// } else {
// System.out.println(displayName + " = " + displayValue);
// }
// }
// } // if
// } // for
// System.out.println("============");
// Thread.sleep(5000);
// }
}
} catch (final InterruptedException e) {
e.printStackTrace();
Observable<Long> workTimer = Observable.interval(tickDuration, TimeUnit.MILLISECONDS);
Observable.combineLatest(workTimer, engine.onResize(), (time, windowSize) -> windowSize).subscribe((windowSize) -> {
double dt = 0;
final long newtime = System.nanoTime();
if (precTime == -1) {
dt = tickDuration;
} else {
dt = (newtime - precTime) / 1000d / 1000d;
}
precTime = newtime;
StaticVars.screenSize[0] = windowSize[0];
StaticVars.screenSize[1] = windowSize[1];
screen.beforeRender((float) (dt / 1000d));
});
PlatformUtils.setDaemon(workThread);
PlatformUtils.setThreadName(workThread, "Work thread");
workThread.start();
engine.start(getDrawable());
} catch (final Exception ex) {

View File

@ -3,6 +3,8 @@ package org.warp.picalculator.gui.graphicengine;
import java.io.IOException;
import java.util.List;
import io.reactivex.Observable;
public interface GraphicEngine {
public int[] getSize();
@ -21,7 +23,7 @@ public interface GraphicEngine {
public void create(Runnable object);
public boolean wasResized();
public Observable<Integer[]> onResize();
public int getWidth();

View File

@ -14,11 +14,13 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin;
import io.reactivex.Observable;
public class CPUEngine implements GraphicEngine {
private SwingWindow INSTANCE;
public final CPURenderer r = new CPURenderer();
public BufferedImage g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_RGB);
public volatile BufferedImage g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_RGB);
public volatile boolean initialized = false;
public Semaphore exitSemaphore = new Semaphore(0);
@ -40,8 +42,7 @@ public class CPUEngine implements GraphicEngine {
INSTANCE.setSize(ww, wh);
r.size = new int[] { ww, wh };
CPURenderer.canvas2d = new int[ww * wh];
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_RGB);
}
@Override
@ -62,21 +63,8 @@ public class CPUEngine implements GraphicEngine {
}
@Override
public boolean wasResized() {
if (INSTANCE.wasResized) {
r.size = new int[] { INSTANCE.getWidth(), INSTANCE.getHeight() };
if (r.size[0] <= 0) {
r.size[0] = 1;
}
if (r.size[1] <= 0) {
r.size[1] = 1;
}
CPURenderer.canvas2d = new int[r.size[0] * r.size[1]];
g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
return true;
}
return false;
public Observable<Integer[]> onResize() {
return INSTANCE.onResize();
}
@Override
@ -104,14 +92,12 @@ public class CPUEngine implements GraphicEngine {
try {
double extratime = 0;
while (initialized) {
final long start = System.currentTimeMillis();
final long start = System.nanoTime();
repaint();
final long end = System.currentTimeMillis();
final double delta = (end - start) / 1000d;
final int deltaInt = (int) Math.floor(delta);
final int extraTimeInt = (int) Math.floor(extratime);
if (extraTimeInt + deltaInt < 50) {
Thread.sleep(50 - (extraTimeInt + deltaInt));
final long end = System.nanoTime();
final double delta = (end - start);
if (extratime + delta < 50 * 1000d * 1000d) {
Thread.sleep((long) Math.floor(50d - (extratime + delta) / 1000d / 1000d));
extratime = 0;
} else {
extratime += delta - 50d;
@ -129,7 +115,7 @@ public class CPUEngine implements GraphicEngine {
@Deprecated()
public void refresh() {
if (HardwareDevice.INSTANCE.getDisplayManager().getScreen() == null || (HardwareDevice.INSTANCE.getDisplayManager().error != null && HardwareDevice.INSTANCE.getDisplayManager().error.length() > 0) || HardwareDevice.INSTANCE.getDisplayManager().getScreen() == null || HardwareDevice.INSTANCE.getDisplayManager().getScreen().mustBeRefreshed()) {
INSTANCE.c.repaint();
INSTANCE.c.paintImmediately(0, 0, getWidth(), getHeight());
}
}

View File

@ -5,11 +5,15 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import javax.imageio.ImageIO;
import org.warp.picalculator.deps.DSystem;
import org.warp.picalculator.deps.StorageUtils;
import org.warp.picalculator.deps.nio.DFiles;
import org.warp.picalculator.deps.nio.DPath;
import org.warp.picalculator.deps.nio.DPaths;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Skin;
@ -33,6 +37,13 @@ public class CPUSkin implements Skin {
if (!file.startsWith("/"))
file = "/" + file;
try {
if (!file.endsWith(".png")) {
File f = File.createTempFile("picalculator-png", ".png");
f.deleteOnExit();
BufferedImage img = ImageIO.read(StorageUtils.getResourceStream(file));
ImageIO.write(img, "PNG", f);
file = f.toString();
}
PngReader r = new PngReader(StorageUtils.getResourceStream(file));
if (r == null) {
skinData = new int[0];
@ -70,8 +81,12 @@ public class CPUSkin implements Skin {
int nextPixel;
if (channels == 4) {
nextPixel = (scanLine[offset] << 16) | (scanLine[offset + 1] << 8) | (scanLine[offset + 2]) | (scanLine[offset + 3] << 24);
} else {
} else if (channels == 3) {
nextPixel = (scanLine[offset] << 16) | (scanLine[offset + 1] << 8) | (scanLine[offset + 2]) | (0xFF << 24);
} else if (channels == 2) {
nextPixel = (scanLine[offset] << 16) | (scanLine[offset + 1] << 8) | 0xFF | (0xFF << 24);
} else {
nextPixel = (scanLine[offset] << 16) | (scanLine[offset] << 8) | scanLine[offset] | (0xFF << 24);
}
// I'm placing the pixels on a memory mapped file

View File

@ -19,6 +19,8 @@ import java.awt.image.DataBufferInt;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.PlatformUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.Utils;
import org.warp.picalculator.device.HardwareDevice;
@ -30,15 +32,18 @@ import org.warp.picalculator.event.TouchStartEvent;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class SwingWindow extends JFrame {
private static final long serialVersionUID = 2945898937634075491L;
public CustomCanvas c;
private RenderingLoop renderingLoop;
public boolean wasResized = false;
private final CPUEngine display;
private int mult = 1;
private BehaviorSubject<Integer[]> onResize;
private Observable<Integer[]> onResize$;
public SwingWindow(CPUEngine disp) {
display = disp;
@ -50,9 +55,7 @@ public class SwingWindow extends JFrame {
// Transparent 16 x 16 pixel cursor image.
final BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
if (StaticVars.debugOn & StaticVars.debugWindow2x) {
mult = 2;
}
mult = StaticVars.windowZoomValue.next().intValue();
if (StaticVars.debugOn) {
if (Utils.debugThirdScreen) {
this.setLocation(2880, 900);
@ -71,6 +74,19 @@ public class SwingWindow extends JFrame {
setTitle("WarpPI Calculator by Andrea Cavalli (@Cavallium)");
onResize = BehaviorSubject.create();
onResize$ = onResize.doOnNext((newSize) -> {
disp.r.size = new int[] { newSize[0], newSize[1] };
if (disp.r.size[0] <= 0) {
disp.r.size[0] = 1;
}
if (disp.r.size[1] <= 0) {
disp.r.size[1] = 1;
}
CPURenderer.canvas2d = new int[disp.r.size[0] * disp.r.size[1]];
disp.g = new BufferedImage(disp.r.size[0], disp.r.size[1], BufferedImage.TYPE_INT_RGB);
});
addComponentListener(new ComponentListener() {
@Override
public void componentHidden(ComponentEvent e) {
@ -82,7 +98,7 @@ public class SwingWindow extends JFrame {
@Override
public void componentResized(ComponentEvent e) {
wasResized = true;
onResize.onNext(new Integer[] {getWidth(), getHeight()});
}
@Override
@ -158,6 +174,18 @@ public class SwingWindow extends JFrame {
@Override
public void mouseExited(MouseEvent e) {}
});
StaticVars.windowZoom$.subscribe((newZoomValue) -> {
if (newZoomValue != mult) {
mult = (int) newZoomValue.floatValue();
this.onResize.onNext(new Integer[] {getWidth(), getHeight()});
ConsoleUtils.out.println(3, "Engine", "CPU", "Zoom changed");
}
});
}
public Observable<Integer[]> onResize() {
return onResize$;
}
@Override
@ -211,7 +239,6 @@ public class SwingWindow extends JFrame {
renderingLoop.refresh();
final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData();
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
CPURenderer.canvas2d = a;
g.clearRect(0, 0, display.r.size[0] * mult, display.r.size[1] * mult);
g.drawImage(display.g, 0, 0, display.r.size[0] * mult, display.r.size[1] * mult, null);

View File

@ -18,6 +18,9 @@ import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.cpu.CPUFont;
import org.warp.picalculator.gui.graphicengine.cpu.CPUSkin;
import io.reactivex.Observable;
import io.reactivex.subjects.BehaviorSubject;
public class FBEngine implements GraphicEngine {
private static final int FB_DISPLAY_WIDTH = 320;
@ -26,6 +29,7 @@ public class FBEngine implements GraphicEngine {
private static final int WIDTH = 480;
private static final int HEIGHT = 320;
private static final int[] SIZE = new int[] { WIDTH, HEIGHT };
private BehaviorSubject<Integer[]> onResize;
private final TestJNI jni = new TestJNI();
public FBRenderer r;
private MappedByteBuffer fb;
@ -33,8 +37,7 @@ public class FBEngine implements GraphicEngine {
private RandomAccessFile fbFileRW;
public volatile boolean initialized = false;
public Semaphore exitSemaphore = new Semaphore(0);
private boolean resizedTrigger = false;
@Override
public int[] getSize() {
return SIZE;
@ -56,11 +59,11 @@ public class FBEngine implements GraphicEngine {
@Override
public void create(Runnable onInitialized) {
resizedTrigger = true;
onResize = BehaviorSubject.createDefault(new Integer[] {SIZE[0], SIZE[1]});
realFb = jni.retrieveBuffer();
final long fbLen = realFb.getLength();
fb = (MappedByteBuffer) ByteBuffer.allocateDirect((int) fbLen);
r = new FBRenderer(this, fb);
initialized = true;
@ -70,13 +73,8 @@ public class FBEngine implements GraphicEngine {
}
@Override
public boolean wasResized() {
if (resizedTrigger) {
resizedTrigger = false;
return true;
} else {
return false;
}
public Observable<Integer[]> onResize() {
return onResize;
}
@Override

View File

@ -18,6 +18,10 @@ import org.warp.picalculator.gui.graphicengine.Skin;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.texture.Texture;
import io.reactivex.Observable;
import io.reactivex.processors.BehaviorProcessor;
import io.reactivex.subjects.BehaviorSubject;
public class GPUEngine implements GraphicEngine {
private volatile boolean initialized = false;
@ -61,7 +65,7 @@ public class GPUEngine implements GraphicEngine {
public void setDisplayMode(int ww, int wh) {
size[0] = ww;
size[1] = wh;
wnd.window.setSize(ww, wh);
wnd.setSize(ww, wh);
}
@Override
@ -82,10 +86,10 @@ public class GPUEngine implements GraphicEngine {
initialized = true;
wnd.onInitialized = onInitialized;
}
@Override
public boolean wasResized() {
return StaticVars.screenSize[0] != size[0] | StaticVars.screenSize[1] != size[1];
public Observable<Integer[]> onResize() {
return wnd.onResize;
}
@Override
@ -100,10 +104,12 @@ public class GPUEngine implements GraphicEngine {
@Override
public void destroy() {
initialized = false;
created = false;
exitSemaphore.release();
wnd.window.destroy();
if (initialized && created) {
initialized = false;
created = false;
exitSemaphore.release();
wnd.window.destroy();
}
}
@Override

View File

@ -28,9 +28,12 @@
package org.warp.picalculator.gui.graphicengine.gpu;
import java.nio.file.WatchService;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.tuple.Pair;
import org.warp.picalculator.ConsoleUtils;
import org.warp.picalculator.StaticVars;
import org.warp.picalculator.device.HardwareDevice;
import org.warp.picalculator.device.Keyboard;
@ -40,6 +43,7 @@ import org.warp.picalculator.event.TouchMoveEvent;
import org.warp.picalculator.event.TouchPoint;
import org.warp.picalculator.event.TouchStartEvent;
import org.warp.picalculator.gui.DisplayManager;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import com.jogamp.newt.event.GestureHandler.GestureEvent;
import com.jogamp.newt.event.GestureHandler.GestureListener;
@ -63,6 +67,15 @@ import com.jogamp.opengl.fixedfunc.GLPointerFunc;
import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.texture.Texture;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.processors.BehaviorProcessor;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.ReplaySubject;
import io.reactivex.subjects.Subject;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
/**
@ -75,19 +88,36 @@ class NEWTWindow implements GLEventListener {
private final GPUEngine disp;
private final GPURenderer renderer;
public float windowZoom;
public GLWindow window;
public volatile float windowZoom = 1;
public int[] realWindowSize;
public Runnable onInitialized;
public volatile boolean refreshViewport;
public List<TouchPoint> touches = new ObjectArrayList<>();
final BehaviorSubject<Integer[]> onResize = BehaviorSubject.create();
private BehaviorSubject<Float> onZoom = BehaviorSubject.create();
private Subject<GL2ES1> onGLContext = PublishSubject.create();
public NEWTWindow(GPUEngine disp) {
this.disp = disp;
renderer = disp.getRenderer();
realWindowSize = new int[] { 1, 1 };
Observable.zip(onZoom, onGLContext, (gl,zoom)->{return Pair.of(gl, zoom);}).subscribe((pair) -> {
windowZoom = pair.getLeft();
onDisplayChanged(pair.getRight(), true, false);
});
Observable.zip(onResize, onGLContext, (gl,size)->{return Pair.of(gl, size);}).subscribe((pair) -> {
final Integer[] size = pair.getLeft();
realWindowSize[0] = size[0];
realWindowSize[1] =size[1];
disp.size[0] = size[0];
disp.size[1] = size[1];
onDisplayChanged(pair.getRight(), false, true);
});
}
public GLWindow window;
public void create() {
System.out.println("Loading OpenGL...");
System.out.println(GLProfile.glAvailabilityToString());
@ -105,11 +135,12 @@ class NEWTWindow implements GLEventListener {
caps.setBackgroundOpaque(true); //transparency window
// caps.setSampleBuffers(true);
// caps.setNumSamples(4);
final GLWindow glWindow = GLWindow.create(caps);
window = glWindow;
glWindow.setTitle("WarpPI Calculator by Andrea Cavalli (@Cavallium)");
glWindow.addWindowListener(new WindowListener() {
@Override
@ -120,7 +151,10 @@ class NEWTWindow implements GLEventListener {
@Override
public void windowDestroyed(WindowEvent e) {
HardwareDevice.INSTANCE.getDisplayManager().engine.destroy();
GraphicEngine engine = HardwareDevice.INSTANCE.getDisplayManager().engine;
if (engine.isInitialized()) {
engine.destroy();
}
}
@Override
@ -250,7 +284,7 @@ class NEWTWindow implements GLEventListener {
Keyboard.keyReleased(Key.SHIFT);
}
break;
case KeyEvent.VK_A:
case KeyEvent.VK_CONTROL:
Keyboard.keyReleased(Key.ALPHA);
if (Keyboard.alpha) {
Keyboard.keyPressed(Key.ALPHA);
@ -402,7 +436,7 @@ class NEWTWindow implements GLEventListener {
}
});
glWindow.addGLEventListener(this /* GLEventListener */);
final Animator animator = new Animator();
animator.add(glWindow);
@ -412,7 +446,8 @@ class NEWTWindow implements GLEventListener {
@Override
public void init(GLAutoDrawable drawable) {
final GL2ES1 gl = drawable.getGL().getGL2ES1();
onGLContext.onNext(gl);
if (StaticVars.debugOn) {
//Vsync
gl.setSwapInterval(1);
@ -431,16 +466,19 @@ class NEWTWindow implements GLEventListener {
//Multisampling
//gl.glEnable(GL.GL_MULTISAMPLE);
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
}
try {
renderer.currentTex = ((GPUSkin) disp.loadSkin("test.png")).t;
} catch (final Exception e) {
e.printStackTrace();
}
StaticVars.windowZoom$.subscribe((zoom) -> {onZoom.onNext(zoom);});
onResize.onNext(new Integer[] {disp.size[0], disp.size[1]});
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
}
System.err.println("Chosen GLCapabilities: " + drawable.getChosenGLCapabilities());
System.err.println("INIT GL IS: " + gl.getClass().getName());
@ -451,55 +489,29 @@ class NEWTWindow implements GLEventListener {
@Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
realWindowSize[0] = width;
realWindowSize[1] = height;
disp.size[0] = width;
disp.size[1] = height;
final GL2ES1 gl = glad.getGL().getGL2ES1();
onZoomChanged(gl, true);
onResize.onNext(new Integer[] {width, height});
}
private void onZoomChanged(GL2ES1 gl, boolean sizeChanged) {
final float precWindowZoom = windowZoom;
windowZoom = StaticVars.getCurrentZoomValue();
if (((precWindowZoom % ((int) precWindowZoom)) != 0f) != ((windowZoom % ((int) windowZoom)) != 0f)) {
private void onDisplayChanged(GL2ES1 gl, boolean zoomChanged, boolean sizeChanged) {
disp.size[0] = (int) (realWindowSize[0] / windowZoom);
disp.size[1] = (int) (realWindowSize[1] / windowZoom);
if (zoomChanged) {
final boolean linear = (windowZoom % ((int) windowZoom)) != 0f;
for (final Texture t : disp.registeredTextures) {
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, linear ? GL.GL_LINEAR : GL.GL_NEAREST);
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
}
}
final int width = realWindowSize[0];
final int height = realWindowSize[1];
disp.size[0] = (int) (realWindowSize[0] / windowZoom);
disp.size[1] = (int) (realWindowSize[1] / windowZoom);
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, disp.size[0], disp.size[1], 0.0, -1, 1);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
refreshViewport = true;
}
@Override
public void display(GLAutoDrawable glad) {
final GL2ES1 gl = glad.getGL().getGL2ES1();
GPURenderer.gl = gl;
if (windowZoom != StaticVars.getCurrentZoomValue()) {
onZoomChanged(gl, false);
}
onGLContext.onNext(gl);
Boolean linear = null;
while (!disp.unregisteredTextures.isEmpty()) {
if (linear == null) {
@ -510,23 +522,45 @@ class NEWTWindow implements GLEventListener {
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
disp.registeredTextures.addLast(t);
}
if (refreshViewport) {
refreshViewport = false;
gl.glViewport(0, 0, realWindowSize[0], realWindowSize[1]);
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(0.0, disp.size[0], disp.size[1], 0.0, -1, 1);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
renderer.initDrawCycle();
disp.repaint();
renderer.endDrawCycle();
GPURenderer.gl = null;
gl.glDisableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glDisableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY);
GPURenderer.gl = null;
}
public void setSize(final int width, final int height) {
int zoom = (int) windowZoom;
if (zoom == 0) {
zoom = onZoom.blockingFirst().intValue();
}
window.setSize(width * zoom, height * zoom);
}
@Override
public void dispose(GLAutoDrawable drawable) {

View File

@ -12,6 +12,8 @@ import org.warp.picalculator.event.Key;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import io.reactivex.Observable;
public class Headless24bitEngine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private final Headless24bitRenderer r = new Headless24bitRenderer();
@ -138,8 +140,8 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
}
@Override
public boolean wasResized() {
return false;
public Observable<Integer[]> onResize() {
return null;
}
@Override

View File

@ -13,6 +13,8 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
import io.reactivex.Observable;
public class Headless256Engine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private final Headless256Renderer r = new Headless256Renderer();
@ -137,8 +139,8 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
}
@Override
public boolean wasResized() {
return false;
public Observable<Integer[]> onResize() {
return null;
}
@Override

View File

@ -13,6 +13,8 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
import io.reactivex.Observable;
public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private final Headless8Renderer r = new Headless8Renderer();
@ -137,8 +139,8 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
}
@Override
public boolean wasResized() {
return false;
public Observable<Integer[]> onResize() {
return null;
}
@Override

View File

@ -11,6 +11,8 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin;
import io.reactivex.Observable;
public class NoGuiEngine implements GraphicEngine {
private boolean initialized;
@ -44,8 +46,8 @@ public class NoGuiEngine implements GraphicEngine {
}
@Override
public boolean wasResized() {
return false;
public Observable<Integer[]> onResize() {
return null;
}
@Override

View File

@ -26,8 +26,8 @@ public class LoadingScreen extends Screen {
@Override
public void initialized() throws InterruptedException {
previousZoomValue = StaticVars.getCurrentZoomValue();
StaticVars.windowZoom = 1;
previousZoomValue = StaticVars.windowZoomValue.next();
StaticVars.windowZoom.onNext(1f);
}
@Override
@ -36,7 +36,7 @@ public class LoadingScreen extends Screen {
endLoading += dt;
if (loaded && (StaticVars.debugOn || endLoading >= 3.5f)) {
StaticVars.windowZoom = previousZoomValue;
StaticVars.windowZoom.onNext(previousZoomValue);
HardwareDevice.INSTANCE.getDisplayManager().setScreen(new MathInputScreen());
}
mustRefresh = true;

View File

@ -61,7 +61,6 @@ public class MarioScreen extends Screen {
try {
gpuTest1 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadFont("gputest12");
gpuTest12 = true;
StaticVars.windowZoom = 1;
} catch (final Exception ex) {
gpuTest12 = false;
try {
@ -72,7 +71,9 @@ public class MarioScreen extends Screen {
if (gpuTest3 == null) {
try {
gpuTest3 = HardwareDevice.INSTANCE.getDisplayManager().engine.loadSkin("font_gputest3.png");
} catch (final Exception ex) {}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
} catch (final IOException e) {
e.printStackTrace();