2017-04-12 13:04:35 +02:00
|
|
|
package org.warp.picalculator.gui.expression.blocks;
|
2017-03-26 22:44:09 +02:00
|
|
|
|
2017-05-26 22:37:18 +02:00
|
|
|
import org.warp.picalculator.Error;
|
2017-04-12 13:04:35 +02:00
|
|
|
import org.warp.picalculator.gui.expression.Caret;
|
2017-03-26 22:44:09 +02:00
|
|
|
import org.warp.picalculator.gui.graphicengine.GraphicEngine;
|
|
|
|
import org.warp.picalculator.gui.graphicengine.Renderer;
|
2017-05-26 22:37:18 +02:00
|
|
|
import org.warp.picalculator.math.Function;
|
|
|
|
import org.warp.picalculator.math.MathContext;
|
|
|
|
import org.warp.picalculator.math.parser.features.FeatureSquareRoot;
|
|
|
|
import org.warp.picalculator.math.parser.features.interfaces.Feature;
|
2017-03-26 22:44:09 +02:00
|
|
|
|
|
|
|
public class BlockSquareRoot extends Block {
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-26 22:44:09 +02:00
|
|
|
private final BlockContainer containerNumber;
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-26 22:44:09 +02:00
|
|
|
private int h1;
|
2017-04-10 22:50:43 +02:00
|
|
|
|
2017-03-26 22:44:09 +02:00
|
|
|
public BlockSquareRoot() {
|
2017-04-10 22:50:43 +02:00
|
|
|
containerNumber = new BlockContainer(false);
|
2017-03-26 22:44:09 +02:00
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void draw(GraphicEngine ge, Renderer r, int x, int y, Caret caret) {
|
|
|
|
BlockContainer.getDefaultFont(small).use(ge);
|
|
|
|
r.glColor(BlockContainer.getDefaultColor());
|
2017-04-10 22:50:43 +02:00
|
|
|
r.glDrawLine(x, y + height - 10 + 1, x, y + height - 10 + 2); // /
|
|
|
|
r.glDrawLine(x + 1, y + height - 10, x + 1, y + height - 10 + 1); // /
|
|
|
|
r.glDrawLine(x + 2, y + height - 10 + 2, x + 2, y + height - 10 + 6); // \
|
|
|
|
r.glDrawLine(x + 3, y + height - 10 + 7, x + 3, y + height - 10 + 9); // \
|
|
|
|
r.glDrawLine(x + 5, y + height - h1 - 1 - 2, x + width - 1, y + height - h1 - 1 - 2); // ----
|
|
|
|
r.glDrawLine(x + 5, y + height - h1 - 1 - 2, x + 5, y + height - (h1 - 2) / 3f * 2f - 1); // |
|
|
|
|
r.glDrawLine(x + 4, y + height - (h1 - 2) / 3f * 2f - 1, x + 4, y + height - (h1 - 2) / 3f - 1); // |
|
|
|
|
r.glDrawLine(x + 3, y + height - (h1 - 2) / 3f - 1, x + 3, y + height - 1); // |
|
|
|
|
containerNumber.draw(ge, r, x + 7, y + 3, caret);
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean putBlock(Caret caret, Block newBlock) {
|
|
|
|
boolean added = false;
|
2017-04-10 22:50:43 +02:00
|
|
|
added = added | containerNumber.putBlock(caret, newBlock);
|
2017-03-26 22:44:09 +02:00
|
|
|
if (added) {
|
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
return added;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean delBlock(Caret caret) {
|
|
|
|
boolean removed = false;
|
2017-04-10 22:50:43 +02:00
|
|
|
removed = removed | containerNumber.delBlock(caret);
|
2017-03-26 22:44:09 +02:00
|
|
|
if (removed) {
|
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
return removed;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-05-05 22:27:11 +02:00
|
|
|
@Override
|
2018-03-11 21:49:41 +01:00
|
|
|
public BlockReference<?> getBlock(Caret caret) {
|
2017-05-05 22:27:11 +02:00
|
|
|
return containerNumber.getBlock(caret);
|
|
|
|
}
|
2017-03-26 22:44:09 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void recomputeDimensions() {
|
|
|
|
final int w1 = containerNumber.getWidth();
|
|
|
|
h1 = containerNumber.getHeight();
|
|
|
|
final int l1 = containerNumber.getLine();
|
2017-04-10 22:50:43 +02:00
|
|
|
width = 8 + w1 + 2;
|
|
|
|
height = 3 + h1;
|
|
|
|
line = 3 + l1;
|
2017-03-26 22:44:09 +02:00
|
|
|
if (height < 9) {
|
|
|
|
height = 9;
|
2017-04-10 22:50:43 +02:00
|
|
|
line += (9 - (3 + h1));
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setSmall(boolean small) {
|
|
|
|
this.small = small;
|
2017-04-10 22:50:43 +02:00
|
|
|
containerNumber.setSmall(small);
|
2017-03-26 22:44:09 +02:00
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockContainer getNumberContainer() {
|
|
|
|
return containerNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-05-26 22:37:18 +02:00
|
|
|
public int computeCaretMaxBound() {
|
|
|
|
return containerNumber.computeCaretMaxBound();
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|
2017-04-09 22:01:03 +02:00
|
|
|
|
|
|
|
@Override
|
2017-05-26 22:37:18 +02:00
|
|
|
public Feature toFeature(MathContext context) throws Error {
|
|
|
|
final Function contnt = getNumberContainer().toFunction(context);
|
|
|
|
return new FeatureSquareRoot(contnt);
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|