Search in sources :

Example 26 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 27 with Bounds

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

the class Pin method paintGhost.

@Override
public void paintGhost(InstancePainter painter) {
    PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
    Location loc = painter.getLocation();
    Bounds bds = painter.getOffsetBounds();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    boolean output = attrs.isOutput();
    if (output) {
        BitWidth width = attrs.getValue(StdAttr.WIDTH);
        if (width == BitWidth.ONE) {
            g.drawOval(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
        } else {
            g.drawRoundRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1, 6, 6);
        }
    } else {
        g.drawRect(x + bds.getX() + 1, y + bds.getY() + 1, bds.getWidth() - 1, bds.getHeight() - 1);
    }
}
Also used : Graphics(java.awt.Graphics) BitWidth(com.cburch.logisim.data.BitWidth) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 28 with Bounds

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

the class Pin method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    PinAttributes attrs = (PinAttributes) painter.getAttributeSet();
    Graphics g = painter.getGraphics();
    // intentionally with no
    Bounds bds = painter.getInstance().getBounds();
    // graphics object - we
    // don't want label
    // included
    int x = bds.getX();
    int y = bds.getY();
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.black);
    if (attrs.type == EndData.OUTPUT_ONLY) {
        if (attrs.width.getWidth() == 1) {
            g.drawOval(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1);
        } else {
            g.drawRoundRect(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1, 12, 12);
        }
    } else {
        g.drawRect(x + 1, y + 1, bds.getWidth() - 1, bds.getHeight() - 1);
    }
    painter.drawLabel();
    if (!painter.getShowState()) {
        g.setColor(Color.BLACK);
        GraphicsUtil.drawCenteredText(g, "x" + attrs.width.getWidth(), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
    } else {
        PinState state = getState(painter);
        if (attrs.width.getWidth() <= 1) {
            Value found = state.foundValue;
            g.setColor(found.getColor());
            g.fillOval(x + 4, y + 4, 13, 13);
            if (attrs.width.getWidth() == 1) {
                g.setColor(Color.WHITE);
                GraphicsUtil.drawCenteredText(g, state.intendedValue.toDisplayString(), x + 11, y + 9);
            }
        } else {
            Probe.paintValue(painter, state.intendedValue);
        }
    }
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Value(com.cburch.logisim.data.Value)

Example 29 with Bounds

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

the class PowerOnReset method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    java.awt.Graphics g = painter.getGraphics();
    Bounds bds = painter.getInstance().getBounds();
    int x = bds.getX();
    int y = bds.getY();
    GraphicsUtil.switchToWidth(g, 2);
    g.setColor(Color.ORANGE);
    g.fillRect(x, y, bds.getWidth(), bds.getHeight());
    g.setColor(Color.BLACK);
    g.drawRect(x, y, bds.getWidth(), bds.getHeight());
    Font old = g.getFont();
    g.setFont(old.deriveFont(18.0f).deriveFont(Font.BOLD));
    FontMetrics fm = g.getFontMetrics();
    String txt = "Power-On Reset";
    int wide = Math.max(bds.getWidth(), bds.getHeight());
    int offset = (wide - fm.stringWidth(txt)) / 2;
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    if (((facing == Direction.NORTH) || (facing == Direction.SOUTH)) && (g instanceof Graphics2D)) {
        Graphics2D g2 = (Graphics2D) g;
        int xpos = facing == Direction.NORTH ? x + 20 - fm.getDescent() : x + 20 + fm.getDescent();
        int ypos = facing == Direction.NORTH ? y + offset : y + bds.getHeight() - offset;
        g2.translate(xpos, ypos);
        g2.rotate(facing.toRadians());
        g.drawString(txt, 0, 0);
        g2.rotate(-facing.toRadians());
        g2.translate(-xpos, -ypos);
    } else {
        g.drawString(txt, x + offset, y + fm.getDescent() + 20);
    }
    painter.drawPorts();
}
Also used : FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 30 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)

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