Search in sources :

Example 51 with Bounds

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

the class LayoutThumbnail method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    if (circuitState != null) {
        Circuit circuit = circuitState.getCircuit();
        Bounds bds = circuit.getBounds(g);
        Dimension size = getSize();
        double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
        double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
        double scale = Math.min(1.0, Math.min(scaleX, scaleY));
        Graphics gCopy = g.create();
        int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
        int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
        gCopy.translate(borderX, borderY);
        if (scale != 1.0 && g instanceof Graphics2D) {
            ((Graphics2D) gCopy).scale(scale, scale);
        }
        gCopy.translate(-bds.getX(), -bds.getY());
        ComponentDrawContext context = new ComponentDrawContext(this, circuit, circuitState, g, gCopy);
        context.setShowState(false);
        context.setShowColor(false);
        circuit.draw(context, Collections.<Component>emptySet());
        if (ports != null) {
            gCopy.setColor(AppearancePort.COLOR);
            int width = Math.max(4, (int) ((2 / scale) + 0.5));
            GraphicsUtil.switchToWidth(gCopy, width);
            for (Instance port : ports) {
                Bounds b = port.getBounds();
                int x = b.getX();
                int y = b.getY();
                int w = b.getWidth();
                int h = b.getHeight();
                if (Pin.FACTORY.isInputPin(port)) {
                    gCopy.drawRect(x, y, w, h);
                } else {
                    if (b.getWidth() > 25) {
                        gCopy.drawRoundRect(x, y, w, h, 4, 4);
                    } else {
                        gCopy.drawOval(x, y, w, h);
                    }
                }
            }
        }
        gCopy.dispose();
        g.setColor(Color.BLACK);
        GraphicsUtil.switchToWidth(g, 2);
        g.drawRect(0, 0, size.width - 2, size.height - 2);
    }
}
Also used : Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Instance(com.cburch.logisim.instance.Instance) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 52 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 53 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 54 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 55 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)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