2018-09-02 13:36:49 +02:00
|
|
|
package it.cavallium.warppi.gui.expression.blocks;
|
|
|
|
|
2019-02-27 23:29:03 +01:00
|
|
|
import it.cavallium.warppi.device.display.DisplayOutputDevice;
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.expression.Caret;
|
2018-10-04 23:39:19 +02:00
|
|
|
import it.cavallium.warppi.gui.expression.InputContext;
|
2018-09-02 13:36:49 +02:00
|
|
|
import it.cavallium.warppi.gui.graphicengine.Renderer;
|
|
|
|
import it.cavallium.warppi.math.MathContext;
|
|
|
|
import it.cavallium.warppi.math.parser.features.interfaces.Feature;
|
2018-09-12 22:16:33 +02:00
|
|
|
import it.cavallium.warppi.util.Error;
|
2017-11-01 22:34:35 +01:00
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
|
|
|
|
2018-09-22 14:10:36 +02:00
|
|
|
public abstract class BlockParenthesisAbstract extends Block implements IParenthesis {
|
2017-06-25 00:23:49 +02:00
|
|
|
|
|
|
|
private final BlockContainer containerNumber;
|
|
|
|
|
|
|
|
private final String prefix;
|
2023-08-23 16:47:55 +02:00
|
|
|
private final ObjectArrayList<BlockContainer> innerContainers;
|
2017-06-25 00:23:49 +02:00
|
|
|
private int prw;
|
|
|
|
private int chw;
|
|
|
|
private int chh;
|
|
|
|
|
2018-09-22 11:17:30 +02:00
|
|
|
protected BlockParenthesisAbstract(final String prefix) {
|
2018-09-22 14:10:36 +02:00
|
|
|
containerNumber = new BlockContainer(this, false);
|
2017-06-25 00:23:49 +02:00
|
|
|
this.prefix = prefix;
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-06-25 00:23:49 +02:00
|
|
|
recomputeDimensions();
|
2023-08-23 16:47:55 +02:00
|
|
|
|
|
|
|
innerContainers = new ObjectArrayList<>(1);
|
|
|
|
innerContainers.add(containerNumber);
|
2017-06-25 00:23:49 +02:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
|
2017-06-25 00:23:49 +02:00
|
|
|
public BlockParenthesisAbstract() {
|
2018-09-22 14:10:36 +02:00
|
|
|
containerNumber = new BlockContainer(this, false);
|
2018-05-12 21:18:29 +02:00
|
|
|
prefix = null;
|
2017-06-25 00:23:49 +02:00
|
|
|
recomputeDimensions();
|
2023-08-23 16:47:55 +02:00
|
|
|
|
|
|
|
innerContainers = new ObjectArrayList<>(1);
|
|
|
|
innerContainers.add(containerNumber);
|
2017-11-01 22:34:35 +01:00
|
|
|
}
|
|
|
|
|
2018-10-09 23:51:42 +02:00
|
|
|
/**
|
|
|
|
* Copy
|
|
|
|
* @param old
|
|
|
|
* @param ic
|
|
|
|
*/
|
2023-08-23 16:47:55 +02:00
|
|
|
BlockParenthesisAbstract(final BlockContainer parent, BlockParenthesisAbstract old, InputContext ic) {
|
2018-10-09 23:51:42 +02:00
|
|
|
super(parent, old);
|
|
|
|
containerNumber = old.containerNumber.clone(this, ic);
|
|
|
|
prefix = old.prefix;
|
|
|
|
prw = old.prw;
|
|
|
|
chw = old.chw;
|
|
|
|
chh = old.chh;
|
2023-08-23 16:47:55 +02:00
|
|
|
|
|
|
|
innerContainers = new ObjectArrayList<>(1);
|
|
|
|
innerContainers.add(containerNumber);
|
2018-10-04 23:39:19 +02:00
|
|
|
}
|
|
|
|
|
2018-09-22 11:17:30 +02:00
|
|
|
public BlockParenthesisAbstract(final ObjectArrayList<Block> blocks) {
|
2018-09-22 14:10:36 +02:00
|
|
|
containerNumber = new BlockContainer(this, false, blocks);
|
2018-05-12 21:18:29 +02:00
|
|
|
prefix = null;
|
2017-11-01 22:34:35 +01:00
|
|
|
recomputeDimensions();
|
2023-08-23 16:47:55 +02:00
|
|
|
|
|
|
|
innerContainers = new ObjectArrayList<>(1);
|
|
|
|
innerContainers.add(containerNumber);
|
2017-06-25 00:23:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-02-27 23:29:03 +01:00
|
|
|
public void draw(final DisplayOutputDevice ge, final Renderer r, final int x, final int y, final Caret caret) {
|
2017-06-25 00:23:49 +02:00
|
|
|
BlockContainer.getDefaultFont(small).use(ge);
|
|
|
|
r.glColor(BlockContainer.getDefaultColor());
|
2018-09-28 11:39:28 +02:00
|
|
|
if (prefix != null) {
|
2023-08-23 12:04:27 +02:00
|
|
|
r.glDrawStringLeft(x + 1, y + line - chh / 2f, prefix);
|
2018-09-28 11:39:28 +02:00
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
r.glDrawCharLeft(x + prw, y, 'â•');
|
|
|
|
r.glDrawCharLeft(x + prw, y + height - chh, 'â•°');
|
2017-11-19 12:55:48 +01:00
|
|
|
if (small) {
|
|
|
|
r.glFillColor(x + prw + 1, y + 5, 1, height - 4 * 2);
|
|
|
|
r.glFillColor(x + width - 3, y + 5, 1, height - 4 * 2);
|
|
|
|
} else {
|
|
|
|
r.glFillColor(x + prw + 3, y + 6, 2, height - 6 * 2);
|
|
|
|
r.glFillColor(x + width - 5, y + 6, 2, height - 6 * 2);
|
|
|
|
}
|
2017-09-24 18:47:30 +02:00
|
|
|
r.glDrawCharLeft(x + width - chw, y, 'â•®');
|
|
|
|
r.glDrawCharLeft(x + width - chw, y + height - chh, '╯');
|
|
|
|
containerNumber.draw(ge, r, x + prw + chw, y, caret);
|
2017-06-25 00:23:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-08-23 16:47:55 +02:00
|
|
|
public boolean appendBlock(final Caret caret, final Block newBlock) {
|
2017-06-25 00:23:49 +02:00
|
|
|
boolean added = false;
|
2023-08-23 16:47:55 +02:00
|
|
|
added = added | containerNumber.appendBlock(caret, newBlock);
|
2018-09-28 11:39:28 +02:00
|
|
|
if (added) {
|
2017-06-25 00:23:49 +02:00
|
|
|
recomputeDimensions();
|
2018-09-28 11:39:28 +02:00
|
|
|
}
|
2017-06-25 00:23:49 +02:00
|
|
|
return added;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void recomputeDimensions() {
|
2018-09-28 11:39:28 +02:00
|
|
|
if (prefix == null) {
|
2017-09-24 18:47:30 +02:00
|
|
|
prw = 0;
|
2018-09-28 11:39:28 +02:00
|
|
|
} else {
|
2017-09-24 18:47:30 +02:00
|
|
|
prw = 1 + BlockContainer.getDefaultCharWidth(small) * prefix.length() + 2;
|
2018-09-28 11:39:28 +02:00
|
|
|
}
|
2017-06-25 00:23:49 +02:00
|
|
|
chw = BlockContainer.getDefaultCharWidth(small);
|
|
|
|
chh = BlockContainer.getDefaultCharHeight(small);
|
|
|
|
width = prw + chw + containerNumber.getWidth() + chw + 3;
|
|
|
|
height = containerNumber.getHeight();
|
|
|
|
line = containerNumber.getLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-22 11:17:30 +02:00
|
|
|
public void setSmall(final boolean small) {
|
2017-06-25 00:23:49 +02:00
|
|
|
this.small = small;
|
|
|
|
containerNumber.setSmall(small);
|
|
|
|
recomputeDimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockContainer getNumberContainer() {
|
|
|
|
return containerNumber;
|
|
|
|
}
|
|
|
|
|
2018-03-26 09:04:09 +02:00
|
|
|
@Override
|
2017-06-25 00:23:49 +02:00
|
|
|
public abstract Feature toFeature(MathContext context) throws Error;
|
|
|
|
|
2018-10-04 08:49:11 +02:00
|
|
|
|
|
|
|
@Override
|
2018-10-04 09:52:14 +02:00
|
|
|
public ObjectArrayList<Block> getInnerBlocks() {
|
2018-10-04 08:49:11 +02:00
|
|
|
return containerNumber.getContent();
|
|
|
|
}
|
2018-10-04 09:52:14 +02:00
|
|
|
|
2018-10-05 22:09:54 +02:00
|
|
|
|
2018-10-04 09:52:14 +02:00
|
|
|
@Override
|
2018-10-05 22:09:54 +02:00
|
|
|
public ObjectArrayList<BlockContainer> getInnerContainers() {
|
2023-08-23 16:47:55 +02:00
|
|
|
return innerContainers;
|
2018-10-04 09:52:14 +02:00
|
|
|
}
|
2018-10-04 08:49:11 +02:00
|
|
|
|
2017-06-25 00:23:49 +02:00
|
|
|
}
|