2018-09-02 13:36:49 +02:00
|
|
|
package it.cavallium.warppi.gui.expression.blocks;
|
2017-03-26 22:44:09 +02:00
|
|
|
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.expression.Caret;
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.GraphicEngine;
|
|
|
|
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
|
|
|
import it.cavallium.warppi.math.Function;
|
|
|
|
import it.cavallium.warppi.math.MathContext;
|
|
|
|
import it.cavallium.warppi.math.parser.features.FeatureSquareRoot;
|
|
|
|
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
2018-09-12 22:16:33 +02:00
|
|
|
import it.cavallium.warppi.util.Error;
|
2018-10-04 08:49:11 +02:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
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() {
|
2018-09-22 14:10:36 +02:00
|
|
|
containerNumber = new BlockContainer(this, false);
|
2017-03-26 22:44:09 +02:00
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void draw(final GraphicEngine ge, final Renderer r, final int x, final int y, final Caret caret) {
|
2017-03-26 22:44:09 +02:00
|
|
|
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
|
2018-09-22 11:17:30 +02:00
|
|
|
public boolean putBlock(final Caret caret, final Block newBlock) {
|
2017-03-26 22:44:09 +02:00
|
|
|
boolean added = false;
|
2017-04-10 22:50:43 +02:00
|
|
|
added = added | containerNumber.putBlock(caret, newBlock);
|
2018-09-28 11:39:28 +02:00
|
|
|
if (added) {
|
2017-03-26 22:44:09 +02:00
|
|
|
recomputeDimensions();
|
2018-09-28 11:39:28 +02:00
|
|
|
}
|
2017-03-26 22:44:09 +02:00
|
|
|
return added;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public boolean delBlock(final Caret caret) {
|
2017-03-26 22:44:09 +02:00
|
|
|
boolean removed = false;
|
2017-04-10 22:50:43 +02:00
|
|
|
removed = removed | containerNumber.delBlock(caret);
|
2018-09-28 11:39:28 +02:00
|
|
|
if (removed) {
|
2017-03-26 22:44:09 +02:00
|
|
|
recomputeDimensions();
|
2018-09-28 11:39:28 +02:00
|
|
|
}
|
2017-03-26 22:44:09 +02:00
|
|
|
return removed;
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-05-05 22:27:11 +02:00
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public BlockReference<?> getBlock(final 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;
|
2018-09-22 11:17:30 +02:00
|
|
|
line += 9 - (3 + h1);
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void setSmall(final boolean small) {
|
2017-03-26 22:44:09 +02:00
|
|
|
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
|
2018-09-22 11:17:30 +02:00
|
|
|
public Feature toFeature(final MathContext context) throws Error {
|
2017-05-26 22:37:18 +02:00
|
|
|
final Function contnt = getNumberContainer().toFunction(context);
|
|
|
|
return new FeatureSquareRoot(contnt);
|
2017-04-09 22:01:03 +02:00
|
|
|
}
|
2018-10-04 08:49:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ObjectArrayList<Block> getAllInnerBlocks() {
|
|
|
|
ObjectArrayList<Block> output = containerNumber.getContent();
|
|
|
|
// output.addAll();
|
|
|
|
return output;
|
|
|
|
}
|
2017-03-26 22:44:09 +02:00
|
|
|
}
|