Search in sources :

Example 81 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class RGBLed method computeTextField.

private void computeTextField(Instance instance) {
    Direction facing = Direction.WEST;
    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);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 82 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class SevenSegment method computeTextField.

private void computeTextField(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    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);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 83 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class Demultiplexer method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    BitWidth select = attrs.getValue(Plexers.ATTR_SELECT);
    int outputs = 1 << select.getWidth();
    Bounds bds;
    if (outputs == 2) {
        bds = Bounds.create(0, -25, 30, 50);
    } else {
        bds = Bounds.create(0, -(outputs / 2) * 10 - 10, 40, outputs * 10 + 20);
    }
    return bds.rotate(Direction.EAST, facing, 0, 0);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 84 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class Demultiplexer method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    boolean enable = painter.getAttributeValue(Plexers.ATTR_ENABLE).booleanValue();
    int outputs = 1 << select.getWidth();
    // draw select and enable inputs
    GraphicsUtil.switchToWidth(g, 3);
    boolean vertical = facing == Direction.NORTH || facing == Direction.SOUTH;
    Object selectLoc = painter.getAttributeValue(Plexers.ATTR_SELECT_LOC);
    int selMult = selectLoc == Plexers.SELECT_BOTTOM_LEFT ? 1 : -1;
    int dx = vertical ? selMult : 0;
    int dy = vertical ? 0 : -selMult;
    if (outputs == 2) {
        // draw select wire
        Location sel = painter.getInstance().getPortLocation(outputs);
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs).getColor());
        }
        g.drawLine(sel.getX(), sel.getY(), sel.getX() + 2 * dx, sel.getY() + 2 * dy);
    }
    if (enable) {
        Location en = painter.getInstance().getPortLocation(outputs + 1);
        if (painter.getShowState()) {
            g.setColor(painter.getPortValue(outputs + 1).getColor());
        }
        int len = outputs == 2 ? 6 : 4;
        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" next to first input
    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, "DMX" label, 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, "DMX", bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 85 with Direction

use of com.cburch.logisim.data.Direction in project logisim-evolution by reds-heig.

the class Demultiplexer method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    BitWidth select = painter.getAttributeValue(Plexers.ATTR_SELECT);
    Bounds bds = painter.getBounds();
    if (select.getWidth() == 1) {
        if (facing == Direction.EAST || facing == Direction.WEST) {
            Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX(), bds.getY() + 5, bds.getWidth(), bds.getHeight() - 10), facing.reverse(), 10);
        } else {
            Plexers.drawTrapezoid(painter.getGraphics(), Bounds.create(bds.getX() + 5, bds.getY(), bds.getWidth() - 10, bds.getHeight()), facing.reverse(), 10);
        }
    } else {
        Plexers.drawTrapezoid(painter.getGraphics(), bds, facing.reverse(), 20);
    }
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) 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