Search in sources :

Example 1 with InstanceDataSingleton

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

the class RGBLed method propagate.

@Override
public void propagate(InstanceState state) {
    int summary = 0;
    for (int i = 0; i < 3; i++) {
        Value val = state.getPortValue(i);
        if (val == Value.TRUE)
            summary |= 1 << i;
    }
    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 2 with InstanceDataSingleton

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

the class RGBLed method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
    int summ = (data == null ? 0 : ((Integer) data.getValue()).intValue());
    Bounds bds = painter.getBounds().expand(-1);
    Graphics g = painter.getGraphics();
    if (painter.getShowState()) {
        Boolean activ = painter.getAttributeValue(Io.ATTR_ACTIVE);
        int mask = activ.booleanValue() ? 0 : 7;
        summ ^= mask;
        int red = ((summ >> RED) & 1) * 0xFF;
        int green = ((summ >> GREEN) & 1) * 0xFF;
        int blue = ((summ >> BLUE) & 1) * 0xFF;
        Color LedColor = new Color(red, green, blue);
        g.setColor(LedColor);
        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) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton)

Example 3 with InstanceDataSingleton

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

the class SevenSegment method propagate.

@Override
public void propagate(InstanceState state) {
    int summary = 0;
    for (int i = 0; i < 8; i++) {
        Value val = state.getPortValue(i);
        if (val == Value.TRUE)
            summary |= 1 << i;
    }
    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 4 with InstanceDataSingleton

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

the class Button method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Bounds bds = painter.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();
    Value val;
    if (painter.getShowState()) {
        InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
        val = data == null ? Value.FALSE : (Value) data.getValue();
    } else {
        val = Value.FALSE;
    }
    Color color = painter.getAttributeValue(Io.ATTR_COLOR);
    if (!painter.shouldDrawColor()) {
        int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
        color = new Color(hue, hue, hue);
    }
    Graphics g = painter.getGraphics();
    int depress;
    if (val == Value.TRUE) {
        x += DEPTH;
        y += DEPTH;
        Object labelLoc = painter.getAttributeValue(Io.ATTR_LABEL_LOC);
        if (labelLoc == Io.LABEL_CENTER || labelLoc == Direction.NORTH || labelLoc == Direction.WEST) {
            depress = DEPTH;
        } else {
            depress = 0;
        }
        Object facing = painter.getAttributeValue(StdAttr.FACING);
        if (facing == Direction.NORTH || facing == Direction.WEST) {
            Location p = painter.getLocation();
            int px = p.getX();
            int py = p.getY();
            GraphicsUtil.switchToWidth(g, Wire.WIDTH);
            g.setColor(Value.TRUE_COLOR);
            if (facing == Direction.NORTH)
                g.drawLine(px, py, px, py + 10);
            else
                g.drawLine(px, py, px + 10, py);
            GraphicsUtil.switchToWidth(g, 1);
        }
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
    } else {
        depress = 0;
        int[] xp = new int[] { x, x + w - DEPTH, x + w, x + w, x + DEPTH, x };
        int[] yp = new int[] { y, y, y + DEPTH, y + h, y + h, y + h - DEPTH };
        g.setColor(color.darker());
        g.fillPolygon(xp, yp, xp.length);
        g.setColor(color);
        g.fillRect(x, y, w - DEPTH, h - DEPTH);
        g.setColor(Color.BLACK);
        g.drawRect(x, y, w - DEPTH, h - DEPTH);
        g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
        g.drawPolygon(xp, yp, xp.length);
    }
    g.translate(depress, depress);
    painter.drawLabel();
    g.translate(-depress, -depress);
    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) Location(com.cburch.logisim.data.Location)

Example 5 with InstanceDataSingleton

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

the class Button method propagate.

@Override
public void propagate(InstanceState state) {
    InstanceDataSingleton data = (InstanceDataSingleton) state.getData();
    Value val = data == null ? Value.FALSE : (Value) data.getValue();
    state.setPort(0, val, 1);
}
Also used : Value(com.cburch.logisim.data.Value) 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