use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AbstractGate method computeLabel.
private void computeLabel(Instance instance) {
GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
Direction facing = attrs.facing;
int baseWidth = ((Integer) attrs.size.getValue()).intValue();
int axis = baseWidth / 2 + (negateOutput ? 10 : 0);
int perp = 0;
if (AppPreferences.GATE_SHAPE.get().equals(AppPreferences.SHAPE_RECTANGULAR)) {
perp += 6;
}
Location loc = instance.getLocation();
int cx;
int cy;
if (facing == Direction.NORTH) {
cx = loc.getX() + perp;
cy = loc.getY() + axis;
} else if (facing == Direction.SOUTH) {
cx = loc.getX() - perp;
cy = loc.getY() - axis;
} else if (facing == Direction.WEST) {
cx = loc.getX() + axis;
cy = loc.getY() - perp;
} else {
cx = loc.getX() - axis;
cy = loc.getY() + perp;
}
instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, cx, cy, TextField.H_CENTER, TextField.V_CENTER);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class AbstractGate method getInputOffset.
Location getInputOffset(GateAttributes attrs, int index) {
int inputs = attrs.inputs;
Direction facing = attrs.facing;
int size = ((Integer) attrs.size.getValue()).intValue();
int axisLength = size + bonusWidth + (negateOutput ? 10 : 0);
int negated = attrs.negated;
int skipStart;
int skipDist;
int skipLowerEven = 10;
if (inputs <= 3) {
if (size < 40) {
skipStart = -5;
skipDist = 10;
skipLowerEven = 10;
} else if (size < 60 || inputs <= 2) {
skipStart = -10;
skipDist = 20;
skipLowerEven = 20;
} else {
skipStart = -15;
skipDist = 30;
skipLowerEven = 30;
}
} else if (inputs == 4 && size >= 60) {
skipStart = -5;
skipDist = 20;
skipLowerEven = 0;
} else {
skipStart = -5;
skipDist = 10;
skipLowerEven = 10;
}
int dy;
if ((inputs & 1) == 1) {
dy = skipStart * (inputs - 1) + skipDist * index;
} else {
dy = skipStart * inputs + skipDist * index;
if (index >= inputs / 2)
dy += skipLowerEven;
}
int dx = axisLength;
int negatedBit = (negated >> index) & 1;
if (negatedBit == 1) {
dx += 10;
}
if (facing == Direction.NORTH) {
return Location.create(dy, dx);
} else if (facing == Direction.SOUTH) {
return Location.create(dy, -dx);
} else if (facing == Direction.WEST) {
return Location.create(dx, dy);
} else {
return Location.create(-dx, dy);
}
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Buffer method configurePorts.
private void configurePorts(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Port[] ports = new Port[2];
ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
Location out = Location.create(0, 0).translate(facing, -20);
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 ControlledBuffer method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
int w = 20;
if (isInverter && !NotGate.SIZE_NARROW.equals(attrs.getValue(NotGate.ATTR_SIZE))) {
w = 30;
}
Direction facing = attrs.getValue(StdAttr.FACING);
if (facing == Direction.NORTH)
return Bounds.create(-10, 0, 20, w);
if (facing == Direction.SOUTH)
return Bounds.create(-10, -w, 20, w);
if (facing == Direction.WEST)
return Bounds.create(0, -10, w, 20);
return Bounds.create(-w, -10, w, 20);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class NotGate method paintBase.
private void paintBase(InstancePainter painter) {
Graphics g = painter.getGraphics();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
g.translate(x, y);
double rotate = 0.0;
if (facing != null && facing != Direction.EAST && g instanceof Graphics2D) {
rotate = -facing.toRadians();
((Graphics2D) g).rotate(rotate);
}
Object shape = painter.getGateShape();
if (shape == AppPreferences.SHAPE_RECTANGULAR) {
paintRectangularBase(g, painter);
} else if (shape == AppPreferences.SHAPE_DIN40700) {
int width = painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW ? 20 : 30;
PainterDin.paintAnd(painter, width, 18, true);
} else {
PainterShaped.paintNot(painter);
}
if (rotate != 0.0) {
((Graphics2D) g).rotate(-rotate);
}
g.translate(-x, -y);
}
Aggregations