Renewed headless graphic engines and console parameters

This commit is contained in:
Andrea Cavalli 2017-07-16 13:47:29 +02:00
parent d02f5c7db8
commit 5aec22fa01
22 changed files with 1505 additions and 512 deletions

View File

@ -54,6 +54,33 @@ public class Main {
Utils.debugOn = true;
}
Utils.debugThirdScreen = Utils.debugOn & false;
for (String arg : args) {
if (arg.contains("headless")) {
Utils.headlessOverride = true;
}
if (arg.contains("console-8")) {
Utils.headlessOverride = true;
Utils.forceEngine = "console-8";
}
if (arg.contains("console-256")) {
Utils.headlessOverride = true;
Utils.forceEngine = "console-256";
}
if (arg.contains("console-24bit")) {
Utils.headlessOverride = true;
Utils.forceEngine = "console-24bit";
}
if (arg.contains("cpu")) {
Utils.forceEngine = "cpu";
}
if (arg.contains("gpu")) {
Utils.forceEngine = "gpu";
}
if (arg.contains("ms-dos")) {
Utils.headlessOverride = true;
Utils.msDosMode = true;
}
}
DisplayManager.setBrightness(0.5f);
Keyboard.startKeyboard();
}

View File

@ -55,6 +55,10 @@ public class Utils {
public static final int OUTPUTLEVEL_DEBUG_MAX = 4;
public static boolean debugThirdScreen;
public static final boolean debugWindow2x = true;
public static boolean headlessOverride = false;
private static String OS = System.getProperty("os.name").toLowerCase();
public static String forceEngine;
public static boolean msDosMode;
public static final class AdvancedOutputStream extends StringWriter {
@ -711,4 +715,8 @@ public class Utils {
}
return false;
}
public static boolean isWindows() {
return (OS.indexOf("win") >= 0);
}
}

View File

@ -12,8 +12,9 @@ import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
import org.warp.picalculator.gui.graphicengine.headless256.Headless8Engine;
import org.warp.picalculator.gui.graphicengine.headless8.Headless256Engine;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitEngine;
import org.warp.picalculator.gui.graphicengine.headless256.Headless256Engine;
import org.warp.picalculator.gui.graphicengine.headless8.Headless8Engine;
import org.warp.picalculator.gui.screens.Screen;
import com.pi4j.wiringpi.Gpio;
@ -85,6 +86,11 @@ public final class DisplayManager implements RenderingLoop {
Utils.out.println(1, "Using CPU Graphic Engine");
return d;
}
d = new Headless24bitEngine();
if (d.isSupported()) {
System.err.println("Using Headless 24 bit Engine! This is a problem! No other graphic engines are available.");
return d;
}
d = new Headless256Engine();
if (d.isSupported()) {
System.err.println("Using Headless 256 Engine! This is a problem! No other graphic engines are available.");

View File

@ -20,12 +20,9 @@ import org.warp.picalculator.gui.graphicengine.Skin;
public class CPUEngine implements GraphicEngine {
private SwingWindow INSTANCE;
public int[] size = new int[] { 1, 1 };
public BufferedImage g = new BufferedImage(size[0], size[1], BufferedImage.TYPE_INT_RGB);
static int[] canvas2d = new int[1];
public int color = 0xFF000000;
public final CPURenderer r = new CPURenderer();
public BufferedImage g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_RGB);
public volatile boolean initialized = false;
private final CPURenderer r = new CPURenderer();
@Override
public void setTitle(String title) {
@ -43,8 +40,8 @@ public class CPUEngine implements GraphicEngine {
@Override
public void setDisplayMode(final int ww, final int wh) {
INSTANCE.setSize(ww, wh);
size = new int[] { ww, wh };
canvas2d = new int[ww * wh];
r.size = new int[] { ww, wh };
r.canvas2d = new int[ww * wh];
g = new BufferedImage(ww, wh, BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
}
@ -61,9 +58,9 @@ public class CPUEngine implements GraphicEngine {
@Override
public boolean wasResized() {
if (INSTANCE.wasResized) {
size = new int[] { INSTANCE.getWidth(), INSTANCE.getHeight() };
canvas2d = new int[size[0] * size[1]];
g = new BufferedImage(size[0], size[1], BufferedImage.TYPE_INT_ARGB);
r.size = new int[] { INSTANCE.getWidth(), INSTANCE.getHeight() };
r.canvas2d = new int[r.size[0] * r.size[1]];
g = new BufferedImage(r.size[0], r.size[1], BufferedImage.TYPE_INT_ARGB);
INSTANCE.wasResized = false;
return true;
}
@ -142,311 +139,9 @@ public class CPUEngine implements GraphicEngine {
public abstract void run();
}
public class CPURenderer implements Renderer {
public int clearcolor = 0xFFc5c2af;
public CPUFont currentFont;
public CPUSkin currentSkin;
@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 + 1));
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 + "");
}
}
@Override
public int[] getSize() {
return size;
return r.size;
}
@Override
@ -482,7 +177,8 @@ public class CPUEngine implements GraphicEngine {
@Override
public boolean isSupported() {
return GraphicsEnvironment.isHeadless() == false;
if (Utils.forceEngine != null && Utils.forceEngine != "cpu") return false;
return (Utils.headlessOverride || GraphicsEnvironment.isHeadless()) == false;
}
@Override

View File

@ -14,7 +14,6 @@ import javax.imageio.ImageIO;
import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine.CPURenderer;
public class CPUFont implements BinaryFont {

View File

@ -0,0 +1,312 @@
package org.warp.picalculator.gui.graphicengine.cpu;
import java.awt.FontMetrics;
import org.warp.picalculator.Main;
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 + 1));
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 + "");
}
}

