use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Button method computeTextField.
private void computeTextField(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Io.LABEL_CENTER) {
x = bds.getX() + (bds.getWidth() - DEPTH) / 2;
y = bds.getY() + (bds.getHeight() - DEPTH) / 2;
} else if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class DipSwitch method computeTextField.
private void computeTextField(Instance instance) {
Direction facing = Direction.NORTH;
Object labelLoc = instance.getAttributeValue(Io.ATTR_LABEL_LOC);
Bounds bds = instance.getBounds();
int x = bds.getX() + bds.getWidth() / 2;
int y = bds.getY() + bds.getHeight() / 2;
int halign = GraphicsUtil.H_CENTER;
int valign = GraphicsUtil.V_CENTER;
if (labelLoc == Direction.NORTH) {
y = bds.getY() - 2;
valign = GraphicsUtil.V_BOTTOM;
} else if (labelLoc == Direction.SOUTH) {
y = bds.getY() + bds.getHeight() + 2;
valign = GraphicsUtil.V_TOP;
} else if (labelLoc == Direction.EAST) {
x = bds.getX() + bds.getWidth() + 2;
halign = GraphicsUtil.H_LEFT;
} else if (labelLoc == Direction.WEST) {
x = bds.getX() - 2;
halign = GraphicsUtil.H_RIGHT;
}
if (labelLoc == facing) {
if (labelLoc == Direction.NORTH || labelLoc == Direction.SOUTH) {
x += 2;
halign = GraphicsUtil.H_LEFT;
} else {
y -= 2;
valign = GraphicsUtil.V_BOTTOM;
}
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
use of com.cburch.logisim.data.Direction 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.Direction 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.Direction in project logisim-evolution by reds-heig.
the class SubcircuitFactory method computePorts.
void computePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Map<Location, Instance> portLocs = source.getAppearance().getPortOffsets(facing);
Port[] ports = new Port[portLocs.size()];
Instance[] pins = new Instance[portLocs.size()];
int i = -1;
for (Map.Entry<Location, Instance> portLoc : portLocs.entrySet()) {
i++;
Location loc = portLoc.getKey();
Instance pin = portLoc.getValue();
String type = Pin.FACTORY.isInputPin(pin) ? Port.INPUT : Port.OUTPUT;
BitWidth width = pin.getAttributeValue(StdAttr.WIDTH);
ports[i] = new Port(loc.getX(), loc.getY(), type, width);
pins[i] = pin;
String label = pin.getAttributeValue(StdAttr.LABEL);
if (label != null && label.length() > 0) {
ports[i].setToolTip(StringUtil.constantGetter(label));
}
}
CircuitAttributes attrs = (CircuitAttributes) instance.getAttributeSet();
attrs.setPinInstances(pins);
instance.setPorts(ports);
instance.recomputeBounds();
// since this affects the circuit's bounds
configureLabel(instance);
}
Aggregations