Implemented history

This commit is contained in:
Cavallium 2018-10-04 12:38:54 +02:00
parent a9395277c9
commit b0637d308b
22 changed files with 202 additions and 81 deletions

View File

@ -6,7 +6,9 @@ import it.cavallium.warppi.device.Keyboard;
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
import it.cavallium.warppi.gui.graphicengine.Renderer;
import it.cavallium.warppi.gui.graphicengine.Skin;
import it.cavallium.warppi.gui.screens.Screen;
import it.cavallium.warppi.util.Utils;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class CalculatorHUD extends HUD {
@ -30,40 +32,40 @@ public class CalculatorHUD extends HUD {
@Override
public void renderTopmostBackground() {
final Renderer renderer = d.renderer;
final Renderer r = d.renderer;
final GraphicEngine engine = d.engine;
renderer.glColor(0xFFc5c2af);
renderer.glFillColor(0, 0, engine.getWidth(), 20);
r.glColor(0xFFc5c2af);
r.glFillColor(0, 0, engine.getWidth(), 20);
}
@Override
public void renderTopmost() {
final Renderer renderer = d.renderer;
final Renderer r = d.renderer;
final GraphicEngine engine = d.engine;
final Skin guiSkin = d.guiSkin;
//DRAW TOP
renderer.glColor3i(0, 0, 0);
renderer.glDrawLine(0, 20, engine.getWidth() - 1, 20);
renderer.glColor3i(255, 255, 255);
r.glColor3i(0, 0, 0);
r.glDrawLine(0, 20, engine.getWidth() - 1, 20);
r.glColor3i(255, 255, 255);
guiSkin.use(engine);
if (Keyboard.shift) {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 2, 16 * 0, 16, 16);
r.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 2, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 3, 16 * 0, 16, 16);
r.glFillRect(2 + 18 * 0, 2, 16, 16, 16 * 3, 16 * 0, 16, 16);
}
if (Keyboard.alpha) {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 0, 16 * 0, 16, 16);
r.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 0, 16 * 0, 16, 16);
} else {
renderer.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 1, 16 * 0, 16, 16);
r.glFillRect(2 + 18 * 1, 2, 16, 16, 16 * 1, 16 * 0, 16, 16);
}
int padding = 2;
final int brightness = (int) Math.ceil(Engine.INSTANCE.getHardwareDevice().getDisplayManager().getBrightness() * 9);
if (brightness <= 10) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * brightness, 16 * 1, 16, 16);
} else {
Engine.getPlatform().getConsoleUtils().out().println(1, "Brightness error");
}
@ -74,34 +76,68 @@ public class CalculatorHUD extends HUD {
final boolean canGoForward = Engine.INSTANCE.getHardwareDevice().getDisplayManager().canGoForward();
if (Engine.getPlatform().getSettings().isDebugEnabled()) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 18, 16 * 0, 16, 16);
padding += 18 + 6;
}
if (canGoBack && canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 14, 16 * 0, 16, 16);
} else if (canGoBack) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 15, 16 * 0, 16, 16);
} else if (canGoForward) {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 16, 16 * 0, 16, 16);
} else {
renderer.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
r.glFillRect(StaticVars.screenSize[0] - (padding + 16), 2, 16, 16, 16 * 17, 16 * 0, 16, 16);
}
padding += 18;
//DRAW BOTTOM
d.renderer.glDrawStringLeft(2, 90, d.displayDebugString);
r.glDrawStringLeft(2, 90, d.displayDebugString);
Utils.getFont(true, false).use(Engine.INSTANCE.getHardwareDevice().getDisplayManager().engine);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(255, 0, 0, 40);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 - 7 + 1, "WORK IN");
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(255, 0, 0, 80);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7 - 7, "WORK IN");
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(255, 0, 0, 40);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 + 1, "PROGRESS.");
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glColor4i(255, 0, 0, 80);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().renderer.glDrawStringLeft(1, StaticVars.screenSize[1] - 7, "PROGRESS.");
Utils.getFont(true, false).use(engine);
r.glColor4i(255, 0, 0, 40);
r.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 - 7 + 1, "WORK IN");
r.glColor4i(255, 0, 0, 80);
r.glDrawStringLeft(1, StaticVars.screenSize[1] - 7 - 7, "WORK IN");
r.glColor4i(255, 0, 0, 40);
r.glDrawStringLeft(1 + 1, StaticVars.screenSize[1] - 7 + 1, "PROGRESS.");
r.glColor4i(255, 0, 0, 80);
r.glDrawStringLeft(1, StaticVars.screenSize[1] - 7, "PROGRESS.");
int currentDebugLine = 2;
if (Engine.getPlatform().getSettings().isDebugEnabled()) {
ObjectArrayList<Screen> allSessions = new ObjectArrayList<>();
for (Screen session : Engine.INSTANCE.getHardwareDevice().getDisplayManager().sessions) {
allSessions.add(0, session);
}
Screen curScreen = Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen();
if (curScreen.canBeInHistory == false) {
allSessions.add(curScreen);
}
for (Screen session : allSessions) {
if (session != null) {
String title = session.getSessionTitle();
if (title != null && title.length() > 0) {
Utils.getFont(true).use(engine);
if (session.canBeInHistory == false) {
r.glColor(0xFF3333FF);
} else {
r.glColor(0xFF990000);
}
r.glDrawStringLeft(0, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), "[" + String.format("%1$03d", session.debugScreenID) + "] " + title.toUpperCase());
if (session == Engine.INSTANCE.getHardwareDevice().getDisplayManager().getScreen()) {
r.glColor(0xFF00CC00);
} else {
r.glColor(0xFF990000);
}
r.glDrawStringLeft(0, StaticVars.screenSize[1] - ((currentDebugLine+1) * (r.getCurrentFont().getCharacterHeight()+1)), " " + title.toUpperCase());
}
currentDebugLine++;
}
}
}
}
@Override