View File

@ -7,7 +7,6 @@ import javax.imageio.ImageIO;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Skin;
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine.CPURenderer;
public class CPUSkin implements Skin {

View File

@ -245,8 +245,8 @@ public class SwingWindow extends JFrame {
final int[] a = ((DataBufferInt) display.g.getRaster().getDataBuffer()).getData();
// System.arraycopy(canvas2d, 0, a, 0, canvas2d.length);
CPUEngine.canvas2d = a;
g.clearRect(0, 0, display.size[0], display.size[1]);
CPURenderer.canvas2d = a;
g.clearRect(0, 0, display.r.size[0], display.r.size[1]);
g.drawImage(display.g, 0, 0, null);
// long time2 = System.nanoTime();
// double timeDelta = ((double)(time2-time1))/1000000000d;

View File

@ -125,7 +125,8 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
@Override
public boolean isSupported() {
if (Utils.debugOn) return false;
if (Utils.forceEngine != null && Utils.forceEngine != "gpu") return false;
if (Utils.headlessOverride) return false;
boolean available = false;
boolean errored = false;
try {

View File

@ -0,0 +1,324 @@
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.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.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
public class Headless24bitEngine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private Headless24bitRenderer r = new Headless24bitRenderer();
private boolean stopped = true;
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;
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]};
}
@Override
public boolean isInitialized() {
return !stopped;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@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() {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){
win = true;
WindowsSupport.setConsoleMode(0x0200);
Thread t = new Thread(()-> {
int ch = -1;
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;
}
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;
}
}
if (key != null) {
Keyboard.keyPressed(key);
}
}
});
t.setDaemon(true);
t.start();
}
stopped = false;
}
@Override
public boolean wasResized() {
return false;
}
@Override
public int getWidth() {
return r.size[0];
}
@Override
public int getHeight() {
return r.size[1];
}
@Override
public void destroy() {
stopped = true;
}
@Override
public void start(RenderingLoop d) {
this.renderLoop = d;
final Thread th = new Thread(() -> {
try {
double extratime = 0;
while (!stopped) {
final long start = System.currentTimeMillis();
repaint();
final long end = System.currentTimeMillis();
final double delta = (end - start) / 1000d;
final int deltaInt = (int) Math.floor(delta);
final int extraTimeInt = (int) Math.floor(extratime);
if (extraTimeInt + deltaInt < 200) {
Thread.sleep(200 - (extraTimeInt + deltaInt));
extratime = 0;
} else {
extratime += delta - 200d;
}
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
});
th.setName("Console rendering thread");
th.setDaemon(true);
th.start();
}
@Override
public void repaint() {
renderLoop.refresh();
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");
} else {
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};
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][];
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]];
}
}
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.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][];
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]];
}
}
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.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];
if (precBgColor != curBgColor) {
out = Headless24bitRenderer.ANSI_PREFIX+Headless24bitRenderer.ansiBgColorPrefix+curBgColor[0]+";"+curBgColor[1]+";"+curBgColor[2]+Headless24bitRenderer.ansiColorSuffix;
if (win) {
WindowsSupport.writeConsole(out);
} else {
AnsiConsole.out.print(out);
}
}
if (precFgColor != curFgColor) {
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];
if (win) {
WindowsSupport.writeConsole(outchar+"");
} else {
AnsiConsole.out.print(outchar);
}
precBgColor = curBgColor;
precFgColor = curFgColor;
}
if (win) {
//System.out.println(ch);
WindowsSupport.writeConsole("\r\n");
} else {
AnsiConsole.out.println();
}
}
}
@Override
public Renderer getRenderer() {
return r;
}
@Override
public Headless24bitFont loadFont(String file) throws IOException {
return new Headless24bitFont();
}
@Override
public Headless24bitSkin loadSkin(String file) throws IOException {
return new Headless24bitSkin(file);
}
@Override
public void waitUntilExit() {
try {
do {
Thread.sleep(500);
} while (stopped==false);
} catch (final InterruptedException e) {
}
}
@Override
public boolean isSupported() {
if (Utils.msDosMode || (Utils.forceEngine != null && Utils.forceEngine != "console-24bit")) return false;
return true;
}
@Override
public boolean doesRefreshPauses() {
return true;
}
}

