Search in sources :

Example 66 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 67 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)

Example 68 with Bounds

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

the class Random method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    StateData state = (StateData) painter.getData();
    int val = state == null ? 0 : state.value;
    BitWidth widthVal = painter.getAttributeValue(StdAttr.WIDTH);
    int width = widthVal == null ? 8 : widthVal.getWidth();
    painter.drawLabel();
    DrawControl(painter, x, y, width);
    DrawData(painter, x, y + 70, width, val);
}
Also used : BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds)

Example 69 with Bounds

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

the class Probe method configureLabel.

static void configureLabel(Instance instance, Direction labelLoc, Direction facing) {
    Bounds bds = instance.getBounds();
    int x;
    int y;
    int halign;
    int valign;
    if (labelLoc == Direction.NORTH) {
        halign = TextField.H_CENTER;
        valign = TextField.V_BOTTOM;
        x = bds.getX() + bds.getWidth() / 2;
        y = bds.getY() - 2;
        if (facing == labelLoc) {
            halign = TextField.H_LEFT;
            x += 2;
        }
    } else if (labelLoc == Direction.SOUTH) {
        halign = TextField.H_CENTER;
        valign = TextField.V_TOP;
        x = bds.getX() + bds.getWidth() / 2;
        y = bds.getY() + bds.getHeight() + 2;
        if (facing == labelLoc) {
            halign = TextField.H_LEFT;
            x += 2;
        }
    } else if (labelLoc == Direction.EAST) {
        halign = TextField.H_LEFT;
        valign = TextField.V_CENTER;
        x = bds.getX() + bds.getWidth() + 2;
        y = bds.getY() + bds.getHeight() / 2;
        if (facing == labelLoc) {
            valign = TextField.V_BOTTOM;
            y -= 2;
        }
    } else {
        // WEST
        halign = TextField.H_RIGHT;
        valign = TextField.V_CENTER;
        x = bds.getX() - 2;
        y = bds.getY() + bds.getHeight() / 2;
        if (facing == labelLoc) {
            valign = TextField.V_BOTTOM;
            y -= 2;
        }
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, x, y, halign, valign);
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Example 70 with Bounds

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

the class Probe method getOffsetBounds.

// 
// static methods
// 
static Bounds getOffsetBounds(Direction dir, BitWidth width, RadixOption radix) {
    Bounds ret = null;
    int len = radix == null || radix == RadixOption.RADIX_2 ? width.getWidth() : radix.getMaxLength(width);
    if (dir == Direction.EAST) {
        switch(len) {
            case 0:
            case 1:
                ret = Bounds.create(-20, -10, 20, 20);
                break;
            case 2:
                ret = Bounds.create(-20, -10, 20, 20);
                break;
            case 3:
                ret = Bounds.create(-30, -10, 30, 20);
                break;
            case 4:
                ret = Bounds.create(-40, -10, 40, 20);
                break;
            case 5:
                ret = Bounds.create(-50, -10, 50, 20);
                break;
            case 6:
                ret = Bounds.create(-60, -10, 60, 20);
                break;
            case 7:
                ret = Bounds.create(-70, -10, 70, 20);
                break;
            case 8:
                ret = Bounds.create(-80, -10, 80, 20);
                break;
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                ret = Bounds.create(-80, -20, 80, 40);
                break;
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                ret = Bounds.create(-80, -30, 80, 60);
                break;
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
                ret = Bounds.create(-80, -40, 80, 80);
                break;
        }
    } else if (dir == Direction.WEST) {
        switch(len) {
            case 0:
            case 1:
                ret = Bounds.create(0, -10, 20, 20);
                break;
            case 2:
                ret = Bounds.create(0, -10, 20, 20);
                break;
            case 3:
                ret = Bounds.create(0, -10, 30, 20);
                break;
            case 4:
                ret = Bounds.create(0, -10, 40, 20);
                break;
            case 5:
                ret = Bounds.create(0, -10, 50, 20);
                break;
            case 6:
                ret = Bounds.create(0, -10, 60, 20);
                break;
            case 7:
                ret = Bounds.create(0, -10, 70, 20);
                break;
            case 8:
                ret = Bounds.create(0, -10, 80, 20);
                break;
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                ret = Bounds.create(0, -20, 80, 40);
                break;
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                ret = Bounds.create(0, -30, 80, 60);
                break;
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
                ret = Bounds.create(0, -40, 80, 80);
                break;
        }
    } else if (dir == Direction.SOUTH) {
        switch(len) {
            case 0:
            case 1:
                ret = Bounds.create(-10, -20, 20, 20);
                break;
            case 2:
                ret = Bounds.create(-10, -20, 20, 20);
                break;
            case 3:
                ret = Bounds.create(-15, -20, 30, 20);
                break;
            case 4:
                ret = Bounds.create(-20, -20, 40, 20);
                break;
            case 5:
                ret = Bounds.create(-25, -20, 50, 20);
                break;
            case 6:
                ret = Bounds.create(-30, -20, 60, 20);
                break;
            case 7:
                ret = Bounds.create(-35, -20, 70, 20);
                break;
            case 8:
                ret = Bounds.create(-40, -20, 80, 20);
                break;
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                ret = Bounds.create(-40, -40, 80, 40);
                break;
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                ret = Bounds.create(-40, -60, 80, 60);
                break;
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
                ret = Bounds.create(-40, -80, 80, 80);
                break;
        }
    } else if (dir == Direction.NORTH) {
        switch(len) {
            case 0:
            case 1:
                ret = Bounds.create(-10, 0, 20, 20);
                break;
            case 2:
                ret = Bounds.create(-10, 0, 20, 20);
                break;
            case 3:
                ret = Bounds.create(-15, 0, 30, 20);
                break;
            case 4:
                ret = Bounds.create(-20, 0, 40, 20);
                break;
            case 5:
                ret = Bounds.create(-25, 0, 50, 20);
                break;
            case 6:
                ret = Bounds.create(-30, 0, 60, 20);
                break;
            case 7:
                ret = Bounds.create(-35, 0, 70, 20);
                break;
            case 8:
                ret = Bounds.create(-40, 0, 80, 20);
                break;
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
                ret = Bounds.create(-40, 0, 80, 40);
                break;
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
                ret = Bounds.create(-40, 0, 80, 60);
                break;
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
                ret = Bounds.create(-40, 0, 80, 80);
                break;
        }
    }
    if (ret == null) {
        // should never happen
        ret = Bounds.create(0, -10, 20, 20);
    }
    return ret;
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Aggregations

Bounds (com.cburch.logisim.data.Bounds)199 Graphics (java.awt.Graphics)71 Direction (com.cburch.logisim.data.Direction)29 Location (com.cburch.logisim.data.Location)29 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics2D (java.awt.Graphics2D)20 Font (java.awt.Font)19 Component (com.cburch.logisim.comp.Component)14 Color (java.awt.Color)14 FontMetrics (java.awt.FontMetrics)12 Value (com.cburch.logisim.data.Value)9 Circuit (com.cburch.logisim.circuit.Circuit)7 Port (com.cburch.logisim.instance.Port)7 Instance (com.cburch.logisim.instance.Instance)6 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)6 Handle (com.cburch.draw.model.Handle)5 RadixOption (com.cburch.logisim.circuit.RadixOption)5 CanvasObject (com.cburch.draw.model.CanvasObject)3 Wire (com.cburch.logisim.circuit.Wire)3 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)3