View File

@ -166,7 +166,15 @@ public final class DisplayManager implements RenderingLoop {
}
public void setScreen(final Screen screen) {
if (screen.initialized == false) {
boolean mustBeAddedToHistory = screen.initialized == false;
if (!mustBeAddedToHistory) {
boolean found = false;
for (Screen s : sessions) {
found = found | s == screen;
}
mustBeAddedToHistory |= !found;
}
if (mustBeAddedToHistory) {
if (screen.canBeInHistory) {
if (currentSession > 0) {
final int sl = sessions.length + 5; //TODO: I don't know why if i don't add +5 or more some items disappear
@ -183,7 +191,9 @@ public final class DisplayManager implements RenderingLoop {
}
screen.d = this;
try {
if (screen.created == false) {
screen.create();
}
this.screen = screen;
screenChange.release();
if (screen.initialized == false) {
@ -345,12 +355,14 @@ public final class DisplayManager implements RenderingLoop {
if (fonts[0] != null && fonts[0] != engine.getRenderer().getCurrentFont()) {
fonts[0].use(engine);
}
hud.renderBackground();
if (hud.visible) hud.renderBackground();
screen.render();
if (hud.visible) {
hud.render();
hud.renderTopmostBackground();
}
screen.renderTopmost();
hud.renderTopmost();
if (hud.visible) hud.renderTopmost();
}
}

View File

@ -4,6 +4,7 @@ public abstract class HUD implements GraphicalInterface {
public DisplayManager d;
public boolean created = false;
public boolean initialized = false;
public boolean visible = true;
public HUD() {}
@ -45,4 +46,12 @@ public abstract class HUD implements GraphicalInterface {
return true;
}
public void hide() {
visible = false;
}
public void show() {
visible = true;
}
}

View File

@ -1,6 +1,8 @@
package it.cavallium.warppi.gui.expression;
public class Caret {
import java.io.Serializable;
public class Caret implements Serializable {
private int pos;
private int remaining;

View File

@ -1,5 +1,7 @@
package it.cavallium.warppi.gui.expression;
public enum CaretState {
import java.io.Serializable;
public enum CaretState implements Serializable {
VISIBLE_ON, VISIBLE_OFF, HIDDEN
}

View File

@ -1,12 +1,13 @@
package it.cavallium.warppi.gui.expression;
import java.io.Serializable;
import java.util.HashMap;
import it.cavallium.warppi.gui.expression.blocks.BlockVariable;
import it.cavallium.warppi.math.MathematicalSymbols;
import it.cavallium.warppi.math.functions.Variable.V_TYPE;
public class InputContext {
public class InputContext implements Serializable {
public final HashMap<Character, V_TYPE> variableTypes;
public BlockVariable variableTypeDirtyID = null;

View File

@ -121,7 +121,6 @@ public class BlockLogarithm extends Block implements IParenthesis {
height = toph + nmbh;
}
} else {
System.out.println("b");
toph = 0;
line = toph + nl;
if (nmbh + bh - bl > toph + nmbh) {

View File

@ -1,6 +1,8 @@
package it.cavallium.warppi.gui.expression.blocks;
public interface TreeBlock {
import java.io.Serializable;
public interface TreeBlock extends Serializable {
TreeContainer getParentContainer();
boolean hasParent();

View File

@ -1,6 +1,8 @@
package it.cavallium.warppi.gui.expression.blocks;
public interface TreeContainer {
import java.io.Serializable;
public interface TreeContainer extends Serializable {
TreeBlock getParentBlock();
boolean hasParent();

View File

@ -78,4 +78,9 @@ public class ChooseVariableValueScreen extends Screen {
}
}
@Override
public String getSessionTitle() {
return "Choose a value for the variable.";
}
}

View File

@ -33,4 +33,9 @@ public class EmptyScreen extends Screen {
return true;
}
@Override
public String getSessionTitle() {
return "empty";
}
}

View File

@ -222,4 +222,9 @@ public class KeyboardDebugScreen extends Screen {
KeyboardDebugScreen.log = newlog;
}
@Override
public String getSessionTitle() {
return "Keyboard debug";
}
}

View File

@ -11,6 +11,7 @@ public class LoadingScreen extends Screen {
public float loadingTextTranslation = 0.0f;
public boolean loaded = false;
private float previousZoomValue = 1;
private volatile boolean ended = false;
public LoadingScreen() {
super();
@ -28,6 +29,7 @@ public class LoadingScreen extends Screen {
@Override
public void initialized() throws InterruptedException {
previousZoomValue = StaticVars.windowZoomFunction.apply(StaticVars.windowZoom.getLastValue());
Engine.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().hide();
StaticVars.windowZoom.onNext(1f);
}
@ -36,8 +38,10 @@ public class LoadingScreen extends Screen {
loadingTextTranslation = GraphicUtils.sinDeg(endLoading * 90f) * 10f;
endLoading += dt;
if (loaded && (Engine.getPlatform().getSettings().isDebugEnabled() || endLoading >= 3.5f)) {
if (!ended && loaded && (Engine.getPlatform().getSettings().isDebugEnabled() || endLoading >= 3.5f)) {
ended = true;
StaticVars.windowZoom.onNext(previousZoomValue);
Engine.INSTANCE.getHardwareDevice().getDisplayManager().getHUD().show();
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(new MathInputScreen());
}
mustRefresh = true;
@ -65,4 +69,9 @@ public class LoadingScreen extends Screen {
}
}
@Override
public String getSessionTitle() {
return "Loading...";
}
}

View File

@ -197,4 +197,9 @@ public class MarioScreen extends Screen {
return true;
}
@Override
public String getSessionTitle() {
return "Absolutely not Super Mario";
}
}

View File

@ -1,6 +1,9 @@
package it.cavallium.warppi.gui.screens;
import java.io.IOException;
import java.util.HashMap;
import org.apache.commons.lang3.SerializationUtils;
import it.cavallium.warppi.Engine;
import it.cavallium.warppi.Platform.ConsoleUtils;
@ -27,6 +30,7 @@ import it.cavallium.warppi.math.MathematicalSymbols;
import it.cavallium.warppi.math.functions.Expression;
import it.cavallium.warppi.math.functions.Number;
import it.cavallium.warppi.math.functions.Variable;
import it.cavallium.warppi.math.functions.Variable.V_TYPE;
import it.cavallium.warppi.math.functions.Variable.VariableValue;
import it.cavallium.warppi.math.parser.MathParser;
import it.cavallium.warppi.math.solver.MathSolver;
@ -238,6 +242,7 @@ public class MathInputScreen extends Screen {
// currentExpression = newExpression;
// simplify();
// });
this.swapInputScreen();
}
} catch (final InterruptedException ex) {
Engine.getPlatform().getConsoleUtils().out().println(ConsoleUtils.OUTPUTLEVEL_DEBUG_MIN, "Computing thread stopped.");
@ -464,6 +469,24 @@ public class MathInputScreen extends Screen {
}
}
@SuppressWarnings("unchecked")
private void swapInputScreen() {
MathInputScreen mis = new MathInputScreen();
mis.calc = SerializationUtils.clone(calc);
mis.canBeInHistory = true;
mis.currentStep = currentStep;
mis.created = created;
mis.d = d;
mis.errorLevel = errorLevel;
mis.ic = SerializationUtils.clone(ic);
mis.initialized = initialized;
mis.mustRefresh = true;
mis.result = SerializationUtils.clone(result);
mis.userInput = SerializationUtils.clone(userInput);
mis.d = d;
Engine.INSTANCE.getHardwareDevice().getDisplayManager().setScreen(mis);
}
@SuppressWarnings("unused")
@Deprecated
private ObjectArrayList<Function> solveExpression(final ObjectArrayList<Function> f22) {
@ -688,17 +711,8 @@ public class MathInputScreen extends Screen {
}
@Override
@Deprecated
public MathInputScreen clone() {
throw new UnsupportedOperationException();
// final MathInputScreen es = this;
// final MathInputScreen es2 = new MathInputScreen();
// es2.errorLevel = es.errorLevel;
// es2.mustRefresh = es.mustRefresh;
// es2.calc = Utils.cloner.deepClone(es.calc);
// es2.userInput = Utils.cloner.deepClone(es.userInput);
// es2.result = Utils.cloner.deepClone(es.result);
// return es2;
public String getSessionTitle() {
return "Calculator";
}
}

View File

@ -1,5 +1,7 @@
package it.cavallium.warppi.gui.screens;
import java.io.Serializable;
import it.cavallium.warppi.event.KeyboardEventListener;
import it.cavallium.warppi.event.TouchEventListener;
import it.cavallium.warppi.gui.DisplayManager;
@ -11,7 +13,12 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene
public boolean initialized = false;
public boolean canBeInHistory = false;
public Screen() {}
public static long lastDebugScreenID = 1;
public final long debugScreenID;
public Screen() {
debugScreenID = lastDebugScreenID++;
}
@Override
public void initialize() throws InterruptedException {
@ -46,4 +53,6 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene
@Override
public abstract boolean mustBeRefreshed();
public abstract String getSessionTitle();
}

View File

@ -67,4 +67,9 @@ public class SolveForXScreen extends Screen {
}
}
@Override
public String getSessionTitle() {
return "Solve for X";
}
}

View File

@ -1,5 +1,7 @@
package it.cavallium.warppi.math;
public enum AngleMode {
import java.io.Serializable;
public enum AngleMode implements Serializable {
DEG, RAD, GRA
}

View File

@ -1,11 +1,13 @@
package it.cavallium.warppi.math;
import java.io.Serializable;
import it.cavallium.warppi.gui.expression.blocks.Block;
import it.cavallium.warppi.math.rules.Rule;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public interface Function {
public interface Function extends Serializable {
/**
* Returns this function and its children in a string form.

View File

@ -1,5 +1,9 @@
package it.cavallium.warppi.math;
import java.io.Serializable;
import org.apache.commons.lang3.SerializationUtils;
import it.cavallium.warppi.math.functions.Variable.VariableValue;
import it.cavallium.warppi.math.rules.Rule;
import it.cavallium.warppi.math.rules.RuleType;
@ -7,7 +11,7 @@ import it.cavallium.warppi.math.rules.RulesManager;
import it.cavallium.warppi.util.Error;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
public class MathContext {
public class MathContext implements Serializable {
public AngleMode angleMode = AngleMode.DEG;
public boolean exactMode = false;
@ -126,20 +130,6 @@ public class MathContext {
}
}*/
@Override
@Deprecated
public MathContext clone() {
// MathContext mc = new MathContext();
// mc.angleMode = this.angleMode;
// mc.exactMode = this.exactMode;
// mc.f = this.f;
// mc.f2 = this.f2;
// mc.variablesValues = this.variablesValues;
// mc.resultsCount = this.resultsCount;
// return mc;
throw new UnsupportedOperationException();
}
public ObjectArrayList<Rule> getAcceptableRules(final RuleType currentAcceptedRules) {
return RulesManager.rules[currentAcceptedRules.ordinal()];
}

View File

@ -1,5 +1,7 @@
package it.cavallium.warppi.math.functions;
import java.io.Serializable;
import it.cavallium.warppi.gui.expression.blocks.Block;
import it.cavallium.warppi.gui.expression.blocks.BlockChar;
import it.cavallium.warppi.math.Function;
@ -45,7 +47,8 @@ public class Variable implements Function {
return "" + getChar();
}
public static class VariableValue {
public static class VariableValue implements Serializable {
private static final long serialVersionUID = -5656281021874324571L;
public final Variable v;
public final Number n;

View File

@ -124,6 +124,7 @@ public class SwingRenderer implements Renderer {
newColors[idx] = getSkinColorAt(currentSkin.skinData, skinIndex);
}
newColor = joinColors(newColors);
if (index >= 0 && index < SwingRenderer.canvas2d.length) {
if (transparent) {
oldColor = SwingRenderer.canvas2d[index];
final float a2 = (newColor >> 24 & 0xFF) / 255f;
@ -138,6 +139,7 @@ public class SwingRenderer implements Renderer {
}
}
}
}
private int joinColors(final int[] newColors) {
int a = 0;