Search in sources :

Example 61 with Direction

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

the class AbstractGate method computeLabel.

private void computeLabel(Instance instance) {
    GateAttributes attrs = (GateAttributes) instance.getAttributeSet();
    Direction facing = attrs.facing;
    int baseWidth = ((Integer) attrs.size.getValue()).intValue();
    int axis = baseWidth / 2 + (negateOutput ? 10 : 0);
    int perp = 0;
    if (AppPreferences.GATE_SHAPE.get().equals(AppPreferences.SHAPE_RECTANGULAR)) {
        perp += 6;
    }
    Location loc = instance.getLocation();
    int cx;
    int cy;
    if (facing == Direction.NORTH) {
        cx = loc.getX() + perp;
        cy = loc.getY() + axis;
    } else if (facing == Direction.SOUTH) {
        cx = loc.getX() - perp;
        cy = loc.getY() - axis;
    } else if (facing == Direction.WEST) {
        cx = loc.getX() + axis;
        cy = loc.getY() - perp;
    } else {
        cx = loc.getX() - axis;
        cy = loc.getY() + perp;
    }
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, cx, cy, TextField.H_CENTER, TextField.V_CENTER);
}
Also used : Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 62 with Direction

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

the class AbstractGate method getInputOffset.

Location getInputOffset(GateAttributes attrs, int index) {
    int inputs = attrs.inputs;
    Direction facing = attrs.facing;
    int size = ((Integer) attrs.size.getValue()).intValue();
    int axisLength = size + bonusWidth + (negateOutput ? 10 : 0);
    int negated = attrs.negated;
    int skipStart;
    int skipDist;
    int skipLowerEven = 10;
    if (inputs <= 3) {
        if (size < 40) {
            skipStart = -5;
            skipDist = 10;
            skipLowerEven = 10;
        } else if (size < 60 || inputs <= 2) {
            skipStart = -10;
            skipDist = 20;
            skipLowerEven = 20;
        } else {
            skipStart = -15;
            skipDist = 30;
            skipLowerEven = 30;
        }
    } else if (inputs == 4 && size >= 60) {
        skipStart = -5;
        skipDist = 20;
        skipLowerEven = 0;
    } else {
        skipStart = -5;
        skipDist = 10;
        skipLowerEven = 10;
    }
    int dy;
    if ((inputs & 1) == 1) {
        dy = skipStart * (inputs - 1) + skipDist * index;
    } else {
        dy = skipStart * inputs + skipDist * index;
        if (index >= inputs / 2)
            dy += skipLowerEven;
    }
    int dx = axisLength;
    int negatedBit = (negated >> index) & 1;
    if (negatedBit == 1) {
        dx += 10;
    }
    if (facing == Direction.NORTH) {
        return Location.create(dy, dx);
    } else if (facing == Direction.SOUTH) {
        return Location.create(dy, -dx);
    } else if (facing == Direction.WEST) {
        return Location.create(dx, dy);
    } else {
        return Location.create(-dx, dy);
    }
}
Also used : Direction(com.cburch.logisim.data.Direction)

Example 63 with Direction

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

the class Buffer method configurePorts.

private void configurePorts(Instance instance) {
    Direction facing = instance.getAttributeValue(StdAttr.FACING);
    Port[] ports = new Port[2];
    ports[0] = new Port(0, 0, Port.OUTPUT, StdAttr.WIDTH);
    Location out = Location.create(0, 0).translate(facing, -20);
    ports[1] = new Port(out.getX(), out.getY(), Port.INPUT, StdAttr.WIDTH);
    instance.setPorts(ports);
}
Also used : Port(com.cburch.logisim.instance.Port) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location)

Example 64 with Direction

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

the class ControlledBuffer method getOffsetBounds.

@Override
public Bounds getOffsetBounds(AttributeSet attrs) {
    int w = 20;
    if (isInverter && !NotGate.SIZE_NARROW.equals(attrs.getValue(NotGate.ATTR_SIZE))) {
        w = 30;
    }
    Direction facing = attrs.getValue(StdAttr.FACING);
    if (facing == Direction.NORTH)
        return Bounds.create(-10, 0, 20, w);
    if (facing == Direction.SOUTH)
        return Bounds.create(-10, -w, 20, w);
    if (facing == Direction.WEST)
        return Bounds.create(0, -10, w, 20);
    return Bounds.create(-w, -10, w, 20);
}
Also used : Direction(com.cburch.logisim.data.Direction)

Example 65 with Direction

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

the class NotGate method paintBase.

private void paintBase(InstancePainter painter) {
    Graphics g = painter.getGraphics();
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    g.translate(x, y);
    double rotate = 0.0;
    if (facing != null && facing != Direction.EAST && g instanceof Graphics2D) {
        rotate = -facing.toRadians();
        ((Graphics2D) g).rotate(rotate);
    }
    Object shape = painter.getGateShape();
    if (shape == AppPreferences.SHAPE_RECTANGULAR) {
        paintRectangularBase(g, painter);
    } else if (shape == AppPreferences.SHAPE_DIN40700) {
        int width = painter.getAttributeValue(ATTR_SIZE) == SIZE_NARROW ? 20 : 30;
        PainterDin.paintAnd(painter, width, 18, true);
    } else {
        PainterShaped.paintNot(painter);
    }
    if (rotate != 0.0) {
        ((Graphics2D) g).rotate(-rotate);
    }
    g.translate(-x, -y);
}
Also used : Graphics(java.awt.Graphics) Direction(com.cburch.logisim.data.Direction) Location(com.cburch.logisim.data.Location) Graphics2D(java.awt.Graphics2D)

Aggregations

Direction (com.cburch.logisim.data.Direction)89 Location (com.cburch.logisim.data.Location)39 Bounds (com.cburch.logisim.data.Bounds)27 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics (java.awt.Graphics)20 Graphics2D (java.awt.Graphics2D)13 Port (com.cburch.logisim.instance.Port)10 Instance (com.cburch.logisim.instance.Instance)9 ArrayList (java.util.ArrayList)7 CanvasObject (com.cburch.draw.model.CanvasObject)5 Color (java.awt.Color)5 Font (java.awt.Font)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 AttributeSet (com.cburch.logisim.data.AttributeSet)4 FontMetrics (java.awt.FontMetrics)4 List (java.util.List)4 Wire (com.cburch.logisim.circuit.Wire)3 Attribute (com.cburch.logisim.data.Attribute)3 Value (com.cburch.logisim.data.Value)3