use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class NotGate method configurePorts.
private void configurePorts(Instance instance) {
Object size = instance.getAttributeValue(ATTR_SIZE);
Direction facing = instance.getAttributeValue(StdAttr.FACING);
int dx = size == SIZE_NARROW ? -20 : -30;
Port[] ports = new Port[2];
ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
Location out = Location.create(0, 0).translate(facing, dx);
ports[1] = new Port(out.getX(), out.getY(), Port.INPUT, StdAttr.WIDTH);
instance.setPorts(ports);
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PainterDin method paintOrLines.
private static void paintOrLines(InstancePainter painter, int width, int height, boolean hasBubble) {
GateAttributes baseAttrs = (GateAttributes) painter.getAttributeSet();
int inputs = baseAttrs.inputs;
GateAttributes attrs = (GateAttributes) OrGate.FACTORY.createAttributeSet();
attrs.inputs = inputs;
attrs.size = baseAttrs.size;
Graphics g = painter.getGraphics();
// draw state if appropriate
// ignore lines if in print view
int r = Math.min(height / 2, width);
Integer hash = Integer.valueOf(r << 4 | inputs);
int[] lens = orLenArrays.get(hash);
if (lens == null) {
lens = new int[inputs];
orLenArrays.put(hash, lens);
int yCurveStart = height / 2 - r;
for (int i = 0; i < inputs; i++) {
int y = OrGate.FACTORY.getInputOffset(attrs, i).getY();
if (y < 0)
y = -y;
if (y <= yCurveStart) {
lens[i] = r;
} else {
int dy = y - yCurveStart;
lens[i] = (int) (Math.sqrt(r * r - dy * dy) + 0.5);
}
}
}
AbstractGate factory = hasBubble ? NorGate.FACTORY : OrGate.FACTORY;
boolean printView = painter.isPrintView() && painter.getInstance() != null;
GraphicsUtil.switchToWidth(g, 2);
for (int i = 0; i < inputs; i++) {
if (!printView || painter.isPortConnected(i)) {
Location loc = factory.getInputOffset(attrs, i);
int x = loc.getX();
int y = loc.getY();
g.drawLine(x, y, x + lens[i], y);
}
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PainterShaped method getInputLineLengths.
private static int[] getInputLineLengths(GateAttributes attrs, AbstractGate factory) {
int inputs = attrs.inputs;
int mainHeight = ((Integer) attrs.size.getValue()).intValue();
Integer key = Integer.valueOf(inputs * 31 + mainHeight);
Object ret = INPUT_LENGTHS.get(key);
if (ret != null) {
return (int[]) ret;
}
Direction facing = attrs.facing;
if (facing != Direction.EAST) {
attrs = (GateAttributes) attrs.clone();
attrs.facing = Direction.EAST;
}
int[] lengths = new int[inputs];
INPUT_LENGTHS.put(key, lengths);
int width = mainHeight;
Location loc0 = OrGate.FACTORY.getInputOffset(attrs, 0);
Location locn = OrGate.FACTORY.getInputOffset(attrs, inputs - 1);
int totalHeight = 10 + loc0.manhattanDistanceTo(locn);
if (totalHeight < width)
totalHeight = width;
GeneralPath path = computeShield(width, totalHeight);
for (int i = 0; i < inputs; i++) {
Location loci = OrGate.FACTORY.getInputOffset(attrs, i);
Point2D p = new Point2D.Float(loci.getX() + 1, loci.getY());
int iters = 0;
while (path.contains(p) && iters < 15) {
iters++;
p.setLocation(p.getX() + 1, p.getY());
}
if (iters >= 15)
iters = 0;
lengths[i] = iters;
}
/*
* used prior to 2.5.1, when moved to GeneralPath int wingHeight =
* (totalHeight - mainHeight) / 2; double wingCenterX = wingHeight *
* Math.sqrt(3) / 2; double mainCenterX = mainHeight * Math.sqrt(3) / 2;
*
* for (int i = 0; i < inputs; i++) { Location loci =
* factory.getInputOffset(attrs, i); int disti = 5 +
* loc0.manhattanDistanceTo(loci); if (disti > totalHeight - disti) { //
* ensure on top half disti = totalHeight - disti; } double dx; if
* (disti < wingHeight) { // point is on wing int dy = wingHeight / 2 -
* disti; dx = Math.sqrt(wingHeight * wingHeight - dy * dy) -
* wingCenterX; } else { // point is on main shield int dy = totalHeight
* / 2 - disti; dx = Math.sqrt(mainHeight * mainHeight - dy * dy) -
* mainCenterX; } lengths[i] = (int) (dx - 0.5); }
*/
return lengths;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class BitAdder method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
painter.drawBounds();
painter.drawPorts();
GraphicsUtil.switchToWidth(g, 2);
Location loc = painter.getLocation();
int x = loc.getX() - 10;
int y = loc.getY();
g.drawLine(x - 2, y - 5, x - 2, y + 5);
g.drawLine(x + 2, y - 5, x + 2, y + 5);
g.drawLine(x - 5, y - 2, x + 5, y - 2);
g.drawLine(x - 5, y + 2, x + 5, y + 2);
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Shifter method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
painter.drawBounds();
painter.drawPorts();
Location loc = painter.getLocation();
int x = loc.getX() - 15;
int y = loc.getY();
Object shift = painter.getAttributeValue(ATTR_SHIFT);
g.setColor(Color.BLACK);
if (shift == SHIFT_LOGICAL_RIGHT) {
g.fillRect(x, y - 1, 8, 3);
drawArrow(g, x + 10, y, -4);
} else if (shift == SHIFT_ARITHMETIC_RIGHT) {
g.fillRect(x, y - 1, 2, 3);
g.fillRect(x + 3, y - 1, 5, 3);
drawArrow(g, x + 10, y, -4);
} else if (shift == SHIFT_ROLL_RIGHT) {
g.fillRect(x, y - 1, 5, 3);
g.fillRect(x + 8, y - 7, 2, 8);
g.fillRect(x, y - 7, 2, 8);
g.fillRect(x, y - 7, 10, 2);
drawArrow(g, x + 8, y, -4);
} else if (shift == SHIFT_ROLL_LEFT) {
g.fillRect(x + 6, y - 1, 4, 3);
g.fillRect(x + 8, y - 7, 2, 8);
g.fillRect(x, y - 7, 2, 8);
g.fillRect(x, y - 7, 10, 2);
drawArrow(g, x + 3, y, 4);
} else {
// SHIFT_LOGICAL_LEFT
g.fillRect(x + 2, y - 1, 8, 3);
drawArrow(g, x, y, 4);
}
}
Aggregations