use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Decoder method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
Object selectLoc = attrs.getValue(Plexers.ATTR_SELECT_LOC);
BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
int outputs = 1 << select.getWidth();
Bounds bds;
boolean reversed = facing == Direction.WEST || facing == Direction.NORTH;
if (selectLoc == Plexers.SELECT_TOP_RIGHT)
reversed = !reversed;
if (outputs == 2) {
int y = reversed ? 0 : -40;
bds = Bounds.create(-20, y - 5, 30, 40 + 10);
} else {
int x = -20;
int y = reversed ? -10 : -(outputs * 10 + 10);
bds = Bounds.create(x, y, 40, outputs * 10 + 20);
}
return bds.rotate(Direction.EAST, facing, 0, 0);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Decoder method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Graphics g = painter.getGraphics();
Bounds bds = painter.getBounds();
Direction facing = painter.getAttributeValue(StdAttr.FACING);
Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
int selMult = selectLoc == Plexers.SELECT_TOP_RIGHT ? -1 : 1;
int outputs = 1 << select.getWidth();
// draw stubs for select and enable ports
GraphicsUtil.switchToWidth(g, 3);
boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
int dx = vertical ? selMult : 0;
int dy = vertical ? 0 : -selMult;
if (outputs == 2) {
// draw select wire
if (painter.getShowState()) {
g.setColor(painter.getPortValue(outputs).getColor());
}
Location pt = painter.getInstance().getPortLocation(outputs);
g.drawLine(pt.getX(), pt.getY(), pt.getX() + 2 * dx, pt.getY() + 2 * dy);
}
if (enable) {
Location en = painter.getInstance().getPortLocation(outputs + 1);
int len = outputs == 2 ? 6 : 4;
if (painter.getShowState()) {
g.setColor(painter.getPortValue(outputs + 1).getColor());
}
g.drawLine(en.getX(), en.getY(), en.getX() + len * dx, en.getY() + len * dy);
}
GraphicsUtil.switchToWidth(g, 1);
// draw a circle indicating where the select input is located
Multiplexer.drawSelectCircle(g, bds, painter.getInstance().getPortLocation(outputs));
// draw "0"
int x0;
int y0;
int halign;
if (facing == Direction.WEST) {
x0 = 3;
y0 = 15 + (outputs == 2 ? 5 : 0);
halign = GraphicsUtil.H_LEFT;
} else if (facing == Direction.NORTH) {
x0 = 10 + (outputs == 2 ? 5 : 0);
y0 = 15;
halign = GraphicsUtil.H_CENTER;
} else if (facing == Direction.SOUTH) {
x0 = 10 + (outputs == 2 ? 5 : 0);
y0 = bds.getHeight() - 3;
halign = GraphicsUtil.H_CENTER;
} else {
x0 = bds.getWidth() - 3;
y0 = 15 + (outputs == 2 ? 5 : 0);
halign = GraphicsUtil.H_RIGHT;
}
g.setColor(Color.GRAY);
GraphicsUtil.drawText(g, "0", bds.getX() + x0, bds.getY() + y0, halign, GraphicsUtil.V_BASELINE);
// draw trapezoid, "Decd", and ports
g.setColor(Color.BLACK);
if (outputs == 2) {
if (facing == Direction.EAST || facing == Direction.WEST) {
Plexers.drawTrapezoid(g, Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
} else {
Plexers.drawTrapezoid(g, Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
}
} else {
Plexers.drawTrapezoid(g, bds, facing.reverse(), 20);
}
GraphicsUtil.drawCenteredText(g, "Decd", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
painter.drawPorts();
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Clock method configureLabel.
//
// private methods
//
private void configureLabel(Instance instance) {
Direction facing = instance.getAttributeValue(StdAttr.FACING);
Direction labelLoc = instance.getAttributeValue(Pin.ATTR_LABEL_LOC);
Probe.configureLabel(instance, labelLoc, facing);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Clock method paintIcon.
//
// graphics methods
//
@Override
public void paintIcon(InstancePainter painter) {
Graphics g = painter.getGraphics();
if (toolIcon != null) {
toolIcon.paintIcon(painter.getDestination(), g, 2, 2);
} else {
g.drawRect(4, 4, 13, 13);
g.setColor(Value.FALSE.getColor());
g.drawPolyline(new int[] { 6, 6, 10, 10, 14, 14 }, new int[] { 10, 6, 6, 14, 14, 10 }, 6);
}
Direction dir = painter.getAttributeValue(StdAttr.FACING);
int pinx = 15;
int piny = 8;
if (dir == Direction.EAST) {
// keep defaults
} else if (dir == Direction.WEST) {
pinx = 3;
} else if (dir == Direction.NORTH) {
pinx = 8;
piny = 3;
} else if (dir == Direction.SOUTH) {
pinx = 8;
piny = 15;
}
g.setColor(Value.TRUE.getColor());
g.fillOval(pinx, piny, 3, 3);
}
use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.
the class Constant method getOffsetBounds.
@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
Direction facing = attrs.getValue(StdAttr.FACING);
BitWidth width = attrs.getValue(StdAttr.WIDTH);
int chars = (width.getWidth() + 3) / 4;
Bounds ret = null;
if (facing == Direction.EAST) {
switch(chars) {
case 1:
ret = Bounds.create(-16, -8, 16, 16);
break;
case 2:
ret = Bounds.create(-16, -8, 16, 16);
break;
case 3:
ret = Bounds.create(-26, -8, 26, 16);
break;
case 4:
ret = Bounds.create(-36, -8, 36, 16);
break;
case 5:
ret = Bounds.create(-46, -8, 46, 16);
break;
case 6:
ret = Bounds.create(-56, -8, 56, 16);
break;
case 7:
ret = Bounds.create(-66, -8, 66, 16);
break;
case 8:
ret = Bounds.create(-76, -8, 76, 16);
break;
}
} else if (facing == Direction.WEST) {
switch(chars) {
case 1:
ret = Bounds.create(0, -8, 16, 16);
break;
case 2:
ret = Bounds.create(0, -8, 16, 16);
break;
case 3:
ret = Bounds.create(0, -8, 26, 16);
break;
case 4:
ret = Bounds.create(0, -8, 36, 16);
break;
case 5:
ret = Bounds.create(0, -8, 46, 16);
break;
case 6:
ret = Bounds.create(0, -8, 56, 16);
break;
case 7:
ret = Bounds.create(0, -8, 66, 16);
break;
case 8:
ret = Bounds.create(0, -8, 76, 16);
break;
}
} else if (facing == Direction.SOUTH) {
switch(chars) {
case 1:
ret = Bounds.create(-8, -16, 16, 16);
break;
case 2:
ret = Bounds.create(-8, -16, 16, 16);
break;
case 3:
ret = Bounds.create(-13, -16, 26, 16);
break;
case 4:
ret = Bounds.create(-18, -16, 36, 16);
break;
case 5:
ret = Bounds.create(-23, -16, 46, 16);
break;
case 6:
ret = Bounds.create(-28, -16, 56, 16);
break;
case 7:
ret = Bounds.create(-33, -16, 66, 16);
break;
case 8:
ret = Bounds.create(-38, -16, 76, 16);
break;
}
} else if (facing == Direction.NORTH) {
switch(chars) {
case 1:
ret = Bounds.create(-8, 0, 16, 16);
break;
case 2:
ret = Bounds.create(-8, 0, 16, 16);
break;
case 3:
ret = Bounds.create(-13, 0, 26, 16);
break;
case 4:
ret = Bounds.create(-18, 0, 36, 16);
break;
case 5:
ret = Bounds.create(-23, 0, 46, 16);
break;
case 6:
ret = Bounds.create(-28, 0, 56, 16);
break;
case 7:
ret = Bounds.create(-33, 0, 66, 16);
break;
case 8:
ret = Bounds.create(-38, 0, 76, 16);
break;
}
}
if (ret == null) {
throw new IllegalArgumentException("unrecognized arguments " + facing + " " + width);
}
return ret;
}
Aggregations