use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Transistor 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 Transistor method drawInstance.
private void drawInstance(InstancePainter painter, boolean isGhost) {
Object type = painter.getAttributeValue(ATTR_TYPE);
Object powerLoc = painter.getAttributeValue(Wiring.ATTR_GATE);
Direction from = painter.getAttributeValue(StdAttr.FACING);
Direction facing = painter.getAttributeValue(StdAttr.FACING);
boolean flip = (facing == Direction.SOUTH || facing == Direction.WEST) == (powerLoc == Wiring.GATE_TOP_LEFT);
int degrees = Direction.EAST.toDegrees() - from.toDegrees();
double radians = Math.toRadians((degrees + 360) % 360);
int m = flip ? 1 : -1;
Graphics2D g = (Graphics2D) painter.getGraphics();
Location loc = painter.getLocation();
g.translate(loc.getX(), loc.getY());
g.rotate(radians);
Color gate;
Color input;
Color output;
Color platform;
if (!isGhost && painter.getShowState()) {
gate = painter.getPortValue(GATE).getColor();
input = painter.getPortValue(INPUT).getColor();
output = painter.getPortValue(OUTPUT).getColor();
Value out = computeOutput(painter);
platform = out.isUnknown() ? Value.UNKNOWN.getColor() : out.getColor();
} else {
Color base = g.getColor();
gate = base;
input = base;
output = base;
platform = base;
}
// input and output lines
GraphicsUtil.switchToWidth(g, Wire.WIDTH);
g.setColor(output);
g.drawLine(0, 0, -11, 0);
g.drawLine(-11, m * 7, -11, 0);
g.setColor(input);
g.drawLine(-40, 0, -29, 0);
g.drawLine(-29, m * 7, -29, 0);
// gate line
g.setColor(gate);
if (type == TYPE_P) {
g.drawLine(-20, m * 20, -20, m * 15);
GraphicsUtil.switchToWidth(g, 1);
g.drawOval(-22, m * 12 - 2, 4, 4);
} else {
g.drawLine(-20, m * 20, -20, m * 11);
GraphicsUtil.switchToWidth(g, 1);
}
// draw platforms
// gate platform
g.drawLine(-10, m * 10, -30, m * 10);
g.setColor(platform);
// input/output platform
g.drawLine(-9, m * 8, -31, m * 8);
// arrow (same color as platform)
g.drawLine(-21, m * 6, -18, m * 3);
g.drawLine(-21, 0, -18, m * 3);
g.rotate(-radians);
g.translate(-loc.getX(), -loc.getY());
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Transistor method updatePorts.
private void updatePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
int dx = 0;
int dy = 0;
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[3];
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[GATE] = new Port(20 * (dx + dy), 20 * (-dx + dy), Port.INPUT, 1);
} else {
ports[GATE] = new Port(20 * (dx - dy), 20 * (dx + dy), Port.INPUT, 1);
}
instance.setPorts(ports);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Tunnel method paintGhost.
//
// graphics methods
//
@Override
public void paintGhost(InstancePainter painter) {
TunnelAttributes attrs = (TunnelAttributes) painter.getAttributeSet();
Direction facing = attrs.getFacing();
String label = attrs.getLabel();
Graphics g = painter.getGraphics();
g.setFont(attrs.getFont());
FontMetrics fm = g.getFontMetrics();
Bounds bds = computeBounds(attrs, fm.stringWidth(label), fm.getAscent() + fm.getDescent(), g, label);
if (attrs.setOffsetBounds(bds)) {
Instance instance = painter.getInstance();
if (instance != null)
instance.recomputeBounds();
}
int x0 = bds.getX();
int y0 = bds.getY();
int x1 = x0 + bds.getWidth();
int y1 = y0 + bds.getHeight();
int mw = ARROW_MAX_WIDTH / 2;
int[] xp;
int[] yp;
if (facing == Direction.NORTH) {
int yb = y0 + ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, 0, x1, x1, x0 };
yp = new int[] { yb, y0, yb, y1, y1 };
} else {
xp = new int[] { x0, -mw, 0, mw, x1, x1, x0 };
yp = new int[] { yb, yb, y0, yb, yb, y1, y1 };
}
} else if (facing == Direction.SOUTH) {
int yb = y1 - ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, x1, x1, 0, x0 };
yp = new int[] { y0, y0, yb, y1, yb };
} else {
xp = new int[] { x0, x1, x1, mw, 0, -mw, x0 };
yp = new int[] { y0, y0, yb, yb, y1, yb, yb };
}
} else if (facing == Direction.EAST) {
int xb = x1 - ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, xb, x1, xb, x0 };
yp = new int[] { y0, y0, 0, y1, y1 };
} else {
xp = new int[] { x0, xb, xb, x1, xb, xb, x0 };
yp = new int[] { y0, y0, -mw, 0, mw, y1, y1 };
}
} else {
int xb = x0 + ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { xb, x1, x1, xb, x0 };
yp = new int[] { y0, y0, y1, y1, 0 };
} else {
xp = new int[] { xb, x1, x1, xb, xb, x0, xb };
yp = new int[] { y0, y0, y1, y1, mw, 0, -mw };
}
}
GraphicsUtil.switchToWidth(g, 2);
g.drawPolygon(xp, yp, xp.length);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class TunnelAttributes method configureLabel.
private void configureLabel() {
Direction facing = this.facing;
int x;
int y;
int halign;
int valign;
int margin = Tunnel.ARROW_MARGIN;
if (facing == Direction.NORTH) {
x = 0;
y = margin;
halign = TextField.H_CENTER;
valign = TextField.V_TOP;
} else if (facing == Direction.SOUTH) {
x = 0;
y = -margin;
halign = TextField.H_CENTER;
valign = TextField.V_BOTTOM;
} else if (facing == Direction.EAST) {
x = -margin;
y = 0;
halign = TextField.H_RIGHT;
valign = TextField.V_CENTER_OVERALL;
} else {
x = margin;
y = 0;
halign = TextField.H_LEFT;
valign = TextField.V_CENTER_OVERALL;
}
labelX = x;
labelY = y;
labelHAlign = halign;
labelVAlign = valign;
}
Aggregations