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"?>
|
||||
<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="src" path="res"/>
|
||||
<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.Renderer;
|
||||
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.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.graphicengine.BinaryFont;
|
||||
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.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.MathematicalSymbols;
|
||||
import org.warp.picalculator.math.functions.Expression;
|
||||
import org.warp.picalculator.math.functions.Root;
|
||||
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 static final GraphicEngine d = new GPUEngine();
|
||||
@ -38,9 +30,105 @@ public class TestGPU {
|
||||
Utils.debugThirdScreen = false;
|
||||
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);
|
||||
}
|
||||
|
||||
private static NormalInputContainer c = null;
|
||||
|
||||
private static class Scene implements RenderingLoop {
|
||||
|
||||
private BinaryFont exampleFont;
|
||||
@ -48,8 +136,7 @@ public class TestGPU {
|
||||
|
||||
private final Renderer r;
|
||||
private final GraphicEngine d;
|
||||
|
||||
private final NormalInputContainer c;
|
||||
private long lastTime = 0L;
|
||||
|
||||
public Scene(GraphicEngine d) throws IOException, Error {
|
||||
this.d = d;
|
||||
@ -76,9 +163,6 @@ public class TestGPU {
|
||||
c.typeChar('2');
|
||||
c.recomputeDimensions();
|
||||
|
||||
Expression expr = MathParser.parseInput(new MathContext(), c.root);
|
||||
System.out.println("Parsed input:"+expr.toString());
|
||||
|
||||
d.start(this);
|
||||
|
||||
// fonts = new RAWFont[1];
|
||||
@ -95,7 +179,10 @@ public class TestGPU {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.exit(0);
|
||||
if (!Utils.debugOn) {
|
||||
d.destroy();
|
||||
System.exit(0);
|
||||
}
|
||||
}).start();
|
||||
|
||||
d.waitUntilExit();
|
||||
@ -119,6 +206,12 @@ public class TestGPU {
|
||||
r.glFillRect(162, 2.5f, 160, 160, 0, 0, 16, 16);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import org.warp.picalculator.Utils;
|
||||
import org.warp.picalculator.device.chip.ParallelToSerial;
|
||||
import org.warp.picalculator.device.chip.SerialToParallel;
|
||||
import org.warp.picalculator.gui.DisplayManager;
|
||||
import org.warp.picalculator.gui.GUIErrorMessage;
|
||||
import org.warp.picalculator.gui.screens.KeyboardDebugScreen;
|
||||
import org.warp.picalculator.gui.screens.MarioScreen;
|
||||
import org.warp.picalculator.gui.screens.Screen;
|
||||
@ -32,7 +33,9 @@ public class Keyboard {
|
||||
|
||||
private static volatile boolean refreshRequest = false;
|
||||
|
||||
public static void startKeyboard() {
|
||||
private static KeyboardEventListener additionalListener;
|
||||
|
||||
public synchronized static void startKeyboard() {
|
||||
final Thread kt = new Thread(() -> {
|
||||
if (Utils.debugOn) {
|
||||
try {
|
||||
@ -94,7 +97,7 @@ public class Keyboard {
|
||||
kt.start();
|
||||
}
|
||||
|
||||
private static void debugKeyPressed(int keyCode) {
|
||||
private synchronized static void debugKeyPressed(int keyCode) {
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
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.keyY = col;
|
||||
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.keyY = col;
|
||||
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) {
|
||||
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
||||
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;
|
||||
} else {
|
||||
switch (k) {
|
||||
@ -756,6 +773,8 @@ public class Keyboard {
|
||||
if (refresh) {
|
||||
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;
|
||||
if (DisplayManager.INSTANCE != null) {
|
||||
final Screen scr = DisplayManager.INSTANCE.getScreen();
|
||||
@ -778,11 +801,17 @@ public class Keyboard {
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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 String displayDebugString = "";
|
||||
public static ObjectArrayList<GUIErrorMessage> errorMessages = new ObjectArrayList<>();
|
||||
|
||||
public DisplayManager(Screen 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 {
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.Renderer;
|
||||
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
||||
@ -27,6 +28,8 @@ public abstract class Block implements GraphicalElement {
|
||||
@Override
|
||||
public abstract void recomputeDimensions();
|
||||
|
||||
public abstract int computeCaretMaxBound();
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return width;
|
||||
|
@ -55,4 +55,9 @@ public class BlockChar extends Block {
|
||||
return CLASS_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int computeCaretMaxBound() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
package org.warp.picalculator.gui.expression;
|
||||
|
||||
import java.io.IOException;
|
||||
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.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
import org.warp.picalculator.gui.graphicengine.gpu.GPUFont;
|
||||
|
||||
public class BlockContainer implements GraphicalElement {
|
||||
|
||||
@ -285,4 +283,12 @@ public class BlockContainer implements GraphicalElement {
|
||||
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() {
|
||||
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 static final int CLASS_ID = 0x00000002;
|
||||
public static final int CLASS_ID = 0x00000003;
|
||||
|
||||
private final BlockContainer containerNumber;
|
||||
|
||||
@ -84,4 +84,9 @@ public class BlockSquareRoot extends Block {
|
||||
public int getClassID() {
|
||||
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;
|
||||
|
||||
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
|
||||
public Block parseChar(char c) {
|
||||
return new BlockChar(MathematicalSymbols.DIVISION);
|
||||
|
@ -1,10 +1,10 @@
|
||||
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.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
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.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
@ -14,6 +14,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
private Caret caret;
|
||||
private static final float CARET_DURATION = 0.5f;
|
||||
private float caretTime;
|
||||
private int maxPosition = 0;
|
||||
|
||||
public InputContainer() {
|
||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||
@ -36,6 +37,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
caret.resetRemaining();
|
||||
if (root.putBlock(caret, b)) {
|
||||
caret.setPosition(caret.getPosition()+1);
|
||||
maxPosition=root.computeCaretMaxBound();
|
||||
root.recomputeDimensions();
|
||||
}
|
||||
}
|
||||
@ -54,21 +56,26 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
}
|
||||
if (caret.getPosition() > 0) {
|
||||
caret.setPosition(caret.getPosition()-1);
|
||||
maxPosition=root.computeCaretMaxBound();
|
||||
}
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
}
|
||||
|
||||
public void moveLeft() {
|
||||
if (caret.getPosition() > 0) {
|
||||
caret.setPosition(caret.getPosition()-1);
|
||||
int curPos = caret.getPosition();
|
||||
if (curPos > 0) {
|
||||
caret.setPosition(curPos-1);
|
||||
}
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
}
|
||||
|
||||
public void moveRight() {
|
||||
caret.setPosition(caret.getPosition()+1);
|
||||
int curPos = caret.getPosition();
|
||||
if (curPos+1 < maxPosition) {
|
||||
caret.setPosition(curPos+1);
|
||||
}
|
||||
caret.turnOn();
|
||||
caretTime = 0;
|
||||
}
|
||||
@ -108,6 +115,7 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
somethingChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
return somethingChanged;
|
||||
}
|
||||
|
||||
@ -121,16 +129,12 @@ public abstract class InputContainer implements GraphicalElement, InputLayout {
|
||||
public void draw(GraphicEngine ge, Renderer r, int x, int y) {
|
||||
caret.resetRemaining();
|
||||
root.draw(ge, r, x, y, caret);
|
||||
|
||||
int remaining = caret.getRemaining();
|
||||
if (remaining >= 0) {
|
||||
caret.setPosition(caret.getPosition()-remaining-1);
|
||||
}
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
caret = new Caret(CaretState.VISIBLE_ON, 0);
|
||||
root.clear();
|
||||
maxPosition=root.computeCaretMaxBound();
|
||||
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.BlockChar;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
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.Caret;
|
||||
import org.warp.picalculator.gui.expression.CaretState;
|
||||
import org.warp.picalculator.math.MathematicalSymbols;
|
||||
|
||||
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
|
||||
public Block parseChar(char c) {
|
||||
switch(c) {
|
||||
@ -14,8 +31,12 @@ public class NormalInputContainer extends InputContainer {
|
||||
return new BlockDivision();
|
||||
case MathematicalSymbols.SQUARE_ROOT:
|
||||
return new BlockSquareRoot();
|
||||
case MathematicalSymbols.PARENTHESIS_OPEN:
|
||||
case MathematicalSymbols.PARENTHESIS_CLOSE:
|
||||
return new BlockParenthesis();
|
||||
case MathematicalSymbols.MULTIPLICATION:
|
||||
case MathematicalSymbols.SUM:
|
||||
case MathematicalSymbols.SUM_SUBTRACTION:
|
||||
case MathematicalSymbols.SUBTRACTION:
|
||||
case '0':
|
||||
case '1':
|
||||
|
@ -1,5 +1,15 @@
|
||||
package org.warp.picalculator.gui.expression.containers;
|
||||
|
||||
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;
|
||||
|
||||
import org.warp.picalculator.gui.GraphicalElement;
|
||||
import org.warp.picalculator.gui.expression.Block;
|
||||
import org.warp.picalculator.gui.expression.BlockContainer;
|
||||
import org.warp.picalculator.gui.expression.Caret;
|
||||
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.graphicengine.GraphicEngine;
|
||||
import org.warp.picalculator.gui.graphicengine.Renderer;
|
||||
|
@ -224,12 +224,17 @@ public class GPURenderer implements Renderer {
|
||||
}
|
||||
|
||||
public void startDrawCycle() {
|
||||
fbVertices = Buffers.newDirectFloatBuffer(3 * 4);
|
||||
txVertices = Buffers.newDirectFloatBuffer(2 * 4);
|
||||
colVertices = Buffers.newDirectFloatBuffer(4 * 4);
|
||||
if (fbVertices == null) {
|
||||
fbVertices = Buffers.newDirectFloatBuffer(3 * 4);
|
||||
txVertices = Buffers.newDirectFloatBuffer(2 * 4);
|
||||
colVertices = Buffers.newDirectFloatBuffer(4 * 4);
|
||||
}
|
||||
fbElements = 0;
|
||||
}
|
||||
|
||||
private boolean precTexEnabled;
|
||||
private Texture precTex;
|
||||
|
||||
public void endDrawCycle() {
|
||||
fbVertices.rewind();
|
||||
txVertices.rewind();
|
||||
@ -239,21 +244,25 @@ public class GPURenderer implements Renderer {
|
||||
gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, txVertices);
|
||||
gl.glVertexPointer(3, GL.GL_FLOAT, 0, fbVertices);
|
||||
|
||||
if (currentTexEnabled) {
|
||||
gl.glEnable(GL2ES1.GL_TEXTURE_2D);
|
||||
currentTex.bind(gl);
|
||||
} else {
|
||||
gl.glDisable(GL2ES1.GL_TEXTURE_2D);
|
||||
if (precTexEnabled != currentTexEnabled | precTex != currentTex) {
|
||||
precTexEnabled = currentTexEnabled;
|
||||
precTex = currentTex;
|
||||
if (currentTexEnabled) {
|
||||
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(txVertices);
|
||||
deleteBuffer(colVertices);
|
||||
fbVertices = null;
|
||||
txVertices = null;
|
||||
colVertices = null;
|
||||
// deleteBuffer(fbVertices);
|
||||
// deleteBuffer(txVertices);
|
||||
// deleteBuffer(colVertices);
|
||||
// fbVertices = null;
|
||||
// txVertices = null;
|
||||
// colVertices = null;
|
||||
}
|
||||
|
||||
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.Utils;
|
||||
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.math.MathContext;
|
||||
import org.warp.picalculator.math.Function;
|
||||
|
Loading…
Reference in New Issue
Block a user