Partially finished the new input API
This commit is contained in:
parent
b86228a8d3
commit
b89883147b
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry excluding="org/warp/picalculator/deprecatedmath/" kind="src" path="src"/>
|
<classpathentry excluding="org/warp/picalculator/deprecatedmath/|org/warp/picalculator/device/PIDisplay.java|org/warp/picalculator/device/graphicengine/Display.java" kind="src" path="src"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
<classpathentry kind="src" path="res"/>
|
<classpathentry kind="src" path="res"/>
|
||||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JOGL"/>
|
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.USER_LIBRARY/JOGL"/>
|
||||||
|
@ -5,30 +5,22 @@ import java.io.IOException;
|
|||||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
import org.warp.picalculator.gui.graphicengine.RenderingLoop;
|
||||||
import org.warp.picalculator.gui.expression.BlockChar;
|
import org.warp.picalculator.device.Keyboard;
|
||||||
|
import org.warp.picalculator.device.Keyboard.Key;
|
||||||
|
import org.warp.picalculator.device.KeyboardEventListener;
|
||||||
|
import org.warp.picalculator.gui.GUIErrorMessage;
|
||||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||||
import org.warp.picalculator.gui.expression.BlockDivision;
|
|
||||||
import org.warp.picalculator.gui.expression.Caret;
|
|
||||||
import org.warp.picalculator.gui.expression.CaretState;
|
|
||||||
import org.warp.picalculator.gui.expression.containers.NormalInputContainer;
|
import org.warp.picalculator.gui.expression.containers.NormalInputContainer;
|
||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.gui.graphicengine.Skin;
|
import org.warp.picalculator.gui.graphicengine.Skin;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
|
import org.warp.picalculator.gui.graphicengine.gpu.GPUEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.gpu.GPURenderer;
|
|
||||||
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
|
|
||||||
import org.warp.picalculator.gui.screens.MarioScreen;
|
|
||||||
import org.warp.picalculator.math.MathContext;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
import org.warp.picalculator.math.functions.Expression;
|
||||||
|
import org.warp.picalculator.math.functions.Root;
|
||||||
import org.warp.picalculator.math.parser.MathParser;
|
import org.warp.picalculator.math.parser.MathParser;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.lang.management.OperatingSystemMXBean;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Modifier;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
||||||
|
|
||||||
public class TestGPU {
|
public class TestGPU {
|
||||||
|
|
||||||
public static final GraphicEngine d = new GPUEngine();
|
public static final GraphicEngine d = new GPUEngine();
|
||||||
@ -38,8 +30,104 @@ public class TestGPU {
|
|||||||
Utils.debugThirdScreen = false;
|
Utils.debugThirdScreen = false;
|
||||||
d.create();
|
d.create();
|
||||||
|
|
||||||
|
Keyboard.startKeyboard();
|
||||||
|
Keyboard.setAdditionalKeyboardListener(new KeyboardEventListener() {
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed(Key k) {
|
||||||
|
switch (k) {
|
||||||
|
case LEFT:
|
||||||
|
c.moveLeft();
|
||||||
|
return true;
|
||||||
|
case RIGHT:
|
||||||
|
c.moveRight();
|
||||||
|
return true;
|
||||||
|
case NUM0:
|
||||||
|
c.typeChar('0');
|
||||||
|
return true;
|
||||||
|
case NUM1:
|
||||||
|
c.typeChar('1');
|
||||||
|
return true;
|
||||||
|
case NUM2:
|
||||||
|
c.typeChar('2');
|
||||||
|
return true;
|
||||||
|
case NUM3:
|
||||||
|
c.typeChar('3');
|
||||||
|
return true;
|
||||||
|
case NUM4:
|
||||||
|
c.typeChar('4');
|
||||||
|
return true;
|
||||||
|
case NUM5:
|
||||||
|
c.typeChar('5');
|
||||||
|
return true;
|
||||||
|
case NUM6:
|
||||||
|
c.typeChar('6');
|
||||||
|
return true;
|
||||||
|
case NUM7:
|
||||||
|
c.typeChar('7');
|
||||||
|
return true;
|
||||||
|
case NUM8:
|
||||||
|
c.typeChar('8');
|
||||||
|
return true;
|
||||||
|
case NUM9:
|
||||||
|
c.typeChar('9');
|
||||||
|
return true;
|
||||||
|
case PLUS:
|
||||||
|
c.typeChar(MathematicalSymbols.SUM);
|
||||||
|
return true;
|
||||||
|
case MINUS:
|
||||||
|
c.typeChar(MathematicalSymbols.SUBTRACTION);
|
||||||
|
return true;
|
||||||
|
case MULTIPLY:
|
||||||
|
c.typeChar(MathematicalSymbols.MULTIPLICATION);
|
||||||
|
return true;
|
||||||
|
case DIVIDE:
|
||||||
|
c.typeChar(MathematicalSymbols.DIVISION);
|
||||||
|
return true;
|
||||||
|
case SQRT:
|
||||||
|
c.typeChar(MathematicalSymbols.SQUARE_ROOT);
|
||||||
|
return true;
|
||||||
|
case PARENTHESIS_OPEN:
|
||||||
|
case SINE:
|
||||||
|
c.typeChar(MathematicalSymbols.PARENTHESIS_OPEN);
|
||||||
|
return true;
|
||||||
|
case PARENTHESIS_CLOSE:
|
||||||
|
case debug_DEG:
|
||||||
|
c.moveRight();
|
||||||
|
return true;
|
||||||
|
case DELETE:
|
||||||
|
c.del();
|
||||||
|
return true;
|
||||||
|
case RESET:
|
||||||
|
c.clear();
|
||||||
|
return true;
|
||||||
|
case POWER:
|
||||||
|
d.destroy();
|
||||||
|
System.exit(0);
|
||||||
|
return true;
|
||||||
|
case EQUAL:
|
||||||
|
Expression expr;
|
||||||
|
try {
|
||||||
|
expr = MathParser.parseInput(new MathContext(), c.root);
|
||||||
|
System.out.println("Parsed input:"+expr.toString());
|
||||||
|
} catch (Error e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyReleased(Key k) {
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final Scene s = new Scene(d);
|
final Scene s = new Scene(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static NormalInputContainer c = null;
|
||||||
|
|
||||||
private static class Scene implements RenderingLoop {
|
private static class Scene implements RenderingLoop {
|
||||||
|
|
||||||
@ -48,8 +136,7 @@ public class TestGPU {
|
|||||||
|
|
||||||
private final Renderer r;
|
private final Renderer r;
|
||||||
private final GraphicEngine d;
|
private final GraphicEngine d;
|
||||||
|
private long lastTime = 0L;
|
||||||
private final NormalInputContainer c;
|
|
||||||
|
|
||||||
public Scene(GraphicEngine d) throws IOException, Error {
|
public Scene(GraphicEngine d) throws IOException, Error {
|
||||||
this.d = d;
|
this.d = d;
|
||||||
@ -76,9 +163,6 @@ public class TestGPU {
|
|||||||
c.typeChar('2');
|
c.typeChar('2');
|
||||||
c.recomputeDimensions();
|
c.recomputeDimensions();
|
||||||
|
|
||||||
Expression expr = MathParser.parseInput(new MathContext(), c.root);
|
|
||||||
System.out.println("Parsed input:"+expr.toString());
|
|
||||||
|
|
||||||
d.start(this);
|
d.start(this);
|
||||||
|
|
||||||
// fonts = new RAWFont[1];
|
// fonts = new RAWFont[1];
|
||||||
@ -95,7 +179,10 @@ public class TestGPU {
|
|||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
System.exit(0);
|
if (!Utils.debugOn) {
|
||||||
|
d.destroy();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
d.waitUntilExit();
|
d.waitUntilExit();
|
||||||
@ -119,6 +206,12 @@ public class TestGPU {
|
|||||||
r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16);
|
r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16);
|
||||||
|
|
||||||
//New expression framework test
|
//New expression framework test
|
||||||
|
if (lastTime == 0) {
|
||||||
|
lastTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
double delta = System.currentTimeMillis()-lastTime;
|
||||||
|
lastTime = System.currentTimeMillis();
|
||||||
|
c.beforeRender((float) (delta/1000d));
|
||||||
c.draw(d, r, 10, 220);
|
c.draw(d, r, 10, 220);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import org.warp.picalculator.Utils;
|
|||||||
import org.warp.picalculator.device.chip.ParallelToSerial;
|
import org.warp.picalculator.device.chip.ParallelToSerial;
|
||||||
import org.warp.picalculator.device.chip.SerialToParallel;
|
import org.warp.picalculator.device.chip.SerialToParallel;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
|
import org.warp.picalculator.gui.GUIErrorMessage;
|
||||||
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
|
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
|
||||||
import org.warp.picalculator.gui.screens.MarioScreen;
|
import org.warp.picalculator.gui.screens.MarioScreen;
|
||||||
import org.warp.picalculator.gui.screens.Screen;
|
import org.warp.picalculator.gui.screens.Screen;
|
||||||
@ -31,8 +32,10 @@ public class Keyboard {
|
|||||||
public static volatile int debugKeyCode = -1;
|
public static volatile int debugKeyCode = -1;
|
||||||
|
|
||||||
private static volatile boolean refreshRequest = false;
|
private static volatile boolean refreshRequest = false;
|
||||||
|
|
||||||
|
private static KeyboardEventListener additionalListener;
|
||||||
|
|
||||||
public static void startKeyboard() {
|
public synchronized static void startKeyboard() {
|
||||||
final Thread kt = new Thread(() -> {
|
final Thread kt = new Thread(() -> {
|
||||||
if (Utils.debugOn) {
|
if (Utils.debugOn) {
|
||||||
try {
|
try {
|
||||||
@ -94,7 +97,7 @@ public class Keyboard {
|
|||||||
kt.start();
|
kt.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void debugKeyPressed(int keyCode) {
|
private synchronized static void debugKeyPressed(int keyCode) {
|
||||||
switch (keyCode) {
|
switch (keyCode) {
|
||||||
case KeyEvent.VK_ESCAPE:
|
case KeyEvent.VK_ESCAPE:
|
||||||
Keyboard.keyPressed(Key.POWER);
|
Keyboard.keyPressed(Key.POWER);
|
||||||
@ -398,7 +401,7 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void keyReleasedRaw(int row, int col) {
|
private synchronized static void keyReleasedRaw(int row, int col) {
|
||||||
KeyboardDebugScreen.keyX = row;
|
KeyboardDebugScreen.keyX = row;
|
||||||
KeyboardDebugScreen.keyY = col;
|
KeyboardDebugScreen.keyY = col;
|
||||||
if (row == 1 && col == 1) {
|
if (row == 1 && col == 1) {
|
||||||
@ -406,7 +409,7 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyPressedRaw(int row, int col) {
|
static synchronized void keyPressedRaw(int row, int col) {
|
||||||
KeyboardDebugScreen.keyX = row;
|
KeyboardDebugScreen.keyX = row;
|
||||||
KeyboardDebugScreen.keyY = col;
|
KeyboardDebugScreen.keyY = col;
|
||||||
if (row == 1 && col == 1) {
|
if (row == 1 && col == 1) {
|
||||||
@ -695,11 +698,25 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void keyPressed(Key k) {
|
public synchronized static void keyPressed(Key k) {
|
||||||
|
boolean done = false;
|
||||||
|
if (additionalListener != null) {
|
||||||
|
try {
|
||||||
|
done = additionalListener.keyPressed(k);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
new GUIErrorMessage(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (DisplayManager.INSTANCE != null) {
|
if (DisplayManager.INSTANCE != null) {
|
||||||
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
||||||
boolean refresh = false;
|
boolean refresh = false;
|
||||||
if (scr != null && scr.initialized && scr.keyPressed(k)) {
|
boolean scrdone = false;
|
||||||
|
try {
|
||||||
|
scrdone = scr.keyPressed(k);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
new GUIErrorMessage(ex);
|
||||||
|
}
|
||||||
|
if (scr != null && scr.initialized && scrdone) {
|
||||||
refresh = true;
|
refresh = true;
|
||||||
} else {
|
} else {
|
||||||
switch (k) {
|
switch (k) {
|
||||||
@ -756,6 +773,8 @@ public class Keyboard {
|
|||||||
if (refresh) {
|
if (refresh) {
|
||||||
refreshRequest = true;
|
refreshRequest = true;
|
||||||
}
|
}
|
||||||
|
} else if (!done) {
|
||||||
|
Utils.debug.println("Key " + k.toString() + " ignored.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -763,7 +782,11 @@ public class Keyboard {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void keyReleased(Key k) {
|
public synchronized static void keyReleased(Key k) {
|
||||||
|
boolean done = false;
|
||||||
|
if (additionalListener != null) {
|
||||||
|
done = additionalListener.keyReleased(k);
|
||||||
|
}
|
||||||
boolean refresh = false;
|
boolean refresh = false;
|
||||||
if (DisplayManager.INSTANCE != null) {
|
if (DisplayManager.INSTANCE != null) {
|
||||||
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
||||||
@ -778,10 +801,16 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
// PIDisplay.display.repaint();
|
refreshRequest = true;
|
||||||
}
|
}
|
||||||
|
} else if (!done) {
|
||||||
|
Utils.debug.println("Key " + k.toString() + " ignored.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setAdditionalKeyboardListener(KeyboardEventListener l) {
|
||||||
|
additionalListener = l;
|
||||||
|
}
|
||||||
|
|
||||||
public static enum Key {
|
public static enum Key {
|
||||||
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI
|
POWER, debug_DEG, debug_RAD, debug_GRA, SHIFT, ALPHA, NONE, HISTORY_BACK, HISTORY_FORWARD, SURD_MODE, DRG_CYCLE, LETTER_X, LETTER_Y, STEP, SIMPLIFY, BRIGHTNESS_CYCLE, BRIGHTNESS_CYCLE_REVERSE, DOT, NUM0, NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, PARENTHESIS_OPEN, PARENTHESIS_CLOSE, PLUS, MINUS, PLUS_MINUS, MULTIPLY, DIVIDE, EQUAL, DELETE, RESET, LEFT, RIGHT, UP, DOWN, OK, debug1, debug2, debug3, debug4, debug5, SQRT, ROOT, POWER_OF_2, POWER_OF_x, SINE, COSINE, TANGENT, ARCSINE, ARCCOSINE, ARCTANGENT, PI
|
||||||
|
13
src/org/warp/picalculator/device/KeyboardEventListener.java
Normal file
13
src/org/warp/picalculator/device/KeyboardEventListener.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package org.warp.picalculator.device;
|
||||||
|
|
||||||
|
import org.warp.picalculator.device.Keyboard.Key;
|
||||||
|
|
||||||
|
public interface KeyboardEventListener {
|
||||||
|
public default boolean keyPressed(Key k) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public default boolean keyReleased(Key k) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,7 @@ public final class DisplayManager implements RenderingLoop {
|
|||||||
|
|
||||||
public static Screen screen;
|
public static Screen screen;
|
||||||
public static String displayDebugString = "";
|
public static String displayDebugString = "";
|
||||||
|
public static ObjectArrayList<GUIErrorMessage> errorMessages = new ObjectArrayList<>();
|
||||||
|
|
||||||
public DisplayManager(Screen screen) {
|
public DisplayManager(Screen screen) {
|
||||||
setScreen(screen);
|
setScreen(screen);
|
||||||
|
36
src/org/warp/picalculator/gui/GUIErrorMessage.java
Normal file
36
src/org/warp/picalculator/gui/GUIErrorMessage.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package org.warp.picalculator.gui;
|
||||||
|
|
||||||
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
|
import org.warp.picalculator.Error;
|
||||||
|
|
||||||
|
public class GUIErrorMessage {
|
||||||
|
|
||||||
|
private String err;
|
||||||
|
private long creationTime;
|
||||||
|
|
||||||
|
public GUIErrorMessage(Error e) {
|
||||||
|
this.err = e.getLocalizedMessage();
|
||||||
|
this.creationTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GUIErrorMessage(Exception ex) {
|
||||||
|
err = ex.getLocalizedMessage();
|
||||||
|
this.creationTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(GraphicEngine g, Renderer r, String msg) {
|
||||||
|
int scrW = g.getWidth();
|
||||||
|
int scrH = g.getHeight();
|
||||||
|
int width = 200;
|
||||||
|
int height = 20;
|
||||||
|
int margin = 4;
|
||||||
|
r.glClearSkin();
|
||||||
|
r.glColor(0x00000000);
|
||||||
|
r.glFillRect(scrW-width-margin, scrH-height-margin, width, height, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreationTime() {
|
||||||
|
return creationTime;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.warp.picalculator.gui.expression;
|
package org.warp.picalculator.gui;
|
||||||
|
|
||||||
public interface GraphicalElement {
|
public interface GraphicalElement {
|
||||||
|
|
@ -1,5 +1,6 @@
|
|||||||
package org.warp.picalculator.gui.expression;
|
package org.warp.picalculator.gui.expression;
|
||||||
|
|
||||||
|
import org.warp.picalculator.gui.GraphicalElement;
|
||||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||||
@ -26,6 +27,8 @@ public abstract class Block implements GraphicalElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void recomputeDimensions();
|
public abstract void recomputeDimensions();
|
||||||
|
|
||||||
|
public abstract int computeCaretMaxBound();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth() {
|
public int getWidth() {
|
||||||
|
@ -55,4 +55,9 @@ public class BlockChar extends Block {
|
|||||||
return CLASS_ID;
|
return CLASS_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int computeCaretMaxBound() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package org.warp.picalculator.gui.expression;
|
package org.warp.picalculator.gui.expression;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
|
||||||
import org.warp.picalculator.device.graphicengine.Display;
|
import org.warp.picalculator.gui.GraphicalElement;
|
||||||
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
import org.warp.picalculator.gui.graphicengine.BinaryFont;
|
||||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
import org.warp.picalculator.gui.graphicengine.gpu.GPUFont;
|
|
||||||
|
|
||||||
public class BlockContainer implements GraphicalElement {
|
public class BlockContainer implements GraphicalElement {
|
||||||
|
|
||||||
@ -284,5 +282,13 @@ public class BlockContainer implements GraphicalElement {
|
|||||||
private static void checkInitialized() {
|
private static void checkInitialized() {
|
||||||
if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
if (!initialized) throw new ExceptionInInitializerError("Please initialize BlockContainer by running the method BlockContainer.initialize(...) first!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int computeCaretMaxBound() {
|
||||||
|
int maxpos = 0;
|
||||||
|
for (Block b : content) {
|
||||||
|
maxpos+=1+b.computeCaretMaxBound();
|
||||||
|
}
|
||||||
|
return maxpos+1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -99,4 +99,9 @@ public class BlockDivision extends Block {
|
|||||||
public int getClassID() {
|
public int getClassID() {
|
||||||
return CLASS_ID;
|
return CLASS_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int computeCaretMaxBound() {
|
||||||
|
return containerUp.computeCaretMaxBound()+containerDown.computeCaretMaxBound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package org.warp.picalculator.gui.expression;
|
||||||
|
|
||||||
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
|
|
||||||
|
public class BlockParenthesis extends Block {
|
||||||
|
|
||||||
|
public static final int CLASS_ID = 0x00000004;
|
||||||
|
|
||||||
|
private final BlockContainer containerNumber;
|
||||||
|
|
||||||
|
public BlockParenthesis() {
|
||||||
|
this.containerNumber = new BlockContainer(false);
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
|
||||||
|
BlockContainer.getDefaultFont(small).use(ge);
|
||||||
|
r.glColor(BlockContainer.getDefaultColor());
|
||||||
|
containerNumber.draw(ge, r, x+7, y+3, caret);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean putBlock(Caret caret, Block newBlock) {
|
||||||
|
boolean added = false;
|
||||||
|
added = added|containerNumber.putBlock(caret, newBlock);
|
||||||
|
if (added) {
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean delBlock(Caret caret) {
|
||||||
|
boolean removed = false;
|
||||||
|
removed = removed|containerNumber.delBlock(caret);
|
||||||
|
if (removed) {
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void recomputeDimensions() {
|
||||||
|
this.width = containerNumber.getWidth()+BlockContainer.getDefaultCharWidth(small)*2;
|
||||||
|
this.height = containerNumber.getHeight();
|
||||||
|
this.line = containerNumber.getLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSmall(boolean small) {
|
||||||
|
this.small = small;
|
||||||
|
this.containerNumber.setSmall(small);
|
||||||
|
recomputeDimensions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockContainer getNumberContainer() {
|
||||||
|
return containerNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getClassID() {
|
||||||
|
return CLASS_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int computeCaretMaxBound() {
|
||||||
|
return containerNumber.computeCaretMaxBound();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,7 +9,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|||||||
|
|
||||||
public class BlockSquareRoot extends Block {
|
public class BlockSquareRoot extends Block {
|
||||||
|
|
||||||
public static final int CLASS_ID = 0x00000002;
|
public static final int CLASS_ID = 0x00000003;
|
||||||
|
|
||||||
private final BlockContainer containerNumber;
|
private final BlockContainer containerNumber;
|
||||||
|
|
||||||
@ -84,4 +84,9 @@ public class BlockSquareRoot extends Block {
|
|||||||
public int getClassID() {
|
public int getClassID() {
|
||||||
return CLASS_ID;
|
return CLASS_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int computeCaretMaxBound() {
|
||||||
|
return containerNumber.computeCaretMaxBound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,19 @@ import org.warp.picalculator.gui.expression.BlockChar;
|
|||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
|
|
||||||
public class InlineInputContainer extends InputContainer {
|
public class InlineInputContainer extends InputContainer {
|
||||||
|
|
||||||
|
public InlineInputContainer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InlineInputContainer(boolean small) {
|
||||||
|
super(small);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InlineInputContainer(boolean small, int minWidth, int minHeight) {
|
||||||
|
super(small, minWidth, minHeight);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Block parseChar(char c) {
|
public Block parseChar(char c) {
|
||||||
return new BlockChar(MathematicalSymbols.DIVISION);
|
return new BlockChar(MathematicalSymbols.DIVISION);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package org.warp.picalculator.gui.expression.containers;
|
package org.warp.picalculator.gui.expression.containers;
|
||||||
|
|
||||||
|
import org.warp.picalculator.gui.GraphicalElement;
|
||||||
import org.warp.picalculator.gui.expression.Block;
|
import org.warp.picalculator.gui.expression.Block;
|
||||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||||
import org.warp.picalculator.gui.expression.Caret;
|
import org.warp.picalculator.gui.expression.Caret;
|
||||||
import org.warp.picalculator.gui.expression.CaretState;
|
import org.warp.picalculator.gui.expression.CaretState;
|
||||||
import org.warp.picalculator.gui.expression.GraphicalElement;
|
|
||||||
import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
||||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
@ -14,6 +14,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||||||
private Caret caret;
|
private Caret caret;
|
||||||
private static final float CARET_DURATION = 0.5f;
|
private static final float CARET_DURATION = 0.5f;
|
||||||
private float caretTime;
|
private float caretTime;
|
||||||
|
private int maxPosition = 0;
|
||||||
|
|
||||||
public InputContainer() {
|
public InputContainer() {
|
||||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||||
@ -36,6 +37,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||||||
caret.resetRemaining();
|
caret.resetRemaining();
|
||||||
if (root.putBlock(caret, b)) {
|
if (root.putBlock(caret, b)) {
|
||||||
caret.setPosition(caret.getPosition()+1);
|
caret.setPosition(caret.getPosition()+1);
|
||||||
|
maxPosition=root.computeCaretMaxBound();
|
||||||
root.recomputeDimensions();
|
root.recomputeDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,21 +56,26 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||||||
}
|
}
|
||||||
if (caret.getPosition() > 0) {
|
if (caret.getPosition() > 0) {
|
||||||
caret.setPosition(caret.getPosition()-1);
|
caret.setPosition(caret.getPosition()-1);
|
||||||
|
maxPosition=root.computeCaretMaxBound();
|
||||||
}
|
}
|
||||||
caret.turnOn();
|
caret.turnOn();
|
||||||
caretTime = 0;
|
caretTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveLeft() {
|
public void moveLeft() {
|
||||||
if (caret.getPosition() > 0) {
|
int curPos = caret.getPosition();
|
||||||
caret.setPosition(caret.getPosition()-1);
|
if (curPos > 0) {
|
||||||
|
caret.setPosition(curPos-1);
|
||||||
}
|
}
|
||||||
caret.turnOn();
|
caret.turnOn();
|
||||||
caretTime = 0;
|
caretTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void moveRight() {
|
public void moveRight() {
|
||||||
caret.setPosition(caret.getPosition()+1);
|
int curPos = caret.getPosition();
|
||||||
|
if (curPos+1 < maxPosition) {
|
||||||
|
caret.setPosition(curPos+1);
|
||||||
|
}
|
||||||
caret.turnOn();
|
caret.turnOn();
|
||||||
caretTime = 0;
|
caretTime = 0;
|
||||||
}
|
}
|
||||||
@ -108,6 +115,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||||||
somethingChanged = true;
|
somethingChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return somethingChanged;
|
return somethingChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,16 +129,12 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
|||||||
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
||||||
caret.resetRemaining();
|
caret.resetRemaining();
|
||||||
root.draw(ge, r, x, y, caret);
|
root.draw(ge, r, x, y, caret);
|
||||||
|
|
||||||
int remaining = caret.getRemaining();
|
|
||||||
if (remaining >= 0) {
|
|
||||||
caret.setPosition(caret.getPosition()-remaining-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||||
root.clear();
|
root.clear();
|
||||||
|
maxPosition=root.computeCaretMaxBound();
|
||||||
recomputeDimensions();
|
recomputeDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,28 @@ package org.warp.picalculator.gui.expression.containers;
|
|||||||
|
|
||||||
import org.warp.picalculator.gui.expression.Block;
|
import org.warp.picalculator.gui.expression.Block;
|
||||||
import org.warp.picalculator.gui.expression.BlockChar;
|
import org.warp.picalculator.gui.expression.BlockChar;
|
||||||
|
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||||
import org.warp.picalculator.gui.expression.BlockDivision;
|
import org.warp.picalculator.gui.expression.BlockDivision;
|
||||||
|
import org.warp.picalculator.gui.expression.BlockParenthesis;
|
||||||
import org.warp.picalculator.gui.expression.BlockSquareRoot;
|
import org.warp.picalculator.gui.expression.BlockSquareRoot;
|
||||||
|
import org.warp.picalculator.gui.expression.Caret;
|
||||||
|
import org.warp.picalculator.gui.expression.CaretState;
|
||||||
import org.warp.picalculator.math.MathematicalSymbols;
|
import org.warp.picalculator.math.MathematicalSymbols;
|
||||||
|
|
||||||
public class NormalInputContainer extends InputContainer {
|
public class NormalInputContainer extends InputContainer {
|
||||||
|
|
||||||
|
public NormalInputContainer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NormalInputContainer(boolean small) {
|
||||||
|
super(small);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NormalInputContainer(boolean small, int minWidth, int minHeight) {
|
||||||
|
super(small, minWidth, minHeight);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Block parseChar(char c) {
|
public Block parseChar(char c) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
@ -14,8 +31,12 @@ public class NormalInputContainer extends InputContainer {
|
|||||||
return new BlockDivision();
|
return new BlockDivision();
|
||||||
case MathematicalSymbols.SQUARE_ROOT:
|
case MathematicalSymbols.SQUARE_ROOT:
|
||||||
return new BlockSquareRoot();
|
return new BlockSquareRoot();
|
||||||
|
case MathematicalSymbols.PARENTHESIS_OPEN:
|
||||||
|
case MathematicalSymbols.PARENTHESIS_CLOSE:
|
||||||
|
return new BlockParenthesis();
|
||||||
case MathematicalSymbols.MULTIPLICATION:
|
case MathematicalSymbols.MULTIPLICATION:
|
||||||
case MathematicalSymbols.SUM:
|
case MathematicalSymbols.SUM:
|
||||||
|
case MathematicalSymbols.SUM_SUBTRACTION:
|
||||||
case MathematicalSymbols.SUBTRACTION:
|
case MathematicalSymbols.SUBTRACTION:
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package org.warp.picalculator.gui.expression.containers;
|
package org.warp.picalculator.gui.expression.containers;
|
||||||
|
|
||||||
public class NormalOutputContainer extends OutputContainer {
|
public class NormalOutputContainer extends OutputContainer {
|
||||||
|
public NormalOutputContainer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NormalOutputContainer(boolean small) {
|
||||||
|
super(small);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NormalOutputContainer(boolean small, int minWidth, int minHeight) {
|
||||||
|
super(small, minWidth, minHeight);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package org.warp.picalculator.gui.expression.containers;
|
package org.warp.picalculator.gui.expression.containers;
|
||||||
|
|
||||||
|
import org.warp.picalculator.gui.GraphicalElement;
|
||||||
import org.warp.picalculator.gui.expression.Block;
|
import org.warp.picalculator.gui.expression.Block;
|
||||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||||
import org.warp.picalculator.gui.expression.Caret;
|
import org.warp.picalculator.gui.expression.Caret;
|
||||||
import org.warp.picalculator.gui.expression.CaretState;
|
import org.warp.picalculator.gui.expression.CaretState;
|
||||||
import org.warp.picalculator.gui.expression.GraphicalElement;
|
|
||||||
import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
import org.warp.picalculator.gui.expression.layouts.InputLayout;
|
||||||
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
||||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||||
|
@ -224,12 +224,17 @@ public class GPURenderer implements Renderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void startDrawCycle() {
|
public void startDrawCycle() {
|
||||||
fbVertices = Buffers.newDirectFloatBuffer(3 * 4);
|
if (fbVertices == null) {
|
||||||
txVertices = Buffers.newDirectFloatBuffer(2 * 4);
|
fbVertices = Buffers.newDirectFloatBuffer(3 * 4);
|
||||||
colVertices = Buffers.newDirectFloatBuffer(4 * 4);
|
txVertices = Buffers.newDirectFloatBuffer(2 * 4);
|
||||||
|
colVertices = Buffers.newDirectFloatBuffer(4 * 4);
|
||||||
|
}
|
||||||
fbElements = 0;
|
fbElements = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean precTexEnabled;
|
||||||
|
private Texture precTex;
|
||||||
|
|
||||||
public void endDrawCycle() {
|
public void endDrawCycle() {
|
||||||
fbVertices.rewind();
|
fbVertices.rewind();
|
||||||
txVertices.rewind();
|
txVertices.rewind();
|
||||||
@ -239,21 +244,25 @@ public class GPURenderer implements Renderer {
|
|||||||
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, txVertices);
|
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, txVertices);
|
||||||
gl.glVertexPointer(3, GL.GL_FLOAT, 0, fbVertices);
|
gl.glVertexPointer(3, GL.GL_FLOAT, 0, fbVertices);
|
||||||
|
|
||||||
if (currentTexEnabled) {
|
if (precTexEnabled != currentTexEnabled | precTex != currentTex) {
|
||||||
gl.glEnable(GL2ES1.GL_TEXTURE_2D);
|
precTexEnabled = currentTexEnabled;
|
||||||
currentTex.bind(gl);
|
precTex = currentTex;
|
||||||
} else {
|
if (currentTexEnabled) {
|
||||||
gl.glDisable(GL2ES1.GL_TEXTURE_2D);
|
gl.glEnable(GL2ES1.GL_TEXTURE_2D);
|
||||||
|
currentTex.bind(gl);
|
||||||
|
} else {
|
||||||
|
gl.glDisable(GL2ES1.GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
|
gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, fbElements*4);
|
||||||
|
|
||||||
deleteBuffer(fbVertices);
|
// deleteBuffer(fbVertices);
|
||||||
deleteBuffer(txVertices);
|
// deleteBuffer(txVertices);
|
||||||
deleteBuffer(colVertices);
|
// deleteBuffer(colVertices);
|
||||||
fbVertices = null;
|
// fbVertices = null;
|
||||||
txVertices = null;
|
// txVertices = null;
|
||||||
colVertices = null;
|
// colVertices = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBuffer(final Buffer realNioBuffer) {
|
public void deleteBuffer(final Buffer realNioBuffer) {
|
||||||
|
@ -5,7 +5,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|||||||
import org.warp.picalculator.Error;
|
import org.warp.picalculator.Error;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.gui.DisplayManager;
|
import org.warp.picalculator.gui.DisplayManager;
|
||||||
import org.warp.picalculator.gui.expression.GraphicalElement;
|
import org.warp.picalculator.gui.GraphicalElement;
|
||||||
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
import org.warp.picalculator.gui.graphicengine.cpu.CPUEngine;
|
||||||
import org.warp.picalculator.math.MathContext;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
|
Loading…
Reference in New Issue
Block a user