Search in sources :

Example 71 with Direction

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);
}
Also used : Graphics(java.awt.Graphics) Value(com.cburch.logisim.data.Value) Direction(com.cburch.logisim.data.Direction)

Example 72 with Direction

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();
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Direction(com.cburch.logisim.data.Direction) Graphics2D(java.awt.Graphics2D) Location(com.cburch.logisim.data.Location)

Example 73 with Direction

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);
    }
}
Also used : Direction(com.cburch.logisim.data.Direction)

Example 74 with Direction

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;
    }
}
Also used : Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 75 with Direction

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);
}
Also used : Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction)

Aggregations

Direction (com.cburch.logisim.data.Direction)89 Location (com.cburch.logisim.data.Location)39 Bounds (com.cburch.logisim.data.Bounds)27 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics (java.awt.Graphics)20 Graphics2D (java.awt.Graphics2D)13 Port (com.cburch.logisim.instance.Port)10 Instance (com.cburch.logisim.instance.Instance)9 ArrayList (java.util.ArrayList)7 CanvasObject (com.cburch.draw.model.CanvasObject)5 Color (java.awt.Color)5 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AttributeSet (com.cburch.logisim.data.AttributeSet)4 FontMetrics (java.awt.FontMetrics)4 List (java.util.List)4 Wire (com.cburch.logisim.circuit.Wire)3 Attribute (com.cburch.logisim.data.Attribute)3 Value (com.cburch.logisim.data.Value)3