Search in sources :

Example 86 with Bounds

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

the class PortIO method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    /*
		 * State state = (State) painter.getData(); if (state == null) { state =
		 * new State(0,painter.getAttributeValue(ATTR_SIZE));
		 * painter.setData(state); }
		 */
    Bounds bds = painter.getBounds().expand(-1);
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.darkGray);
    g.fillRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
    GraphicsUtil.switchToWidth(g, 1);
    if (painter.getAttributeValue(ATTR_BUS).equals(PINS)) {
        // TODO YSY PINS
        g.setColor(Color.white);
        g.setFont(StdAttr.DEFAULT_LABEL_FONT.deriveFont(StdAttr.DEFAULT_LABEL_FONT.getSize2D() * 0.6f));
        for (int i = 0; i < painter.getAttributeValue(ATTR_SIZE); i++) {
            g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 15, 6, 6);
            if (i == 0 || i == painter.getAttributeValue(ATTR_SIZE) - 1) {
                g.drawChars(Integer.toString(i).toCharArray(), 0, Integer.toString(i).toCharArray().length, bds.getX() + 6 + (i < 10 ? 0 : -2) + i * 10, bds.getY() + 12);
            }
        }
    } else {
        g.setColor(Color.LIGHT_GRAY);
        for (int i = 0; i < 9; i++) {
            g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 15, 6, 6);
            g.fillRect(bds.getX() + 6 + (i * 10), bds.getY() + 25, 6, 6);
        }
        g.setColor(Color.WHITE);
        g.setFont(StdAttr.DEFAULT_LABEL_FONT);
        String text = painter.getAttributeValue(ATTR_SIZE).toString() + " PIN";
        g.drawChars(text.toCharArray(), 0, text.toCharArray().length, bds.getX() + 6, bds.getY() + 12);
    }
    painter.drawLabel();
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds)

Example 87 with Bounds

use of com.cburch.logisim.data.Bounds 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 88 with Bounds

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

the class Tty method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    boolean showState = painter.getShowState();
    Graphics g = painter.getGraphics();
    Bounds bds = painter.getBounds();
    painter.drawClock(CK, Direction.EAST);
    if (painter.shouldDrawColor()) {
        g.setColor(painter.getAttributeValue(Io.ATTR_BACKGROUND));
        g.fillRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 10, 10);
    }
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.BLACK);
    g.drawRoundRect(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight(), 2 * BORDER, 2 * BORDER);
    GraphicsUtil.switchToWidth(g, 1);
    painter.drawPort(CLR);
    painter.drawPort(WE);
    painter.drawPort(IN);
    int rows = getRowCount(painter.getAttributeValue(ATTR_ROWS));
    int cols = getColumnCount(painter.getAttributeValue(ATTR_COLUMNS));
    if (showState) {
        String[] rowData = new String[rows];
        int curRow;
        int curCol;
        TtyState state = getTtyState(painter);
        synchronized (state) {
            for (int i = 0; i < rows; i++) {
                rowData[i] = state.getRowString(i);
            }
            curRow = state.getCursorRow();
            curCol = state.getCursorColumn();
        }
        g.setFont(DEFAULT_FONT);
        g.setColor(painter.getAttributeValue(Io.ATTR_COLOR));
        FontMetrics fm = g.getFontMetrics();
        int x = bds.getX() + BORDER;
        int y = bds.getY() + BORDER + (ROW_HEIGHT + fm.getAscent()) / 2;
        for (int i = 0; i < rows; i++) {
            g.drawString(rowData[i], x, y);
            if (i == curRow) {
                int x0 = x + fm.stringWidth(rowData[i].substring(0, curCol));
                g.drawLine(x0, y - fm.getAscent(), x0, y);
            }
            y += ROW_HEIGHT;
        }
    } else {
        String str = Strings.get("ttyDesc", "" + rows, "" + cols);
        FontMetrics fm = g.getFontMetrics();
        int strWidth = fm.stringWidth(str);
        if (strWidth + BORDER > bds.getWidth()) {
            str = Strings.get("ttyDescShort");
            strWidth = fm.stringWidth(str);
        }
        int x = bds.getX() + (bds.getWidth() - strWidth) / 2;
        int y = bds.getY() + (bds.getHeight() + fm.getAscent()) / 2;
        g.drawString(str, x, y);
    }
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds)

Example 89 with Bounds

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

the class Button 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 == Io.LABEL_CENTER) {
        x = bds.getX() + (bds.getWidth() - DEPTH) / 2;
        y = bds.getY() + (bds.getHeight() - DEPTH) / 2;
    } else 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 90 with Bounds

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

the class DipSwitch method computeTextField.

private void computeTextField(Instance instance) {
    Direction facing = Direction.NORTH;
    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)

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