use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class ControlledBuffer method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Direction face = painter.getAttributeValue(StdAttr.FACING);
Graphics g = painter.getGraphics();
// draw control wire
GraphicsUtil.switchToWidth(g, 3);
Location pt0 = painter.getInstance().getPortLocation(2);
Location pt1;
if (painter.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
pt1 = pt0.translate(face, 0, 6);
} else {
pt1 = pt0.translate(face, 0, -6);
}
if (painter.getShowState()) {
g.setColor(painter.getPortValue(2).getColor());
}
g.drawLine(pt0.getX(), pt0.getY(), pt1.getX(), pt1.getY());
// draw triangle
g.setColor(Color.BLACK);
paintShape(painter);
// draw input and output pins
if (!painter.isPrintView()) {
painter.drawPort(0);
painter.drawPort(1);
}
painter.drawLabel();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class ControlledBuffer method configurePorts.
private void configurePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Bounds bds = getOffsetBounds(instance.getAttributeSet());
int d = Math.max(bds.getWidth(), bds.getHeight()) - 20;
Location loc0 = Location.create(0, 0);
Location loc1 = loc0.translate(facing.reverse(), 20 + d);
Location loc2;
if (instance.getAttributeValue(ATTR_CONTROL) == LEFT_HANDED) {
loc2 = loc0.translate(facing.reverse(), 10 + d, 10);
} else {
loc2 = loc0.translate(facing.reverse(), 10 + d, -10);
}
Port[] ports = new Port[3];
ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
ports[1] = new Port(loc1.getX(), loc1.getY(), Port.INPUT, StdAttr.WIDTH);
ports[2] = new Port(loc2.getX(), loc2.getY(), Port.INPUT, 1);
instance.setPorts(ports);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class ControlledBuffer method paintShape.
private void paintShape(InstancePainter painter) {
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
double rotate = 0.0;
Graphics g = painter.getGraphics();
g.translate(x, y);
if (facing != Direction.EAST && g instanceof Graphics2D) {
rotate = -facing.toRadians();
((Graphics2D) g).rotate(rotate);
}
if (isInverter) {
PainterShaped.paintNot(painter);
} else {
GraphicsUtil.switchToWidth(g, 2);
int d = isInverter ? 10 : 0;
int[] xp = new int[] { -d, -19 - d, -19 - d, -d };
int[] yp = new int[] { 0, -7, 7, 0 };
g.drawPolyline(xp, yp, 4);
// if (isInverter) g.drawOval(-9, -4, 9, 9);
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
g.translate(-x, -y);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class GateAttributeList method get.
@Override
public Attribute<?> get(int index) {
int len = BASE_ATTRIBUTES.length;
if (index < len) {
return BASE_ATTRIBUTES[index];
}
index -= len;
if (attrs.xorBehave != null) {
index--;
if (index < 0)
return GateAttributes.ATTR_XOR;
}
Direction facing = attrs.facing;
int inputs = attrs.inputs;
if (index == 0) {
if (facing == Direction.EAST || facing == Direction.WEST) {
return new NegateAttribute(index, Direction.NORTH);
} else {
return new NegateAttribute(index, Direction.WEST);
}
} else if (index == inputs - 1) {
if (facing == Direction.EAST || facing == Direction.WEST) {
return new NegateAttribute(index, Direction.SOUTH);
} else {
return new NegateAttribute(index, Direction.EAST);
}
} else if (index < inputs) {
return new NegateAttribute(index, null);
}
return null;
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class PortIO 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);
}
Aggregations