View File

@ -0,0 +1,42 @@
package org.warp.picalculator.gui.graphicengine.headless24bit;
import java.io.IOException;
import org.warp.picalculator.gui.graphicengine.BinaryFont;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
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();
}
@Override
public int getCharacterWidth() {
return 5;
}
@Override
public int getCharacterHeight() {
return 5;
}
}

View File

@ -0,0 +1,313 @@
package org.warp.picalculator.gui.graphicengine.headless24bit;
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];
protected int[] clearColor = rgbToIntArray(0xc5, 0xc2, 0xaf);
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 int[] rgbToIntArray(int r_U, int g_U, int 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);
}
@Override
public void glColor(int c) {
curColor = rgbToIntArray(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF);
}
@Override
public void glColor4i(int red, int green, int blue, int alpha) {
curColor = rgbToIntArray(red, green, blue);
}
@Override
public void glColor3f(float red, float green, float blue) {
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));
}
@Override
public void glClearColor4i(int red, int green, int blue, int alpha) {
clearColor = rgbToIntArray(red, green, blue);
}
@Override
public void glClearColor4f(float red, float green, float blue, float alpha) {
clearColor = rgbToIntArray((int)(red*255), (int)(green*255), (int)(blue*255));
}
@Override
public int glGetClearColor() {
return clearColor[2] << 16 | clearColor[1] << 8 | clearColor[0];
}
@Override
public void glClearColor(int c) {
clearColor = rgbToIntArray(c >> 16 & 0xFF, c >> 8 & 0xFF, c & 0xFF);
}
@Override
public void glClear(int screenWidth, int screenHeight) {
clearAll();
}
@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);
int sx = (x1 < x2) ? 1 : -1;
int sy = (y1 < y2) ? 1 : -1;
int err = dx - dy;
while (true) {
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] = ' ';
if (x1 == x2 && y1 == y2) {
break;
}
int e2 = 2 * err;
if (e2 > -dy) {
err = err - dy;
x1 = x1 + sx;
}
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) {
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) {
final int ix = (int) x;
final int iy = (int) y;
final int iw = (int) width;
final int ih = (int) height;
int x1 = ix + iw;
int y1 = iy + ih;
if (ix >= size[0] || iy >= size[1]) {
return;
}
if (x1 >= size[0]) {
x1 = size[0];
}
if (y1 >= size[1]) {
y1 = size[1];
}
final int sizeW = size[0];
for (int px = ix; px < x1; px++) {
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] = ' ';
}
}
}
@Override
public void glDrawCharLeft(int x, int y, char ch) {
final int cx = 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;
}
@Override
public void glDrawCharCenter(int x, int y, char 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 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;
}
@Override
public void glDrawStringLeft(float x, float y, String text) {
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]) {
break;
}
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);
int i = 0;
for (char c : text.toCharArray()) {
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;
i++;
}
}
@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;
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[1]) {
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 (pixelY < size[1]) {
if (pixelX - (pixelX % size[0]) == 0) {
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] = ' ';
bgColorMatrixSs[pixelX + pixelY * size[0]] = newColor;
}
}
}
}
}
}
}
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 < size[0]*size[1]; i++) {
bgColorMatrixSs[i] = clearColor;
fgColorMatrixSs[i] = new int[] {0,0,0};
}
}
@Override
public Headless24bitFont getCurrentFont() {
return currentFont;
}
}

