Search in sources :

Example 6 with InstanceDataSingleton

use of com.cburch.logisim.instance.InstanceDataSingleton in project logisim-evolution by reds-heig.

the class HexDigit method propagate.

@Override
public void propagate(InstanceState state) {
    int summary = 0;
    Value baseVal = state.getPortValue(0);
    if (baseVal == null)
        baseVal = Value.createUnknown(BitWidth.create(4));
    // each nibble is one segment, in top-down, left-to-right
    int segs;
    // order: middle three nibbles are the three horizontal segments
    switch(baseVal.toIntValue()) {
        case 0:
            segs = 0x1110111;
            break;
        case 1:
            segs = 0x0000011;
            break;
        case 2:
            segs = 0x0111110;
            break;
        case 3:
            segs = 0x0011111;
            break;
        case 4:
            segs = 0x1001011;
            break;
        case 5:
            segs = 0x1011101;
            break;
        case 6:
            segs = 0x1111101;
            break;
        case 7:
            segs = 0x0010011;
            break;
        case 8:
            segs = 0x1111111;
            break;
        case 9:
            segs = 0x1011011;
            break;
        case 10:
            segs = 0x1111011;
            break;
        case 11:
            segs = 0x1101101;
            break;
        case 12:
            segs = 0x1110100;
            break;
        case 13:
            segs = 0x0101111;
            break;
        case 14:
            segs = 0x1111100;
            break;
        case 15:
            segs = 0x1111000;
            break;
        default:
            segs = 0x0001000;
            // a dash '-'
            break;
    }
    if ((segs & 0x1) != 0)
        // vertical seg in bottom right
        summary |= 4;
    if ((segs & 0x10) != 0)
        // vertical seg in top right
        summary |= 2;
    if ((segs & 0x100) != 0)
        // horizontal seg at bottom
        summary |= 8;
    if ((segs & 0x1000) != 0)
        // horizontal seg at middle
        summary |= 64;
    if ((segs & 0x10000) != 0)
        // horizontal seg at top
        summary |= 1;
    if ((segs & 0x100000) != 0)
        // vertical seg at bottom left
        summary |= 16;
    if ((segs & 0x1000000) != 0)
        // vertical seg at top left
        summary |= 32;
    Object value = Integer.valueOf(summary);
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    if (data == null) {
        state.setData(new InstanceDataSingleton(value));
    } else {
        data.setValue(value);
    }
}
Also used : Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 7 with InstanceDataSingleton

use of com.cburch.logisim.instance.InstanceDataSingleton in project logisim-evolution by reds-heig.

the class Led method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    Value val = data == null ? Value.FALSE : (Value) data.getValue();
    Bounds bds = painter.getBounds().expand(-1);
    Graphics g = painter.getGraphics();
    if (painter.getShowState()) {
        Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
        Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
        Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
        Object desired = activ.booleanValue() ? Value.TRUE : Value.FALSE;
        g.setColor(val == desired ? onColor : offColor);
        g.fillOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    }
    g.setColor(Color.BLACK);
    GraphicsUtil.switchToWidth(g, 2);
    g.drawOval(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawLabel();
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 8 with InstanceDataSingleton

use of com.cburch.logisim.instance.InstanceDataSingleton in project logisim-evolution by reds-heig.

the class Led method propagate.

@Override
public void propagate(InstanceState state) {
    Value val = state.getPortValue(0);
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    if (data == null) {
        state.setData(new InstanceDataSingleton(val));
    } else {
        data.setValue(val);
    }
}
Also used : Value(com.cburch.logisim.data.Value) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 9 with InstanceDataSingleton

use of com.cburch.logisim.instance.InstanceDataSingleton in project logisim-evolution by reds-heig.

the class SevenSegment method drawBase.

static void drawBase(InstancePainter painter, boolean DrawPoint) {
    ensureSegments();
    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    int summ = (data == null ? 0 : ((Integer) data.getValue()).intValue());
    Boolean active = painter.getAttributeValue(Io.ATTR_ACTIVE);
    int desired = active == null || active.booleanValue() ? 1 : 0;
    Bounds bds = painter.getBounds();
    int x = bds.getX() + 5;
    int y = bds.getY();
    Graphics g = painter.getGraphics();
    Color onColor = painter.getAttributeValue(Io.ATTR_ON_COLOR);
    Color offColor = painter.getAttributeValue(Io.ATTR_OFF_COLOR);
    Color bgColor = painter.getAttributeValue(Io.ATTR_BACKGROUND);
    if (painter.shouldDrawColor() && bgColor.getAlpha() != 0) {
        g.setColor(bgColor);
        g.fillRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
        g.setColor(Color.BLACK);
    }
    painter.drawBounds();
    g.setColor(Color.DARK_GRAY);
    for (int i = 0; i <= 7; i++) {
        if (painter.getShowState()) {
            g.setColor(((summ >> i) & 1) == desired ? onColor : offColor);
        }
        if (i < 7) {
            Bounds seg = SEGMENTS[i];
            g.fillRect(x + seg.getX(), y + seg.getY(), seg.getWidth(), seg.getHeight());
        } else {
            if (DrawPoint)
                // draw decimal point
                g.fillOval(x + 28, y + 48, 5, 5);
        }
    }
    g.setColor(Color.BLACK);
    painter.drawLabel();
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Aggregations

InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)9 Value (com.cburch.logisim.data.Value)7 Bounds (com.cburch.logisim.data.Bounds)4 Color (java.awt.Color)4 Graphics (java.awt.Graphics)4 Location (com.cburch.logisim.data.Location)1