diff --git a/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java b/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java index 2fdf2789..ee556815 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java +++ b/core/src/main/java/it/cavallium/warppi/gui/CalculatorHUD.java @@ -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 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 diff --git a/core/src/main/java/it/cavallium/warppi/gui/DisplayManager.java b/core/src/main/java/it/cavallium/warppi/gui/DisplayManager.java index 08faeac0..b0ddc15c 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/DisplayManager.java +++ b/core/src/main/java/it/cavallium/warppi/gui/DisplayManager.java @@ -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 { - screen.create(); + 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(); - hud.render(); - hud.renderTopmostBackground(); + if (hud.visible) { + hud.render(); + hud.renderTopmostBackground(); + } screen.renderTopmost(); - hud.renderTopmost(); + if (hud.visible) hud.renderTopmost(); } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/HUD.java b/core/src/main/java/it/cavallium/warppi/gui/HUD.java index 9b863493..06e13a26 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/HUD.java +++ b/core/src/main/java/it/cavallium/warppi/gui/HUD.java @@ -4,7 +4,8 @@ public abstract class HUD implements GraphicalInterface { public DisplayManager d; public boolean created = false; public boolean initialized = false; - + public boolean visible = true; + public HUD() {} @Override @@ -45,4 +46,12 @@ public abstract class HUD implements GraphicalInterface { return true; } + public void hide() { + visible = false; + } + + public void show() { + visible = true; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java b/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java index f4188c27..43b32f0e 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/Caret.java @@ -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; diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java b/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java index c7949f42..a00d8917 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/CaretState.java @@ -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 } diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java b/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java index caae8619..cb6c5452 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/InputContext.java @@ -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 variableTypes; public BlockVariable variableTypeDirtyID = null; diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java index c9cd2c03..3d99f9a8 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/BlockLogarithm.java @@ -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) { diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java index 0979854d..c0d751fa 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeBlock.java @@ -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(); diff --git a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java index 9cb15777..4c77b148 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java +++ b/core/src/main/java/it/cavallium/warppi/gui/expression/blocks/TreeContainer.java @@ -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(); diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/ChooseVariableValueScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/ChooseVariableValueScreen.java index 57b66fbe..d3034faa 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/ChooseVariableValueScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/ChooseVariableValueScreen.java @@ -78,4 +78,9 @@ public class ChooseVariableValueScreen extends Screen { } } + @Override + public String getSessionTitle() { + return "Choose a value for the variable."; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/EmptyScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/EmptyScreen.java index 314c9be1..9775ee2a 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/EmptyScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/EmptyScreen.java @@ -33,4 +33,9 @@ public class EmptyScreen extends Screen { return true; } + @Override + public String getSessionTitle() { + return "empty"; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/KeyboardDebugScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/KeyboardDebugScreen.java index da71e602..3ba02837 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/KeyboardDebugScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/KeyboardDebugScreen.java @@ -222,4 +222,9 @@ public class KeyboardDebugScreen extends Screen { KeyboardDebugScreen.log = newlog; } + @Override + public String getSessionTitle() { + return "Keyboard debug"; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/LoadingScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/LoadingScreen.java index 9744c6c3..43ed3f56 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/LoadingScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/LoadingScreen.java @@ -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..."; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/MarioScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/MarioScreen.java index adef9149..d897eb11 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/MarioScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/MarioScreen.java @@ -197,4 +197,9 @@ public class MarioScreen extends Screen { return true; } + @Override + public String getSessionTitle() { + return "Absolutely not Super Mario"; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java index 2e03ca62..dda9fa22 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/MathInputScreen.java @@ -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 solveExpression(final ObjectArrayList 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"; } } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java index 58c4735c..e006b59e 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/Screen.java @@ -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; @@ -10,8 +12,13 @@ public abstract class Screen implements KeyboardEventListener, TouchEventListene public boolean created = false; public boolean initialized = false; public boolean canBeInHistory = false; + + public static long lastDebugScreenID = 1; + public final long debugScreenID; - public Screen() {} + 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(); } diff --git a/core/src/main/java/it/cavallium/warppi/gui/screens/SolveForXScreen.java b/core/src/main/java/it/cavallium/warppi/gui/screens/SolveForXScreen.java index 0812c176..1984d904 100644 --- a/core/src/main/java/it/cavallium/warppi/gui/screens/SolveForXScreen.java +++ b/core/src/main/java/it/cavallium/warppi/gui/screens/SolveForXScreen.java @@ -67,4 +67,9 @@ public class SolveForXScreen extends Screen { } } + @Override + public String getSessionTitle() { + return "Solve for X"; + } + } diff --git a/core/src/main/java/it/cavallium/warppi/math/AngleMode.java b/core/src/main/java/it/cavallium/warppi/math/AngleMode.java index 09625f7d..26b7b73c 100644 --- a/core/src/main/java/it/cavallium/warppi/math/AngleMode.java +++ b/core/src/main/java/it/cavallium/warppi/math/AngleMode.java @@ -1,5 +1,7 @@ package it.cavallium.warppi.math; -public enum AngleMode { +import java.io.Serializable; + +public enum AngleMode implements Serializable { DEG, RAD, GRA } diff --git a/core/src/main/java/it/cavallium/warppi/math/Function.java b/core/src/main/java/it/cavallium/warppi/math/Function.java index 64390589..04b75ed1 100644 --- a/core/src/main/java/it/cavallium/warppi/math/Function.java +++ b/core/src/main/java/it/cavallium/warppi/math/Function.java @@ -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. diff --git a/core/src/main/java/it/cavallium/warppi/math/MathContext.java b/core/src/main/java/it/cavallium/warppi/math/MathContext.java index f3bb5711..3813b300 100644 --- a/core/src/main/java/it/cavallium/warppi/math/MathContext.java +++ b/core/src/main/java/it/cavallium/warppi/math/MathContext.java @@ -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 getAcceptableRules(final RuleType currentAcceptedRules) { return RulesManager.rules[currentAcceptedRules.ordinal()]; } diff --git a/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java b/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java index 8bb177ba..d2ef1e03 100644 --- a/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java +++ b/core/src/main/java/it/cavallium/warppi/math/functions/Variable.java @@ -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; diff --git a/desktop/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/swing/SwingRenderer.java b/desktop/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/swing/SwingRenderer.java index f48d1340..f5a55260 100644 --- a/desktop/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/swing/SwingRenderer.java +++ b/desktop/src/main/java/it/cavallium/warppi/gui/graphicengine/impl/swing/SwingRenderer.java @@ -124,17 +124,19 @@ public class SwingRenderer implements Renderer { newColors[idx] = getSkinColorAt(currentSkin.skinData, skinIndex); } newColor = joinColors(newColors); - if (transparent) { - oldColor = SwingRenderer.canvas2d[index]; - 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; + if (index >= 0 && index < SwingRenderer.canvas2d.length) { + if (transparent) { + oldColor = SwingRenderer.canvas2d[index]; + 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; + } + + SwingRenderer.canvas2d[index] = stackColors(SwingRenderer.canvas2d[index], newColor); } - - SwingRenderer.canvas2d[index] = stackColors(SwingRenderer.canvas2d[index], newColor); } } }