View File

@ -0,0 +1,61 @@
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;
import javax.imageio.ImageIO;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Skin;
public class Headless24bitSkin implements Skin {
public int[][] skinData;
public int[] skinSize;
Headless24bitSkin(String file) throws IOException {
load(file);
}
@Override
public void load(String file) throws IOException {
final BufferedImage img = ImageIO.read(this.getClass().getResource("/" + file));
skinData = getMatrixOfImage(img);
skinSize = new int[] { img.getWidth(), img.getHeight() };
}
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;
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};
}
}
return pixels;
}
@Override
public void initialize(GraphicEngine d) {
}
@Override
public void use(GraphicEngine d) {
((Headless24bitRenderer) d.getRenderer()).currentSkin = this;
}
}

View File

@ -1,23 +1,30 @@
package org.warp.picalculator.gui.graphicengine.headless8;
package org.warp.picalculator.gui.graphicengine.headless256;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
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.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
public class Headless256Engine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private Headless256Renderer r = new Headless256Renderer();
private boolean stopped = true;
private RenderingLoop renderLoop;
protected static final int C_WIDTH = Main.screenSize[0]/2;//;60;
protected static final int C_HEIGHT = Main.screenSize[1]/3;//;40;
public static final int C_MUL_X = 2;//8;
public static final int C_MUL_Y = 3;//8;
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;
private String title = Main.calculatorName;
private boolean win = false;
private Key precKey = null;
@Override
public int[] getSize() {
@ -49,8 +56,75 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
@Override
public void create() {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
AnsiConsole.out.print(Headless256Renderer.ANSI_PREFIX+"?25l");
if(Utils.isWindows() && !Utils.msDosMode){
win = true;
WindowsSupport.setConsoleMode(0x0200);
Thread t = new Thread(()-> {
int ch = -1;
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;
}
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;
}
}
if (key != null) {
Keyboard.keyPressed(key);
}
}
});
t.setDaemon(true);
t.start();
}
stopped = false;
}
@ -108,7 +182,15 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
renderLoop.refresh();
r.curColor = 0x1C;
r.glDrawStringCenter((C_WIDTH*C_MUL_X)/2, 0, title);
AnsiConsole.out.print(Headless256Renderer.ANSI_PREFIX+"1;1H");
if (win) {
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");
}
for (int y = 0; y < C_HEIGHT; y++) {
int precBgColor = -1;
int precFgColor = -1;
@ -118,19 +200,38 @@ public class Headless256Engine implements org.warp.picalculator.gui.graphicengin
curBgColor = r.bgColorMatrix[x+y*C_WIDTH];
curFgColor = r.fgColorMatrix[x+y*C_WIDTH];
if (precBgColor != curBgColor) {
AnsiConsole.out.print(Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiBgColorPrefix+curBgColor+Headless256Renderer.ansiColorSuffix);
String str = Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiBgColorPrefix+curBgColor+Headless256Renderer.ansiColorSuffix;
if (win) {
WindowsSupport.writeConsole(str);
} else {
AnsiConsole.out.print(str);
}
}
if (precFgColor != curFgColor) {
AnsiConsole.out.print(Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiFgColorPrefix+curFgColor+Headless256Renderer.ansiColorSuffix);
String str = Headless256Renderer.ANSI_PREFIX+Headless256Renderer.ansiFgColorPrefix+curFgColor+Headless256Renderer.ansiColorSuffix;
if (win) {
WindowsSupport.writeConsole(str);
} else {
AnsiConsole.out.print(str);
}
}
String stri = r.charmatrix[x+y*C_WIDTH]+"";
if (win) {
WindowsSupport.writeConsole(stri);
} else {
AnsiConsole.out.print(stri);
}
AnsiConsole.out.print(r.charmatrix[x+y*C_WIDTH]);
precBgColor = curBgColor;
precFgColor = curFgColor;
}
AnsiConsole.out.println();
if (win) {
WindowsSupport.writeConsole("\r\n");
} else {
AnsiConsole.out.println();
}
}
}
@ -162,6 +263,7 @@ 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;
return true;
}

