use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Constant method paintIcon.
//
// painting methods
//
@Override
public void paintIcon(InstancePainter painter) {
int w = painter.getAttributeValue(StdAttr.WIDTH).getWidth();
int pinx = 16;
int piny = 9;
Direction dir = painter.getAttributeValue(StdAttr.FACING);
if (dir == Direction.EAST) {
} else // keep defaults
if (dir == Direction.WEST) {
pinx = 4;
} else if (dir == Direction.NORTH) {
pinx = 9;
piny = 4;
} else if (dir == Direction.SOUTH) {
pinx = 9;
piny = 16;
}
Graphics g = painter.getGraphics();
if (w == 1) {
int v = painter.getAttributeValue(ATTR_VALUE).intValue();
Value val = v == 1 ? Value.TRUE : Value.FALSE;
g.setColor(val.getColor());
GraphicsUtil.drawCenteredText(g, "" + v, 10, 9);
} else {
g.setFont(g.getFont().deriveFont(9.0f));
GraphicsUtil.drawCenteredText(g, "x" + w, 10, 9);
}
g.fillOval(pinx, piny, 3, 3);
}
use of com.cburch.logisim.data.Direction 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.Direction in project logisim-evolution by reds-heig.
the class Transistor method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
Object gateLoc = attrs.getValue(Wiring.ATTR_GATE);
int delta = gateLoc == Wiring.GATE_TOP_LEFT ? -20 : 0;
if (facing == Direction.NORTH) {
return Bounds.create(delta, 0, 20, 40);
} else if (facing == Direction.SOUTH) {
return Bounds.create(delta, -40, 20, 40);
} else if (facing == Direction.WEST) {
return Bounds.create(0, delta, 40, 20);
} else {
// facing == Direction.EAST
return Bounds.create(-40, delta, 40, 20);
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class TransmissionGate method contains.
@Override
public boolean contains(Location loc, AttributeSet attrs) {
if (super.contains(loc, attrs)) {
Direction facing = attrs.getValue(StdAttr.FACING);
Location center = Location.create(0, 0).translate(facing, -20);
return center.manhattanDistanceTo(loc) < 24;
} else {
return false;
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class TransmissionGate method updatePorts.
private void updatePorts(Instance instance) {
int dx = 0;
int dy = 0;
Direction facing = instance.getAttributeValue(StdAttr.FACING);
if (facing == Direction.NORTH) {
dy = 1;
} else if (facing == Direction.EAST) {
dx = -1;
} else if (facing == Direction.SOUTH) {
dy = -1;
} else if (facing == Direction.WEST) {
dx = 1;
}
Object powerLoc = instance.getAttributeValue(Wiring.ATTR_GATE);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
Port[] ports = new Port[4];
ports[OUTPUT] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ports[INPUT] = new Port(40 * dx, 40 * dy, Port.INPUT, StdAttr.WIDTH);
if (flip) {
ports[GATE1] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
ports[GATE0] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
} else {
ports[GATE0] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
ports[GATE1] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
}
instance.setPorts(ports);
}
Aggregations