use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Constant method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Bounds bds = painter.getOffsetBounds();
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
int intValue = painter.getAttributeValue(ATTR_VALUE).intValue();
Value v = Value.createKnown(width, intValue);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
Graphics g = painter.getGraphics();
if (painter.shouldDrawColor()) {
g.setColor(BACKGROUND_COLOR);
g.fillRect(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
}
if (v.getWidth() == 1) {
if (painter.shouldDrawColor())
g.setColor(v.getColor());
GraphicsUtil.drawCenteredText(g, v.toString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2);
} else {
g.setColor(Color.BLACK);
GraphicsUtil.drawCenteredText(g, v.toHexString(), x + bds.getX() + bds.getWidth() / 2, y + bds.getY() + bds.getHeight() / 2 - 2);
}
painter.drawPorts();
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Constant method propagate.
@Override
public void propagate(InstanceState state) {
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
int value = state.getAttributeValue(ATTR_VALUE).intValue();
state.setPort(0, Value.createKnown(width, value), 1);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Ground method propagate.
@Override
public void propagate(InstanceState state) {
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
state.setPort(0, Value.repeat(Value.FALSE, width.getWidth()), 1);
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Ground method drawInstance.
private void drawInstance(InstancePainter painter, boolean isGhost) {
Graphics2D g = (Graphics2D) painter.getGraphics().create();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
Direction from = painter.getAttributeValue(StdAttr.FACING);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
g.rotate(radians);
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
if (!isGhost && painter.getShowState()) {
g.setColor(painter.getPortValue(0).getColor());
}
g.drawLine(0, 0, 5, 0);
GraphicsUtil.switchToWidth(g, 1);
if (!isGhost && painter.shouldDrawColor()) {
BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
g.setColor(Value.repeat(Value.FALSE, width.getWidth()).getColor());
}
g.drawLine(6, -8, 6, 8);
g.drawLine(9, -5, 9, 5);
g.drawLine(12, -2, 12, 2);
g.dispose();
}
use of com.cburch.logisim.data.BitWidth in project logisim-evolution by reds-heig.
the class Transistor method computeOutput.
private Value computeOutput(InstanceState state) {
BitWidth width = state.getAttributeValue(StdAttr.WIDTH);
Value gate = state.getPortValue(GATE);
Value input = state.getPortValue(INPUT);
Value desired = state.getAttributeValue(ATTR_TYPE) == TYPE_P ? Value.FALSE : Value.TRUE;
if (!gate.isFullyDefined()) {
if (input.isFullyDefined()) {
return Value.createError(width);
} else {
Value[] v = input.getAll();
for (int i = 0; i < v.length; i++) {
if (v[i] != Value.UNKNOWN) {
v[i] = Value.ERROR;
}
}
return Value.create(v);
}
} else if (gate != desired) {
return Value.createUnknown(width);
} else {
return input;
}
}
Aggregations