View File

@ -1,4 +1,4 @@
package org.warp.picalculator.gui.graphicengine.headless8;
package org.warp.picalculator.gui.graphicengine.headless256;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.warp.picalculator.gui.graphicengine.headless8;
package org.warp.picalculator.gui.graphicengine.headless256;
import org.warp.picalculator.gui.graphicengine.Renderer;

View File

@ -1,4 +1,4 @@
package org.warp.picalculator.gui.graphicengine.headless8;
package org.warp.picalculator.gui.graphicengine.headless256;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;

View File

@ -1,172 +0,0 @@
package org.warp.picalculator.gui.graphicengine.headless256;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
import org.warp.picalculator.Main;
import org.warp.picalculator.gui.graphicengine.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private Headless8Renderer r = new Headless8Renderer();
private boolean stopped = true;
private RenderingLoop renderLoop;
protected static final int C_WIDTH = Main.screenSize[0]/2;//;60;
protected static final int C_HEIGHT = Main.screenSize[1]/3;//;40;
public static final int C_MUL_X = 2;//8;
public static final int C_MUL_Y = 3;//8;
private String title = Main.calculatorName;
@Override
public int[] getSize() {
new ConsoleHandler();
return new int[]{C_WIDTH, C_HEIGHT};
}
@Override
public boolean isInitialized() {
return !stopped;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@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() {
AnsiConsole.systemInstall();
AnsiConsole.out.print(Headless8Renderer.ANSI_PREFIX+"?25l");
stopped = false;
}
@Override
public boolean wasResized() {
return false;
}
@Override
public int getWidth() {
return C_WIDTH*C_MUL_X;
}
@Override
public int getHeight() {
return C_HEIGHT*C_MUL_Y;
}
@Override
public void destroy() {
stopped = true;
}
@Override
public void start(RenderingLoop d) {
this.renderLoop = d;
final Thread th = new Thread(() -> {
try {
double extratime = 0;
while (!stopped) {
final long start = System.currentTimeMillis();
repaint();
final long end = System.currentTimeMillis();
final double delta = (end - start) / 1000d;
final int deltaInt = (int) Math.floor(delta);
final int extraTimeInt = (int) Math.floor(extratime);
if (extraTimeInt + deltaInt < 200) {
Thread.sleep(200 - (extraTimeInt + deltaInt));
extratime = 0;
} else {
extratime += delta - 200d;
}
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
});
th.setName("Console rendering thread");
th.setDaemon(true);
th.start();
}
@Override
public void repaint() {
renderLoop.refresh();
r.curColor = 0x1C;
r.glDrawStringCenter((C_WIDTH*C_MUL_X)/2, 0, title);
AnsiConsole.out.print(Headless8Renderer.ANSI_PREFIX+"1;1H");
for (int y = 0; y < C_HEIGHT; y++) {
int precBgColor = -1;
int precFgColor = -1;
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;
if (precBgColor != curBgColor) {
AnsiConsole.out.print(Headless8Renderer.ANSI_PREFIX+Headless8Renderer.ansiBgColorPrefix+Headless8Renderer.colorANSI[curBgColor]+Headless8Renderer.ansiColorSuffix);
}
if (precFgColor != curFgColor) {
AnsiConsole.out.print(Headless8Renderer.ANSI_PREFIX+Headless8Renderer.ansiFgColorPrefix+Headless8Renderer.colorANSI[curFgColor]+Headless8Renderer.ansiColorSuffix);
}
AnsiConsole.out.print(r.charmatrix[x+y*C_WIDTH]);
precBgColor = curBgColor;
precFgColor = curFgColor;
}
AnsiConsole.out.println();
}
}
@Override
public Renderer getRenderer() {
return r;
}
@Override
public Headless8Font loadFont(String file) throws IOException {
return new Headless8Font();
}
@Override
public Headless8Skin loadSkin(String file) throws IOException {
return new Headless8Skin(file);
}
@Override
public void waitUntilExit() {
try {
do {
Thread.sleep(500);
} while (stopped==false);
} catch (final InterruptedException e) {
}
}
@Override
public boolean isSupported() {
return true;
}
@Override
public boolean doesRefreshPauses() {
return true;
}
}

View File

@ -0,0 +1,274 @@
package org.warp.picalculator.gui.graphicengine.headless8;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import org.fusesource.jansi.AnsiConsole;
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.Renderer;
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.headless24bit.Headless24bitRenderer;
public class Headless8Engine implements org.warp.picalculator.gui.graphicengine.GraphicEngine {
private Headless8Renderer r = new Headless8Renderer();
private boolean stopped = true;
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;
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};
}
@Override
public boolean isInitialized() {
return !stopped;
}
@Override
public void setTitle(String title) {
this.title = title;
}
@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() {
Utils.outputLevel = -1;
AnsiConsole.systemInstall();
if(Utils.isWindows() && !Utils.msDosMode){
win = true;
WindowsSupport.setConsoleMode(0x0200);
Thread t = new Thread(()-> {
int ch = -1;
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;
}
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;
}
}
if (key != null) {
Keyboard.keyPressed(key);
}
}
});
t.setDaemon(true);
t.start();
}
stopped = false;
}
@Override
public boolean wasResized() {
return false;
}
@Override
public int getWidth() {
return C_WIDTH*C_MUL_X;
}
@Override
public int getHeight() {
return C_HEIGHT*C_MUL_Y;
}
@Override
public void destroy() {
stopped = true;
}
@Override
public void start(RenderingLoop d) {
this.renderLoop = d;
final Thread th = new Thread(() -> {
try {
double extratime = 0;
while (!stopped) {
final long start = System.currentTimeMillis();
repaint();
final long end = System.currentTimeMillis();
final double delta = (end - start) / 1000d;
final int deltaInt = (int) Math.floor(delta);
final int extraTimeInt = (int) Math.floor(extratime);
if (extraTimeInt + deltaInt < 200) {
Thread.sleep(200 - (extraTimeInt + deltaInt));
extratime = 0;
} else {
extratime += delta - 200d;
}
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
});
th.setName("Console rendering thread");
th.setDaemon(true);
th.start();
}
@Override
public void repaint() {
renderLoop.refresh();
r.curColor = 0x1C;
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");
} else {
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;
int precFgColor = -1;
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;
if (precBgColor != curBgColor) {
String str = Headless8Renderer.ANSI_PREFIX+Headless8Renderer.ansiBgColorPrefix+Headless8Renderer.colorANSI[curBgColor]+Headless8Renderer.ansiColorSuffix;
if (win) {
WindowsSupport.writeConsole(str);
} else {
AnsiConsole.out.print(str);
}
}
if (precFgColor != curFgColor) {
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]+"";
if (win) {
WindowsSupport.writeConsole(stri);
} else {
AnsiConsole.out.print(stri);
}
precBgColor = curBgColor;
precFgColor = curFgColor;
}
if (win) {
WindowsSupport.writeConsole("\r\n");
} else {
AnsiConsole.out.println();
}
}
}
@Override
public Renderer getRenderer() {
return r;
}
@Override
public Headless8Font loadFont(String file) throws IOException {
return new Headless8Font();
}
@Override
public Headless8Skin loadSkin(String file) throws IOException {
return new Headless8Skin(file);
}
@Override
public void waitUntilExit() {
try {
do {
Thread.sleep(500);
} while (stopped==false);
} catch (final InterruptedException e) {
}
}
@Override
public boolean isSupported() {
if (Utils.forceEngine != null && Utils.forceEngine != "console-8") return false;
return true;
}
@Override
public boolean doesRefreshPauses() {
return true;
}
}

View File

@ -1,4 +1,4 @@
package org.warp.picalculator.gui.graphicengine.headless256;
package org.warp.picalculator.gui.graphicengine.headless8;
import java.io.IOException;

View File

@ -1,5 +1,6 @@
package org.warp.picalculator.gui.graphicengine.headless256;
package org.warp.picalculator.gui.graphicengine.headless8;
import org.warp.picalculator.Utils;
import org.warp.picalculator.gui.graphicengine.Renderer;
public class Headless8Renderer implements Renderer {
@ -18,7 +19,7 @@ public class Headless8Renderer implements Renderer {
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 = 0xDB;
public static final char FILL = Utils.msDosMode ? 0xDB : '█';
private int hexColor(int red, int green, int blue) {

View File

@ -1,4 +1,4 @@
package org.warp.picalculator.gui.graphicengine.headless256;
package org.warp.picalculator.gui.graphicengine.headless8;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;