Made DisplayManager not static and organized Imports
This commit is contained in:
parent
89d8073b96
commit
3ce9eb61df
3
.gitignore
vendored
3
.gitignore
vendored
@ -7,6 +7,9 @@
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
Thumbs.db
|
||||
font_easter.png
|
||||
font_easter.rft
|
||||
|
||||
/target/
|
||||
/backups/
|
||||
|
@ -6,10 +6,10 @@ import java.math.RoundingMode;
|
||||
import org.warp.picalculator.Utils;
|
||||
|
||||
public final class SafeMathContext {
|
||||
|
||||
|
||||
public static MathContext newMathContext(int precision) {
|
||||
if (precision <= 0) {
|
||||
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 ("+precision+")");
|
||||
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
|
||||
precision = 1;
|
||||
}
|
||||
return new MathContext(precision);
|
||||
@ -17,7 +17,7 @@ public final class SafeMathContext {
|
||||
|
||||
public static MathContext newMathContext(int precision, RoundingMode roundingMode) {
|
||||
if (precision <= 0) {
|
||||
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 ("+precision+")");
|
||||
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MIN, "Warning! MathContext precision is <= 0 (" + precision + ")");
|
||||
precision = 1;
|
||||
}
|
||||
return new MathContext(precision, roundingMode);
|
||||
|
@ -1,16 +1,9 @@
|
||||
package org.warp.picalculator;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.nevec.rjm.BigIntegerMath;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.screens.LoadingScreen;
|
||||
import org.warp.picalculator.gui.screens.Screen;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
||||
import com.pi4j.system.SystemInfo.BoardType;
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
@ -37,6 +30,8 @@ public class Main {
|
||||
Main.args = args;
|
||||
beforeStart();
|
||||
new DisplayManager(screen);
|
||||
afterStart();
|
||||
DisplayManager.INSTANCE.waitForExit();
|
||||
Utils.out.println(1, "Shutdown...");
|
||||
beforeShutdown();
|
||||
Utils.out.println(1, "");
|
||||
@ -45,7 +40,10 @@ public class Main {
|
||||
}
|
||||
|
||||
public void beforeStart() {
|
||||
boolean isRaspi = false; try {isRaspi = com.pi4j.system.SystemInfo.getBoardType() != BoardType.UNKNOWN;} catch (Exception e) {}
|
||||
boolean isRaspi = false;
|
||||
try {
|
||||
isRaspi = com.pi4j.system.SystemInfo.getBoardType() != BoardType.UNKNOWN;
|
||||
} catch (Exception e) {}
|
||||
if (Utils.isRunningOnRaspberry() && !Utils.isInArray("-noraspi", args) && isRaspi) {
|
||||
Gpio.wiringPiSetupPhys();
|
||||
Gpio.pinMode(12, Gpio.PWM_OUTPUT);
|
||||
@ -81,11 +79,13 @@ public class Main {
|
||||
Utils.msDosMode = true;
|
||||
}
|
||||
}
|
||||
DisplayManager.preInitialization();
|
||||
DisplayManager.setBrightness(0.2f);
|
||||
Keyboard.startKeyboard();
|
||||
}
|
||||
|
||||
public void afterStart() {
|
||||
DisplayManager.INSTANCE.setBrightness(0.2f);
|
||||
}
|
||||
|
||||
public void beforeShutdown() {
|
||||
Keyboard.stopKeyboard();
|
||||
}
|
||||
@ -120,7 +120,7 @@ public class Main {
|
||||
time2 = System.currentTimeMillis();
|
||||
System.out.println("BigIntegerMath HCN: "+(time2-time1)+" ("+empty.toString()+")");
|
||||
|
||||
|
||||
|
||||
bigintegers[0] = BigInteger.valueOf(LCN);
|
||||
for (int i = 0; i < max; i++) {
|
||||
bigintegers[i] = bigintegers[0];
|
||||
@ -139,7 +139,7 @@ public class Main {
|
||||
}
|
||||
time2 = System.currentTimeMillis();
|
||||
System.out.println("BigIntegerMath HCN: "+(time2-time1)+" ("+empty2.toString()+")");
|
||||
|
||||
|
||||
numbers[0] = new Number(mc, LCN);
|
||||
for (int i = 0; i < max; i++) {
|
||||
numbers[i] = numbers[0];
|
||||
|
@ -184,7 +184,7 @@ public class TestGPU {
|
||||
}
|
||||
}).start();
|
||||
|
||||
d.waitUntilExit();
|
||||
d.waitForExit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,7 @@ public class Utils {
|
||||
public static boolean debugThirdScreen;
|
||||
public static final boolean debugWindow2x = true;
|
||||
public static boolean headlessOverride = false;
|
||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||
public static String forceEngine;
|
||||
public static boolean msDosMode;
|
||||
|
||||
@ -65,7 +65,7 @@ public class Utils {
|
||||
public void println(String str) {
|
||||
println(0, str);
|
||||
}
|
||||
|
||||
|
||||
public void println(int level) {
|
||||
if (outputLevel >= level) {
|
||||
if (outputLevel == 0) {
|
||||
@ -75,7 +75,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void println(int level, String str) {
|
||||
if (outputLevel >= level) {
|
||||
if (outputLevel == 0) {
|
||||
@ -85,7 +85,7 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void print(int level, String str) {
|
||||
if (outputLevel >= level) {
|
||||
if (outputLevel == 0) {
|
||||
@ -451,12 +451,12 @@ public class Utils {
|
||||
//
|
||||
// var.draw(x + wsegno, y + (hsegno - h1), null, null);
|
||||
//
|
||||
// DisplayManager.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3);
|
||||
// DisplayManager.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2);
|
||||
// DisplayManager.renderer.glDrawLine(x + 3, y + hsegno - 1, x + 3, y + hsegno - 1);
|
||||
// DisplayManager.renderer.glDrawLine(x + 3, y + (hsegno - 1) / 2 + 1, x + 3, y + hsegno - 1);
|
||||
// DisplayManager.renderer.glDrawLine(x + 4, y, x + 4, y + (hsegno - 1) / 2);
|
||||
// DisplayManager.renderer.glDrawLine(x + 4, y, x + 4 + 1 + w1 + 1, y);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 1, y + hsegno - 3, x + 1, y + hsegno - 3);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 2, y + hsegno - 2, x + 2, y + hsegno - 2);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 3, y + hsegno - 1, x + 3, y + hsegno - 1);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 3, y + (hsegno - 1) / 2 + 1, x + 3, y + hsegno - 1);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 4, y, x + 4, y + (hsegno - 1) / 2);
|
||||
// DisplayManager.INSTANCE.renderer.glDrawLine(x + 4, y, x + 4 + 1 + w1 + 1, y);
|
||||
}
|
||||
|
||||
public static final int getFontHeight() {
|
||||
@ -468,7 +468,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static final BinaryFont getFont(boolean small, boolean zoomed) {
|
||||
return DisplayManager.fonts[getFontIndex(small, zoomed)];
|
||||
return DisplayManager.INSTANCE.fonts[getFontIndex(small, zoomed)];
|
||||
}
|
||||
|
||||
public static final int getFontIndex(boolean small, boolean zoomed) {
|
||||
@ -494,15 +494,15 @@ public class Utils {
|
||||
public static final int getFontHeight(boolean small, boolean zoomed) {
|
||||
if (small) {
|
||||
if (zoomed) {
|
||||
return DisplayManager.glyphsHeight[3];
|
||||
return DisplayManager.INSTANCE.glyphsHeight[3];
|
||||
} else {
|
||||
return DisplayManager.glyphsHeight[1];
|
||||
return DisplayManager.INSTANCE.glyphsHeight[1];
|
||||
}
|
||||
} else {
|
||||
if (zoomed) {
|
||||
return DisplayManager.glyphsHeight[2];
|
||||
return DisplayManager.INSTANCE.glyphsHeight[2];
|
||||
} else {
|
||||
return DisplayManager.glyphsHeight[0];
|
||||
return DisplayManager.INSTANCE.glyphsHeight[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@ public class CacheFile {
|
||||
private FileOutputStream lastFOS;
|
||||
private ObjectInputStream lastOIS;
|
||||
private FileInputStream lastFIS;
|
||||
|
||||
|
||||
public CacheFile() {
|
||||
do {
|
||||
path = UUID.randomUUID().toString()+".ser";
|
||||
path = UUID.randomUUID().toString() + ".ser";
|
||||
} while (Files.exists(Paths.get(path)));
|
||||
try {
|
||||
Files.createTempFile(Main.calculatorNameLOWER, "");
|
||||
@ -28,7 +28,7 @@ public class CacheFile {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ObjectOutputStream getObjectOutputStram() {
|
||||
if (lastOOS == null) {
|
||||
try {
|
||||
@ -41,7 +41,7 @@ public class CacheFile {
|
||||
return lastOOS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ObjectInputStream getObjectInputStram() {
|
||||
if (lastOIS == null) {
|
||||
try {
|
||||
|
@ -8,7 +8,6 @@ import org.warp.picalculator.device.chip.SerialToParallel;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.GUIErrorMessage;
|
||||
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
|
||||
import org.warp.picalculator.gui.screens.MarioScreen;
|
||||
import org.warp.picalculator.gui.screens.Screen;
|
||||
|
||||
import com.pi4j.wiringpi.Gpio;
|
||||
@ -780,7 +779,7 @@ public class Keyboard {
|
||||
} else {
|
||||
switch (k) {
|
||||
case POWER:
|
||||
DisplayManager.engine.destroy();
|
||||
DisplayManager.INSTANCE.engine.destroy();
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
@ -788,12 +787,12 @@ public class Keyboard {
|
||||
letterPressed('X');
|
||||
break;
|
||||
case BRIGHTNESS_CYCLE:
|
||||
DisplayManager.cycleBrightness(false);
|
||||
DisplayManager.INSTANCE.cycleBrightness(false);
|
||||
refresh = true;
|
||||
break;
|
||||
case BRIGHTNESS_CYCLE_REVERSE:
|
||||
DisplayManager.INSTANCE.setScreen(new MarioScreen()); //TODO: rimuovere: prova
|
||||
DisplayManager.cycleBrightness(true);
|
||||
//DisplayManager.INSTANCE.setScreen(new MarioScreen()); //TODO: rimuovere: prova
|
||||
DisplayManager.INSTANCE.cycleBrightness(true);
|
||||
refresh = true;
|
||||
break;
|
||||
case HISTORY_BACK:
|
||||
|
@ -1,9 +1,7 @@
|
||||
package org.warp.picalculator.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
@ -27,37 +25,30 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
public final class DisplayManager implements RenderingLoop {
|
||||
public static DisplayManager INSTANCE;
|
||||
private static float brightness;
|
||||
private float brightness;
|
||||
|
||||
public static final GraphicEngine engine;
|
||||
public static final boolean supportsPauses;
|
||||
public static Renderer renderer;
|
||||
public final GraphicEngine engine;
|
||||
public final boolean supportsPauses;
|
||||
public Renderer renderer;
|
||||
|
||||
public static Skin guiSkin;
|
||||
public static BinaryFont[] fonts;
|
||||
public Skin guiSkin;
|
||||
public BinaryFont[] fonts;
|
||||
|
||||
public static String error;
|
||||
public String error;
|
||||
public String[] errorStackTrace;
|
||||
public final static int[] glyphsHeight;
|
||||
public final int[] glyphsHeight;
|
||||
|
||||
private static Screen screen;
|
||||
public static Semaphore screenChange = new Semaphore(0);
|
||||
public static String displayDebugString;
|
||||
public static ObjectArrayList<GUIErrorMessage> errorMessages;
|
||||
|
||||
static {
|
||||
private Screen screen;
|
||||
public Semaphore screenChange = new Semaphore(0);
|
||||
public String displayDebugString;
|
||||
public ObjectArrayList<GUIErrorMessage> errorMessages;
|
||||
|
||||
public DisplayManager(Screen screen) {
|
||||
engine = chooseGraphicEngine();
|
||||
supportsPauses = engine.doesRefreshPauses();
|
||||
glyphsHeight = new int[] { 9, 6, 12, 9 };
|
||||
displayDebugString = "";
|
||||
errorMessages = new ObjectArrayList<>();
|
||||
}
|
||||
|
||||
public static void preInitialization() {
|
||||
//Nothing. When called for the first time the static methods will be loaded
|
||||
}
|
||||
|
||||
public DisplayManager(Screen screen) {
|
||||
setScreen(screen);
|
||||
INSTANCE = this;
|
||||
loop();
|
||||
@ -91,7 +82,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
* }
|
||||
*/
|
||||
|
||||
private static GraphicEngine chooseGraphicEngine() {
|
||||
private GraphicEngine chooseGraphicEngine() {
|
||||
GraphicEngine d;
|
||||
d = new GPUEngine();
|
||||
if (d.isSupported()) {
|
||||
@ -124,19 +115,19 @@ public final class DisplayManager implements RenderingLoop {
|
||||
public void setScreen(Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.canBeInHistory) {
|
||||
DisplayManager.currentSession = 0;
|
||||
for (int i = DisplayManager.sessions.length - 1; i >= 1; i--) {
|
||||
DisplayManager.sessions[i] = DisplayManager.sessions[i - 1];
|
||||
DisplayManager.INSTANCE.currentSession = 0;
|
||||
for (int i = DisplayManager.INSTANCE.sessions.length - 1; i >= 1; i--) {
|
||||
DisplayManager.INSTANCE.sessions[i] = DisplayManager.INSTANCE.sessions[i - 1];
|
||||
}
|
||||
DisplayManager.sessions[0] = screen;
|
||||
DisplayManager.INSTANCE.sessions[0] = screen;
|
||||
} else {
|
||||
DisplayManager.currentSession = -1;
|
||||
DisplayManager.INSTANCE.currentSession = -1;
|
||||
}
|
||||
}
|
||||
screen.d = this;
|
||||
try {
|
||||
screen.create();
|
||||
DisplayManager.screen = screen;
|
||||
DisplayManager.INSTANCE.screen = screen;
|
||||
screenChange.release();
|
||||
if (screen.initialized == false) {
|
||||
screen.initialize();
|
||||
@ -150,18 +141,18 @@ public final class DisplayManager implements RenderingLoop {
|
||||
public void replaceScreen(Screen screen) {
|
||||
if (screen.initialized == false) {
|
||||
if (screen.canBeInHistory) {
|
||||
DisplayManager.sessions[DisplayManager.currentSession] = screen;
|
||||
DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] = screen;
|
||||
} else {
|
||||
DisplayManager.currentSession = -1;
|
||||
for (int i = 0; i < DisplayManager.sessions.length - 2; i++) {
|
||||
DisplayManager.sessions[i] = DisplayManager.sessions[i + 1];
|
||||
DisplayManager.INSTANCE.currentSession = -1;
|
||||
for (int i = 0; i < DisplayManager.INSTANCE.sessions.length - 2; i++) {
|
||||
DisplayManager.INSTANCE.sessions[i] = DisplayManager.INSTANCE.sessions[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
screen.d = this;
|
||||
try {
|
||||
screen.create();
|
||||
DisplayManager.screen = screen;
|
||||
DisplayManager.INSTANCE.screen = screen;
|
||||
screenChange.release();
|
||||
if (screen.initialized == false) {
|
||||
screen.initialize();
|
||||
@ -173,13 +164,13 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
|
||||
public boolean canGoBack() {
|
||||
if (DisplayManager.currentSession == -1) {
|
||||
return DisplayManager.sessions[0] != null;
|
||||
if (DisplayManager.INSTANCE.currentSession == -1) {
|
||||
return DisplayManager.INSTANCE.sessions[0] != null;
|
||||
}
|
||||
if (DisplayManager.screen != DisplayManager.sessions[DisplayManager.currentSession]) {
|
||||
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
||||
|
||||
} else if (DisplayManager.currentSession + 1 < DisplayManager.sessions.length) {
|
||||
if (DisplayManager.sessions[DisplayManager.currentSession + 1] != null) {
|
||||
} else if (DisplayManager.INSTANCE.currentSession + 1 < DisplayManager.INSTANCE.sessions.length) {
|
||||
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession + 1] != null) {
|
||||
|
||||
} else {
|
||||
return false;
|
||||
@ -187,7 +178,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (DisplayManager.sessions[DisplayManager.currentSession] != null) {
|
||||
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -195,22 +186,22 @@ public final class DisplayManager implements RenderingLoop {
|
||||
|
||||
public void goBack() {
|
||||
if (canGoBack()) {
|
||||
if (DisplayManager.currentSession >= 0 && DisplayManager.screen != DisplayManager.sessions[DisplayManager.currentSession]) {} else {
|
||||
DisplayManager.currentSession += 1;
|
||||
if (DisplayManager.INSTANCE.currentSession >= 0 && DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {} else {
|
||||
DisplayManager.INSTANCE.currentSession += 1;
|
||||
}
|
||||
DisplayManager.screen = DisplayManager.sessions[DisplayManager.currentSession];
|
||||
DisplayManager.INSTANCE.screen = DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession];
|
||||
screenChange.release();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canGoForward() {
|
||||
if (DisplayManager.currentSession <= 0) { // -1 e 0
|
||||
if (DisplayManager.INSTANCE.currentSession <= 0) { // -1 e 0
|
||||
return false;
|
||||
}
|
||||
if (DisplayManager.screen != DisplayManager.sessions[DisplayManager.currentSession]) {
|
||||
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
||||
|
||||
} else if (DisplayManager.currentSession > 0) {
|
||||
if (DisplayManager.sessions[DisplayManager.currentSession - 1] != null) {
|
||||
} else if (DisplayManager.INSTANCE.currentSession > 0) {
|
||||
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession - 1] != null) {
|
||||
|
||||
} else {
|
||||
return false;
|
||||
@ -218,7 +209,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (DisplayManager.sessions[DisplayManager.currentSession] != null) {
|
||||
if (DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession] != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -226,18 +217,18 @@ public final class DisplayManager implements RenderingLoop {
|
||||
|
||||
public void goForward() {
|
||||
if (canGoForward()) {
|
||||
if (DisplayManager.screen != DisplayManager.sessions[DisplayManager.currentSession]) {
|
||||
if (DisplayManager.INSTANCE.screen != DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession]) {
|
||||
|
||||
} else {
|
||||
DisplayManager.currentSession -= 1;
|
||||
DisplayManager.INSTANCE.currentSession -= 1;
|
||||
}
|
||||
DisplayManager.screen = DisplayManager.sessions[DisplayManager.currentSession];
|
||||
DisplayManager.INSTANCE.screen = DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession];
|
||||
screenChange.release();
|
||||
}
|
||||
}
|
||||
|
||||
public static Screen getScreen() {
|
||||
return DisplayManager.screen;
|
||||
public Screen getScreen() {
|
||||
return DisplayManager.INSTANCE.screen;
|
||||
}
|
||||
|
||||
private void load_skin() throws IOException {
|
||||
@ -250,7 +241,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
fonts[1] = engine.loadFont("small");
|
||||
fonts[2] = engine.loadFont("ex");
|
||||
fonts[3] = engine.loadFont("big");
|
||||
fonts[4] = engine.loadFont("32");
|
||||
//4
|
||||
fonts[5] = engine.loadFont("square");
|
||||
}
|
||||
|
||||
@ -304,7 +295,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
|
||||
int padding = 2;
|
||||
|
||||
final int brightness = (int) (Math.ceil(DisplayManager.brightness * 9));
|
||||
final int brightness = (int) (Math.ceil(DisplayManager.INSTANCE.brightness * 9));
|
||||
if (brightness <= 10) {
|
||||
renderer.glFillRect(Main.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
|
||||
} else {
|
||||
@ -343,15 +334,15 @@ public final class DisplayManager implements RenderingLoop {
|
||||
private void draw_bottom() {
|
||||
renderer.glDrawStringLeft(2, 90, displayDebugString);
|
||||
|
||||
Utils.getFont(true, false).use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glColor4i(255, 0, 0, 40);
|
||||
DisplayManager.renderer.glDrawStringLeft(1 + 1, Main.screenSize[1] - 7 - 7 + 1, "WORK IN");
|
||||
DisplayManager.renderer.glColor4i(255, 0, 0, 80);
|
||||
DisplayManager.renderer.glDrawStringLeft(1, Main.screenSize[1] - 7 - 7, "WORK IN");
|
||||
DisplayManager.renderer.glColor4i(255, 0, 0, 40);
|
||||
DisplayManager.renderer.glDrawStringLeft(1 + 1, Main.screenSize[1] - 7 + 1, "PROGRESS.");
|
||||
DisplayManager.renderer.glColor4i(255, 0, 0, 80);
|
||||
DisplayManager.renderer.glDrawStringLeft(1, Main.screenSize[1] - 7, "PROGRESS.");
|
||||
Utils.getFont(true, false).use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, Main.screenSize[1] - 7 - 7 + 1, "WORK IN");
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, Main.screenSize[1] - 7 - 7, "WORK IN");
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 40);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1 + 1, Main.screenSize[1] - 7 + 1, "PROGRESS.");
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(255, 0, 0, 80);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringLeft(1, Main.screenSize[1] - 7, "PROGRESS.");
|
||||
}
|
||||
|
||||
private void draw_world() {
|
||||
@ -410,7 +401,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
|
||||
load_skin();
|
||||
load_fonts();
|
||||
|
||||
|
||||
try {
|
||||
screen.initialize();
|
||||
} catch (final Exception e) {
|
||||
@ -497,18 +488,16 @@ public final class DisplayManager implements RenderingLoop {
|
||||
workThread.start();
|
||||
|
||||
engine.start(getDrawable());
|
||||
|
||||
engine.waitUntilExit();
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} finally {}
|
||||
}
|
||||
|
||||
public static void changeBrightness(float change) {
|
||||
public void changeBrightness(float change) {
|
||||
setBrightness(brightness + change);
|
||||
}
|
||||
|
||||
public static void setBrightness(float newval) {
|
||||
public void setBrightness(float newval) {
|
||||
if (newval >= 0 && newval <= 1) {
|
||||
brightness = newval;
|
||||
if (Utils.debugOn == false) {
|
||||
@ -520,7 +509,7 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
}
|
||||
|
||||
public static void cycleBrightness(boolean reverse) {
|
||||
public void cycleBrightness(boolean reverse) {
|
||||
final float step = reverse ? -0.1f : 0.1f;
|
||||
if (brightness + step > 1f) {
|
||||
setBrightness(0f);
|
||||
@ -531,24 +520,28 @@ public final class DisplayManager implements RenderingLoop {
|
||||
}
|
||||
}
|
||||
|
||||
public static float getBrightness() {
|
||||
public float getBrightness() {
|
||||
return brightness;
|
||||
}
|
||||
|
||||
public static int currentSession = 0;
|
||||
public static Screen[] sessions = new Screen[5];
|
||||
public int currentSession = 0;
|
||||
public Screen[] sessions = new Screen[5];
|
||||
|
||||
@Deprecated
|
||||
public static void colore(float f1, float f2, float f3, float f4) {
|
||||
public void colore(float f1, float f2, float f3, float f4) {
|
||||
renderer.glColor4f(f1, f2, f3, f4);
|
||||
}
|
||||
|
||||
public static RenderingLoop getDrawable() {
|
||||
public RenderingLoop getDrawable() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void drawSkinPart(int x, int y, int uvX, int uvY, int uvX2, int uvY2) {
|
||||
public void drawSkinPart(int x, int y, int uvX, int uvY, int uvX2, int uvY2) {
|
||||
renderer.glFillRect(x, y, uvX2 - uvX, uvY2 - uvY, uvX, uvY, uvX2 - uvX, uvY2 - uvY);
|
||||
}
|
||||
|
||||
public void waitForExit() {
|
||||
engine.waitForExit();
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ public class Caret {
|
||||
private int[] lastLocation;
|
||||
|
||||
public Caret(CaretState state, int pos) {
|
||||
this(state, pos, new int[]{0, 0}, new int[]{2, 5});
|
||||
this(state, pos, new int[] { 0, 0 }, new int[] { 2, 5 });
|
||||
}
|
||||
|
||||
public Caret(CaretState state, int pos, int[] lastLocation, int[] lastSize) {
|
||||
@ -19,7 +19,7 @@ public class Caret {
|
||||
this.lastLocation = lastLocation;
|
||||
this.lastSize = lastSize;
|
||||
}
|
||||
|
||||
|
||||
public void skip(int i) {
|
||||
remaining -= i;
|
||||
}
|
||||
@ -59,21 +59,21 @@ public class Caret {
|
||||
}
|
||||
|
||||
public void setLastLocation(int x, int y) {
|
||||
lastLocation[0]=x;
|
||||
lastLocation[1]=y;
|
||||
lastLocation[0] = x;
|
||||
lastLocation[1] = y;
|
||||
}
|
||||
|
||||
|
||||
public int[] getLastLocation() {
|
||||
return new int[]{lastLocation[0],lastLocation[1]};
|
||||
return new int[] { lastLocation[0], lastLocation[1] };
|
||||
}
|
||||
|
||||
public void setLastSize(int w, int h) {
|
||||
lastSize[0]=w;
|
||||
lastSize[1]=h;
|
||||
lastSize[0] = w;
|
||||
lastSize[1] = h;
|
||||
}
|
||||
|
||||
|
||||
public int[] getLastSize() {
|
||||
return new int[]{lastSize[0],lastSize[1]};
|
||||
return new int[] { lastSize[0], lastSize[1] };
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,32 +8,32 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public abstract class ExtraMenu<T extends Block> implements Serializable, KeyboardEventListener {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -6944683477814944299L;
|
||||
|
||||
public ExtraMenu(T block) {
|
||||
this.block = block;
|
||||
this.location = new int[]{0,0};
|
||||
this.location = new int[] { 0, 0 };
|
||||
this.width = 0;
|
||||
this.height = 0;
|
||||
}
|
||||
|
||||
|
||||
public final T block;
|
||||
protected int width;
|
||||
protected int height;
|
||||
protected int[] location;
|
||||
|
||||
|
||||
public abstract void draw(GraphicEngine ge, Renderer r, Caret caret);
|
||||
|
||||
public abstract void open();
|
||||
|
||||
|
||||
public abstract void close();
|
||||
|
||||
public boolean beforeRender(float delta, Caret caret) {
|
||||
int[] l = caret.getLastLocation();
|
||||
int[] cs = caret.getLastSize();
|
||||
location[0]=l[0]-block.getWidth()/2-width/2;
|
||||
location[1]=l[1]+cs[1];
|
||||
location[0] = l[0] - block.getWidth() / 2 - width / 2;
|
||||
location[1] = l[1] + cs[1];
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,12 @@ import org.warp.picalculator.math.functions.Variable.V_TYPE;
|
||||
public class InputContext {
|
||||
public final HashMap<Character, V_TYPE> variableTypes;
|
||||
public BlockVariable variableTypeDirtyID = null;
|
||||
|
||||
|
||||
public InputContext() {
|
||||
this.variableTypes = new HashMap<>();
|
||||
this.variableTypes.put(MathematicalSymbols.PI, V_TYPE.CONSTANT);
|
||||
}
|
||||
|
||||
|
||||
public InputContext(HashMap<Character, V_TYPE> variableTypes) {
|
||||
this.variableTypes = variableTypes;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ public abstract class Block implements GraphicalElement {
|
||||
public boolean isSmall() {
|
||||
return small;
|
||||
}
|
||||
|
||||
|
||||
public abstract void setSmall(boolean small);
|
||||
|
||||
|
||||
public ExtraMenu<?> getExtraMenu() {
|
||||
return null;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class BlockChar extends Block {
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
width = BlockContainer.getDefaultCharWidth(small)-1;
|
||||
width = BlockContainer.getDefaultCharWidth(small) - 1;
|
||||
height = BlockContainer.getDefaultCharHeight(small);
|
||||
line = height / 2;
|
||||
}
|
||||
|
@ -199,14 +199,14 @@ public class BlockContainer implements GraphicalElement {
|
||||
|
||||
public Block getBlock(Caret caret) {
|
||||
Block block = null;
|
||||
|
||||
|
||||
int pos = 0;
|
||||
for (final Block b : content) {
|
||||
caret.skip(1);
|
||||
pos++;
|
||||
final int deltaCaret = caret.getRemaining();
|
||||
|
||||
block= b.getBlock(caret);
|
||||
|
||||
block = b.getBlock(caret);
|
||||
if (block != null) {
|
||||
return block;
|
||||
}
|
||||
@ -310,9 +310,9 @@ public class BlockContainer implements GraphicalElement {
|
||||
public static void drawCaret(GraphicEngine ge, Renderer r, Caret caret, boolean small, int x, int y, int height) {
|
||||
if (caret.getState() == CaretState.VISIBLE_ON) {
|
||||
r.glColor(getDefaultColor());
|
||||
r.glFillColor(x, y, small?2:3, height);
|
||||
r.glFillColor(x, y, small ? 2 : 3, height);
|
||||
caret.setLastLocation(x, y);
|
||||
caret.setLastSize(small?2:3, height);
|
||||
caret.setLastSize(small ? 2 : 3, height);
|
||||
}
|
||||
}
|
||||
|
||||
@ -352,12 +352,13 @@ public class BlockContainer implements GraphicalElement {
|
||||
|
||||
for (final Block block : blocks) {
|
||||
final Feature blockFeature = block.toFeature(context);
|
||||
if (blockFeature == null) throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known Block");
|
||||
if (blockFeature == null)
|
||||
throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known Block");
|
||||
blockFeatures.add(blockFeature);
|
||||
}
|
||||
|
||||
final Function result = MathParser.joinFeatures(context, blockFeatures);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -7,20 +7,20 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
public class BlockExponentialNotation extends BlockPower {
|
||||
private int bw;
|
||||
private int bh;
|
||||
|
||||
|
||||
@Override
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
r.glDrawStringLeft(x, y+height-bh, "ℯ℮");
|
||||
super.draw(ge, r, x+bw, y, caret);
|
||||
r.glDrawStringLeft(x, y + height - bh, "ℯ℮");
|
||||
super.draw(ge, r, x + bw, y, caret);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
super.recomputeDimensions();
|
||||
bw = (int) (BlockContainer.getDefaultCharWidth(small)*1.5);
|
||||
bw = (int) (BlockContainer.getDefaultCharWidth(small) * 1.5);
|
||||
bh = BlockContainer.getDefaultCharHeight(small);
|
||||
this.width+=bw;
|
||||
this.width += bw;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
package org.warp.picalculator.gui.expression.blocks;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.parser.features.FeatureParenthesis;
|
||||
|
@ -4,9 +4,7 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.parser.features.FeatureParenthesis;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
public abstract class BlockParenthesisAbstract extends Block {
|
||||
@ -21,10 +19,10 @@ public abstract class BlockParenthesisAbstract extends Block {
|
||||
protected BlockParenthesisAbstract(String prefix) {
|
||||
containerNumber = new BlockContainer(false);
|
||||
this.prefix = prefix;
|
||||
|
||||
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
||||
public BlockParenthesisAbstract() {
|
||||
containerNumber = new BlockContainer(false);
|
||||
this.prefix = null;
|
||||
@ -36,15 +34,15 @@ public abstract class BlockParenthesisAbstract extends Block {
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(BlockContainer.getDefaultColor());
|
||||
if (prefix != null) {
|
||||
r.glDrawStringLeft(x+1, y+line-chh/2, prefix);
|
||||
r.glDrawStringLeft(x + 1, y + line - chh / 2, prefix);
|
||||
}
|
||||
r.glDrawCharLeft(x+prw, y, '╭');
|
||||
r.glDrawCharLeft(x+prw, y+height-chh, '╰');
|
||||
r.glFillColor(x+prw+3, y+6, 2, height-6*2);
|
||||
r.glFillColor(x+width-5, y+6, 2, height-6*2);
|
||||
r.glDrawCharLeft(x+width-chw, y, '╮');
|
||||
r.glDrawCharLeft(x+width-chw, y+height-chh, '╯');
|
||||
containerNumber.draw(ge, r, x+prw+chw, y, caret);
|
||||
r.glDrawCharLeft(x + prw, y, '╭');
|
||||
r.glDrawCharLeft(x + prw, y + height - chh, '╰');
|
||||
r.glFillColor(x + prw + 3, y + 6, 2, height - 6 * 2);
|
||||
r.glFillColor(x + width - 5, y + 6, 2, height - 6 * 2);
|
||||
r.glDrawCharLeft(x + width - chw, y, '╮');
|
||||
r.glDrawCharLeft(x + width - chw, y + height - chh, '╯');
|
||||
containerNumber.draw(ge, r, x + prw + chw, y, caret);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,9 +73,9 @@ public abstract class BlockParenthesisAbstract extends Block {
|
||||
@Override
|
||||
public void recomputeDimensions() {
|
||||
if (prefix == null) {
|
||||
prw=0;
|
||||
prw = 0;
|
||||
} else {
|
||||
prw = 1+BlockContainer.getDefaultCharWidth(small)*prefix.length()+2;
|
||||
prw = 1 + BlockContainer.getDefaultCharWidth(small) * prefix.length() + 2;
|
||||
}
|
||||
chw = BlockContainer.getDefaultCharWidth(small);
|
||||
chh = BlockContainer.getDefaultCharHeight(small);
|
||||
|
@ -44,7 +44,7 @@ public class BlockPower extends Block {
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Block getBlock(Caret caret) {
|
||||
return containerExponent.getBlock(caret);
|
||||
@ -54,9 +54,9 @@ public class BlockPower extends Block {
|
||||
public void recomputeDimensions() {
|
||||
final int w2 = containerExponent.getWidth();
|
||||
final int h2 = containerExponent.getHeight();
|
||||
width = w2+1;
|
||||
height = h2+BlockContainer.getDefaultCharHeight(small)-3;
|
||||
line = h2+BlockContainer.getDefaultCharHeight(small)/2-3;
|
||||
width = w2 + 1;
|
||||
height = h2 + BlockContainer.getDefaultCharHeight(small) - 3;
|
||||
line = h2 + BlockContainer.getDefaultCharHeight(small) / 2 - 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,6 @@ package org.warp.picalculator.gui.expression.blocks;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.parser.features.FeatureParenthesis;
|
||||
import org.warp.picalculator.math.parser.features.FeatureSine;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public class BlockSquareRoot extends Block {
|
||||
}
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Block getBlock(Caret caret) {
|
||||
return containerNumber.getBlock(caret);
|
||||
|
@ -28,6 +28,7 @@ public class BlockVariable extends Block {
|
||||
public BlockVariable(InputContext ic, char ch) {
|
||||
this(ic, ch, false);
|
||||
}
|
||||
|
||||
public BlockVariable(InputContext ic, char ch, boolean typeLocked) {
|
||||
this.ic = ic;
|
||||
this.ch = ch;
|
||||
@ -47,7 +48,7 @@ public class BlockVariable extends Block {
|
||||
menu.mustRefreshMenu = true;
|
||||
}
|
||||
mustRefresh = true;
|
||||
System.out.println("retrieve:"+type.toString());
|
||||
System.out.println("retrieve:" + type.toString());
|
||||
}
|
||||
|
||||
public void pushValue() {
|
||||
@ -59,12 +60,12 @@ public class BlockVariable extends Block {
|
||||
ic.variableTypeDirtyID = null;
|
||||
}
|
||||
ic.variableTypes.put(ch, type);
|
||||
System.out.println("push:"+type.toString());
|
||||
System.out.println("push:" + type.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
|
||||
if(ic.variableTypeDirtyID != typeDirtyID) {
|
||||
if (ic.variableTypeDirtyID != typeDirtyID) {
|
||||
retrieveValue();
|
||||
}
|
||||
if (mustRefresh) {
|
||||
@ -82,7 +83,7 @@ public class BlockVariable extends Block {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BlockContainer.getDefaultFont(small).use(ge);
|
||||
r.glColor(color);
|
||||
r.glDrawCharLeft(x, y, ch);
|
||||
@ -124,7 +125,7 @@ public class BlockVariable extends Block {
|
||||
public int computeCaretMaxBound() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ExtraMenu<?> getExtraMenu() {
|
||||
return menu;
|
||||
@ -134,7 +135,7 @@ public class BlockVariable extends Block {
|
||||
|
||||
String text = "";
|
||||
boolean mustRefreshMenu = true;
|
||||
|
||||
|
||||
public VariableMenu(BlockVariable var) {
|
||||
super(var);
|
||||
}
|
||||
@ -143,12 +144,11 @@ public class BlockVariable extends Block {
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
public void close() {}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(Key k) {
|
||||
@ -206,9 +206,9 @@ public class BlockVariable extends Block {
|
||||
mustRefreshMenu = false;
|
||||
text = block.type.toString();
|
||||
BinaryFont f = BlockContainer.getDefaultFont(true);
|
||||
width = 7+f.getStringWidth(text)+7;
|
||||
height = 2+f.getCharacterHeight()+2;
|
||||
|
||||
width = 7 + f.getStringWidth(text) + 7;
|
||||
height = 2 + f.getCharacterHeight() + 2;
|
||||
|
||||
super.beforeRender(delta, caret);
|
||||
return true;
|
||||
}
|
||||
@ -218,7 +218,7 @@ public class BlockVariable extends Block {
|
||||
@Override
|
||||
public void draw(GraphicEngine ge, Renderer r, Caret caret) {
|
||||
r.glColor3f(1.0f, 1.0f, 1.0f);
|
||||
DisplayManager.guiSkin.use(ge);
|
||||
DisplayManager.INSTANCE.guiSkin.use(ge);
|
||||
int popupX = location[0];
|
||||
int popupY = location[1];
|
||||
if (popupX < 0) {
|
||||
@ -228,23 +228,23 @@ public class BlockVariable extends Block {
|
||||
popupY = 0;
|
||||
}
|
||||
int[] screenSize = ge.getSize();
|
||||
if (popupX+width >= screenSize[0]) {
|
||||
popupX=screenSize[0]-width-1;
|
||||
if (popupX + width >= screenSize[0]) {
|
||||
popupX = screenSize[0] - width - 1;
|
||||
}
|
||||
if (popupY+height >= screenSize[1]) {
|
||||
popupY=screenSize[1]-height-1;
|
||||
if (popupY + height >= screenSize[1]) {
|
||||
popupY = screenSize[1] - height - 1;
|
||||
}
|
||||
r.glFillRect(location[0]+width/2-5, popupY+1, 10, 5, 163, 16, 10, 5);
|
||||
r.glFillColor(popupX, popupY+5, width, height);
|
||||
r.glFillColor(popupX+2, popupY+4, width-4, height+2);
|
||||
r.glFillColor(popupX-1, popupY+7, width+2, height-4);
|
||||
r.glFillRect(popupX+2, popupY+5+height/2-7/2, 4, 7, 160, 21, 4, 7);
|
||||
r.glFillRect(popupX+width-2-4, popupY+5+height/2-7/2, 4, 7, 172, 21, 4, 7);
|
||||
r.glFillRect(location[0] + width / 2 - 5, popupY + 1, 10, 5, 163, 16, 10, 5);
|
||||
r.glFillColor(popupX, popupY + 5, width, height);
|
||||
r.glFillColor(popupX + 2, popupY + 4, width - 4, height + 2);
|
||||
r.glFillColor(popupX - 1, popupY + 7, width + 2, height - 4);
|
||||
r.glFillRect(popupX + 2, popupY + 5 + height / 2 - 7 / 2, 4, 7, 160, 21, 4, 7);
|
||||
r.glFillRect(popupX + width - 2 - 4, popupY + 5 + height / 2 - 7 / 2, 4, 7, 172, 21, 4, 7);
|
||||
r.glColor(color);
|
||||
BlockContainer.getDefaultFont(true).use(ge);
|
||||
r.glDrawStringCenter(popupX+width/2, popupY+2+5, text);
|
||||
r.glDrawStringCenter(popupX + width / 2, popupY + 2 + 5, text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,6 @@ package org.warp.picalculator.gui.expression.containers;
|
||||
import org.warp.picalculator.gui.expression.InputContext;
|
||||
import org.warp.picalculator.gui.expression.blocks.Block;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockChar;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
public class InlineInputContainer extends InputContainer {
|
||||
|
||||
@ -16,7 +15,7 @@ public class InlineInputContainer extends InputContainer {
|
||||
public InlineInputContainer() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public InlineInputContainer(InputContext ic) {
|
||||
super(ic);
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.parser.MathParser;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
@ -35,6 +33,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
public synchronized InputContext getInputContext() {
|
||||
return inputContext;
|
||||
}
|
||||
|
||||
@Deprecated()
|
||||
/**
|
||||
* Use InputContainer(InputContext) instead
|
||||
@ -75,7 +74,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
public void typeChar(String c) {
|
||||
typeChar(c.charAt(0));
|
||||
}
|
||||
|
||||
|
||||
public void del() {
|
||||
caret.resetRemaining();
|
||||
if (root.delBlock(caret)) {
|
||||
@ -90,7 +89,6 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
closeExtra();
|
||||
}
|
||||
|
||||
|
||||
public Block getSelectedBlock() {
|
||||
caret.resetRemaining();
|
||||
Block selectedBlock = root.getBlock(caret);
|
||||
@ -102,7 +100,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
if (curPos > 0) {
|
||||
caret.setPosition(curPos - 1);
|
||||
} else {
|
||||
caret.setPosition(maxPosition-1);
|
||||
caret.setPosition(maxPosition - 1);
|
||||
}
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
@ -157,9 +155,9 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
somethingChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (extra != null) {
|
||||
somethingChanged = somethingChanged|extra.beforeRender(delta, caret);
|
||||
somethingChanged = somethingChanged | extra.beforeRender(delta, caret);
|
||||
}
|
||||
|
||||
return somethingChanged;
|
||||
@ -237,21 +235,22 @@ public abstract class InputContainer implements GraphicalElement, InputLayout, S
|
||||
extra = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void closeExtra() {
|
||||
if (extra != null) {
|
||||
extra.close();
|
||||
extra = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isExtraOpened() {
|
||||
return extra != null;
|
||||
}
|
||||
|
||||
|
||||
public KeyboardEventListener getExtraKeyboardEventListener() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public Function toFunction(MathContext context) throws Error {
|
||||
return root.toFunction(context);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ public class NormalInputContainer extends InputContainer {
|
||||
public NormalInputContainer() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public NormalInputContainer(InputContext ic) {
|
||||
super(ic);
|
||||
}
|
||||
@ -77,7 +77,7 @@ public class NormalInputContainer extends InputContainer {
|
||||
return new BlockChar(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void typeChar(char c) {
|
||||
super.typeChar(c);
|
||||
|
@ -31,7 +31,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
roots = new ObjectArrayList<>();
|
||||
roots.add(new BlockContainer(small));
|
||||
}
|
||||
|
||||
|
||||
public void setContentAsSingleGroup(ObjectArrayList<Block> blocks) {
|
||||
roots.clear();
|
||||
BlockContainer bcnt = new BlockContainer();
|
||||
@ -41,7 +41,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
roots.add(bcnt);
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
||||
public void setContentAsMultipleGroups(ObjectArrayList<ObjectArrayList<Block>> roots) {
|
||||
this.roots.clear();
|
||||
for (ObjectArrayList<Block> blocks : roots) {
|
||||
@ -53,7 +53,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
}
|
||||
recomputeDimensions();
|
||||
}
|
||||
|
||||
|
||||
public void setContentAsMultipleElements(ObjectArrayList<Block> elems) {
|
||||
this.roots.clear();
|
||||
for (Block block : elems) {
|
||||
@ -76,7 +76,8 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
int maxw = 0;
|
||||
for (BlockContainer root : roots) {
|
||||
int w = root.getWidth();
|
||||
if (w > maxw) maxw = w;
|
||||
if (w > maxw)
|
||||
maxw = w;
|
||||
}
|
||||
return maxw;
|
||||
}
|
||||
@ -85,10 +86,10 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
public int getHeight() {
|
||||
int h = 0;
|
||||
for (BlockContainer root : roots) {
|
||||
h+=root.getHeight()+2;
|
||||
h += root.getHeight() + 2;
|
||||
}
|
||||
if (h > 0) {
|
||||
return h-2;
|
||||
return h - 2;
|
||||
} else {
|
||||
return h;
|
||||
}
|
||||
@ -122,8 +123,8 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
||||
int offset = 0;
|
||||
for (BlockContainer root : roots) {
|
||||
root.draw(ge, r, x, y+offset, caret);
|
||||
offset+=root.getHeight()+2;
|
||||
root.draw(ge, r, x, y + offset, caret);
|
||||
offset += root.getHeight() + 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,7 +135,7 @@ public abstract class OutputContainer implements GraphicalElement, OutputLayout,
|
||||
}
|
||||
|
||||
public boolean isContentEmpty() {
|
||||
for(BlockContainer root : roots) {
|
||||
for (BlockContainer root : roots) {
|
||||
ObjectArrayList<Block> cnt = root.getContent();
|
||||
if (cnt != null && !cnt.isEmpty()) {
|
||||
return false;
|
||||
|
@ -1,4 +1,3 @@
|
||||
package org.warp.picalculator.gui.expression.containers;
|
||||
|
||||
public interface OutputLayout {
|
||||
}
|
||||
public interface OutputLayout {}
|
||||
|
@ -2,7 +2,6 @@ package org.warp.picalculator.gui.graphicengine;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public interface GraphicEngine {
|
||||
|
||||
@ -17,7 +16,7 @@ public interface GraphicEngine {
|
||||
public void setDisplayMode(final int ww, final int wh);
|
||||
|
||||
public void create();
|
||||
|
||||
|
||||
public void create(Runnable object);
|
||||
|
||||
public boolean wasResized();
|
||||
@ -38,7 +37,7 @@ public interface GraphicEngine {
|
||||
|
||||
public Skin loadSkin(String file) throws IOException;
|
||||
|
||||
public void waitUntilExit();
|
||||
public void waitForExit();
|
||||
|
||||
public boolean isSupported();
|
||||
|
||||
@ -47,7 +46,7 @@ public interface GraphicEngine {
|
||||
public default boolean supportsFontRegistering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public default List<BinaryFont> getRegisteredFonts() {
|
||||
return null;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ public interface Skin {
|
||||
public void load(String file) throws IOException;
|
||||
|
||||
public void initialize(GraphicEngine d);
|
||||
|
||||
|
||||
public boolean isInitialized();
|
||||
|
||||
public void use(GraphicEngine d);
|
||||
|
@ -1,21 +1,15 @@
|
||||
package org.warp.picalculator.gui.graphicengine.cpu;
|
||||
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
@ -48,12 +42,12 @@ public class CPUEngine implements GraphicEngine {
|
||||
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB);
|
||||
INSTANCE.wasResized = false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
create(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
INSTANCE = new SwingWindow(this);
|
||||
@ -126,7 +120,7 @@ public class CPUEngine implements GraphicEngine {
|
||||
|
||||
@Deprecated()
|
||||
public void refresh() {
|
||||
if (DisplayManager.getScreen() == null || (DisplayManager.error != null && DisplayManager.error.length() > 0) || DisplayManager.getScreen() == null || DisplayManager.getScreen().mustBeRefreshed()) {
|
||||
if (DisplayManager.INSTANCE.getScreen() == null || (DisplayManager.INSTANCE.error != null && DisplayManager.INSTANCE.error.length() > 0) || DisplayManager.INSTANCE.getScreen() == null || DisplayManager.INSTANCE.getScreen().mustBeRefreshed()) {
|
||||
INSTANCE.c.repaint();
|
||||
}
|
||||
}
|
||||
@ -176,16 +170,16 @@ public class CPUEngine implements GraphicEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilExit() {
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "cpu") return false;
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "cpu")
|
||||
return false;
|
||||
return (Utils.headlessOverride || GraphicsEnvironment.isHeadless()) == false;
|
||||
}
|
||||
|
||||
|
@ -148,8 +148,7 @@ public class CPUFont implements BinaryFont {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
}
|
||||
public void initialize(GraphicEngine d) {}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
|
@ -7,306 +7,306 @@ import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
||||
public class CPURenderer implements Renderer {
|
||||
public int clearcolor = 0xFFc5c2af;
|
||||
public CPUFont currentFont;
|
||||
public CPUSkin currentSkin;
|
||||
public int color = 0xFF000000;
|
||||
public int[] size = new int[] { 1, 1 };
|
||||
static int[] canvas2d = new int[1];
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
glColor4i(r, gg, b, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor(int c) {
|
||||
color = c & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(int c) {
|
||||
clearcolor = c & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4i(int red, int green, int blue, int alpha) {
|
||||
color = (alpha << 24) + (red << 16) + (green << 8) + (blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4i(int red, int green, int blue, int alpha) {
|
||||
clearcolor = (alpha << 24) + (red << 16) + (green << 8) + (blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearcolor = ((int) (alpha * 255) << 24) + ((int) (red * 255) << 16) + ((int) (green * 255) << 8) + ((int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int screenWidth, int screenHeight) {
|
||||
for (int x = 0; x < screenWidth; x++) {
|
||||
for (int y = 0; y < screenHeight; y++) {
|
||||
canvas2d[x + y * size[0]] = clearcolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
|
||||
x0 += Main.screenPos[0];
|
||||
y0 += Main.screenPos[1];
|
||||
int oldColor;
|
||||
int newColor;
|
||||
final int onex = s0 <= s1 ? 1 : -1;
|
||||
final int oney = t0 <= t1 ? 1 : -1;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (onex == -1) {
|
||||
final int s00 = s0;
|
||||
s0 = s1;
|
||||
s1 = s00;
|
||||
width = s1 - s0;
|
||||
}
|
||||
if (oney == -1) {
|
||||
final int t00 = t0;
|
||||
t0 = t1;
|
||||
t1 = t00;
|
||||
height = t1 - t0;
|
||||
}
|
||||
if (x0 >= size[0] || y0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 + width >= size[0]) {
|
||||
s1 = size[0] - x0 + s0;
|
||||
}
|
||||
if (y0 + height >= size[1]) {
|
||||
t1 = size[1] - y0 + t0;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
if (onex == -1) {
|
||||
width += x0;
|
||||
s1 += x0 + 1;
|
||||
} else {
|
||||
s0 -= x0;
|
||||
}
|
||||
x0 = 0;
|
||||
}
|
||||
if (y0 < 0) {
|
||||
if (oney == -1) {
|
||||
height += y0;
|
||||
t1 += y0 + 1;
|
||||
} else {
|
||||
t0 -= y0;
|
||||
}
|
||||
y0 = 0;
|
||||
}
|
||||
int pixelX;
|
||||
int pixelY;
|
||||
for (int texx = 0; texx < s1 - s0; texx++) {
|
||||
for (int texy = 0; texy < t1 - t0; texy++) {
|
||||
pixelX = (x0 + texx * onex + width);
|
||||
pixelY = (y0 + texy * oney + height);
|
||||
if (pixelX - (pixelX % size[0]) == 0) {
|
||||
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
|
||||
if (transparent) {
|
||||
oldColor = canvas2d[pixelX + pixelY * size[0]];
|
||||
final float a2 = (newColor >> 24 & 0xFF) / 255f;
|
||||
final float a1 = 1f - a2;
|
||||
final int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
|
||||
final int g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
|
||||
final int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
|
||||
newColor = 0xFF000000 | r << 16 | g << 8 | b;
|
||||
}
|
||||
canvas2d[pixelX + pixelY * size[0]] = newColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1) {
|
||||
x0 += Main.screenPos[0];
|
||||
x1 += Main.screenPos[0];
|
||||
y0 += Main.screenPos[1];
|
||||
y1 += Main.screenPos[1];
|
||||
final int ix0 = (int) x0;
|
||||
final int ix1 = (int) x1;
|
||||
final int iy0 = (int) y0;
|
||||
final int iy1 = (int) y1;
|
||||
if (ix0 >= size[0] || iy0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (iy0 == iy1) {
|
||||
for (int x = 0; x <= ix1 - ix0; x++) {
|
||||
if ((ix0 + x < size[0]) & (iy0 < size[1])) {
|
||||
canvas2d[ix0 + x + iy0 * size[0]] = color;
|
||||
}
|
||||
}
|
||||
} else if (ix0 == ix1) {
|
||||
for (int y = 0; y <= iy1 - iy0; y++) {
|
||||
if ((ix0 < size[0]) & (iy0 + y < size[1])) {
|
||||
canvas2d[ix0 + (iy0 + y) * size[0]] = color;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final int m = (iy1 - iy0) / (ix1 - ix0);
|
||||
for (int texx = 0; texx <= ix1 - ix0; texx++) {
|
||||
if (ix0 + texx < size[0] && iy0 + (m * texx) < size[1]) {
|
||||
if ((ix0 + texx < size[0]) & ((iy0 + (m * texx)) < size[1])) {
|
||||
canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) x, (int) y, (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
x += Main.screenPos[0];
|
||||
y += Main.screenPos[1];
|
||||
|
||||
final int ix = (int) x;
|
||||
final int iy = (int) y;
|
||||
final int iw = (int) width;
|
||||
final int ih = (int) height;
|
||||
|
||||
int x0 = ix;
|
||||
int y0 = iy;
|
||||
int x1 = ix + iw;
|
||||
int y1 = iy + ih;
|
||||
if (ix >= size[0] || iy >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
x0 = 0;
|
||||
}
|
||||
if (x1 >= size[0]) {
|
||||
x1 = size[0];
|
||||
}
|
||||
if (y0 < 0) {
|
||||
y0 = 0;
|
||||
}
|
||||
if (y1 >= size[1]) {
|
||||
y1 = size[1];
|
||||
}
|
||||
final int sizeW = size[0];
|
||||
for (int px = x0; px < x1; px++) {
|
||||
for (int py = y0; py < y1; py++) {
|
||||
canvas2d[(px) + (py) * sizeW] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String textString) {
|
||||
x += Main.screenPos[0];
|
||||
y += Main.screenPos[1];
|
||||
|
||||
final int ix = (int) x;
|
||||
final int iy = (int) y;
|
||||
|
||||
final int[] text = currentFont.getCharIndexes(textString);
|
||||
final int[] screen = canvas2d;
|
||||
final int[] screenSize = size;
|
||||
final int screenLength = screen.length;
|
||||
int screenPos = 0;
|
||||
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
int cpos;
|
||||
int j;
|
||||
final int l = text.length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
cpos = (i * (currentFont.charW));
|
||||
final int charIndex = text[i];
|
||||
for (int dy = 0; dy < currentFont.charH; dy++) {
|
||||
for (int dx = 0; dx < currentFont.charW; dx++) {
|
||||
j = ix + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
final int bit = dx + dy * currentFont.charW;
|
||||
currentInt = (int) (Math.floor(bit) / (CPUFont.intBits));
|
||||
currentIntBitPosition = bit - (currentInt * CPUFont.intBits);
|
||||
bitData = (currentFont.chars32[charIndex * currentFont.charIntCount + currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = ix + cpos + dx + (iy + dy) * screenSize[0];
|
||||
if (bitData == 1 & screenLength > screenPos) {
|
||||
screen[screenPos] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
glDrawStringLeft(x - (currentFont.getStringWidth(text) / 2), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
glDrawStringLeft(x - currentFont.getStringWidth(text), y, text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int glGetFontWidth(FontMetrics fm, String text) {
|
||||
return fm.stringWidth(text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int glGetCurrentFontHeight() {
|
||||
return currentFont.charH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetClearColor() {
|
||||
return clearcolor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryFont getCurrentFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
glColor3i((int) (red * 255f), (int) (green * 255f), (int) (blue * 255f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
glColor4i((int) (red * 255f), (int) (green * 255f), (int) (blue * 255f), (int) (alpha * 255f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
glDrawStringLeft(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawStringCenter(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
glDrawStringRight(x, y, ch + "");
|
||||
}
|
||||
public int clearcolor = 0xFFc5c2af;
|
||||
public CPUFont currentFont;
|
||||
public CPUSkin currentSkin;
|
||||
public int color = 0xFF000000;
|
||||
public int[] size = new int[] { 1, 1 };
|
||||
static int[] canvas2d = new int[1];
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
glColor4i(r, gg, b, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor(int c) {
|
||||
color = c & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor(int c) {
|
||||
clearcolor = c & 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4i(int red, int green, int blue, int alpha) {
|
||||
color = (alpha << 24) + (red << 16) + (green << 8) + (blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4i(int red, int green, int blue, int alpha) {
|
||||
clearcolor = (alpha << 24) + (red << 16) + (green << 8) + (blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearcolor = ((int) (alpha * 255) << 24) + ((int) (red * 255) << 16) + ((int) (green * 255) << 8) + ((int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClear(int screenWidth, int screenHeight) {
|
||||
for (int x = 0; x < screenWidth; x++) {
|
||||
for (int y = 0; y < screenHeight; y++) {
|
||||
canvas2d[x + y * size[0]] = clearcolor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
|
||||
x0 += Main.screenPos[0];
|
||||
y0 += Main.screenPos[1];
|
||||
int oldColor;
|
||||
int newColor;
|
||||
final int onex = s0 <= s1 ? 1 : -1;
|
||||
final int oney = t0 <= t1 ? 1 : -1;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (onex == -1) {
|
||||
final int s00 = s0;
|
||||
s0 = s1;
|
||||
s1 = s00;
|
||||
width = s1 - s0;
|
||||
}
|
||||
if (oney == -1) {
|
||||
final int t00 = t0;
|
||||
t0 = t1;
|
||||
t1 = t00;
|
||||
height = t1 - t0;
|
||||
}
|
||||
if (x0 >= size[0] || y0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 + width >= size[0]) {
|
||||
s1 = size[0] - x0 + s0;
|
||||
}
|
||||
if (y0 + height >= size[1]) {
|
||||
t1 = size[1] - y0 + t0;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
if (onex == -1) {
|
||||
width += x0;
|
||||
s1 += x0 + 1;
|
||||
} else {
|
||||
s0 -= x0;
|
||||
}
|
||||
x0 = 0;
|
||||
}
|
||||
if (y0 < 0) {
|
||||
if (oney == -1) {
|
||||
height += y0;
|
||||
t1 += y0 + 1;
|
||||
} else {
|
||||
t0 -= y0;
|
||||
}
|
||||
y0 = 0;
|
||||
}
|
||||
int pixelX;
|
||||
int pixelY;
|
||||
for (int texx = 0; texx < s1 - s0; texx++) {
|
||||
for (int texy = 0; texy < t1 - t0; texy++) {
|
||||
pixelX = (x0 + texx * onex + width);
|
||||
pixelY = (y0 + texy * oney + height);
|
||||
if (pixelX - (pixelX % size[0]) == 0) {
|
||||
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
|
||||
if (transparent) {
|
||||
oldColor = canvas2d[pixelX + pixelY * size[0]];
|
||||
final float a2 = (newColor >> 24 & 0xFF) / 255f;
|
||||
final float a1 = 1f - a2;
|
||||
final int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
|
||||
final int g = (int) ((oldColor >> 8 & 0xFF) * a1 + (newColor >> 8 & 0xFF) * a2);
|
||||
final int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
|
||||
newColor = 0xFF000000 | r << 16 | g << 8 | b;
|
||||
}
|
||||
canvas2d[pixelX + pixelY * size[0]] = newColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x0, float y0, float x1, float y1) {
|
||||
x0 += Main.screenPos[0];
|
||||
x1 += Main.screenPos[0];
|
||||
y0 += Main.screenPos[1];
|
||||
y1 += Main.screenPos[1];
|
||||
final int ix0 = (int) x0;
|
||||
final int ix1 = (int) x1;
|
||||
final int iy0 = (int) y0;
|
||||
final int iy1 = (int) y1;
|
||||
if (ix0 >= size[0] || iy0 >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (iy0 == iy1) {
|
||||
for (int x = 0; x <= ix1 - ix0; x++) {
|
||||
if ((ix0 + x < size[0]) & (iy0 < size[1])) {
|
||||
canvas2d[ix0 + x + iy0 * size[0]] = color;
|
||||
}
|
||||
}
|
||||
} else if (ix0 == ix1) {
|
||||
for (int y = 0; y <= iy1 - iy0; y++) {
|
||||
if ((ix0 < size[0]) & (iy0 + y < size[1])) {
|
||||
canvas2d[ix0 + (iy0 + y) * size[0]] = color;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final int m = (iy1 - iy0) / (ix1 - ix0);
|
||||
for (int texx = 0; texx <= ix1 - ix0; texx++) {
|
||||
if (ix0 + texx < size[0] && iy0 + (m * texx) < size[1]) {
|
||||
if ((ix0 + texx < size[0]) & ((iy0 + (m * texx)) < size[1])) {
|
||||
canvas2d[(ix0 + texx) + (iy0 + (m * texx)) * size[0]] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) x, (int) y, (int) uvX, (int) uvY, (int) (uvWidth + uvX), (int) (uvHeight + uvY), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
x += Main.screenPos[0];
|
||||
y += Main.screenPos[1];
|
||||
|
||||
final int ix = (int) x;
|
||||
final int iy = (int) y;
|
||||
final int iw = (int) width;
|
||||
final int ih = (int) height;
|
||||
|
||||
int x0 = ix;
|
||||
int y0 = iy;
|
||||
int x1 = ix + iw;
|
||||
int y1 = iy + ih;
|
||||
if (ix >= size[0] || iy >= size[0]) {
|
||||
return;
|
||||
}
|
||||
if (x0 < 0) {
|
||||
x0 = 0;
|
||||
}
|
||||
if (x1 >= size[0]) {
|
||||
x1 = size[0];
|
||||
}
|
||||
if (y0 < 0) {
|
||||
y0 = 0;
|
||||
}
|
||||
if (y1 >= size[1]) {
|
||||
y1 = size[1];
|
||||
}
|
||||
final int sizeW = size[0];
|
||||
for (int px = x0; px < x1; px++) {
|
||||
for (int py = y0; py < y1; py++) {
|
||||
canvas2d[(px) + (py) * sizeW] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String textString) {
|
||||
x += Main.screenPos[0];
|
||||
y += Main.screenPos[1];
|
||||
|
||||
final int ix = (int) x;
|
||||
final int iy = (int) y;
|
||||
|
||||
final int[] text = currentFont.getCharIndexes(textString);
|
||||
final int[] screen = canvas2d;
|
||||
final int[] screenSize = size;
|
||||
final int screenLength = screen.length;
|
||||
int screenPos = 0;
|
||||
|
||||
int currentInt;
|
||||
int currentIntBitPosition;
|
||||
int bitData;
|
||||
int cpos;
|
||||
int j;
|
||||
final int l = text.length;
|
||||
for (int i = 0; i < l; i++) {
|
||||
cpos = (i * (currentFont.charW));
|
||||
final int charIndex = text[i];
|
||||
for (int dy = 0; dy < currentFont.charH; dy++) {
|
||||
for (int dx = 0; dx < currentFont.charW; dx++) {
|
||||
j = ix + cpos + dx;
|
||||
if (j > 0 & j < screenSize[0]) {
|
||||
final int bit = dx + dy * currentFont.charW;
|
||||
currentInt = (int) (Math.floor(bit) / (CPUFont.intBits));
|
||||
currentIntBitPosition = bit - (currentInt * CPUFont.intBits);
|
||||
bitData = (currentFont.chars32[charIndex * currentFont.charIntCount + currentInt] >> currentIntBitPosition) & 1;
|
||||
screenPos = ix + cpos + dx + (iy + dy) * screenSize[0];
|
||||
if (bitData == 1 & screenLength > screenPos) {
|
||||
screen[screenPos] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
glDrawStringLeft(x - (currentFont.getStringWidth(text) / 2), y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
glDrawStringLeft(x - currentFont.getStringWidth(text), y, text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int glGetFontWidth(FontMetrics fm, String text) {
|
||||
return fm.stringWidth(text);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int glGetCurrentFontHeight() {
|
||||
return currentFont.charH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int glGetClearColor() {
|
||||
return clearcolor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BinaryFont getCurrentFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
glColor3i((int) (red * 255f), (int) (green * 255f), (int) (blue * 255f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
glColor4i((int) (red * 255f), (int) (green * 255f), (int) (blue * 255f), (int) (alpha * 255f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
glDrawStringLeft(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawStringCenter(x, y, ch + "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
glDrawStringRight(x, y, ch + "");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ import java.awt.image.DataBufferInt;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
@ -61,7 +59,7 @@ public class SwingWindow extends JFrame {
|
||||
addComponentListener(new ComponentListener() {
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
DisplayManager.engine.destroy();
|
||||
DisplayManager.INSTANCE.engine.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -402,7 +402,7 @@ public class DeallocationHelper {
|
||||
attachmentOrByteBufferFieldMap.put(bufferClass, bufferField);
|
||||
}
|
||||
} catch (final ClassNotFoundException cnfe) {// TODO The Java version
|
||||
// isn't very useful
|
||||
// isn't very useful
|
||||
// under
|
||||
// Android as it is
|
||||
// always zero, rather
|
||||
@ -419,7 +419,7 @@ public class DeallocationHelper {
|
||||
// if a known implementation has drastically changed or if the current
|
||||
// implementation is unknown
|
||||
if (attachmentOrByteBufferFieldNameMap.isEmpty()) {// detects everything
|
||||
// with the
|
||||
// with the
|
||||
// reflection API
|
||||
// creates all
|
||||
// possible kinds of
|
||||
@ -581,7 +581,7 @@ public class DeallocationHelper {
|
||||
}
|
||||
// if there is no known implementation class of the direct byte buffers
|
||||
if (deallocatableBufferClassSet.isEmpty()) {// creates a read write
|
||||
// direct byte buffer
|
||||
// direct byte buffer
|
||||
final ByteBuffer dummyReadWriteDirectByteBuffer = ByteBuffer.allocateDirect(1);
|
||||
// gets its class
|
||||
final Class<?> readWriteDirectByteBufferClass = dummyReadWriteDirectByteBuffer.getClass();
|
||||
@ -625,7 +625,7 @@ public class DeallocationHelper {
|
||||
final ByteBuffer deallocatableDirectByteBuffer;
|
||||
// looks only for the direct buffers
|
||||
if (buffer != null && buffer.isDirect()) {// looks for any contained
|
||||
// buffer in the passed buffer
|
||||
// buffer in the passed buffer
|
||||
final Class<?> bufferClass = buffer.getClass();
|
||||
final Field attachmentOrByteBufferField = attachmentOrByteBufferFieldMap == null ? null : attachmentOrByteBufferFieldMap.get(bufferClass);
|
||||
final Buffer attachmentBufferOrByteBuffer;
|
||||
@ -650,20 +650,20 @@ public class DeallocationHelper {
|
||||
}
|
||||
// if there is no buffer inside the buffer given in input
|
||||
if (attachmentBufferOrByteBuffer == null) {// if it's a direct byte
|
||||
// buffer and if it's an
|
||||
// buffer and if it's an
|
||||
// instance of
|
||||
// a deallocatable buffer
|
||||
// class
|
||||
if (buffer instanceof ByteBuffer && deallocatableBufferClassSet.contains(bufferClass)) {
|
||||
deallocatableDirectByteBuffer = (ByteBuffer) buffer;
|
||||
} else {// it's not a byte buffer or it's not a
|
||||
// deallocatable buffer
|
||||
// deallocatable buffer
|
||||
deallocatableDirectByteBuffer = null;
|
||||
final String bufferClassName = bufferClass.getName();
|
||||
logger.warning("No deallocatable buffer has been found for an instance of the class " + bufferClassName + " whereas it is a direct NIO buffer");
|
||||
}
|
||||
} else {// the passed buffer contains another buffer, looks for a
|
||||
// deallocatable buffer inside it
|
||||
// deallocatable buffer inside it
|
||||
deallocatableDirectByteBuffer = findDeallocatableBuffer(attachmentBufferOrByteBuffer);
|
||||
}
|
||||
} else {// there is no need to clean the heap based buffers
|
||||
|
@ -1,10 +1,6 @@
|
||||
package org.warp.picalculator.gui.graphicengine.gpu;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
@ -64,7 +60,7 @@ public class GPUEngine implements GraphicEngine {
|
||||
public void create() {
|
||||
create(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
created = true;
|
||||
@ -129,25 +125,26 @@ public class GPUEngine implements GraphicEngine {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilExit() {
|
||||
public void waitForExit() {
|
||||
try {
|
||||
exitSemaphore.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "gpu") return false;
|
||||
if (Utils.headlessOverride) return false;
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "gpu")
|
||||
return false;
|
||||
if (Utils.headlessOverride)
|
||||
return false;
|
||||
boolean available = false;
|
||||
boolean errored = false;
|
||||
try {
|
||||
available = GLProfile.isAvailable(GLProfile.GL2ES1);
|
||||
} catch (Exception ex) {
|
||||
errored = true;
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
errored = true;
|
||||
System.err.println(ex.getMessage());
|
||||
}
|
||||
if (!available && !errored) {
|
||||
System.err.println(GLProfile.glAvailabilityToString());
|
||||
}
|
||||
@ -158,7 +155,7 @@ public class GPUEngine implements GraphicEngine {
|
||||
public boolean doesRefreshPauses() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void registerFont(GPUFont gpuFont) {
|
||||
registeredFonts.add(gpuFont);
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class GPUFont implements BinaryFont {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void genTexture() {
|
||||
try {
|
||||
texture = GPURenderer.importTexture(tmpFont);
|
||||
|
@ -3,7 +3,6 @@ package org.warp.picalculator.gui.graphicengine.gpu;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -29,7 +28,7 @@ public class GPURenderer implements Renderer {
|
||||
|
||||
private static final int ELEMENT_VERTICES_COUNT = 6;
|
||||
private static final int ELEMENTS_MAX_COUNT_PER_BUFFER = 128;
|
||||
|
||||
|
||||
private final DeallocationHelper deallocationHelper = new DeallocationHelper();
|
||||
FloatBuffer fbVertices;
|
||||
FloatBuffer txVertices;
|
||||
@ -51,40 +50,19 @@ public class GPURenderer implements Renderer {
|
||||
final float gre = (gg) / 255f;
|
||||
final float blu = (b) / 255f;
|
||||
//currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, };
|
||||
currentColor = new float[] {
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
}; //OK
|
||||
currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, }; //OK
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float gre, float blu) {
|
||||
// currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, };
|
||||
currentColor = new float[] {
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
red, gre, blu, 1.0f,
|
||||
};//OK
|
||||
currentColor = new float[] { red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, red, gre, blu, 1.0f, };//OK
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float gre, float blu, float alp) {
|
||||
// currentColor = new float[] { red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, };
|
||||
currentColor = new float[] {
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
};//ok
|
||||
currentColor = new float[] { red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, };//ok
|
||||
|
||||
}
|
||||
|
||||
@ -118,14 +96,7 @@ public class GPURenderer implements Renderer {
|
||||
final float blu = (b) / 255f;
|
||||
final float alp = (a) / 255f;
|
||||
//currentColor = new float[] { red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, };
|
||||
currentColor = new float[] {
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
red, gre, blu, alp,
|
||||
};//OK
|
||||
currentColor = new float[] { red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, red, gre, blu, alp, };//OK
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -167,31 +138,17 @@ public class GPURenderer implements Renderer {
|
||||
//V1 x, y + height, 0.0f
|
||||
//V2 x + width, y, 0.0f
|
||||
//V3 x + width, y + height, 0.0f
|
||||
|
||||
|
||||
//NV0 = V1
|
||||
//NV1 = V3
|
||||
//NV2 = V0
|
||||
|
||||
|
||||
//NV3 = V0
|
||||
//NV4 = V3
|
||||
//NV5 = V2
|
||||
|
||||
final float[] vertices = {
|
||||
x, y + height, 0.0f,
|
||||
x + width, y + height, 0.0f,
|
||||
x, y, 0.0f,
|
||||
x, y, 0.0f,
|
||||
x + width, y + height, 0.0f,
|
||||
x + width, y, 0.0f
|
||||
};
|
||||
final float[] tex_vertices = {
|
||||
uvX, uvY,
|
||||
uvX + uvWidth, uvY,
|
||||
uvX, uvY + uvHeight,
|
||||
uvX, uvY + uvHeight,
|
||||
uvX + uvWidth, uvY,
|
||||
uvX + uvWidth, uvY + uvHeight
|
||||
};
|
||||
|
||||
final float[] vertices = { x, y + height, 0.0f, x + width, y + height, 0.0f, x, y, 0.0f, x, y, 0.0f, x + width, y + height, 0.0f, x + width, y, 0.0f };
|
||||
final float[] tex_vertices = { uvX, uvY, uvX + uvWidth, uvY, uvX, uvY + uvHeight, uvX, uvY + uvHeight, uvX + uvWidth, uvY, uvX + uvWidth, uvY + uvHeight };
|
||||
fbElements++;
|
||||
fbVertices.put(vertices);
|
||||
txVertices.put(tex_vertices);
|
||||
@ -207,31 +164,17 @@ public class GPURenderer implements Renderer {
|
||||
//V1 x0, y0 + h1, 0.0f
|
||||
//V2 x0 + w1, y0, 0.0f
|
||||
//V3 x0 + w1, y0 + h1, 0.0f
|
||||
|
||||
|
||||
//NV0 = V1
|
||||
//NV1 = V3
|
||||
//NV2 = V0
|
||||
|
||||
|
||||
//NV3 = V0
|
||||
//NV4 = V3
|
||||
//NV5 = V2
|
||||
|
||||
final float[] vertices = {
|
||||
x0, y0 + h1, 0.0f,
|
||||
x0 + w1, y0 + h1, 0.0f,
|
||||
x0, y0, 0.0f,
|
||||
x0, y0, 0.0f,
|
||||
x0 + w1, y0 + h1, 0.0f,
|
||||
x0 + w1, y0, 0.0f,
|
||||
};
|
||||
final float[] tex_vertices = {
|
||||
0.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
final float[] vertices = { x0, y0 + h1, 0.0f, x0 + w1, y0 + h1, 0.0f, x0, y0, 0.0f, x0, y0, 0.0f, x0 + w1, y0 + h1, 0.0f, x0 + w1, y0, 0.0f, };
|
||||
final float[] tex_vertices = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, };
|
||||
fbElements++;
|
||||
fbVertices.put(vertices);
|
||||
txVertices.put(tex_vertices);
|
||||
@ -328,7 +271,7 @@ public class GPURenderer implements Renderer {
|
||||
public void updateDrawCycle() {
|
||||
updateDrawCycle(false, false);
|
||||
}
|
||||
|
||||
|
||||
public void updateDrawCycle(boolean first, boolean last) {
|
||||
final boolean textureChange = precTexEnabled != currentTexEnabled || precTex != currentTex;
|
||||
final boolean changeRequired = last || fbElements >= ELEMENTS_MAX_COUNT_PER_BUFFER;
|
||||
@ -359,7 +302,7 @@ public class GPURenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void endDrawCycle() {
|
||||
fbVertices.limit(fbVertices.position());
|
||||
txVertices.limit(txVertices.position());
|
||||
@ -400,7 +343,7 @@ public class GPURenderer implements Renderer {
|
||||
updateDrawCycle();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void disableTexture() {
|
||||
currentTexEnabled = false;
|
||||
updateDrawCycle();
|
||||
|
@ -97,7 +97,7 @@ class NEWTWindow implements GLEventListener {
|
||||
|
||||
@Override
|
||||
public void windowDestroyed(WindowEvent e) {
|
||||
DisplayManager.engine.destroy();
|
||||
DisplayManager.INSTANCE.engine.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -280,7 +280,7 @@ class NEWTWindow implements GLEventListener {
|
||||
@Override
|
||||
public void init(GLAutoDrawable drawable) {
|
||||
final GL2ES1 gl = drawable.getGL().getGL2ES1();
|
||||
|
||||
|
||||
//Vsync
|
||||
gl.setSwapInterval(2);
|
||||
|
||||
@ -335,7 +335,7 @@ class NEWTWindow implements GLEventListener {
|
||||
@Override
|
||||
public void display(GLAutoDrawable glad) {
|
||||
final GL2ES1 gl = glad.getGL().getGL2ES1();
|
||||
|
||||
|
||||
GPURenderer.gl = gl;
|
||||
|
||||
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
|
||||
|
@ -1,23 +1,14 @@
|
||||
package org.warp.picalculator.gui.graphicengine.headless24bit;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Console;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.fusesource.jansi.internal.Kernel32;
|
||||
import org.fusesource.jansi.internal.Kernel32.INPUT_RECORD;
|
||||
import org.fusesource.jansi.internal.WindowsSupport;
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
|
||||
@ -28,16 +19,16 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
private RenderingLoop renderLoop;
|
||||
public static final int C_MUL_X = 4;//8;
|
||||
public static final int C_MUL_Y = 8;//8;
|
||||
protected static final int C_WIDTH = Main.screenSize[0]/C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1]/C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
protected static final int C_WIDTH = Main.screenSize[0] / C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1] / C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
private String title = Main.calculatorName;
|
||||
private boolean win = false;
|
||||
private Key precKey = null;
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
new ConsoleHandler();
|
||||
return new int[]{r.size[0], r.size[1]};
|
||||
return new int[] { r.size[0], r.size[1] };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,87 +44,87 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
@Override
|
||||
public void setResizable(boolean r) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
private long outHandle;
|
||||
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
this.create(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
Utils.outputLevel = -1;
|
||||
AnsiConsole.systemInstall();
|
||||
if(Utils.isWindows() && !Utils.msDosMode){
|
||||
if (Utils.isWindows() && !Utils.msDosMode) {
|
||||
win = true;
|
||||
WindowsSupport.setConsoleMode(0x0200);
|
||||
Thread t = new Thread(()-> {
|
||||
Thread t = new Thread(() -> {
|
||||
int ch = -1;
|
||||
while(true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
while (true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch (ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch(ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
@ -197,68 +188,68 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
@Override
|
||||
public void repaint() {
|
||||
renderLoop.refresh();
|
||||
r.curColor = new int[] {0x00, 0x87, 0x00};
|
||||
r.glDrawStringCenter((C_WIDTH*C_MUL_X)/2, 0, title);
|
||||
r.curColor = new int[] { 0x00, 0x87, 0x00 };
|
||||
r.glDrawStringCenter((C_WIDTH * C_MUL_X) / 2, 0, title);
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
} else {
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
}
|
||||
int[] precBgColor = new int[] {-1, -1, -1};
|
||||
int[] precFgColor = new int[] {-1, -1, -1};
|
||||
int[] curBgColor = new int[] {-1, -1, -1};
|
||||
int[] curFgColor = new int[] {-1, -1, -1};
|
||||
int[] precBgColor = new int[] { -1, -1, -1 };
|
||||
int[] precFgColor = new int[] { -1, -1, -1 };
|
||||
int[] curBgColor = new int[] { -1, -1, -1 };
|
||||
int[] curFgColor = new int[] { -1, -1, -1 };
|
||||
String out = "";
|
||||
char outchar = ' ';
|
||||
for (int y = 0; y < C_HEIGHT; y++) {
|
||||
for (int x = 0; x < C_WIDTH; x++) {
|
||||
//BG color
|
||||
int[][] pixs = new int[C_MUL_X*C_MUL_Y][];
|
||||
int[][] pixs = new int[C_MUL_X * C_MUL_Y][];
|
||||
for (int paddY = 0; paddY < C_MUL_Y; paddY++) {
|
||||
for (int paddX = 0; paddX < C_MUL_X; paddX++) {
|
||||
pixs[paddX+paddY*C_MUL_X] = r.bgColorMatrixSs[(x*C_MUL_X+paddX)+(y*C_MUL_Y+paddY)*r.size[0]];
|
||||
pixs[paddX + paddY * C_MUL_X] = r.bgColorMatrixSs[(x * C_MUL_X + paddX) + (y * C_MUL_Y + paddY) * r.size[0]];
|
||||
}
|
||||
}
|
||||
int[] newpix = new int[3];
|
||||
for (int i = 0; i < pixs.length; i++) {
|
||||
newpix[0]+=pixs[i][0];
|
||||
newpix[1]+=pixs[i][1];
|
||||
newpix[2]+=pixs[i][2];
|
||||
newpix[0] += pixs[i][0];
|
||||
newpix[1] += pixs[i][1];
|
||||
newpix[2] += pixs[i][2];
|
||||
}
|
||||
newpix[0]/=pixs.length;
|
||||
newpix[1]/=pixs.length;
|
||||
newpix[2]/=pixs.length;
|
||||
r.bgColorMatrix[x+y*C_WIDTH] = newpix;
|
||||
|
||||
newpix[0] /= pixs.length;
|
||||
newpix[1] /= pixs.length;
|
||||
newpix[2] /= pixs.length;
|
||||
r.bgColorMatrix[x + y * C_WIDTH] = newpix;
|
||||
|
||||
//FG color
|
||||
pixs = new int[C_MUL_X*C_MUL_Y][];
|
||||
pixs = new int[C_MUL_X * C_MUL_Y][];
|
||||
for (int paddY = 0; paddY < C_MUL_Y; paddY++) {
|
||||
for (int paddX = 0; paddX < C_MUL_X; paddX++) {
|
||||
pixs[paddX+paddY*C_MUL_X] = r.fgColorMatrixSs[(x*C_MUL_X+paddX)+(y*C_MUL_Y+paddY)*r.size[0]];
|
||||
pixs[paddX + paddY * C_MUL_X] = r.fgColorMatrixSs[(x * C_MUL_X + paddX) + (y * C_MUL_Y + paddY) * r.size[0]];
|
||||
}
|
||||
}
|
||||
newpix = new int[3];
|
||||
for (int i = 0; i < pixs.length; i++) {
|
||||
newpix[0]+=pixs[i][0];
|
||||
newpix[1]+=pixs[i][1];
|
||||
newpix[2]+=pixs[i][2];
|
||||
newpix[0] += pixs[i][0];
|
||||
newpix[1] += pixs[i][1];
|
||||
newpix[2] += pixs[i][2];
|
||||
}
|
||||
newpix[0]/=pixs.length;
|
||||
newpix[1]/=pixs.length;
|
||||
newpix[2]/=pixs.length;
|
||||
r.fgColorMatrix[x+y*C_WIDTH] = newpix;
|
||||
newpix[0] /= pixs.length;
|
||||
newpix[1] /= pixs.length;
|
||||
newpix[2] /= pixs.length;
|
||||
r.fgColorMatrix[x + y * C_WIDTH] = newpix;
|
||||
}
|
||||
}
|
||||
for (int y = 0; y < C_HEIGHT; y++) {
|
||||
for (int x = 0; x < C_WIDTH; x++) {
|
||||
curBgColor = r.bgColorMatrix[x+y*C_WIDTH];
|
||||
curFgColor = r.fgColorMatrix[x+y*C_WIDTH];
|
||||
curBgColor = r.bgColorMatrix[x + y * C_WIDTH];
|
||||
curFgColor = r.fgColorMatrix[x + y * C_WIDTH];
|
||||
if (precBgColor != curBgColor) {
|
||||
out = Headless24bitRenderer.ANSI_PREFIX+Headless24bitRenderer.ansiBgColorPrefix+curBgColor[0]+";"+curBgColor[1]+";"+curBgColor[2]+Headless24bitRenderer.ansiColorSuffix;
|
||||
out = Headless24bitRenderer.ANSI_PREFIX + Headless24bitRenderer.ansiBgColorPrefix + curBgColor[0] + ";" + curBgColor[1] + ";" + curBgColor[2] + Headless24bitRenderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(out);
|
||||
} else {
|
||||
@ -266,25 +257,25 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
}
|
||||
}
|
||||
if (precFgColor != curFgColor) {
|
||||
out = Headless24bitRenderer.ANSI_PREFIX+Headless24bitRenderer.ansiFgColorPrefix+curFgColor[0]+";"+curFgColor[1]+";"+curFgColor[2]+Headless24bitRenderer.ansiColorSuffix;
|
||||
out = Headless24bitRenderer.ANSI_PREFIX + Headless24bitRenderer.ansiFgColorPrefix + curFgColor[0] + ";" + curFgColor[1] + ";" + curFgColor[2] + Headless24bitRenderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(out);
|
||||
} else {
|
||||
AnsiConsole.out.print(out);
|
||||
}
|
||||
}
|
||||
|
||||
outchar = r.charmatrix[x+y*C_WIDTH];
|
||||
|
||||
outchar = r.charmatrix[x + y * C_WIDTH];
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(outchar+"");
|
||||
WindowsSupport.writeConsole(outchar + "");
|
||||
} else {
|
||||
AnsiConsole.out.print(outchar);
|
||||
}
|
||||
|
||||
|
||||
precBgColor = curBgColor;
|
||||
precFgColor = curFgColor;
|
||||
}
|
||||
|
||||
|
||||
if (win) {
|
||||
//System.out.println(ch);
|
||||
WindowsSupport.writeConsole("\r\n");
|
||||
@ -310,11 +301,11 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilExit() {
|
||||
public void waitForExit() {
|
||||
try {
|
||||
do {
|
||||
Thread.sleep(500);
|
||||
} while (stopped==false);
|
||||
} while (stopped == false);
|
||||
} catch (final InterruptedException e) {
|
||||
|
||||
}
|
||||
@ -322,7 +313,8 @@ public class Headless24bitEngine implements org.warp.picalculator.gui.graphiceng
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-24bit")) return false;
|
||||
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-24bit"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,24 +9,24 @@ public class Headless24bitFont implements BinaryFont {
|
||||
|
||||
@Override
|
||||
public void load(String file) throws IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(String text) {
|
||||
return 5*text.length();
|
||||
return 5 * text.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,32 +5,30 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
public class Headless24bitRenderer implements Renderer {
|
||||
|
||||
Headless24bitFont currentFont;
|
||||
public int[] size = new int[] { Headless24bitEngine.C_WIDTH*Headless24bitEngine.C_MUL_X, Headless24bitEngine.C_HEIGHT*Headless24bitEngine.C_MUL_Y };
|
||||
protected int[][] fgColorMatrixSs = new int[size[0]*size[1]][3];
|
||||
protected int[][] bgColorMatrixSs = new int[size[0]*size[1]][3];
|
||||
|
||||
|
||||
protected char[] charmatrix = new char[Headless24bitEngine.C_WIDTH*Headless24bitEngine.C_HEIGHT];
|
||||
protected int[][] fgColorMatrix = new int[Headless24bitEngine.C_WIDTH*Headless24bitEngine.C_HEIGHT][3];
|
||||
protected int[][] bgColorMatrix = new int[Headless24bitEngine.C_WIDTH*Headless24bitEngine.C_HEIGHT][3];
|
||||
public int[] size = new int[] { Headless24bitEngine.C_WIDTH * Headless24bitEngine.C_MUL_X, Headless24bitEngine.C_HEIGHT * Headless24bitEngine.C_MUL_Y };
|
||||
protected int[][] fgColorMatrixSs = new int[size[0] * size[1]][3];
|
||||
protected int[][] bgColorMatrixSs = new int[size[0] * size[1]][3];
|
||||
|
||||
protected char[] charmatrix = new char[Headless24bitEngine.C_WIDTH * Headless24bitEngine.C_HEIGHT];
|
||||
protected int[][] fgColorMatrix = new int[Headless24bitEngine.C_WIDTH * Headless24bitEngine.C_HEIGHT][3];
|
||||
protected int[][] bgColorMatrix = new int[Headless24bitEngine.C_WIDTH * Headless24bitEngine.C_HEIGHT][3];
|
||||
protected int[] clearColor = rgbToIntArray(0xc5, 0xc2, 0xaf);
|
||||
protected int[] curColor = new int[] {clearColor[0], clearColor[1], clearColor[2]};
|
||||
protected int[] curColor = new int[] { clearColor[0], clearColor[1], clearColor[2] };
|
||||
public Headless24bitSkin currentSkin;
|
||||
|
||||
public static final String ANSI_PREFIX = "\u001B[";
|
||||
public static final String ansiFgColorPrefix = "38;2;";
|
||||
public static final String ansiBgColorPrefix = "48;2;";
|
||||
public static final String ansiColorSuffix = "m";
|
||||
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final char FILL = 0xDB;
|
||||
public static final int[] TRANSPARENT = new int[] {0,0,0, 1};
|
||||
public static final int[] TRANSPARENT = new int[] { 0, 0, 0, 1 };
|
||||
|
||||
|
||||
public static int[] rgbToIntArray(int r_U, int g_U, int b_U) {
|
||||
return new int[] {r_U, g_U, b_U};
|
||||
return new int[] { r_U, g_U, b_U };
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
curColor = rgbToIntArray(r, gg, b);
|
||||
@ -48,12 +46,12 @@ public class Headless24bitRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
curColor = rgbToIntArray((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = rgbToIntArray((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
curColor = rgbToIntArray((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = rgbToIntArray((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,7 +61,7 @@ public class Headless24bitRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearColor = rgbToIntArray((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
clearColor = rgbToIntArray((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -83,7 +81,7 @@ public class Headless24bitRenderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x1, float y1, float x2, float y2) {
|
||||
|
||||
|
||||
int dx = (int) Math.abs(x2 - x1);
|
||||
int dy = (int) Math.abs(y2 - y1);
|
||||
|
||||
@ -93,33 +91,33 @@ public class Headless24bitRenderer implements Renderer {
|
||||
int err = dx - dy;
|
||||
|
||||
while (true) {
|
||||
if (((int)x1) >= size[0] || ((int)y1) >= size[1] ||
|
||||
((int)x2) >= size[0] || ((int)y2) >= size[1]) {
|
||||
if (((int) x1) >= size[0] || ((int) y1) >= size[1] || ((int) x2) >= size[0] || ((int) y2) >= size[1]) {
|
||||
break;
|
||||
}
|
||||
bgColorMatrixSs[((int)x1) + ((int)y1) * size[0]] = curColor;
|
||||
charmatrix[((int)x1/Headless24bitEngine.C_MUL_X) + ((int)y1/Headless24bitEngine.C_MUL_Y) * Headless24bitEngine.C_WIDTH] = ' ';
|
||||
bgColorMatrixSs[((int) x1) + ((int) y1) * size[0]] = curColor;
|
||||
charmatrix[((int) x1 / Headless24bitEngine.C_MUL_X) + ((int) y1 / Headless24bitEngine.C_MUL_Y) * Headless24bitEngine.C_WIDTH] = ' ';
|
||||
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
|
||||
int e2 = 2 * err;
|
||||
int e2 = 2 * err;
|
||||
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) (x), (int) (y), (int) (uvX), (int) (uvY), (int) ((uvWidth + uvX)), (int) ((uvHeight + uvY)), true);
|
||||
} else {
|
||||
@ -150,11 +148,10 @@ public class Headless24bitRenderer implements Renderer {
|
||||
for (int py = iy; py < y1; py++) {
|
||||
drawPixelAt(' ', curColor, px, py);
|
||||
bgColorMatrixSs[(px) + (py) * sizeW] = curColor;
|
||||
charmatrix[(px/Headless24bitEngine.C_MUL_X) + (py/Headless24bitEngine.C_MUL_Y) * sizeW/Headless24bitEngine.C_MUL_X] = ' ';
|
||||
charmatrix[(px / Headless24bitEngine.C_MUL_X) + (py / Headless24bitEngine.C_MUL_Y) * sizeW / Headless24bitEngine.C_MUL_X] = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
@ -163,52 +160,52 @@ public class Headless24bitRenderer implements Renderer {
|
||||
if (cx >= size[0] || cy >= size[1]) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx/Headless24bitEngine.C_MUL_X+cy/Headless24bitEngine.C_MUL_Y*Headless24bitEngine.C_WIDTH] = ch;
|
||||
fgColorMatrixSs[cx+cy*size[0]] = curColor;
|
||||
charmatrix[cx / Headless24bitEngine.C_MUL_X + cy / Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = ch;
|
||||
fgColorMatrixSs[cx + cy * size[0]] = curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawCharLeft(x,y,ch);
|
||||
glDrawCharLeft(x, y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
final int cx = x-1*Headless24bitEngine.C_MUL_X;
|
||||
final int cx = x - 1 * Headless24bitEngine.C_MUL_X;
|
||||
final int cy = y;
|
||||
if (cx >= size[0] || cy >= size[1]) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx/Headless24bitEngine.C_MUL_X+cy/Headless24bitEngine.C_MUL_Y*Headless24bitEngine.C_WIDTH] = ch;
|
||||
fgColorMatrixSs[cx+cy*size[0]] = curColor;
|
||||
charmatrix[cx / Headless24bitEngine.C_MUL_X + cy / Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = ch;
|
||||
fgColorMatrixSs[cx + cy * size[0]] = curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String text) {
|
||||
final int cx = (int)x;
|
||||
final int cy = (int)y;
|
||||
final int cx = (int) x;
|
||||
final int cy = (int) y;
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= size[0] || cy >= size[1]) {
|
||||
if (cx + i >= size[0] || cy >= size[1]) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx/Headless24bitEngine.C_MUL_X+i+cy/Headless24bitEngine.C_MUL_Y*Headless24bitEngine.C_WIDTH] = c;
|
||||
fgColorMatrixSs[cx+i+cy*size[0]] = curColor;
|
||||
charmatrix[cx / Headless24bitEngine.C_MUL_X + i + cy / Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = c;
|
||||
fgColorMatrixSs[cx + i + cy * size[0]] = curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
final int cx = ((int)x)-(text.length()/2)*Headless24bitEngine.C_MUL_X;
|
||||
final int cy = ((int)y);
|
||||
final int cx = ((int) x) - (text.length() / 2) * Headless24bitEngine.C_MUL_X;
|
||||
final int cy = ((int) y);
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= size[0] || cy >= size[1]) {
|
||||
if (cx + i >= size[0] || cy >= size[1]) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx/Headless24bitEngine.C_MUL_X+i+cy/Headless24bitEngine.C_MUL_Y*Headless24bitEngine.C_WIDTH] = c;
|
||||
fgColorMatrixSs[cx+i+cy*size[0]] = curColor;
|
||||
charmatrix[cx / Headless24bitEngine.C_MUL_X + i + cy / Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = c;
|
||||
fgColorMatrixSs[cx + i + cy * size[0]] = curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -216,9 +213,8 @@ public class Headless24bitRenderer implements Renderer {
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
|
||||
int[] newColor;
|
||||
@ -276,7 +272,7 @@ public class Headless24bitRenderer implements Renderer {
|
||||
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
|
||||
if (transparent) {
|
||||
if (newColor.length == 3 || (newColor.length == 4 && newColor[3] != 1)) {
|
||||
charmatrix[pixelX/Headless24bitEngine.C_MUL_X + pixelY/Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = ' ';
|
||||
charmatrix[pixelX / Headless24bitEngine.C_MUL_X + pixelY / Headless24bitEngine.C_MUL_Y * Headless24bitEngine.C_WIDTH] = ' ';
|
||||
bgColorMatrixSs[pixelX + pixelY * size[0]] = newColor;
|
||||
}
|
||||
}
|
||||
@ -285,23 +281,23 @@ public class Headless24bitRenderer implements Renderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void drawPixelAt(char ch, int[] color, double x, double y) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
|
||||
protected void clearAll() {
|
||||
for (int i = 0; i < Headless24bitEngine.C_WIDTH*Headless24bitEngine.C_HEIGHT; i++) {
|
||||
charmatrix[i]=' ';
|
||||
for (int i = 0; i < Headless24bitEngine.C_WIDTH * Headless24bitEngine.C_HEIGHT; i++) {
|
||||
charmatrix[i] = ' ';
|
||||
}
|
||||
for (int i = 0; i < size[0]*size[1]; i++) {
|
||||
for (int i = 0; i < size[0] * size[1]; i++) {
|
||||
bgColorMatrixSs[i] = clearColor;
|
||||
fgColorMatrixSs[i] = new int[] {0,0,0};
|
||||
fgColorMatrixSs[i] = new int[] { 0, 0, 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@ -309,5 +305,5 @@ public class Headless24bitRenderer implements Renderer {
|
||||
public Headless24bitFont getCurrentFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.warp.picalculator.gui.graphicengine.headless24bit;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -27,20 +25,19 @@ public class Headless24bitSkin implements Skin {
|
||||
}
|
||||
|
||||
public static int[][] getMatrixOfImage(BufferedImage bufferedImage) {
|
||||
|
||||
|
||||
|
||||
final int width = bufferedImage.getWidth(null);
|
||||
final int height = bufferedImage.getHeight(null);
|
||||
final int[][] pixels = new int[width * height][];
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
int rgb = bufferedImage.getRGB(i, j);
|
||||
int r = (rgb >> 16) &0xFF;
|
||||
int g = (rgb >> 8) &0xFF;
|
||||
int b = rgb &0xFF;
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
boolean transparent = ((rgb >> 24) & 0xFF) <= 128;
|
||||
int[] curCol = Headless24bitRenderer.rgbToIntArray(r, g, b);
|
||||
pixels[i + j * width] = new int[] {curCol[0], curCol[1], curCol[2], transparent?1:0};
|
||||
pixels[i + j * width] = new int[] { curCol[0], curCol[1], curCol[2], transparent ? 1 : 0 };
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,7 +46,7 @@ public class Headless24bitSkin implements Skin {
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,5 +59,4 @@ public class Headless24bitSkin implements Skin {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.warp.picalculator.gui.graphicengine.headless256;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
@ -10,7 +9,6 @@ import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
|
||||
@ -22,16 +20,16 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
private RenderingLoop renderLoop;
|
||||
public static final int C_MUL_X = 4;//8;
|
||||
public static final int C_MUL_Y = 8;//8;
|
||||
protected static final int C_WIDTH = Main.screenSize[0]/C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1]/C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
protected static final int C_WIDTH = Main.screenSize[0] / C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1] / C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
private String title = Main.calculatorName;
|
||||
private boolean win = false;
|
||||
private Key precKey = null;
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
new ConsoleHandler();
|
||||
return new int[]{C_WIDTH, C_HEIGHT};
|
||||
return new int[] { C_WIDTH, C_HEIGHT };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -47,85 +45,85 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
@Override
|
||||
public void setResizable(boolean r) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
this.create(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
Utils.outputLevel = -1;
|
||||
AnsiConsole.systemInstall();
|
||||
if(Utils.isWindows() && !Utils.msDosMode){
|
||||
if (Utils.isWindows() && !Utils.msDosMode) {
|
||||
win = true;
|
||||
WindowsSupport.setConsoleMode(0x0200);
|
||||
Thread t = new Thread(()-> {
|
||||
Thread t = new Thread(() -> {
|
||||
int ch = -1;
|
||||
while(true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
while (true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch (ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch(ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
@ -144,12 +142,12 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return C_WIDTH*C_MUL_X;
|
||||
return C_WIDTH * C_MUL_X;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return C_HEIGHT*C_MUL_Y;
|
||||
return C_HEIGHT * C_MUL_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -190,15 +188,15 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
public void repaint() {
|
||||
renderLoop.refresh();
|
||||
r.curColor = 0x1C;
|
||||
r.glDrawStringCenter((C_WIDTH*C_MUL_X)/2, 0, title);
|
||||
r.glDrawStringCenter((C_WIDTH * C_MUL_X) / 2, 0, title);
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
} else {
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
}
|
||||
for (int y = 0; y < C_HEIGHT; y++) {
|
||||
int precBgColor = -1;
|
||||
@ -206,10 +204,10 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
int curBgColor = -1;
|
||||
int curFgColor = -1;
|
||||
for (int x = 0; x < C_WIDTH; x++) {
|
||||
curBgColor = r.bgColorMatrix[x+y*C_WIDTH];
|
||||
curFgColor = r.fgColorMatrix[x+y*C_WIDTH];
|
||||
curBgColor = r.bgColorMatrix[x + y * C_WIDTH];
|
||||
curFgColor = r.fgColorMatrix[x + y * C_WIDTH];
|
||||
if (precBgColor != curBgColor) {
|
||||
String str = Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiBgColorPrefix+curBgColor+Headless256Renderer.ansiColorSuffix;
|
||||
String str = Headless256Renderer.ANSI_PREFIX + Headless256Renderer.ansiBgColorPrefix + curBgColor + Headless256Renderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(str);
|
||||
} else {
|
||||
@ -217,7 +215,7 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
}
|
||||
}
|
||||
if (precFgColor != curFgColor) {
|
||||
String str = Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiFgColorPrefix+curFgColor+Headless256Renderer.ansiColorSuffix;
|
||||
String str = Headless256Renderer.ANSI_PREFIX + Headless256Renderer.ansiFgColorPrefix + curFgColor + Headless256Renderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(str);
|
||||
} else {
|
||||
@ -225,17 +223,17 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
}
|
||||
}
|
||||
|
||||
String stri = r.charmatrix[x+y*C_WIDTH]+"";
|
||||
String stri = r.charmatrix[x + y * C_WIDTH] + "";
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(stri);
|
||||
} else {
|
||||
AnsiConsole.out.print(stri);
|
||||
}
|
||||
|
||||
|
||||
precBgColor = curBgColor;
|
||||
precFgColor = curFgColor;
|
||||
}
|
||||
|
||||
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole("\r\n");
|
||||
} else {
|
||||
@ -260,11 +258,11 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilExit() {
|
||||
public void waitForExit() {
|
||||
try {
|
||||
do {
|
||||
Thread.sleep(500);
|
||||
} while (stopped==false);
|
||||
} while (stopped == false);
|
||||
} catch (final InterruptedException e) {
|
||||
|
||||
}
|
||||
@ -272,7 +270,8 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-256")) return false;
|
||||
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-256"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,24 +9,24 @@ public class Headless256Font implements BinaryFont {
|
||||
|
||||
@Override
|
||||
public void load(String file) throws IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(String text) {
|
||||
return 5*text.length();
|
||||
return 5 * text.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -5,9 +5,9 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
public class Headless256Renderer implements Renderer {
|
||||
|
||||
Headless256Font currentFont;
|
||||
protected char[] charmatrix = new char[Headless256Engine.C_WIDTH*Headless256Engine.C_HEIGHT];
|
||||
protected int[] fgColorMatrix = new int[Headless256Engine.C_WIDTH*Headless256Engine.C_HEIGHT];
|
||||
protected int[] bgColorMatrix = new int[Headless256Engine.C_WIDTH*Headless256Engine.C_HEIGHT];
|
||||
protected char[] charmatrix = new char[Headless256Engine.C_WIDTH * Headless256Engine.C_HEIGHT];
|
||||
protected int[] fgColorMatrix = new int[Headless256Engine.C_WIDTH * Headless256Engine.C_HEIGHT];
|
||||
protected int[] bgColorMatrix = new int[Headless256Engine.C_WIDTH * Headless256Engine.C_HEIGHT];
|
||||
protected int clearColor = rgbToX256(0xc5, 0xc2, 0xaf);
|
||||
protected int curColor = clearColor;
|
||||
public Headless256Skin currentSkin;
|
||||
@ -16,12 +16,11 @@ public class Headless256Renderer implements Renderer {
|
||||
public static final String ansiFgColorPrefix = "38;5;";
|
||||
public static final String ansiBgColorPrefix = "48;5;";
|
||||
public static final String ansiColorSuffix = "m";
|
||||
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final char FILL = 0xDB;
|
||||
public static final int TRANSPARENT = 0xF0000;
|
||||
|
||||
|
||||
public static int v2ci(int v_U) {
|
||||
return v_U < 48 ? 0 : v_U < 115 ? 1 : (v_U - 35) / 40;
|
||||
}
|
||||
@ -37,7 +36,7 @@ public class Headless256Renderer implements Renderer {
|
||||
/**
|
||||
* Calculate the represented colors back from the index
|
||||
*/
|
||||
public static int[] i2cv = {0, 0x5f, 0x87, 0xaf, 0xd7, 0xff};
|
||||
public static int[] i2cv = { 0, 0x5f, 0x87, 0xaf, 0xd7, 0xff };
|
||||
|
||||
public static int rgbToX256(int r_U, int g_U, int b_U) {
|
||||
// Calculate the nearest 0-based color index at 16 .. 231
|
||||
@ -58,7 +57,7 @@ public class Headless256Renderer implements Renderer {
|
||||
int grayErr = distSquare(gv, gv, gv, r_U, g_U, b_U);
|
||||
return colorErr <= grayErr ? 16 + colorIndex(ir, ig, ib) : 232 + grayIndex;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
curColor = rgbToX256(r, gg, b);
|
||||
@ -76,12 +75,12 @@ public class Headless256Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
curColor = rgbToX256((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = rgbToX256((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
curColor = rgbToX256((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = rgbToX256((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -91,7 +90,7 @@ public class Headless256Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearColor = rgbToX256((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
clearColor = rgbToX256((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -111,11 +110,11 @@ public class Headless256Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x1, float y1, float x2, float y2) {
|
||||
x1/=Headless256Engine.C_MUL_X;
|
||||
x2/=Headless256Engine.C_MUL_X;
|
||||
y1/=Headless256Engine.C_MUL_Y;
|
||||
y2/=Headless256Engine.C_MUL_Y;
|
||||
|
||||
x1 /= Headless256Engine.C_MUL_X;
|
||||
x2 /= Headless256Engine.C_MUL_X;
|
||||
y1 /= Headless256Engine.C_MUL_Y;
|
||||
y2 /= Headless256Engine.C_MUL_Y;
|
||||
|
||||
int dx = (int) Math.abs(x2 - x1);
|
||||
int dy = (int) Math.abs(y2 - y1);
|
||||
|
||||
@ -125,35 +124,35 @@ public class Headless256Renderer implements Renderer {
|
||||
int err = dx - dy;
|
||||
|
||||
while (true) {
|
||||
if (((int)x1) >= Headless256Engine.C_WIDTH || ((int)y1) >= Headless256Engine.C_HEIGHT ||
|
||||
((int)x2) >= Headless256Engine.C_WIDTH || ((int)y2) >= Headless256Engine.C_HEIGHT) {
|
||||
if (((int) x1) >= Headless256Engine.C_WIDTH || ((int) y1) >= Headless256Engine.C_HEIGHT || ((int) x2) >= Headless256Engine.C_WIDTH || ((int) y2) >= Headless256Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
bgColorMatrix[((int)x1) + ((int)y1) * Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[((int)x1) + ((int)y1) * Headless256Engine.C_WIDTH] = ' ';
|
||||
bgColorMatrix[((int) x1) + ((int) y1) * Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[((int) x1) + ((int) y1) * Headless256Engine.C_WIDTH] = ' ';
|
||||
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
|
||||
int e2 = 2 * err;
|
||||
int e2 = 2 * err;
|
||||
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) (x/Headless256Engine.C_MUL_X), (int) (y/Headless256Engine.C_MUL_Y), (int) (uvX/Headless256Engine.C_MUL_X), (int) (uvY/Headless256Engine.C_MUL_Y), (int) ((uvWidth + uvX)/Headless256Engine.C_MUL_X), (int) ((uvHeight + uvY)/Headless256Engine.C_MUL_Y), true);
|
||||
glDrawSkin((int) (x / Headless256Engine.C_MUL_X), (int) (y / Headless256Engine.C_MUL_Y), (int) (uvX / Headless256Engine.C_MUL_X), (int) (uvY / Headless256Engine.C_MUL_Y), (int) ((uvWidth + uvX) / Headless256Engine.C_MUL_X), (int) ((uvHeight + uvY) / Headless256Engine.C_MUL_Y), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
@ -161,10 +160,10 @@ public class Headless256Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
final int ix = (int) x/Headless256Engine.C_MUL_X;
|
||||
final int iy = (int) y/Headless256Engine.C_MUL_Y;
|
||||
final int iw = (int) width/Headless256Engine.C_MUL_X;
|
||||
final int ih = (int) height/Headless256Engine.C_MUL_Y;
|
||||
final int ix = (int) x / Headless256Engine.C_MUL_X;
|
||||
final int iy = (int) y / Headless256Engine.C_MUL_Y;
|
||||
final int iw = (int) width / Headless256Engine.C_MUL_X;
|
||||
final int ih = (int) height / Headless256Engine.C_MUL_Y;
|
||||
|
||||
int x1 = ix + iw;
|
||||
int y1 = iy + ih;
|
||||
@ -185,61 +184,60 @@ public class Headless256Renderer implements Renderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
final int cx = ((int)x)/Headless256Engine.C_MUL_X;
|
||||
final int cy = ((int)y)/Headless256Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless256Engine.C_MUL_X;
|
||||
final int cy = ((int) y) / Headless256Engine.C_MUL_Y;
|
||||
if (cx >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx+cy*Headless256Engine.C_WIDTH] = ch;
|
||||
fgColorMatrix[cx+cy*Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[cx + cy * Headless256Engine.C_WIDTH] = ch;
|
||||
fgColorMatrix[cx + cy * Headless256Engine.C_WIDTH] = curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawCharLeft(x,y,ch);
|
||||
glDrawCharLeft(x, y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
final int cx = ((int)x)/Headless256Engine.C_MUL_X-1;
|
||||
final int cy = ((int)y)/Headless256Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless256Engine.C_MUL_X - 1;
|
||||
final int cy = ((int) y) / Headless256Engine.C_MUL_Y;
|
||||
if (cx >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx+cy*Headless256Engine.C_WIDTH] = ch;
|
||||
fgColorMatrix[cx+cy*Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[cx + cy * Headless256Engine.C_WIDTH] = ch;
|
||||
fgColorMatrix[cx + cy * Headless256Engine.C_WIDTH] = curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String text) {
|
||||
final int cx = ((int)x)/Headless256Engine.C_MUL_X;
|
||||
final int cy = ((int)y)/Headless256Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless256Engine.C_MUL_X;
|
||||
final int cy = ((int) y) / Headless256Engine.C_MUL_Y;
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
if (cx + i >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx+i+cy*Headless256Engine.C_WIDTH] = c;
|
||||
fgColorMatrix[cx+i+cy*Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[cx + i + cy * Headless256Engine.C_WIDTH] = c;
|
||||
fgColorMatrix[cx + i + cy * Headless256Engine.C_WIDTH] = curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
final int cx = ((int)x)/Headless256Engine.C_MUL_X-text.length()/2;
|
||||
final int cy = ((int)y)/Headless256Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless256Engine.C_MUL_X - text.length() / 2;
|
||||
final int cy = ((int) y) / Headless256Engine.C_MUL_Y;
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
if (cx + i >= Headless256Engine.C_WIDTH || cy >= Headless256Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx+i+cy*Headless256Engine.C_WIDTH] = c;
|
||||
fgColorMatrix[cx+i+cy*Headless256Engine.C_WIDTH] = curColor;
|
||||
charmatrix[cx + i + cy * Headless256Engine.C_WIDTH] = c;
|
||||
fgColorMatrix[cx + i + cy * Headless256Engine.C_WIDTH] = curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -247,9 +245,8 @@ public class Headless256Renderer implements Renderer {
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
|
||||
int newColor;
|
||||
@ -305,7 +302,7 @@ public class Headless256Renderer implements Renderer {
|
||||
if (pixelY < Headless256Engine.C_HEIGHT) {
|
||||
if (pixelX - (pixelX % Headless256Engine.C_WIDTH) == 0) {
|
||||
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
|
||||
if (transparent && !((newColor&TRANSPARENT) == TRANSPARENT)) {
|
||||
if (transparent && !((newColor & TRANSPARENT) == TRANSPARENT)) {
|
||||
charmatrix[pixelX + pixelY * Headless256Engine.C_WIDTH] = ' ';
|
||||
bgColorMatrix[pixelX + pixelY * Headless256Engine.C_WIDTH] = newColor;
|
||||
}
|
||||
@ -313,16 +310,16 @@ public class Headless256Renderer implements Renderer {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
|
||||
protected void clearAll() {
|
||||
for (int i = 0; i < Headless256Engine.C_WIDTH*Headless256Engine.C_HEIGHT; i++) {
|
||||
charmatrix[i]=' ';
|
||||
for (int i = 0; i < Headless256Engine.C_WIDTH * Headless256Engine.C_HEIGHT; i++) {
|
||||
charmatrix[i] = ' ';
|
||||
bgColorMatrix[i] = clearColor;
|
||||
fgColorMatrix[i] = 0;
|
||||
}
|
||||
@ -332,5 +329,5 @@ public class Headless256Renderer implements Renderer {
|
||||
public Headless256Font getCurrentFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,22 +29,21 @@ public class Headless256Skin implements Skin {
|
||||
public static int[] getMatrixOfImage(BufferedImage bufferedImage) {
|
||||
BufferedImage after = new BufferedImage(bufferedImage.getWidth(null), bufferedImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
AffineTransform at = new AffineTransform();
|
||||
at.scale(1f/((float)Headless256Engine.C_MUL_X), 1f/((float)Headless256Engine.C_MUL_Y));
|
||||
at.scale(1f / ((float) Headless256Engine.C_MUL_X), 1f / ((float) Headless256Engine.C_MUL_Y));
|
||||
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
|
||||
after = scaleOp.filter(bufferedImage, after);
|
||||
|
||||
|
||||
|
||||
final int width = after.getWidth(null);
|
||||
final int height = after.getHeight(null);
|
||||
final int[] pixels = new int[width * height];
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
int rgb = after.getRGB(i, j);
|
||||
int r = (rgb >> 16) &0xFF;
|
||||
int g = (rgb >> 8) &0xFF;
|
||||
int b = rgb &0xFF;
|
||||
int r = (rgb >> 16) & 0xFF;
|
||||
int g = (rgb >> 8) & 0xFF;
|
||||
int b = rgb & 0xFF;
|
||||
boolean transparent = ((rgb >> 24) & 0xFF) <= 128;
|
||||
pixels[i + j * width] = Headless256Renderer.rgbToX256(r, g, b)|(transparent?Headless256Renderer.TRANSPARENT:0);
|
||||
pixels[i + j * width] = Headless256Renderer.rgbToX256(r, g, b) | (transparent ? Headless256Renderer.TRANSPARENT : 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +52,7 @@ public class Headless256Skin implements Skin {
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,5 +65,4 @@ public class Headless256Skin implements Skin {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.warp.picalculator.gui.graphicengine.headless8;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
@ -10,8 +9,6 @@ import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
|
||||
@ -23,16 +20,16 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
private RenderingLoop renderLoop;
|
||||
public static final int C_MUL_X = 4;//8;
|
||||
public static final int C_MUL_Y = 8;//8;
|
||||
protected static final int C_WIDTH = Main.screenSize[0]/C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1]/C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
protected static final int C_WIDTH = Main.screenSize[0] / C_MUL_X;//Main.screenSize[0]/2;//;60;
|
||||
protected static final int C_HEIGHT = Main.screenSize[1] / C_MUL_Y;//Main.screenSize[1]/3;//;40;
|
||||
private String title = Main.calculatorName;
|
||||
private boolean win = false;
|
||||
private Key precKey = null;
|
||||
|
||||
|
||||
@Override
|
||||
public int[] getSize() {
|
||||
new ConsoleHandler();
|
||||
return new int[]{C_WIDTH, C_HEIGHT};
|
||||
return new int[] { C_WIDTH, C_HEIGHT };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,85 +45,85 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
@Override
|
||||
public void setResizable(boolean r) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayMode(int ww, int wh) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
this.create(null);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(Runnable onInitialized) {
|
||||
Utils.outputLevel = -1;
|
||||
AnsiConsole.systemInstall();
|
||||
if(Utils.isWindows() && !Utils.msDosMode){
|
||||
if (Utils.isWindows() && !Utils.msDosMode) {
|
||||
win = true;
|
||||
WindowsSupport.setConsoleMode(0x0200);
|
||||
Thread t = new Thread(()-> {
|
||||
Thread t = new Thread(() -> {
|
||||
int ch = -1;
|
||||
while(true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
while (true) {
|
||||
if (precKey != null) {
|
||||
Keyboard.keyReleased(precKey);
|
||||
precKey = null;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch (ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
ch = WindowsSupport.readByte();
|
||||
Key key = null;
|
||||
switch(ch) {
|
||||
case 72: { // UP
|
||||
key = Key.UP;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
case 80: { // DOWN
|
||||
key = Key.DOWN;
|
||||
break;
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
case 77: { // RIGHT
|
||||
key = Key.RIGHT;
|
||||
break;
|
||||
}
|
||||
case 75: { // LEFT
|
||||
key = Key.LEFT;
|
||||
break;
|
||||
}
|
||||
case 49: { // 1
|
||||
key = Key.NUM1;
|
||||
break;
|
||||
}
|
||||
case 50: { // 2
|
||||
key = Key.NUM2;
|
||||
break;
|
||||
}
|
||||
case 51: { // 3
|
||||
key = Key.NUM3;
|
||||
break;
|
||||
}
|
||||
case 52: { // 4
|
||||
key = Key.NUM4;
|
||||
break;
|
||||
}
|
||||
case 53: { // 5
|
||||
key = Key.NUM5;
|
||||
break;
|
||||
}
|
||||
case 54: { // 6
|
||||
key = Key.NUM6;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
key = Key.NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (key != null) {
|
||||
Keyboard.keyPressed(key);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
@ -145,12 +142,12 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return C_WIDTH*C_MUL_X;
|
||||
return C_WIDTH * C_MUL_X;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return C_HEIGHT*C_MUL_Y;
|
||||
return C_HEIGHT * C_MUL_Y;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -191,15 +188,15 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
public void repaint() {
|
||||
renderLoop.refresh();
|
||||
r.curColor = 0x1C;
|
||||
r.glDrawStringCenter((C_WIDTH*C_MUL_X)/2, 0, title);
|
||||
r.glDrawStringCenter((C_WIDTH * C_MUL_X) / 2, 0, title);
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
WindowsSupport.writeConsole(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
} else {
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX+"?25l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "0;0f");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?12l");
|
||||
AnsiConsole.out.print(Headless24bitRenderer.ANSI_PREFIX + "?25l");
|
||||
}
|
||||
for (int y = 0; y < C_HEIGHT; y++) {
|
||||
int precBgColor = -1;
|
||||
@ -207,10 +204,10 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
int curBgColor = -1;
|
||||
int curFgColor = -1;
|
||||
for (int x = 0; x < C_WIDTH; x++) {
|
||||
curBgColor = (r.colorMatrix[x+y*C_WIDTH]&0xF0)>>4;
|
||||
curFgColor = r.colorMatrix[x+y*C_WIDTH]&0x0F;
|
||||
curBgColor = (r.colorMatrix[x + y * C_WIDTH] & 0xF0) >> 4;
|
||||
curFgColor = r.colorMatrix[x + y * C_WIDTH] & 0x0F;
|
||||
if (precBgColor != curBgColor) {
|
||||
String str = Headless8Renderer.ANSI_PREFIX+Headless8Renderer.ansiBgColorPrefix+Headless8Renderer.colorANSI[curBgColor]+Headless8Renderer.ansiColorSuffix;
|
||||
String str = Headless8Renderer.ANSI_PREFIX + Headless8Renderer.ansiBgColorPrefix + Headless8Renderer.colorANSI[curBgColor] + Headless8Renderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(str);
|
||||
} else {
|
||||
@ -218,25 +215,25 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
}
|
||||
}
|
||||
if (precFgColor != curFgColor) {
|
||||
String str = Headless8Renderer.ANSI_PREFIX+Headless8Renderer.ansiFgColorPrefix+Headless8Renderer.colorANSI[curFgColor]+Headless8Renderer.ansiColorSuffix;
|
||||
String str = Headless8Renderer.ANSI_PREFIX + Headless8Renderer.ansiFgColorPrefix + Headless8Renderer.colorANSI[curFgColor] + Headless8Renderer.ansiColorSuffix;
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(str);
|
||||
} else {
|
||||
AnsiConsole.out.print(str);
|
||||
}
|
||||
}
|
||||
|
||||
String stri = r.charmatrix[x+y*C_WIDTH]+"";
|
||||
|
||||
String stri = r.charmatrix[x + y * C_WIDTH] + "";
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole(stri);
|
||||
} else {
|
||||
AnsiConsole.out.print(stri);
|
||||
}
|
||||
|
||||
|
||||
precBgColor = curBgColor;
|
||||
precFgColor = curFgColor;
|
||||
}
|
||||
|
||||
|
||||
if (win) {
|
||||
WindowsSupport.writeConsole("\r\n");
|
||||
} else {
|
||||
@ -261,11 +258,11 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitUntilExit() {
|
||||
public void waitForExit() {
|
||||
try {
|
||||
do {
|
||||
Thread.sleep(500);
|
||||
} while (stopped==false);
|
||||
} while (stopped == false);
|
||||
} catch (final InterruptedException e) {
|
||||
|
||||
}
|
||||
@ -273,7 +270,8 @@ public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.
|
||||
|
||||
@Override
|
||||
public boolean isSupported() {
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "console-8") return false;
|
||||
if (Utils.forceEngine != null && Utils.forceEngine != "console-8")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,24 +9,24 @@ public class Headless8Font implements BinaryFont {
|
||||
|
||||
@Override
|
||||
public void load(String file) throws IOException {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(GraphicEngine d) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStringWidth(String text) {
|
||||
return 5*text.length();
|
||||
return 5 * text.length();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -6,8 +6,8 @@ import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
public class Headless8Renderer implements Renderer {
|
||||
|
||||
Headless8Font currentFont;
|
||||
protected char[] charmatrix = new char[Headless8Engine.C_WIDTH*Headless8Engine.C_HEIGHT];
|
||||
protected int[] colorMatrix = new int[Headless8Engine.C_WIDTH*Headless8Engine.C_HEIGHT];
|
||||
protected char[] charmatrix = new char[Headless8Engine.C_WIDTH * Headless8Engine.C_HEIGHT];
|
||||
protected int[] colorMatrix = new int[Headless8Engine.C_WIDTH * Headless8Engine.C_HEIGHT];
|
||||
protected int clearColor = hexColor(0xc5, 0xc2, 0xaf);
|
||||
protected int curColor = clearColor;
|
||||
public Headless8Skin currentSkin;
|
||||
@ -16,165 +16,164 @@ public class Headless8Renderer implements Renderer {
|
||||
public static final String ansiFgColorPrefix = "3";
|
||||
public static final String ansiBgColorPrefix = "4";
|
||||
public static final String ansiColorSuffix = "m";
|
||||
public static final String[] colorANSI = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "0;1", "1;1", "2;1", "3;1", "4;1", "5;1", "6;1", "7;1"};
|
||||
|
||||
public static final String[] colorANSI = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "0;1", "1;1", "2;1", "3;1", "4;1", "5;1", "6;1", "7;1" };
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final char FILL = Utils.msDosMode ? 0xDB : '█';
|
||||
|
||||
|
||||
private int hexColor(int red, int green, int blue) {
|
||||
int r1=red, r2, g1=green, g2, b1=blue, b2;
|
||||
|
||||
int r1 = red, r2, g1 = green, g2, b1 = blue, b2;
|
||||
|
||||
float[] match = new float[16];
|
||||
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 0;
|
||||
b2 = 0;
|
||||
match[0]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 205;
|
||||
g2 = 0;
|
||||
b2 = 0;
|
||||
match[1]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[1] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 205;
|
||||
b2 = 0;
|
||||
match[2]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[2] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 205;
|
||||
g2 = 205;
|
||||
b2 = 0;
|
||||
match[3]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[3] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 0;
|
||||
b2 = 238;
|
||||
match[4]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[4] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 205;
|
||||
g2 = 0;
|
||||
b2 = 205;
|
||||
match[5]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[5] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 205;
|
||||
b2 = 205;
|
||||
match[6]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[6] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 229;
|
||||
g2 = 229;
|
||||
b2 = 229;
|
||||
match[7]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[7] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 127;
|
||||
g2 = 127;
|
||||
b2 = 127;
|
||||
match[8]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[8] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 255;
|
||||
g2 = 0;
|
||||
b2 = 0;
|
||||
match[9]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[9] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 255;
|
||||
b2 = 0;
|
||||
match[0xa]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xa] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 255;
|
||||
g2 = 255;
|
||||
b2 = 0;
|
||||
match[0xb]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xb] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 92;
|
||||
g2 = 92;
|
||||
b2 = 255;
|
||||
match[0xc]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xc] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 255;
|
||||
g2 = 0;
|
||||
b2 = 255;
|
||||
match[0xd]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xd] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 0;
|
||||
g2 = 255;
|
||||
b2 = 255;
|
||||
match[0xe]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xe] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
// COLOR
|
||||
r2 = 255;
|
||||
g2 = 255;
|
||||
b2 = 255;
|
||||
match[0xf]=(r2-r1)*(r2-r1)+(g2-g1)*(g2-g1)+(b2-b1)*(b2-b1);
|
||||
|
||||
match[0xf] = (r2 - r1) * (r2 - r1) + (g2 - g1) * (g2 - g1) + (b2 - b1) * (b2 - b1);
|
||||
|
||||
int minIndex = 0;
|
||||
for (int i = 1; i < match.length; i++) {
|
||||
float newnumber = match[i];
|
||||
if ((newnumber < match[minIndex])) {
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return minIndex;
|
||||
for (int i = 1; i < match.length; i++) {
|
||||
float newnumber = match[i];
|
||||
if ((newnumber < match[minIndex])) {
|
||||
minIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
return minIndex;
|
||||
}
|
||||
|
||||
private int[] hexColorReverse(int i) {
|
||||
switch (i) {
|
||||
case 0x0:
|
||||
return new int[]{0,0,0};
|
||||
return new int[] { 0, 0, 0 };
|
||||
case 0x1:
|
||||
return new int[]{205,0,0};
|
||||
return new int[] { 205, 0, 0 };
|
||||
case 0x2:
|
||||
return new int[]{0,205,0};
|
||||
return new int[] { 0, 205, 0 };
|
||||
case 0x3:
|
||||
return new int[]{205,205,0};
|
||||
return new int[] { 205, 205, 0 };
|
||||
case 0x4:
|
||||
return new int[]{0,0,238};
|
||||
return new int[] { 0, 0, 238 };
|
||||
case 0x5:
|
||||
return new int[]{205,0,205};
|
||||
return new int[] { 205, 0, 205 };
|
||||
case 0x6:
|
||||
return new int[]{0,205,205};
|
||||
return new int[] { 0, 205, 205 };
|
||||
case 0x7:
|
||||
return new int[]{229,229,229};
|
||||
return new int[] { 229, 229, 229 };
|
||||
case 0x8:
|
||||
return new int[]{127,127,127};
|
||||
return new int[] { 127, 127, 127 };
|
||||
case 0x9:
|
||||
return new int[]{255,0,0};
|
||||
return new int[] { 255, 0, 0 };
|
||||
case 0xa:
|
||||
return new int[]{0,255,0};
|
||||
return new int[] { 0, 255, 0 };
|
||||
case 0xb:
|
||||
return new int[]{255,255,0};
|
||||
return new int[] { 255, 255, 0 };
|
||||
case 0xc:
|
||||
return new int[]{92,92,255};
|
||||
return new int[] { 92, 92, 255 };
|
||||
case 0xd:
|
||||
return new int[]{255,0,255};
|
||||
return new int[] { 255, 0, 255 };
|
||||
case 0xe:
|
||||
return new int[]{0,255,255};
|
||||
return new int[] { 0, 255, 255 };
|
||||
default:
|
||||
return new int[]{255,255,255};
|
||||
return new int[] { 255, 255, 255 };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int colorUnion(int[] col) {
|
||||
return 0xFF<<24|col[0]<<16|col[1]<<8|col[2];
|
||||
return 0xFF << 24 | col[0] << 16 | col[1] << 8 | col[2];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glColor3i(int r, int gg, int b) {
|
||||
curColor = hexColor(r, gg, b);
|
||||
@ -192,12 +191,12 @@ public class Headless8Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glColor3f(float red, float green, float blue) {
|
||||
curColor = hexColor((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = hexColor((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glColor4f(float red, float green, float blue, float alpha) {
|
||||
curColor = hexColor((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
curColor = hexColor((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -207,7 +206,7 @@ public class Headless8Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glClearColor4f(float red, float green, float blue, float alpha) {
|
||||
clearColor = hexColor((int)(red*255), (int)(green*255), (int)(blue*255));
|
||||
clearColor = hexColor((int) (red * 255), (int) (green * 255), (int) (blue * 255));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -227,11 +226,11 @@ public class Headless8Renderer implements Renderer {
|
||||
|
||||
@Override
|
||||
public void glDrawLine(float x1, float y1, float x2, float y2) {
|
||||
x1/=Headless8Engine.C_MUL_X;
|
||||
x2/=Headless8Engine.C_MUL_X;
|
||||
y1/=Headless8Engine.C_MUL_Y;
|
||||
y2/=Headless8Engine.C_MUL_Y;
|
||||
|
||||
x1 /= Headless8Engine.C_MUL_X;
|
||||
x2 /= Headless8Engine.C_MUL_X;
|
||||
y1 /= Headless8Engine.C_MUL_Y;
|
||||
y2 /= Headless8Engine.C_MUL_Y;
|
||||
|
||||
int dx = (int) Math.abs(x2 - x1);
|
||||
int dy = (int) Math.abs(y2 - y1);
|
||||
|
||||
@ -241,36 +240,36 @@ public class Headless8Renderer implements Renderer {
|
||||
int err = dx - dy;
|
||||
|
||||
while (true) {
|
||||
if (((int)x1) >= Headless8Engine.C_WIDTH || ((int)y1) >= Headless8Engine.C_HEIGHT ||
|
||||
((int)x2) >= Headless8Engine.C_WIDTH || ((int)y2) >= Headless8Engine.C_HEIGHT) {
|
||||
if (((int) x1) >= Headless8Engine.C_WIDTH || ((int) y1) >= Headless8Engine.C_HEIGHT || ((int) x2) >= Headless8Engine.C_WIDTH || ((int) y2) >= Headless8Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
int precBG = colorMatrix[((int)x1) + ((int)y1) * Headless8Engine.C_WIDTH]&0xF0;
|
||||
colorMatrix[((int)x1) + ((int)y1) * Headless8Engine.C_WIDTH] = precBG|curColor;
|
||||
charmatrix[((int)x1) + ((int)y1) * Headless8Engine.C_WIDTH] = FILL;
|
||||
int precBG = colorMatrix[((int) x1) + ((int) y1) * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[((int) x1) + ((int) y1) * Headless8Engine.C_WIDTH] = precBG | curColor;
|
||||
charmatrix[((int) x1) + ((int) y1) * Headless8Engine.C_WIDTH] = FILL;
|
||||
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
if (x1 == x2 && y1 == y2) {
|
||||
break;
|
||||
}
|
||||
|
||||
int e2 = 2 * err;
|
||||
int e2 = 2 * err;
|
||||
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
if (e2 > -dy) {
|
||||
err = err - dy;
|
||||
x1 = x1 + sx;
|
||||
}
|
||||
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
if (e2 < dx) {
|
||||
err = err + dx;
|
||||
y1 = y1 + sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth, float uvHeight) {
|
||||
public void glFillRect(float x, float y, float width, float height, float uvX, float uvY, float uvWidth,
|
||||
float uvHeight) {
|
||||
if (currentSkin != null) {
|
||||
glDrawSkin((int) (x/Headless8Engine.C_MUL_X), (int) (y/Headless8Engine.C_MUL_Y), (int) (uvX/Headless8Engine.C_MUL_X), (int) (uvY/Headless8Engine.C_MUL_Y), (int) ((uvWidth + uvX)/Headless8Engine.C_MUL_X), (int) ((uvHeight + uvY)/Headless8Engine.C_MUL_Y), true);
|
||||
glDrawSkin((int) (x / Headless8Engine.C_MUL_X), (int) (y / Headless8Engine.C_MUL_Y), (int) (uvX / Headless8Engine.C_MUL_X), (int) (uvY / Headless8Engine.C_MUL_Y), (int) ((uvWidth + uvX) / Headless8Engine.C_MUL_X), (int) ((uvHeight + uvY) / Headless8Engine.C_MUL_Y), true);
|
||||
} else {
|
||||
glFillColor(x, y, width, height);
|
||||
}
|
||||
@ -280,12 +279,12 @@ public class Headless8Renderer implements Renderer {
|
||||
public void glFillColor(float x, float y, float width, float height) {
|
||||
glFillColor(x, y, width, height, FILL, curColor);
|
||||
}
|
||||
|
||||
|
||||
private void glFillColor(float x, float y, float width, float height, char character, int color) {
|
||||
final int ix = (int) x/Headless8Engine.C_MUL_X;
|
||||
final int iy = (int) y/Headless8Engine.C_MUL_Y;
|
||||
final int iw = (int) width/Headless8Engine.C_MUL_X;
|
||||
final int ih = (int) height/Headless8Engine.C_MUL_Y;
|
||||
final int ix = (int) x / Headless8Engine.C_MUL_X;
|
||||
final int iy = (int) y / Headless8Engine.C_MUL_Y;
|
||||
final int iw = (int) width / Headless8Engine.C_MUL_X;
|
||||
final int ih = (int) height / Headless8Engine.C_MUL_Y;
|
||||
|
||||
int x1 = ix + iw;
|
||||
int y1 = iy + ih;
|
||||
@ -301,71 +300,70 @@ public class Headless8Renderer implements Renderer {
|
||||
final int sizeW = Headless8Engine.C_WIDTH;
|
||||
for (int px = ix; px < x1; px++) {
|
||||
for (int py = iy; py < y1; py++) {
|
||||
int precBG = colorMatrix[(px) + (py) * sizeW]&0xF0;
|
||||
colorMatrix[(px) + (py) * sizeW] = precBG|color;
|
||||
int precBG = colorMatrix[(px) + (py) * sizeW] & 0xF0;
|
||||
colorMatrix[(px) + (py) * sizeW] = precBG | color;
|
||||
charmatrix[(px) + (py) * sizeW] = character;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void glDrawCharLeft(int x, int y, char ch) {
|
||||
final int cx = ((int)x)/Headless8Engine.C_MUL_X;
|
||||
final int cy = ((int)y)/Headless8Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless8Engine.C_MUL_X;
|
||||
final int cy = ((int) y) / Headless8Engine.C_MUL_Y;
|
||||
if (cx >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx+cy*Headless8Engine.C_WIDTH] = ch;
|
||||
int precBG = colorMatrix[cx+cy*Headless8Engine.C_WIDTH]&0xF0;
|
||||
colorMatrix[cx+cy*Headless8Engine.C_WIDTH] = precBG|curColor;
|
||||
charmatrix[cx + cy * Headless8Engine.C_WIDTH] = ch;
|
||||
int precBG = colorMatrix[cx + cy * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[cx + cy * Headless8Engine.C_WIDTH] = precBG | curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharCenter(int x, int y, char ch) {
|
||||
glDrawCharLeft(x,y,ch);
|
||||
glDrawCharLeft(x, y, ch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawCharRight(int x, int y, char ch) {
|
||||
final int cx = ((int)x)/Headless8Engine.C_MUL_X-1;
|
||||
final int cy = ((int)y)/Headless8Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless8Engine.C_MUL_X - 1;
|
||||
final int cy = ((int) y) / Headless8Engine.C_MUL_Y;
|
||||
if (cx >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
return;
|
||||
}
|
||||
charmatrix[cx+cy*Headless8Engine.C_WIDTH] = ch;
|
||||
int precBG = colorMatrix[cx+cy*Headless8Engine.C_WIDTH]&0xF0;
|
||||
colorMatrix[cx+cy*Headless8Engine.C_WIDTH] = precBG|curColor;
|
||||
charmatrix[cx + cy * Headless8Engine.C_WIDTH] = ch;
|
||||
int precBG = colorMatrix[cx + cy * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[cx + cy * Headless8Engine.C_WIDTH] = precBG | curColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringLeft(float x, float y, String text) {
|
||||
final int cx = ((int)x)/Headless8Engine.C_MUL_X;
|
||||
final int cy = ((int)y)/Headless8Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless8Engine.C_MUL_X;
|
||||
final int cy = ((int) y) / Headless8Engine.C_MUL_Y;
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
if (cx + i >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx+i+cy*Headless8Engine.C_WIDTH] = c;
|
||||
int precBG = colorMatrix[cx+i+cy*Headless8Engine.C_WIDTH]&0xF0;
|
||||
colorMatrix[cx+i+cy*Headless8Engine.C_WIDTH] = precBG|curColor;
|
||||
charmatrix[cx + i + cy * Headless8Engine.C_WIDTH] = c;
|
||||
int precBG = colorMatrix[cx + i + cy * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[cx + i + cy * Headless8Engine.C_WIDTH] = precBG | curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glDrawStringCenter(float x, float y, String text) {
|
||||
final int cx = ((int)x)/Headless8Engine.C_MUL_X-text.length()/2;
|
||||
final int cy = ((int)y)/Headless8Engine.C_MUL_Y;
|
||||
final int cx = ((int) x) / Headless8Engine.C_MUL_X - text.length() / 2;
|
||||
final int cy = ((int) y) / Headless8Engine.C_MUL_Y;
|
||||
int i = 0;
|
||||
for (char c : text.toCharArray()) {
|
||||
if (cx+i >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
if (cx + i >= Headless8Engine.C_WIDTH || cy >= Headless8Engine.C_HEIGHT) {
|
||||
break;
|
||||
}
|
||||
charmatrix[cx+i+cy*Headless8Engine.C_WIDTH] = c;
|
||||
int precBG = colorMatrix[cx+i+cy*Headless8Engine.C_WIDTH]&0xF0;
|
||||
colorMatrix[cx+i+cy*Headless8Engine.C_WIDTH] = precBG|curColor;
|
||||
charmatrix[cx + i + cy * Headless8Engine.C_WIDTH] = c;
|
||||
int precBG = colorMatrix[cx + i + cy * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[cx + i + cy * Headless8Engine.C_WIDTH] = precBG | curColor;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -373,9 +371,8 @@ public class Headless8Renderer implements Renderer {
|
||||
@Override
|
||||
public void glDrawStringRight(float x, float y, String text) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void glDrawSkin(int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
|
||||
int oldColor;
|
||||
@ -433,7 +430,7 @@ public class Headless8Renderer implements Renderer {
|
||||
if (pixelX - (pixelX % Headless8Engine.C_WIDTH) == 0) {
|
||||
newColor = currentSkin.skinData[(s0 + texx) + (t0 + texy) * currentSkin.skinSize[0]];
|
||||
if (transparent) {
|
||||
oldColor = colorUnion(hexColorReverse((colorMatrix[pixelX + pixelY * Headless8Engine.C_WIDTH]&0xF0)>>4));
|
||||
oldColor = colorUnion(hexColorReverse((colorMatrix[pixelX + pixelY * Headless8Engine.C_WIDTH] & 0xF0) >> 4));
|
||||
final float a2 = (newColor >> 24 & 0xFF) / 255f;
|
||||
final float a1 = 1f - a2;
|
||||
final int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
|
||||
@ -442,23 +439,23 @@ public class Headless8Renderer implements Renderer {
|
||||
newColor = 0xFF000000 | r << 16 | g << 8 | b;
|
||||
}
|
||||
int bgColor = colorMatrix[pixelX + pixelY * Headless8Engine.C_WIDTH] & 0xF0;
|
||||
colorMatrix[pixelX + pixelY * Headless8Engine.C_WIDTH] = bgColor|hexColor(newColor >> 16 & 0xFF, newColor >> 8 & 0xFF, newColor & 0xFF);
|
||||
colorMatrix[pixelX + pixelY * Headless8Engine.C_WIDTH] = bgColor | hexColor(newColor >> 16 & 0xFF, newColor >> 8 & 0xFF, newColor & 0xFF);
|
||||
charmatrix[pixelX + pixelY * Headless8Engine.C_WIDTH] = FILL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void glClearSkin() {
|
||||
currentSkin = null;
|
||||
}
|
||||
|
||||
|
||||
protected void clearAll() {
|
||||
for (int i = 0; i < Headless8Engine.C_WIDTH*Headless8Engine.C_HEIGHT; i++) {
|
||||
charmatrix[i]=' ';
|
||||
colorMatrix[i] = clearColor<<4;
|
||||
for (int i = 0; i < Headless8Engine.C_WIDTH * Headless8Engine.C_HEIGHT; i++) {
|
||||
charmatrix[i] = ' ';
|
||||
colorMatrix[i] = clearColor << 4;
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,5 +463,5 @@ public class Headless8Renderer implements Renderer {
|
||||
public Headless8Font getCurrentFont() {
|
||||
return currentFont;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -29,11 +29,10 @@ public class Headless8Skin implements Skin {
|
||||
public static int[] getMatrixOfImage(BufferedImage bufferedImage) {
|
||||
BufferedImage after = new BufferedImage(bufferedImage.getWidth(null), bufferedImage.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
AffineTransform at = new AffineTransform();
|
||||
at.scale(1f/((float)Headless8Engine.C_MUL_X), 1f/((float)Headless8Engine.C_MUL_Y));
|
||||
at.scale(1f / ((float) Headless8Engine.C_MUL_X), 1f / ((float) Headless8Engine.C_MUL_Y));
|
||||
AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
|
||||
after = scaleOp.filter(bufferedImage, after);
|
||||
|
||||
|
||||
|
||||
final int width = after.getWidth(null);
|
||||
final int height = after.getHeight(null);
|
||||
final int[] pixels = new int[width * height];
|
||||
@ -48,7 +47,7 @@ public class Headless8Skin implements Skin {
|
||||
|
||||
@Override
|
||||
public void initialize(GraphicEngine d) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,5 +60,4 @@ public class Headless8Skin implements Skin {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -28,21 +28,21 @@ public class ChooseVariableValueScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
Utils.getFont(false, true).use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
DisplayManager.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
Utils.getFont(false, true).use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 - 20 + 1, "WORK IN PROGRESS.");
|
||||
DisplayManager.INSTANCE.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 - 20, "WORK IN PROGRESS.");
|
||||
|
||||
Utils.getFont(false, false).use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
Utils.getFont(false, false).use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 2 + 1, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 2, "THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.warp.picalculator.gui.screens;
|
||||
|
||||
import static org.warp.picalculator.gui.DisplayManager.fonts;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
@ -29,19 +27,19 @@ public class KeyboardDebugScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
final Renderer renderer = DisplayManager.renderer;
|
||||
fonts[2].use(DisplayManager.engine);
|
||||
final Renderer renderer = DisplayManager.INSTANCE.renderer;
|
||||
DisplayManager.INSTANCE.fonts[2].use(DisplayManager.INSTANCE.engine);
|
||||
renderer.glColor4f(0.75f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glDrawStringRight(Main.screenSize[0] - 10, 30, "-" + keyevent.toUpperCase() + "-");
|
||||
if (keyevent != "NONE") {
|
||||
fonts[2].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[2].use(DisplayManager.INSTANCE.engine);
|
||||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
renderer.glDrawStringLeft(10, 30, "Key position");
|
||||
renderer.glDrawStringLeft(10, 45, "X: " + keyX + ", Y:" + keyY);
|
||||
renderer.glDrawStringLeft(10, 65, "Key value");
|
||||
renderer.glDrawStringLeft(10, 80, key);
|
||||
}
|
||||
fonts[3].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[3].use(DisplayManager.INSTANCE.engine);
|
||||
renderer.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (log[i] != null) {
|
||||
@ -53,10 +51,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);
|
||||
fonts[2].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[2].use(DisplayManager.INSTANCE.engine);
|
||||
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");
|
||||
fonts[3].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[3].use(DisplayManager.INSTANCE.engine);
|
||||
renderer.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (pinsA[i] == 1) {
|
||||
@ -99,10 +97,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);
|
||||
fonts[2].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[2].use(DisplayManager.INSTANCE.engine);
|
||||
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");
|
||||
fonts[3].use(DisplayManager.engine);
|
||||
DisplayManager.INSTANCE.fonts[3].use(DisplayManager.INSTANCE.engine);
|
||||
renderer.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
for (int i = 15; i >= 8; i--) {
|
||||
if (pinsB[i] == 1) {
|
||||
|
@ -37,13 +37,13 @@ public class LoadingScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
DisplayManager.guiSkin.use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glColor3i(255, 255, 255);
|
||||
DisplayManager.renderer.glFillRect(Main.screenSize[0] / 2f - 80, Main.screenSize[1] / 2f - 64, 160, 48, 0, 32, 160, 48);
|
||||
DisplayManager.renderer.glFillRect(Main.screenSize[0] / 2f - 24, Main.screenSize[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
|
||||
DisplayManager.INSTANCE.guiSkin.use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glColor3i(255, 255, 255);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(Main.screenSize[0] / 2f - 80, Main.screenSize[1] / 2f - 64, 160, 48, 0, 32, 160, 48);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(Main.screenSize[0] / 2f - 24, Main.screenSize[1] / 2f - loadingTextTranslation, 48, 48, 160, 32, 48, 48);
|
||||
|
||||
DisplayManager.renderer.glFillRect(Main.screenSize[0] - 224, Main.screenSize[1] - 48, 224, 48, 0, 80, 224, 48);
|
||||
DisplayManager.renderer.glFillRect(Main.screenSize[0] - 160 - 24 - 224, Main.screenSize[1] - 48, 160, 48, 224, 80, 160, 48);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(Main.screenSize[0] - 224, Main.screenSize[1] - 48, 224, 48, 0, 80, 224, 48);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(Main.screenSize[0] - 160 - 24 - 224, Main.screenSize[1] - 48, 160, 48, 224, 80, 160, 48);
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,15 +2,21 @@ package org.warp.picalculator.gui.screens;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.warp.picalculator.Main;
|
||||
import org.warp.picalculator.device.Keyboard;
|
||||
import org.warp.picalculator.device.Keyboard.Key;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||
|
||||
public class MarioScreen extends Screen {
|
||||
|
||||
private Skin skin;
|
||||
private Skin groundskin;
|
||||
private static Skin skin;
|
||||
private static Skin groundskin;
|
||||
private static BinaryFont easterfont;
|
||||
private static Skin easterskin;
|
||||
private int easterNum = 0;
|
||||
private int easterMax = 21;
|
||||
private boolean errored;
|
||||
public float[] marioPos = new float[] { 30, 0 };
|
||||
public float[] marioForces = new float[] { 0, 0 };
|
||||
@ -31,8 +37,18 @@ public class MarioScreen extends Screen {
|
||||
@Override
|
||||
public void init() {
|
||||
try {
|
||||
skin = DisplayManager.engine.loadSkin("marioskin.png");
|
||||
groundskin = DisplayManager.engine.loadSkin("marioground.png");
|
||||
if (skin == null)
|
||||
skin = DisplayManager.INSTANCE.engine.loadSkin("marioskin.png");
|
||||
if (groundskin == null)
|
||||
groundskin = DisplayManager.INSTANCE.engine.loadSkin("marioground.png");
|
||||
if (easterfont == null)
|
||||
try {
|
||||
easterfont = DisplayManager.INSTANCE.engine.loadFont("easter");
|
||||
} catch (Exception ex) {}
|
||||
if (easterskin == null)
|
||||
try {
|
||||
easterskin = DisplayManager.INSTANCE.engine.loadSkin("font_easter.png");
|
||||
} catch (Exception ex) {}
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -112,57 +128,63 @@ public class MarioScreen extends Screen {
|
||||
}
|
||||
marioForces[0] *= 0.75;
|
||||
|
||||
DisplayManager.renderer.glClearColor(0xff9290ff);
|
||||
DisplayManager.INSTANCE.renderer.glClearColor(0xff9290ff);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (errored) {
|
||||
DisplayManager.renderer.glDrawStringLeft(0, 20, "ERROR");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringLeft(0, 20, "ERROR");
|
||||
} else {
|
||||
DisplayManager.fonts[0].use(DisplayManager.engine);
|
||||
groundskin.use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glFillRect(16 * 0, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 1, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 2, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 3, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 4, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 5, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 6, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 7, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 8, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
groundskin.use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 0, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 1, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 2, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 3, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 4, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 5, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 6, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 7, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 8, 25 + 25, 16, 16, 0, 0, 16, 16);
|
||||
|
||||
DisplayManager.renderer.glFillRect(16 * 0, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 1, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 2, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 3, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 4, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 5, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 6, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 7, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.renderer.glFillRect(16 * 8, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 0, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 1, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 2, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 3, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 4, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 5, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 6, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 7, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(16 * 8, 25 + 25 + 16 * 1, 16, 16, 0, 0, 16, 16);
|
||||
|
||||
// EASTER EGG
|
||||
// glSetFont(PIDisplay.fonts[4]);
|
||||
// glColor(0xFF000000);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "A");
|
||||
// glColor(0xFF800000);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "B");
|
||||
// glColor(0xFFeea28e);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "C");
|
||||
// glColor(0xFFee7255);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "D");
|
||||
// glColor(0xFFeac0b0);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "E");
|
||||
// glColor(0xFFf3d8ce);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "F");
|
||||
// glColor(0xffede7);
|
||||
// glDrawStringRight(0, Main.screenSize[1]-glGetCurrentFontHeight(), "G");
|
||||
if (easterfont != null) {
|
||||
easterfont.use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFF000000);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "A");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFF800000);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "B");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFFeea28e);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "C");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFFee7255);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "D");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFFeac0b0);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "E");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFFf3d8ce);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "F");
|
||||
DisplayManager.INSTANCE.renderer.glColor(0xFFffede7);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringRight(Main.screenSize[0], DisplayManager.INSTANCE.engine.getHeight() - easterfont.getCharacterHeight(), "G");
|
||||
}
|
||||
if (easterskin != null) {
|
||||
easterskin.use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(0, Main.screenSize[1] - 128, 224, 128, easterNum * 224, 0, 224, 128);
|
||||
easterNum = (easterNum < easterMax) ? easterNum + 1 : 0;
|
||||
}
|
||||
|
||||
//DRAW MARIO
|
||||
skin.use(DisplayManager.engine);
|
||||
DisplayManager.renderer.glFillRect(getPosX() - 18, 25 + getPosY(), 35, 27, 35 * (marioSkinPos[0] + 1), 27 * marioSkinPos[1], 35, 27);
|
||||
skin.use(DisplayManager.INSTANCE.engine);
|
||||
DisplayManager.INSTANCE.renderer.glFillRect(getPosX() - 18, 25 + getPosY(), 35, 27, 35 * (marioSkinPos[0] + 1), 27 * marioSkinPos[1], 35, 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);
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,7 @@ package org.warp.picalculator.gui.screens;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
@ -34,7 +31,6 @@ import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.parser.MathParser;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@ -59,7 +55,7 @@ public class MathInputScreen extends Screen {
|
||||
calc = new MathContext();
|
||||
|
||||
try {
|
||||
BlockContainer.initializeFonts(DisplayManager.engine.loadFont("ex"), DisplayManager.engine.loadFont("big"));
|
||||
BlockContainer.initializeFonts(DisplayManager.INSTANCE.engine.loadFont("ex"), DisplayManager.INSTANCE.engine.loadFont("big"));
|
||||
} catch (final IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
@ -79,10 +75,10 @@ public class MathInputScreen extends Screen {
|
||||
@Override
|
||||
public void beforeRender(float dt) {
|
||||
|
||||
if (DisplayManager.error == null) {
|
||||
DisplayManager.renderer.glClearColor(0xFFc5c2af);
|
||||
if (DisplayManager.INSTANCE.error == null) {
|
||||
DisplayManager.INSTANCE.renderer.glClearColor(0xFFc5c2af);
|
||||
} else {
|
||||
DisplayManager.renderer.glClearColor(0xFFDC3C32);
|
||||
DisplayManager.INSTANCE.renderer.glClearColor(0xFFDC3C32);
|
||||
}
|
||||
if (userInput.beforeRender(dt)) {
|
||||
mustRefresh = true;
|
||||
@ -93,7 +89,7 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void renderStatusbar() {
|
||||
final Renderer renderer = DisplayManager.renderer;
|
||||
final Renderer renderer = DisplayManager.INSTANCE.renderer;
|
||||
renderer.glColor3f(1, 1, 1);
|
||||
final int pos = 2;
|
||||
final int spacersNumb = 1;
|
||||
@ -108,15 +104,15 @@ public class MathInputScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
fontBig.use(DisplayManager.engine);
|
||||
fontBig.use(DisplayManager.INSTANCE.engine);
|
||||
final int textColor = 0xFF000000;
|
||||
final int padding = 4;
|
||||
DisplayManager.renderer.glColor(textColor);
|
||||
DisplayManager.INSTANCE.renderer.glColor(textColor);
|
||||
|
||||
userInput.draw(DisplayManager.engine, DisplayManager.renderer, padding, padding + 20);
|
||||
userInput.draw(DisplayManager.INSTANCE.engine, DisplayManager.INSTANCE.renderer, padding, padding + 20);
|
||||
|
||||
if (!result.isContentEmpty()) {
|
||||
result.draw(DisplayManager.engine, DisplayManager.renderer, DisplayManager.engine.getWidth() - result.getWidth() - 2, DisplayManager.engine.getHeight() - result.getHeight() - 2);
|
||||
result.draw(DisplayManager.INSTANCE.engine, DisplayManager.INSTANCE.renderer, DisplayManager.INSTANCE.engine.getWidth() - result.getWidth() - 2, DisplayManager.INSTANCE.engine.getHeight() - result.getHeight() - 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,41 +147,41 @@ public class MathInputScreen extends Screen {
|
||||
switch (k) {
|
||||
|
||||
case STEP:
|
||||
// if (newExpression.length() > 0) {
|
||||
// if (firstStep) {
|
||||
// try {
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// showVariablesDialog(() -> {
|
||||
// currentExpression = newExpression;
|
||||
// calc.f2 = calc.f;
|
||||
// firstStep = false;
|
||||
// step();
|
||||
// });
|
||||
// } catch (final Exception ex) {
|
||||
// if (Utils.debugOn) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// throw new Error(Errors.SYNTAX_ERROR);
|
||||
// }
|
||||
// } catch (final Error e) {
|
||||
// final StringWriter sw = new StringWriter();
|
||||
// final PrintWriter pw = new PrintWriter(sw);
|
||||
// e.printStackTrace(pw);
|
||||
// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
// DisplayManager.error = e.id.toString();
|
||||
// System.err.println(e.id);
|
||||
// }
|
||||
// } else {
|
||||
// step();
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// if (newExpression.length() > 0) {
|
||||
// if (firstStep) {
|
||||
// try {
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// showVariablesDialog(() -> {
|
||||
// currentExpression = newExpression;
|
||||
// calc.f2 = calc.f;
|
||||
// firstStep = false;
|
||||
// step();
|
||||
// });
|
||||
// } catch (final Exception ex) {
|
||||
// if (Utils.debugOn) {
|
||||
// ex.printStackTrace();
|
||||
// }
|
||||
// throw new Error(Errors.SYNTAX_ERROR);
|
||||
// }
|
||||
// } catch (final Error e) {
|
||||
// final StringWriter sw = new StringWriter();
|
||||
// final PrintWriter pw = new PrintWriter(sw);
|
||||
// e.printStackTrace(pw);
|
||||
// d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
// DisplayManager.INSTANCE.error = e.id.toString();
|
||||
// System.err.println(e.id);
|
||||
// }
|
||||
// } else {
|
||||
// step();
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
case SIMPLIFY:
|
||||
if (DisplayManager.error != null) {
|
||||
if (DisplayManager.INSTANCE.error != null) {
|
||||
//TODO: make the error management a global API rather than being relegated to this screen.
|
||||
Utils.out.println(1, "Resetting after error...");
|
||||
DisplayManager.error = null;
|
||||
DisplayManager.INSTANCE.error = null;
|
||||
calc.f = null;
|
||||
calc.f2 = null;
|
||||
calc.resultsCount = 0;
|
||||
@ -215,7 +211,7 @@ public class MathInputScreen extends Screen {
|
||||
if (f.isSimplified() == false) {
|
||||
done = false;
|
||||
if (f instanceof Expression) {
|
||||
ObjectArrayList<Function> fncResult = ((Expression)f).solve();
|
||||
ObjectArrayList<Function> fncResult = ((Expression) f).solve();
|
||||
for (Function resultItem : fncResult) {
|
||||
newResultExpressions.add(resultItem);
|
||||
}
|
||||
@ -235,16 +231,16 @@ public class MathInputScreen extends Screen {
|
||||
resultExpressions = newResultExpressions;
|
||||
stop++;
|
||||
}
|
||||
Utils.out.println(2, "INPUT: "+expr);
|
||||
Utils.out.println(2, "INPUT: " + expr);
|
||||
for (Function rr : resultExpressions) {
|
||||
Utils.out.println(1, "RESULT: " + rr.toString());
|
||||
}
|
||||
ObjectArrayList<ObjectArrayList<Block>> resultBlocks = MathParser.parseOutput(calc, resultExpressions);
|
||||
result.setContentAsMultipleGroups(resultBlocks);
|
||||
// showVariablesDialog(() -> {
|
||||
// currentExpression = newExpression;
|
||||
// simplify();
|
||||
// });
|
||||
// showVariablesDialog(() -> {
|
||||
// currentExpression = newExpression;
|
||||
// simplify();
|
||||
// });
|
||||
}
|
||||
} catch (final Exception ex) {
|
||||
if (Utils.debugOn) {
|
||||
@ -257,7 +253,7 @@ public class MathInputScreen extends Screen {
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
DisplayManager.error = e.id.toString();
|
||||
DisplayManager.INSTANCE.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return true;
|
||||
@ -373,9 +369,9 @@ public class MathInputScreen extends Screen {
|
||||
case RESET:
|
||||
userInput.clear();
|
||||
result.clear();
|
||||
if (DisplayManager.error != null) {
|
||||
if (DisplayManager.INSTANCE.error != null) {
|
||||
Utils.out.println(1, "Resetting after error...");
|
||||
DisplayManager.error = null;
|
||||
DisplayManager.INSTANCE.error = null;
|
||||
}
|
||||
return true;
|
||||
case SURD_MODE:
|
||||
@ -387,24 +383,24 @@ public class MathInputScreen extends Screen {
|
||||
DisplayManager.INSTANCE.setScreen(new EmptyScreen());
|
||||
return true;
|
||||
case HISTORY_BACK:
|
||||
// if (DisplayManager.INSTANCE.canGoBack()) {
|
||||
// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession + 1] instanceof MathInputScreen) {
|
||||
// newExpression = currentExpression;
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// } catch (final Error e) {}
|
||||
// }
|
||||
// }
|
||||
// if (DisplayManager.INSTANCE.canGoBack()) {
|
||||
// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession + 1] instanceof MathInputScreen) {
|
||||
// newExpression = currentExpression;
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// } catch (final Error e) {}
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
case HISTORY_FORWARD:
|
||||
// if (DisplayManager.INSTANCE.canGoForward()) {
|
||||
// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.sessions[DisplayManager.currentSession - 1] instanceof MathInputScreen) {
|
||||
// newExpression = currentExpression;
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// } catch (final Error e) {}
|
||||
// }
|
||||
// }
|
||||
// if (DisplayManager.INSTANCE.canGoForward()) {
|
||||
// if (currentExpression != null && currentExpression.length() > 0 & DisplayManager.INSTANCE.sessions[DisplayManager.INSTANCE.currentSession - 1] instanceof MathInputScreen) {
|
||||
// newExpression = currentExpression;
|
||||
// try {
|
||||
// interpreta(true);
|
||||
// } catch (final Error e) {}
|
||||
// }
|
||||
// }
|
||||
return false;
|
||||
case debug_DEG:
|
||||
if (calc.angleMode.equals(AngleMode.DEG) == false) {
|
||||
@ -459,7 +455,7 @@ public class MathInputScreen extends Screen {
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
DisplayManager.error = e.id.toString();
|
||||
DisplayManager.INSTANCE.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
return null;
|
||||
@ -491,7 +487,7 @@ public class MathInputScreen extends Screen {
|
||||
partialResults.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (results.size() == 0) {
|
||||
calc.resultsCount = 0;
|
||||
} else {
|
||||
@ -516,7 +512,7 @@ public class MathInputScreen extends Screen {
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
DisplayManager.error = e.id.toString();
|
||||
DisplayManager.INSTANCE.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
*/
|
||||
@ -533,7 +529,7 @@ public class MathInputScreen extends Screen {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final ObjectArrayList<Function> results = solveExpression(calc.f);
|
||||
if (results.size() == 0) {
|
||||
calc.resultsCount = 0;
|
||||
@ -558,7 +554,7 @@ public class MathInputScreen extends Screen {
|
||||
final PrintWriter pw = new PrintWriter(sw);
|
||||
e.printStackTrace(pw);
|
||||
d.errorStackTrace = sw.toString().toUpperCase().replace("\t", " ").replace("\r", "").split("\n");
|
||||
DisplayManager.error = e.id.toString();
|
||||
DisplayManager.INSTANCE.error = e.id.toString();
|
||||
System.err.println(e.id);
|
||||
}
|
||||
*/
|
||||
@ -618,7 +614,7 @@ public class MathInputScreen extends Screen {
|
||||
final ChooseVariableValueScreen cvs = new ChooseVariableValueScreen(this, new VariableValue((Variable) f, new Number(calc, 0)));
|
||||
DisplayManager.INSTANCE.setScreen(cvs);
|
||||
try {
|
||||
DisplayManager.screenChange.acquire();
|
||||
DisplayManager.INSTANCE.screenChange.acquire();
|
||||
} catch (final InterruptedException e) {}
|
||||
if (cvs.resultNumberValue == null) {
|
||||
cancelled = true;
|
||||
|
@ -24,12 +24,12 @@ public class SolveEquationScreen extends Screen {
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
DisplayManager.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glColor4i(0, 0, 0, 64);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2 + 1, Main.screenSize[1] / 4 + 1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
DisplayManager.INSTANCE.renderer.glColor3i(255, 0, 0);
|
||||
DisplayManager.INSTANCE.renderer.glDrawStringCenter(Main.screenSize[0] / 2, Main.screenSize[1] / 4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -68,9 +68,10 @@ public interface Function {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param context Mathematical Context
|
||||
* @param context
|
||||
* Mathematical Context
|
||||
* @return An ArrayList of parsed Blocks
|
||||
* @throws Error
|
||||
* @throws Error
|
||||
*/
|
||||
public ObjectArrayList<Block> toBlock(MathContext context) throws Error;
|
||||
}
|
||||
|
@ -177,9 +177,9 @@ public abstract class FunctionOperator implements Function {
|
||||
|
||||
@Override
|
||||
public abstract boolean equals(Object o);
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName()+"("+this.getParameter1()+","+this.getParameter2()+")";
|
||||
return this.getClass().getSimpleName() + "(" + this.getParameter1() + "," + this.getParameter2() + ")";
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,7 @@
|
||||
package org.warp.picalculator.math;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Variable.VariableValue;
|
||||
import org.warp.picalculator.math.functions.equations.Equation;
|
||||
import org.warp.picalculator.math.functions.equations.EquationsSystem;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
|
@ -3,16 +3,13 @@ package org.warp.picalculator.math.functions;
|
||||
import java.math.BigInteger;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.nevec.rjm.BigIntegerMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.expression.blocks.Block;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockChar;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockDivision;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.rules.FractionsRule1;
|
||||
import org.warp.picalculator.math.rules.FractionsRule11;
|
||||
import org.warp.picalculator.math.rules.FractionsRule12;
|
||||
|
@ -1,25 +1,14 @@
|
||||
package org.warp.picalculator.math.functions;
|
||||
|
||||
import static org.warp.picalculator.Utils.ArrayToRegex;
|
||||
import static org.warp.picalculator.Utils.concat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.gui.expression.blocks.Block;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockParenthesis;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionDynamic;
|
||||
import org.warp.picalculator.math.FunctionOperator;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcCosine;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcSine;
|
||||
import org.warp.picalculator.math.functions.trigonometry.ArcTangent;
|
||||
@ -49,12 +38,12 @@ public class Expression extends FunctionSingle {
|
||||
@Deprecated
|
||||
public Expression(MathContext root, String string, String debugSpaces, boolean initialParenthesis) throws Error {
|
||||
super(root);
|
||||
|
||||
|
||||
/*
|
||||
super(root);
|
||||
this.initialParenthesis = initialParenthesis;
|
||||
boolean isNumber = false;
|
||||
|
||||
|
||||
// Determine if the expression is already a number:
|
||||
// Determina se l'espressione è già un numero:
|
||||
try {
|
||||
@ -63,12 +52,12 @@ public class Expression extends FunctionSingle {
|
||||
} catch (final NumberFormatException ex) {
|
||||
isNumber = false;
|
||||
}
|
||||
|
||||
|
||||
String processExpression = string;
|
||||
Utils.debug.println(debugSpaces + "•Analyzing expression:" + processExpression);
|
||||
|
||||
|
||||
isNumber = false; //TODO: rimuovere isNumber, alcune semplificazione come la divisione per zero altrimenti verrebbero saltate.
|
||||
|
||||
|
||||
if (isNumber) {
|
||||
// If the expression is already a number:
|
||||
// Se l'espressione è già un numero:
|
||||
@ -79,10 +68,10 @@ public class Expression extends FunctionSingle {
|
||||
// Else prepare the expression:
|
||||
// Altrimenti prepara l'espressione:
|
||||
debugSpaces += " ";
|
||||
|
||||
|
||||
// IF the expression is not a number:
|
||||
// Se l'espressione non è già un numero:
|
||||
|
||||
|
||||
// Check if there are more than one equal symbol (=)
|
||||
// Controlla se ci sono più di un uguale (=)
|
||||
int equationsFound = 0;
|
||||
@ -102,7 +91,7 @@ public class Expression extends FunctionSingle {
|
||||
if (equationsFound != systemsFound) {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
|
||||
|
||||
//Solve the exceeding symbols ++ and --
|
||||
// Correggi i segni ++ e -- in eccesso
|
||||
Pattern pattern = Pattern.compile("\\+\\++?|\\-\\-+?");
|
||||
@ -114,7 +103,7 @@ public class Expression extends FunctionSingle {
|
||||
processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
matcher = pattern.matcher(processExpression);
|
||||
}
|
||||
|
||||
|
||||
// Correct the exceeding symbols +- and -+
|
||||
// Correggi i segni +- e -+ in eccesso
|
||||
pattern = Pattern.compile("\\+\\-|\\-\\+");
|
||||
@ -125,25 +114,25 @@ public class Expression extends FunctionSingle {
|
||||
processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
matcher = pattern.matcher(processExpression);
|
||||
}
|
||||
|
||||
|
||||
// Rimuovi i segni appena dopo le parentesi
|
||||
if (processExpression.contains("(+")) {
|
||||
symbolsChanged = true;
|
||||
processExpression = processExpression.replace("(+", "(");
|
||||
}
|
||||
|
||||
// // Cambia i segni appena prima le parentesi
|
||||
// if (processExpression.contains("-(")) {
|
||||
// symbolsChanged = true;
|
||||
// processExpression = processExpression.replace("-(", "-1*(");
|
||||
// }
|
||||
|
||||
|
||||
// // Cambia i segni appena prima le parentesi
|
||||
// if (processExpression.contains("-(")) {
|
||||
// symbolsChanged = true;
|
||||
// processExpression = processExpression.replace("-(", "-1*(");
|
||||
// }
|
||||
|
||||
// Rimuovi i segni appena dopo l'inizio
|
||||
if (processExpression.startsWith("+")) {
|
||||
symbolsChanged = true;
|
||||
processExpression = processExpression.substring(1, processExpression.length());
|
||||
}
|
||||
|
||||
|
||||
// Rimuovi i + in eccesso
|
||||
pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), '(')) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), new char[] { '(', ')' })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions)) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions)) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true), MathematicalSymbols.functions), new char[] { '(', ')' })) + "]");
|
||||
matcher = pattern.matcher(processExpression);
|
||||
@ -154,10 +143,10 @@ public class Expression extends FunctionSingle {
|
||||
processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
matcher = pattern.matcher(processExpression);
|
||||
}
|
||||
|
||||
|
||||
// Correggi i segni - in −
|
||||
processExpression = processExpression.replace('-', MathematicalSymbols.SUBTRACTION);
|
||||
|
||||
|
||||
// Correggi i segni − dopo di espressioni o funzioni SN in -
|
||||
pattern = Pattern.compile("[" + Utils.ArrayToRegex(concat(concat(MathematicalSymbols.functions, new char[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true))) + "]" + MathematicalSymbols.SUBTRACTION);
|
||||
matcher = pattern.matcher(processExpression);
|
||||
@ -167,30 +156,30 @@ public class Expression extends FunctionSingle {
|
||||
processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + 2, processExpression.length());
|
||||
matcher = pattern.matcher(processExpression);
|
||||
}
|
||||
|
||||
|
||||
// Cambia il segno iniziale − in -
|
||||
if (processExpression.startsWith("−")) {
|
||||
symbolsChanged = true;
|
||||
processExpression = "-" + processExpression.substring(1, processExpression.length());
|
||||
}
|
||||
|
||||
|
||||
if (symbolsChanged) {
|
||||
Utils.debug.println(debugSpaces + "•Resolved signs:" + processExpression);
|
||||
}
|
||||
|
||||
// // Aggiungi le parentesi implicite per le potenze con una incognita
|
||||
// pattern = Pattern.compile("(?<!(?:\\(|^))(["+Utils.ArrayToRegex(MathematicalSymbols.variables())+"]+"+MathematicalSymbols.POWER+"[^" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functionsNSN(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), ")")) + "])(?!\\))");
|
||||
// matcher = pattern.matcher(processExpression);
|
||||
// symbolsChanged = false;
|
||||
// while (matcher.find()) {
|
||||
// symbolsChanged = true;
|
||||
// String correzione = matcher.group().replace(MathematicalSymbols.POWER, "⑴");
|
||||
// processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
// matcher = pattern.matcher(processExpression);
|
||||
// }
|
||||
//
|
||||
// processExpression = processExpression.replace("⑴", MathematicalSymbols.POWER);
|
||||
|
||||
|
||||
// // Aggiungi le parentesi implicite per le potenze con una incognita
|
||||
// pattern = Pattern.compile("(?<!(?:\\(|^))(["+Utils.ArrayToRegex(MathematicalSymbols.variables())+"]+"+MathematicalSymbols.POWER+"[^" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functionsNSN(), concat(MathematicalSymbols.signums(true), MathematicalSymbols.genericSyntax())), ")")) + "])(?!\\))");
|
||||
// matcher = pattern.matcher(processExpression);
|
||||
// symbolsChanged = false;
|
||||
// while (matcher.find()) {
|
||||
// symbolsChanged = true;
|
||||
// String correzione = matcher.group().replace(MathematicalSymbols.POWER, "⑴");
|
||||
// processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
|
||||
// matcher = pattern.matcher(processExpression);
|
||||
// }
|
||||
//
|
||||
// processExpression = processExpression.replace("⑴", MathematicalSymbols.POWER);
|
||||
|
||||
// Aggiungi i segni * accanto alle parentesi
|
||||
pattern = Pattern.compile("\\([^\\(]+?\\)");
|
||||
matcher = pattern.matcher(processExpression);
|
||||
@ -211,17 +200,17 @@ public class Expression extends FunctionSingle {
|
||||
processExpression = beforeexp + "⑴" + newexp + "⑵" + afterexp;
|
||||
matcher = pattern.matcher(processExpression);
|
||||
}
|
||||
|
||||
|
||||
processExpression = processExpression.replace("⑴", "(").replace("⑵", ")");
|
||||
|
||||
|
||||
if (symbolsChanged) {
|
||||
Utils.debug.println(debugSpaces + "•Added implicit multiplications:" + processExpression);
|
||||
}
|
||||
|
||||
|
||||
Utils.debug.println(debugSpaces + "•Subdivision in classes:");
|
||||
|
||||
|
||||
debugSpaces += " ";
|
||||
|
||||
|
||||
// Convert the expression to a list of objects
|
||||
Expression imputRawParenthesis = new Expression(root);
|
||||
imputRawParenthesis = (Expression) imputRawParenthesis.setParameter(null);
|
||||
@ -231,7 +220,7 @@ public class Expression extends FunctionSingle {
|
||||
// Per ogni carattere cerca se è un numero o una funzione:
|
||||
final char charI = processExpression.charAt(i);
|
||||
if (Utils.isInArray(charI, functions)) {
|
||||
|
||||
|
||||
// Finds the type of function fron the following list
|
||||
// Cerca il tipo di funzione tra le esistenti
|
||||
Function f = null;
|
||||
@ -306,7 +295,7 @@ public class Expression extends FunctionSingle {
|
||||
}
|
||||
startIndex += 1;
|
||||
i = startIndex;
|
||||
|
||||
|
||||
String tmpExpr = "";
|
||||
while (i < endIndex) {
|
||||
tmpExpr += processExpression.charAt(i);
|
||||
@ -324,7 +313,7 @@ public class Expression extends FunctionSingle {
|
||||
System.err.println("Unexpected character while parsing expression: " + charI);
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
// throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
|
||||
// throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
|
||||
}
|
||||
}
|
||||
if (f instanceof Expression) {
|
||||
@ -392,7 +381,7 @@ public class Expression extends FunctionSingle {
|
||||
}
|
||||
tmp = "";
|
||||
}
|
||||
|
||||
|
||||
int dsl = debugSpaces.length();
|
||||
debugSpaces = "";
|
||||
for (int i = 0; i < dsl - 2; i++) {
|
||||
@ -400,7 +389,7 @@ public class Expression extends FunctionSingle {
|
||||
}
|
||||
Utils.debug.println(debugSpaces + "•Finished the subdivision in classes.");
|
||||
// Fine suddivisione di insieme
|
||||
|
||||
|
||||
Utils.debug.println(debugSpaces + "•Removing useless parentheses");
|
||||
for (int i = 0; i < imputRawParenthesis.getParametersLength(); i++) {
|
||||
if (imputRawParenthesis.getParameter(i) instanceof Expression) {
|
||||
@ -414,10 +403,10 @@ public class Expression extends FunctionSingle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Inizia l'affinazione dell'espressione
|
||||
Utils.debug.println(debugSpaces + "•Pushing classes...");
|
||||
|
||||
|
||||
final Function[] oldFunctionsArray = imputRawParenthesis.getParameters();
|
||||
final ObjectArrayList<Function> oldFunctionsList = new ObjectArrayList<>();
|
||||
for (int i = 0; i < oldFunctionsArray.length; i++) {
|
||||
@ -437,10 +426,10 @@ public class Expression extends FunctionSingle {
|
||||
oldFunctionsList.add(funzione);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (oldFunctionsList.size() > 1) {
|
||||
Utils.debug.println(debugSpaces + " •Correcting classes:");
|
||||
|
||||
|
||||
int before = 0;
|
||||
String step = "SN Functions";
|
||||
int n = 0;
|
||||
@ -457,9 +446,9 @@ public class Expression extends FunctionSingle {
|
||||
} else if (Utils.areThereEmptySums(oldFunctionsList)) {
|
||||
step = "sums"; // QUINTA FASE
|
||||
} else {
|
||||
// fase = "errore";
|
||||
// fase = "errore";
|
||||
System.out.println("WARN: ---> POSSIBILE ERRORE????? <---");// BOH
|
||||
// throw new Errore(Errori.SYNTAX_ERROR);
|
||||
// throw new Errore(Errori.SYNTAX_ERROR);
|
||||
while (oldFunctionsList.size() > 1) {
|
||||
oldFunctionsList.set(0, new Multiplication(root, oldFunctionsList.get(0), oldFunctionsList.remove(1)));
|
||||
}
|
||||
@ -471,18 +460,18 @@ public class Expression extends FunctionSingle {
|
||||
if (step != "SN Functions") {
|
||||
if ((step == "sums" && (funzioneTMP instanceof Sum || funzioneTMP instanceof SumSubtraction || funzioneTMP instanceof Subtraction) == true && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator)))) || (step.equals("multiplications") && ((funzioneTMP instanceof Multiplication) || (funzioneTMP instanceof Division)) && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (step == "NSN Functions" && (funzioneTMP instanceof Sum) == false && (funzioneTMP instanceof SumSubtraction) == false && (funzioneTMP instanceof Subtraction) == false && (funzioneTMP instanceof Multiplication) == false && (funzioneTMP instanceof Division) == false && ((funzioneTMP instanceof FunctionSingle && ((FunctionSingle) funzioneTMP).getParameter() == null) || (funzioneTMP instanceof FunctionOperator && ((FunctionOperator) funzioneTMP).getParameter1() == null && ((FunctionOperator) funzioneTMP).getParameter2() == null) || (!(funzioneTMP instanceof FunctionSingle) && !(funzioneTMP instanceof FunctionOperator))))) {
|
||||
change = true;
|
||||
|
||||
|
||||
if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
|
||||
funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter1(oldFunctionsList.get(i - 1));
|
||||
funzioneTMP = ((FunctionOperator) funzioneTMP).setParameter2(oldFunctionsList.get(i + 1));
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
|
||||
// è importante togliere prima gli elementi
|
||||
// in fondo e poi quelli davanti, perché gli
|
||||
// indici scalano da destra a sinistra.
|
||||
oldFunctionsList.remove(i + 1);
|
||||
oldFunctionsList.remove(i - 1);
|
||||
|
||||
|
||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getClass().getSimpleName());
|
||||
try {
|
||||
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionOperator) funzioneTMP).getParameter1().toString());
|
||||
@ -493,7 +482,7 @@ public class Expression extends FunctionSingle {
|
||||
try {
|
||||
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionOperator) funzioneTMP).toString());
|
||||
} catch (final NullPointerException ex2) {}
|
||||
|
||||
|
||||
} else {
|
||||
throw new Error(Errors.SYNTAX_ERROR);
|
||||
}
|
||||
@ -504,17 +493,17 @@ public class Expression extends FunctionSingle {
|
||||
if (i + 1 < oldFunctionsList.size()) {
|
||||
final Function nextFunc = oldFunctionsList.get(i + 1);
|
||||
if (nextFunc instanceof FunctionSingle && ((FunctionSingle) nextFunc).getParameter() == null) {
|
||||
|
||||
|
||||
} else {
|
||||
change = true;
|
||||
funzioneTMP = ((FunctionSingle) funzioneTMP).setParameter(nextFunc);
|
||||
oldFunctionsList.set(i, funzioneTMP);
|
||||
|
||||
|
||||
// è importante togliere prima gli elementi in
|
||||
// fondo e poi quelli davanti, perché gli indici
|
||||
// scalano da destra a sinistra.
|
||||
oldFunctionsList.remove(i + 1);
|
||||
|
||||
|
||||
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getClass().getSimpleName());
|
||||
final Function var = ((FunctionSingle) funzioneTMP).getParameter();
|
||||
if (var == null) {
|
||||
@ -545,14 +534,14 @@ public class Expression extends FunctionSingle {
|
||||
} else {
|
||||
super.functions = oldFunctionsList.toArray(new Function[oldFunctionsList.size()]);
|
||||
}
|
||||
|
||||
|
||||
dsl = debugSpaces.length();
|
||||
debugSpaces = "";
|
||||
for (int i = 0; i < dsl - 2; i++) {
|
||||
debugSpaces += " ";
|
||||
}
|
||||
Utils.debug.println(debugSpaces + "•Finished correcting classes.");
|
||||
|
||||
|
||||
final String result = toString();
|
||||
Utils.debug.println(debugSpaces + "•Result:" + result);
|
||||
}
|
||||
|
@ -113,15 +113,15 @@ public class Multiplication extends FunctionOperator {
|
||||
Function par2 = getParameter2();
|
||||
ObjectArrayList<Block> sub1 = par1.toBlock(context);
|
||||
ObjectArrayList<Block> sub2 = par2.toBlock(context);
|
||||
Block nearLeft = sub1.get(sub1.size()-1);
|
||||
Block nearLeft = sub1.get(sub1.size() - 1);
|
||||
Block nearRight = sub2.get(0);
|
||||
|
||||
if (par1 instanceof Number && ((Number)par1).equals(new Number(context, -1))) {
|
||||
|
||||
if (par1 instanceof Number && ((Number) par1).equals(new Number(context, -1))) {
|
||||
result.add(new BlockChar(MathematicalSymbols.MINUS));
|
||||
if (new Expression(context, par2).parenthesisNeeded()) {
|
||||
BlockParenthesis par = new BlockParenthesis();
|
||||
ObjectArrayList<Block> parBlocks = par2.toBlock(context);
|
||||
for (Block b: parBlocks) {
|
||||
for (Block b : parBlocks) {
|
||||
par.getNumberContainer().appendBlockUnsafe(b); // Skips recomputeDimension
|
||||
}
|
||||
par.recomputeDimensions(); // Recompute dimensions after appendBlockUnsafe
|
||||
@ -133,7 +133,7 @@ public class Multiplication extends FunctionOperator {
|
||||
} else {
|
||||
result.addAll(sub1);
|
||||
if ((nearLeft instanceof BlockChar && nearRight instanceof BlockChar) && !(par2 instanceof Negative)) {
|
||||
|
||||
|
||||
} else {
|
||||
result.add(new BlockChar(MathematicalSymbols.MULTIPLICATION));
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class Negative extends FunctionSingle {
|
||||
public Negative clone() {
|
||||
return new Negative(mathContext, parameter);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ObjectArrayList<Block> toBlock(MathContext context) throws Error {
|
||||
ObjectArrayList<Block> blocks = new ObjectArrayList<Block>();
|
||||
@ -81,7 +81,7 @@ public class Negative extends FunctionSingle {
|
||||
if (new Expression(context, getParameter()).parenthesisNeeded()) {
|
||||
BlockParenthesis par = new BlockParenthesis();
|
||||
ObjectArrayList<Block> parBlocks = getParameter().toBlock(context);
|
||||
for (Block b: parBlocks) {
|
||||
for (Block b : parBlocks) {
|
||||
par.getNumberContainer().appendBlockUnsafe(b); // Skips recomputeDimension
|
||||
}
|
||||
par.recomputeDimensions(); // Recompute dimensions after appendBlockUnsafe
|
||||
|
@ -197,7 +197,7 @@ public class Number implements Function {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author programmingpraxis
|
||||
* @return
|
||||
@ -222,9 +222,9 @@ public class Number implements Function {
|
||||
}
|
||||
}
|
||||
|
||||
if (n.compareTo(two) < 0) {
|
||||
throw new IllegalArgumentException("must be greater than one");
|
||||
}
|
||||
if (n.compareTo(two) < 0) {
|
||||
throw new IllegalArgumentException("must be greater than one");
|
||||
}
|
||||
|
||||
while (n.mod(two).equals(BigInteger.ZERO)) {
|
||||
fs.add(two);
|
||||
@ -260,7 +260,7 @@ public class Number implements Function {
|
||||
}
|
||||
for (char c : numberParts[1].toCharArray()) {
|
||||
bpec.appendBlockUnsafe(new BlockChar(c));
|
||||
};
|
||||
} ;
|
||||
bpec.recomputeDimensions();
|
||||
bp.recomputeDimensions();
|
||||
result.add(bp);
|
||||
|
@ -75,7 +75,7 @@ public class Root extends FunctionOperator {
|
||||
public Root clone() {
|
||||
return new Root(mathContext, parameter1, parameter2);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ObjectArrayList<Block> toBlock(MathContext context) throws Error {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -4,7 +4,6 @@ import org.nevec.rjm.BigDecimalMath;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.gui.expression.blocks.Block;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockParenthesis;
|
||||
import org.warp.picalculator.gui.expression.blocks.BlockSine;
|
||||
import org.warp.picalculator.math.AngleMode;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
@ -22,11 +22,11 @@ import org.warp.picalculator.math.parser.features.FeatureSum;
|
||||
import org.warp.picalculator.math.parser.features.FeatureSumSubtraction;
|
||||
import org.warp.picalculator.math.parser.features.FeatureVariable;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
import org.warp.picalculator.math.parser.steps.JoinNumberAndVariables;
|
||||
import org.warp.picalculator.math.parser.steps.AddImplicitMultiplications;
|
||||
import org.warp.picalculator.math.parser.steps.FixMultiplicationsAndDivisions;
|
||||
import org.warp.picalculator.math.parser.steps.FixSingleFunctionArgs;
|
||||
import org.warp.picalculator.math.parser.steps.FixSumsAndSubtractions;
|
||||
import org.warp.picalculator.math.parser.steps.JoinNumberAndVariables;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
@ -40,11 +40,13 @@ public class MathParser {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ObjectArrayList<ObjectArrayList<Block>> parseOutput(MathContext context, ObjectArrayList<Function> resultExpressions) throws Error {
|
||||
public static ObjectArrayList<ObjectArrayList<Block>> parseOutput(MathContext context,
|
||||
ObjectArrayList<Function> resultExpressions) throws Error {
|
||||
final ObjectArrayList<ObjectArrayList<Block>> result = new ObjectArrayList<>();
|
||||
for (Function resultExpression : resultExpressions) {
|
||||
ObjectArrayList<Block> resultBlocks = resultExpression.toBlock(context);
|
||||
if (resultBlocks == null) throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + resultExpression.getClass().getSimpleName());
|
||||
if (resultBlocks == null)
|
||||
throw new Error(Errors.NOT_IMPLEMENTED, "Unknown function " + resultExpression.getClass().getSimpleName());
|
||||
result.add(resultBlocks);
|
||||
}
|
||||
return result;
|
||||
@ -55,13 +57,14 @@ public class MathParser {
|
||||
features = fixFeatures(context, features);
|
||||
|
||||
ObjectArrayList<Function> process = new ObjectArrayList<>();
|
||||
|
||||
|
||||
for (final Feature f : features) {
|
||||
Function fnc = f.toFunction(context);
|
||||
if (fnc == null) throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
|
||||
if (fnc == null)
|
||||
throw new Error(Errors.SYNTAX_ERROR, "\"" + f.getClass().getSimpleName() + "\" can't be converted into a Function!");
|
||||
process.add(fnc);
|
||||
}
|
||||
|
||||
|
||||
process = fixStack(context, process);
|
||||
|
||||
if (process.size() > 1) {
|
||||
@ -71,14 +74,9 @@ public class MathParser {
|
||||
return process.get(0);
|
||||
}
|
||||
|
||||
private static ObjectArrayList<Function> fixStack(MathContext context, ObjectArrayList<Function> functionsList) throws Error {
|
||||
final MathParserStep[] steps = new MathParserStep[] {
|
||||
new JoinNumberAndVariables(context),
|
||||
new FixSingleFunctionArgs(),
|
||||
new FixMultiplicationsAndDivisions(),
|
||||
new FixSumsAndSubtractions(),
|
||||
new AddImplicitMultiplications(context),
|
||||
};
|
||||
private static ObjectArrayList<Function> fixStack(MathContext context, ObjectArrayList<Function> functionsList)
|
||||
throws Error {
|
||||
final MathParserStep[] steps = new MathParserStep[] { new JoinNumberAndVariables(context), new FixSingleFunctionArgs(), new FixMultiplicationsAndDivisions(), new FixSumsAndSubtractions(), new AddImplicitMultiplications(context), };
|
||||
boolean lastLoopDidSomething;
|
||||
Function lastElement;
|
||||
|
||||
@ -89,29 +87,30 @@ public class MathParser {
|
||||
}
|
||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MAX);
|
||||
}
|
||||
|
||||
|
||||
for (MathParserStep step : steps) {
|
||||
if (Utils.debugOn) {
|
||||
Utils.out.println(2, "Stack fixing step \""+step.getStepName()+"\"");
|
||||
Utils.out.println(2, "Stack fixing step \"" + step.getStepName() + "\"");
|
||||
}
|
||||
int stepQty = step.requiresReversedIteration()?-1:1, initialIndex = step.requiresReversedIteration()?functionsList.size()-1:0;
|
||||
int stepQty = step.requiresReversedIteration() ? -1 : 1,
|
||||
initialIndex = step.requiresReversedIteration() ? functionsList.size() - 1 : 0;
|
||||
do {
|
||||
lastLoopDidSomething = false;
|
||||
lastElement = null;
|
||||
IntegerObj curIndex = new IntegerObj(initialIndex);
|
||||
while(curIndex.i >= 0 && curIndex.i < functionsList.size()) {
|
||||
while (curIndex.i >= 0 && curIndex.i < functionsList.size()) {
|
||||
final int i = curIndex.i;
|
||||
final Function f = functionsList.get(i);
|
||||
|
||||
|
||||
if (step.eval(curIndex, lastElement, f, functionsList)) {
|
||||
lastLoopDidSomething = true;
|
||||
}
|
||||
|
||||
|
||||
lastElement = (i >= functionsList.size()) ? null : functionsList.get(i);
|
||||
curIndex.i += stepQty;
|
||||
}
|
||||
} while (lastLoopDidSomething);
|
||||
|
||||
|
||||
if (Utils.debugOn) {
|
||||
Utils.out.print(Utils.OUTPUTLEVEL_DEBUG_MAX, "\tStatus: ");
|
||||
for (Function f : functionsList) {
|
||||
@ -120,7 +119,7 @@ public class MathParser {
|
||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// //Phase 4
|
||||
// do {
|
||||
// lastLoopDidSomething = false;
|
||||
@ -133,7 +132,7 @@ public class MathParser {
|
||||
// }
|
||||
// }
|
||||
// } while (lastLoopDidSomething);
|
||||
|
||||
|
||||
return functionsList;
|
||||
}
|
||||
|
||||
@ -145,7 +144,7 @@ public class MathParser {
|
||||
features = makeNumbers(context, features);
|
||||
|
||||
features = makePowers(context, features);
|
||||
|
||||
|
||||
features = convertFunctionChars(context, features);
|
||||
|
||||
return features;
|
||||
@ -183,7 +182,7 @@ public class MathParser {
|
||||
result = new FeatureDivision(null, null);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
for (char var : MathematicalSymbols.variables) {
|
||||
if (featureChar == var) {
|
||||
result = new FeatureVariable(featureChar, V_TYPE.VARIABLE);
|
||||
@ -296,9 +295,10 @@ public class MathParser {
|
||||
* @param context
|
||||
* @param features
|
||||
* @return
|
||||
* @throws Error
|
||||
* @throws Error
|
||||
*/
|
||||
private static ObjectArrayList<Feature> makePowers(MathContext context, ObjectArrayList<Feature> features) throws Error {
|
||||
private static ObjectArrayList<Feature> makePowers(MathContext context, ObjectArrayList<Feature> features)
|
||||
throws Error {
|
||||
final ObjectArrayList<Feature> process = new ObjectArrayList<>();
|
||||
|
||||
Feature lastFeature = null;
|
||||
|
@ -8,6 +8,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Join number and variables together ([2][4][x] => [[24]*[x]])
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
@ -19,8 +20,9 @@ public interface MathParserStep {
|
||||
* @param process
|
||||
* @return true if something changed
|
||||
*/
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction, ObjectArrayList<Function> functionsfunctionsList) throws Error;
|
||||
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction,
|
||||
ObjectArrayList<Function> functionsfunctionsList) throws Error;
|
||||
|
||||
public boolean requiresReversedIteration();
|
||||
|
||||
public String getStepName();
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
|
||||
|
||||
public abstract class FeatureDoubleImpl implements FeatureDouble {
|
||||
private Object child_1;
|
||||
@ -31,11 +31,11 @@ public abstract class FeatureDoubleImpl implements FeatureDouble {
|
||||
public void setChild2(Object obj) {
|
||||
child_2 = obj;
|
||||
}
|
||||
|
||||
|
||||
protected Function getFunction1() {
|
||||
return (Function) child_1;
|
||||
}
|
||||
|
||||
|
||||
protected Function getFunction2() {
|
||||
return (Function) child_2;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
|
@ -3,7 +3,6 @@ package org.warp.picalculator.math.parser.features;
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Power;
|
||||
|
||||
public class FeaturePowerChar extends FeatureSingleImpl {
|
||||
|
||||
|
@ -14,7 +14,7 @@ public abstract class FeatureSingleImpl implements FeatureSingle {
|
||||
public Object getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
protected Function getFunction1() {
|
||||
return (Function) child;
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.FeatureDouble;
|
||||
|
||||
public class FeatureSubtraction extends FeatureDoubleImpl {
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package org.warp.picalculator.math.parser.features;
|
||||
|
||||
import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
|
||||
public class FeatureSumSubtraction extends FeatureDoubleImpl {
|
||||
|
||||
|
@ -5,8 +5,6 @@ import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.FunctionSingle;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Number;
|
||||
import org.warp.picalculator.math.functions.Variable;
|
||||
import org.warp.picalculator.math.parser.MathParserStep;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
@ -14,13 +12,14 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
public class AddImplicitMultiplications implements MathParserStep {
|
||||
|
||||
private MathContext context;
|
||||
|
||||
|
||||
public AddImplicitMultiplications(MathContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction, ObjectArrayList<Function> functionsList) {
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction,
|
||||
ObjectArrayList<Function> functionsList) {
|
||||
if (currentFunction instanceof FunctionSingle) {
|
||||
if (lastFunction instanceof Function) {
|
||||
functionsList.set(curIndex.i, new Multiplication(context, currentFunction, lastFunction));
|
||||
@ -36,7 +35,7 @@ public class AddImplicitMultiplications implements MathParserStep {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean requiresReversedIteration() {
|
||||
return true;
|
||||
|
@ -11,6 +11,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
|
||||
/**
|
||||
* Puts the argument of Single Functions inside them
|
||||
*
|
||||
* @author Andrea Cavalli
|
||||
*
|
||||
*/
|
||||
@ -25,7 +26,7 @@ public class FixSingleFunctionArgs implements MathParserStep {
|
||||
throw new Error(Errors.MISSING_ARGUMENTS, "There is a function at the end without any argument specified.");
|
||||
} else {
|
||||
((FunctionSingle) currentFunction).setParameter(lastFunction);
|
||||
functionsList.remove(curIndex.i+1);
|
||||
functionsList.remove(curIndex.i + 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import org.warp.picalculator.Error;
|
||||
import org.warp.picalculator.Errors;
|
||||
import org.warp.picalculator.IntegerObj;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.functions.Multiplication;
|
||||
import org.warp.picalculator.math.functions.Subtraction;
|
||||
import org.warp.picalculator.math.functions.Sum;
|
||||
import org.warp.picalculator.math.functions.SumSubtraction;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.warp.picalculator.math.parser.steps;
|
||||
|
||||
import org.warp.picalculator.IntegerObj;
|
||||
import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.math.Function;
|
||||
import org.warp.picalculator.math.MathContext;
|
||||
import org.warp.picalculator.math.functions.Division;
|
||||
@ -15,15 +14,16 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
public class JoinNumberAndVariables implements MathParserStep {
|
||||
|
||||
private MathContext context;
|
||||
|
||||
|
||||
public JoinNumberAndVariables(MathContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction, ObjectArrayList<Function> functionsList) {
|
||||
public boolean eval(IntegerObj curIndex, Function lastFunction, Function currentFunction,
|
||||
ObjectArrayList<Function> functionsList) {
|
||||
if (currentFunction instanceof Number | currentFunction instanceof Variable | currentFunction instanceof Division) {
|
||||
if (lastFunction instanceof Variable | lastFunction instanceof Number | (lastFunction instanceof Multiplication && ((Multiplication)lastFunction).getParameter2() != null)) {
|
||||
if (lastFunction instanceof Variable | lastFunction instanceof Number | (lastFunction instanceof Multiplication && ((Multiplication) lastFunction).getParameter2() != null)) {
|
||||
final Function a = currentFunction;
|
||||
final Function b = lastFunction;
|
||||
functionsList.set(curIndex.i, new Multiplication(context, a, b));
|
||||
@ -33,7 +33,7 @@ public class JoinNumberAndVariables implements MathParserStep {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean requiresReversedIteration() {
|
||||
return true;
|
||||
|
@ -36,7 +36,7 @@ public class ExpandRule5 {
|
||||
|
||||
public static ObjectArrayList<Function> execute(Function f) throws Error {
|
||||
final ObjectArrayList<Function> result = new ObjectArrayList<>();
|
||||
|
||||
|
||||
if (f instanceof Negative) {
|
||||
final Negative fnc = (Negative) f;
|
||||
result.add(((Negative) ((Expression) fnc.getParameter()).getParameter()).getParameter());
|
||||
|
@ -40,9 +40,8 @@ public class DivisionRule1 {
|
||||
prec = new Multiplication(root, a, b);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
final int[] size = new int[] {elements[0].size(), elements[1].size()};
|
||||
final int[] size = new int[] { elements[0].size(), elements[1].size() };
|
||||
Function separatedDivision = new Division(root, elem1, elem2);
|
||||
|
||||
Function[] resultDivisionArray = new Function[2];
|
||||
@ -90,12 +89,12 @@ public class DivisionRule1 {
|
||||
denomMult = ((Multiplication) denomMult).getParameter2();
|
||||
}
|
||||
elementsDenominator.add(denomMult);
|
||||
|
||||
return new ObjectArrayList[] {elementsNumerator, elementsDenominator};
|
||||
|
||||
return new ObjectArrayList[] { elementsNumerator, elementsDenominator };
|
||||
}
|
||||
|
||||
private static int[] getFirstWorkingDivisionCouple(ObjectArrayList<Function>[] elements) {
|
||||
final int[] size = new int[] {elements[0].size(), elements[1].size()};
|
||||
final int[] size = new int[] { elements[0].size(), elements[1].size() };
|
||||
Function a;
|
||||
Function b;
|
||||
if (elements[0].size() + elements[1].size() <= 2) {
|
||||
|
Loading…
Reference in New Issue
Block a user