Search in sources :

Example 6 with Bounds

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

the class AddTool method expose.

private void expose(java.awt.Component c, int x, int y) {
    Bounds bds = getBounds();
    c.repaint(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Example 7 with Bounds

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

the class AddTool method getBounds.

private Bounds getBounds() {
    Bounds ret = bounds;
    if (ret == null) {
        ComponentFactory source = getFactory();
        if (source == null) {
            ret = Bounds.EMPTY_BOUNDS;
        } else {
            AttributeSet base = getBaseAttributes();
            ret = source.getOffsetBounds(base).expand(5);
        }
        bounds = ret;
    }
    return ret;
}
Also used : AttributeSet(com.cburch.logisim.data.AttributeSet) Bounds(com.cburch.logisim.data.Bounds) ComponentFactory(com.cburch.logisim.comp.ComponentFactory)

Example 8 with Bounds

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

the class Tunnel method paintGhost.

// 
// graphics methods
// 
@Override
public void paintGhost(InstancePainter painter) {
    TunnelAttributes attrs = (TunnelAttributes) painter.getAttributeSet();
    Direction facing = attrs.getFacing();
    String label = attrs.getLabel();
    Graphics g = painter.getGraphics();
    g.setFont(attrs.getFont());
    FontMetrics fm = g.getFontMetrics();
    Bounds bds = computeBounds(attrs, fm.stringWidth(label), fm.getAscent() + fm.getDescent(), g, label);
    if (attrs.setOffsetBounds(bds)) {
        Instance instance = painter.getInstance();
        if (instance != null)
            instance.recomputeBounds();
    }
    int x0 = bds.getX();
    int y0 = bds.getY();
    int x1 = x0 + bds.getWidth();
    int y1 = y0 + bds.getHeight();
    int mw = ARROW_MAX_WIDTH / 2;
    int[] xp;
    int[] yp;
    if (facing == Direction.NORTH) {
        int yb = y0 + ARROW_DEPTH;
        if (x1 - x0 <= ARROW_MAX_WIDTH) {
            xp = new int[] { x0, 0, x1, x1, x0 };
            yp = new int[] { yb, y0, yb, y1, y1 };
        } else {
            xp = new int[] { x0, -mw, 0, mw, x1, x1, x0 };
            yp = new int[] { yb, yb, y0, yb, yb, y1, y1 };
        }
    } else if (facing == Direction.SOUTH) {
        int yb = y1 - ARROW_DEPTH;
        if (x1 - x0 <= ARROW_MAX_WIDTH) {
            xp = new int[] { x0, x1, x1, 0, x0 };
            yp = new int[] { y0, y0, yb, y1, yb };
        } else {
            xp = new int[] { x0, x1, x1, mw, 0, -mw, x0 };
            yp = new int[] { y0, y0, yb, yb, y1, yb, yb };
        }
    } else if (facing == Direction.EAST) {
        int xb = x1 - ARROW_DEPTH;
        if (y1 - y0 <= ARROW_MAX_WIDTH) {
            xp = new int[] { x0, xb, x1, xb, x0 };
            yp = new int[] { y0, y0, 0, y1, y1 };
        } else {
            xp = new int[] { x0, xb, xb, x1, xb, xb, x0 };
            yp = new int[] { y0, y0, -mw, 0, mw, y1, y1 };
        }
    } else {
        int xb = x0 + ARROW_DEPTH;
        if (y1 - y0 <= ARROW_MAX_WIDTH) {
            xp = new int[] { xb, x1, x1, xb, x0 };
            yp = new int[] { y0, y0, y1, y1, 0 };
        } else {
            xp = new int[] { xb, x1, x1, xb, xb, x0, xb };
            yp = new int[] { y0, y0, y1, y1, mw, 0, -mw };
        }
    }
    GraphicsUtil.switchToWidth(g, 2);
    g.drawPolygon(xp, yp, xp.length);
}
Also used : Graphics(java.awt.Graphics) Instance(com.cburch.logisim.instance.Instance) FontMetrics(java.awt.FontMetrics) Bounds(com.cburch.logisim.data.Bounds) Direction(com.cburch.logisim.data.Direction)

Example 9 with Bounds

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

the class SelectTool method computeDxDy.

private void computeDxDy(Project proj, MouseEvent e, Graphics g) {
    Bounds bds = proj.getSelection().getBounds(g);
    int dx;
    int dy;
    if (bds == Bounds.EMPTY_BOUNDS) {
        dx = e.getX() - start.getX();
        dy = e.getY() - start.getY();
    } else {
        dx = Math.max(e.getX() - start.getX(), -bds.getX());
        dy = Math.max(e.getY() - start.getY(), -bds.getY());
    }
    Selection sel = proj.getSelection();
    if (sel.shouldSnap()) {
        dx = Canvas.snapXToGrid(dx);
        dy = Canvas.snapYToGrid(dy);
    }
    curDx = dx;
    curDy = dy;
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) Bounds(com.cburch.logisim.data.Bounds)

Example 10 with Bounds

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

the class PropagationPoints method draw.

void draw(ComponentDrawContext context) {
    if (data.isEmpty())
        return;
    CircuitState state = context.getCircuitState();
    HashMap<CircuitState, CircuitState> stateMap = new HashMap<CircuitState, CircuitState>();
    for (CircuitState s : state.getSubstates()) {
        addSubstates(stateMap, s, s);
    }
    Graphics g = context.getGraphics();
    GraphicsUtil.switchToWidth(g, 2);
    for (Entry e : data) {
        if (e.state == state) {
            Location p = e.loc;
            g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
        } else if (stateMap.containsKey(e.state)) {
            CircuitState substate = stateMap.get(e.state);
            Component subcirc = substate.getSubcircuit();
            Bounds b = subcirc.getBounds();
            g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
        }
    }
    GraphicsUtil.switchToWidth(g, 1);
}
Also used : Graphics(java.awt.Graphics) HashMap(java.util.HashMap) Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component) Location(com.cburch.logisim.data.Location)

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