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 debugThirdScreen;
public static boolean debugWindow2x;
public static final class DebugStream extends StringWriter {

View File

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

View File

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

View File

@ -48,7 +48,7 @@ public class GPUEngine implements org.warp.picalculator.gui.graphicengine.Graphi
public void setDisplayMode(int ww, int wh) {
size[0] = ww;
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

View File

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

View File

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

View File

@ -125,15 +125,11 @@ public class MathParser {
}
if (func instanceof Power) {
BlockPower bp = new BlockPower();
BlockContainer nc = bp.getNumberContainer();
BlockContainer ec = bp.getExponentContainer();
for (Block b : sub1) {
nc.appendBlockUnsafe(b);
}
result.addAll(sub1);
for (Block b : sub2) {
ec.appendBlockUnsafe(b);
}
nc.recomputeDimensions();
ec.recomputeDimensions();
bp.recomputeDimensions();
result.add(bp);
@ -172,17 +168,14 @@ public class MathParser {
String numberString = numb.toString();
if (numberString.contains("")) {
String[] numberParts = numberString.split("", 2);
numberParts[0]+="";
BlockPower bp = new BlockExponentialNotation();
BlockContainer bpnc = bp.getNumberContainer();
BlockContainer bpec = bp.getExponentContainer();
for (char c : numberParts[0].toCharArray()) {
bpnc.appendBlockUnsafe(new BlockChar(c));
result.add(new BlockChar(c));
}
for (char c : numberParts[1].toCharArray()) {
bpec.appendBlockUnsafe(new BlockChar(c));
}
bpnc.recomputeDimensions();
};
bpec.recomputeDimensions();
bp.recomputeDimensions();
result.add(bp);
@ -241,9 +234,8 @@ public class MathParser {
break;
case BlockPower.CLASS_ID:
final BlockPower blp = (BlockPower) block;
final Function nmb = parseContainer(context, blp.getNumberContainer().getContent());
final Function exp = parseContainer(context, blp.getExponentContainer().getContent());
result = new FeaturePower(nmb, exp);
result = new FeaturePower(exp);
break;
default:
throw new Error(Errors.NOT_IMPLEMENTED, "The block " + block.getClass().getSimpleName() + " isn't a known BLock");
@ -396,7 +388,12 @@ public class MathParser {
} else if (f instanceof FeatureSum) {
process.add(new Sum(context, (Function) ((FeatureDouble) f).getChild1(), (Function) ((FeatureDouble) f).getChild2()));
} 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) {
process.add(new RootSquare(context, (Function) ((FeatureSingle) f).getChild()));
} else if (f instanceof FeatureParenthesis) {

View File

@ -1,11 +1,9 @@
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 child1, Object child2) {
super(child1, child2);
public FeaturePower(Object child) {
super(child);
}
}