Search in sources :

Example 21 with Bounds

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

the class BitSelector method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    Direction facing = attrs.getValue(StdAttr.FACING);
    Bounds base = Bounds.create(-30, -15, 30, 30);
    return base.rotate(Direction.EAST, facing, 0, 0);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 22 with Bounds

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

Example 23 with Bounds

use of com.cburch.logisim.data.Bounds 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();
}
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 24 with Bounds

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

Example 25 with Bounds

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

the class Random method configureNewInstance.

@Override
protected void configureNewInstance(Instance instance) {
    Bounds bds = instance.getBounds();
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, bds.getX() + bds.getWidth() / 2, bds.getY() - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Aggregations

Bounds (com.cburch.logisim.data.Bounds)133 Graphics (java.awt.Graphics)50 Direction (com.cburch.logisim.data.Direction)27 Location (com.cburch.logisim.data.Location)24 BitWidth (com.cburch.logisim.data.BitWidth)21 Component (com.cburch.logisim.comp.Component)11 Color (java.awt.Color)10 FontMetrics (java.awt.FontMetrics)10 Value (com.cburch.logisim.data.Value)7 Font (java.awt.Font)7 Circuit (com.cburch.logisim.circuit.Circuit)6 Port (com.cburch.logisim.instance.Port)6 Handle (com.cburch.draw.model.Handle)5 CanvasObject (com.cburch.draw.model.CanvasObject)4 Instance (com.cburch.logisim.instance.Instance)4 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)4 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)3 AttributeSet (com.cburch.logisim.data.AttributeSet)3 Project (com.cburch.logisim.proj.Project)3 Dimension (java.awt.Dimension)3