This commit is contained in:
XDrake99 2017-04-23 14:11:37 +02:00
parent 74dc027642
commit 3efb8f6c26
12 changed files with 49 additions and 54 deletions

BIN
res/algebra_input.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

View File

@ -49,6 +49,7 @@ public class Utils {
public static boolean debugOn; public static boolean debugOn;
public static boolean debugThirdScreen; public static boolean debugThirdScreen;
public static boolean debugWindow2x;
public static final class DebugStream extends StringWriter { public static final class DebugStream extends StringWriter {

View File

@ -733,7 +733,7 @@ public class Keyboard {
refresh = true; refresh = true;
break; break;
case BRIGHTNESS_CYCLE_REVERSE: case BRIGHTNESS_CYCLE_REVERSE:
DisplayManager.INSTANCE.setScreen(new MarioScreen()); //TODO: rimuovere: prova // DisplayManager.INSTANCE.setScreen(new MarioScreen()); //TODO: rimuovere: prova
DisplayManager.cycleBrightness(true); DisplayManager.cycleBrightness(true);
refresh = true; refresh = true;
break; break;

View File

@ -51,7 +51,7 @@ public abstract class Block implements GraphicalElement {
public boolean isSmall() { public boolean isSmall() {
return small; return small;
} }
public abstract void setSmall(boolean small); public abstract void setSmall(boolean small);
public abstract int getClassID(); public abstract int getClassID();

View File

@ -1,8 +1,26 @@
package org.warp.picalculator.gui.expression.blocks; package org.warp.picalculator.gui.expression.blocks;
import org.warp.picalculator.gui.expression.Caret;
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.Renderer;
public class BlockExponentialNotation extends BlockPower { public class BlockExponentialNotation extends BlockPower {
private int bw;
private int bh;
@Override @Override
protected int getSpacing() { public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
return -3; BlockContainer.getDefaultFont(small).use(ge);
r.glColor(BlockContainer.getDefaultColor());
r.glDrawStringLeft(x, y+height-bh, "");
super.draw(ge, r, x+bw, y, caret);
}
@Override
public void recomputeDimensions() {
super.recomputeDimensions();
bw = (int) (BlockContainer.getDefaultCharWidth(small)*1.5);
bh = BlockContainer.getDefaultCharHeight(small);
this.width+=bw;
} }
} }

View File

@ -10,31 +10,23 @@ public class BlockPower extends Block {
public static final int CLASS_ID = 0x00000005; public static final int CLASS_ID = 0x00000005;
private final BlockContainer containerNumber;
private final BlockContainer containerExponent; private final BlockContainer containerExponent;
private int h1;
private int w1;
public BlockPower() { public BlockPower() {
containerNumber = new BlockContainer(false);
containerExponent = new BlockContainer(true); containerExponent = new BlockContainer(true);
recomputeDimensions(); recomputeDimensions();
} }
@Override @Override
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) { 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, y+height-h1, caret);
BlockContainer.getDefaultFont(true).use(ge); BlockContainer.getDefaultFont(true).use(ge);
containerExponent.draw(ge, r, x+w1+getSpacing(), y, caret); r.glColor(BlockContainer.getDefaultColor());
containerExponent.draw(ge, r, x, y, caret);
} }
@Override @Override
public boolean putBlock(Caret caret, Block newBlock) { public boolean putBlock(Caret caret, Block newBlock) {
boolean added = false; boolean added = false;
added = added | containerNumber.putBlock(caret, newBlock);
added = added | containerExponent.putBlock(caret, newBlock); added = added | containerExponent.putBlock(caret, newBlock);
if (added) { if (added) {
recomputeDimensions(); recomputeDimensions();
@ -45,7 +37,6 @@ public class BlockPower extends Block {
@Override @Override
public boolean delBlock(Caret caret) { public boolean delBlock(Caret caret) {
boolean removed = false; boolean removed = false;
removed = removed | containerNumber.delBlock(caret);
removed = removed | containerExponent.delBlock(caret); removed = removed | containerExponent.delBlock(caret);
if (removed) { if (removed) {
recomputeDimensions(); recomputeDimensions();
@ -55,28 +46,21 @@ public class BlockPower extends Block {
@Override @Override
public void recomputeDimensions() { public void recomputeDimensions() {
w1 = containerNumber.getWidth();
final int w2 = containerExponent.getWidth(); final int w2 = containerExponent.getWidth();
h1 = containerNumber.getHeight();
final int h2 = containerExponent.getHeight(); final int h2 = containerExponent.getHeight();
final int l1 = containerNumber.getLine(); final int l2 = containerExponent.getLine();
width = w1+getSpacing()+1+w2; width = w2+1;
height = h1 + h2 - 3; height = h2+BlockContainer.getDefaultCharHeight(small)-3;
line = height-h1+l1; line = h2+BlockContainer.getDefaultCharHeight(small)/2-3;
} }
@Override @Override
public void setSmall(boolean small) { public void setSmall(boolean small) {
this.small = small; this.small = small;
containerNumber.setSmall(small);
containerExponent.setSmall(true); containerExponent.setSmall(true);
recomputeDimensions(); recomputeDimensions();
} }
public BlockContainer getNumberContainer() {
return containerNumber;
}
public BlockContainer getExponentContainer() { public BlockContainer getExponentContainer() {
return containerExponent; return containerExponent;
} }
@ -88,10 +72,6 @@ public class BlockPower extends Block {
@Override @Override
public int computeCaretMaxBound() { public int computeCaretMaxBound() {
return containerNumber.computeCaretMaxBound() + containerExponent.computeCaretMaxBound(); return containerExponent.computeCaretMaxBound();
}
protected int getSpacing() {
return 1;
} }
} }

View File

@ -48,7 +48,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
public void setDisplayMode(int ww, int wh) { public void setDisplayMode(int ww, int wh) {
size[0] = ww; size[0] = ww;
size[1] = wh; size[1] = wh;
wnd.window.setSize(Utils.debugOn ? ww * 2 : ww, Utils.debugOn ? wh * 2 : wh); wnd.window.setSize((Utils.debugOn & Utils.debugWindow2x) ? ww * 2 : ww, (Utils.debugOn & Utils.debugWindow2x) ? wh * 2 : wh);
} }
@Override @Override

View File

@ -287,8 +287,8 @@ class NEWTWindow implements GLEventListener {
@Override @Override
public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
disp.size[0] = Utils.debugOn ? width / 2 : width; disp.size[0] = (Utils.debugOn & Utils.debugWindow2x) ? width / 2 : width;
disp.size[1] = Utils.debugOn ? height / 2 : height; disp.size[1] = (Utils.debugOn & Utils.debugWindow2x) ? height / 2 : height;
final GL2ES1 gl = glad.getGL().getGL2ES1(); final GL2ES1 gl = glad.getGL().getGL2ES1();
float max_wh, min_wh; float max_wh, min_wh;
if (width == 0) { if (width == 0) {
@ -310,7 +310,7 @@ class NEWTWindow implements GLEventListener {
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity(); gl.glLoadIdentity();
gl.glOrtho(0.0, Utils.debugOn ? width / 2 : width, Utils.debugOn ? height / 2 : height, 0.0, -1, 1); gl.glOrtho(0.0, (Utils.debugOn & Utils.debugWindow2x) ? width / 2 : width, (Utils.debugOn & Utils.debugWindow2x) ? height / 2 : height, 0.0, -1, 1);
gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity(); gl.glLoadIdentity();

View File

@ -2,6 +2,7 @@ package org.warp.picalculator.gui.screens;
import java.io.IOException; import java.io.IOException;
import org.warp.picalculator.Main;
import org.warp.picalculator.device.Keyboard; import org.warp.picalculator.device.Keyboard;
import org.warp.picalculator.device.Keyboard.Key; import org.warp.picalculator.device.Keyboard.Key;
import org.warp.picalculator.gui.DisplayManager; import org.warp.picalculator.gui.DisplayManager;

View File

@ -125,15 +125,11 @@ public class MathParser {
} }
if (func instanceof Power) { if (func instanceof Power) {
BlockPower bp = new BlockPower(); BlockPower bp = new BlockPower();
BlockContainer nc = bp.getNumberContainer();
BlockContainer ec = bp.getExponentContainer(); BlockContainer ec = bp.getExponentContainer();
for (Block b : sub1) { result.addAll(sub1);
nc.appendBlockUnsafe(b);
}
for (Block b : sub2) { for (Block b : sub2) {
ec.appendBlockUnsafe(b); ec.appendBlockUnsafe(b);
} }
nc.recomputeDimensions();
ec.recomputeDimensions(); ec.recomputeDimensions();
bp.recomputeDimensions(); bp.recomputeDimensions();
result.add(bp); result.add(bp);
@ -172,17 +168,14 @@ public class MathParser {
String numberString = numb.toString(); String numberString = numb.toString();
if (numberString.contains("")) { if (numberString.contains("")) {
String[] numberParts = numberString.split("", 2); String[] numberParts = numberString.split("", 2);
numberParts[0]+="";
BlockPower bp = new BlockExponentialNotation(); BlockPower bp = new BlockExponentialNotation();
BlockContainer bpnc = bp.getNumberContainer();
BlockContainer bpec = bp.getExponentContainer(); BlockContainer bpec = bp.getExponentContainer();
for (char c : numberParts[0].toCharArray()) { for (char c : numberParts[0].toCharArray()) {
bpnc.appendBlockUnsafe(new BlockChar(c)); result.add(new BlockChar(c));
} }
for (char c : numberParts[1].toCharArray()) { for (char c : numberParts[1].toCharArray()) {
bpec.appendBlockUnsafe(new BlockChar(c)); bpec.appendBlockUnsafe(new BlockChar(c));
} };
bpnc.recomputeDimensions();
bpec.recomputeDimensions(); bpec.recomputeDimensions();
bp.recomputeDimensions(); bp.recomputeDimensions();
result.add(bp); result.add(bp);
@ -241,9 +234,8 @@ public class MathParser {
break; break;
case BlockPower.CLASS_ID: case BlockPower.CLASS_ID:
final BlockPower blp = (BlockPower) block; final BlockPower blp = (BlockPower) block;
final Function nmb = parseContainer(context, blp.getNumberContainer().getContent());
final Function exp = parseContainer(context, blp.getExponentContainer().getContent()); final Function exp = parseContainer(context, blp.getExponentContainer().getContent());
result = new FeaturePower(nmb, exp); result = new FeaturePower(exp);
break; break;
default: default:
throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known BLock"); throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known BLock");
@ -385,7 +377,7 @@ public class MathParser {
private static ObjectArrayList<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features) private static ObjectArrayList<Function> makeFunctions(MathContext context, ObjectArrayList<Feature> features)
throws Error { throws Error {
final ObjectArrayList<Function> process = new ObjectArrayList<>(); final ObjectArrayList<Function> process = new ObjectArrayList<>();
for (final Feature f : features) { for (final Feature f : features) {
if (f instanceof FeatureDivision) { if (f instanceof FeatureDivision) {
process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); process.add(new Division(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
@ -396,7 +388,12 @@ public class MathParser {
} else if (f instanceof FeatureSum) { } else if (f instanceof FeatureSum) {
process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} else if (f instanceof FeaturePower) { } else if (f instanceof FeaturePower) {
process.add(new Power(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2())); if (process.isEmpty()) {
throw new Error(Errors.SYNTAX_ERROR, "There is a power at the beginning of the expression!");
} else {
Function prec = process.remove(process.size()-1);
process.add(new Power(context, prec, (Function) ((FeatureSingle) f).getChild()));
}
} else if (f instanceof FeatureSquareRoot) { } else if (f instanceof FeatureSquareRoot) {
process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild())); process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild()));
} else if (f instanceof FeatureParenthesis) { } else if (f instanceof FeatureParenthesis) {

View File

@ -1,11 +1,9 @@
package org.warp.picalculator.math.parser.features; package org.warp.picalculator.math.parser.features;
import org.warp.picalculator.math.parser.features.interfaces.Feature; public class FeaturePower extends FeatureSingleImpl {
public class FeaturePower extends FeatureDoubleImpl { public FeaturePower(Object child) {
super(child);
public FeaturePower(Object child1, Object child2) {
super(child1, child2);
} }
} }