Search in sources :

Example 6 with Direction

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

Example 7 with Direction

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

Example 8 with Direction

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

Example 9 with Direction

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

Example 10 with Direction

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;
}
Also used : 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