Search in sources :

Example 1 with Bounds

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

the class CanvasPainter method exposeHaloedComponent.

private void exposeHaloedComponent(Graphics g) {
    Component c = haloedComponent;
    if (c == null)
        return;
    Bounds bds = c.getBounds(g).expand(7);
    int w = bds.getWidth();
    int h = bds.getHeight();
    double a = Canvas.SQRT_2 * w;
    double b = Canvas.SQRT_2 * h;
    canvas.repaint((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component)

Example 2 with Bounds

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

the class SelectionBase method getBounds.

public Bounds getBounds(Graphics g) {
    Iterator<Component> it = unionSet.iterator();
    if (it.hasNext()) {
        bounds = it.next().getBounds(g);
        while (it.hasNext()) {
            Component comp = it.next();
            Bounds bds = comp.getBounds(g);
            bounds = bounds.add(bds);
        }
    } else {
        bounds = Bounds.EMPTY_BOUNDS;
    }
    return bounds;
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component)

Example 3 with Bounds

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

the class Canvas method computeSize.

public void computeSize(boolean immediate) {
    Bounds bounds = proj.getCurrentCircuit().getBounds();
    int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
    int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
    Dimension dim;
    if (canvasPane == null) {
        dim = new Dimension(width, height);
    } else {
        dim = canvasPane.supportPreferredSize(width, height);
    }
    if (!immediate) {
        Bounds old = oldPreferredSize;
        if (old != null && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
            return;
        }
    }
    oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
    setPreferredSize(dim);
    revalidate();
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Dimension(java.awt.Dimension)

Example 4 with Bounds

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

the class Canvas method computeViewportContents.

private void computeViewportContents() {
    Set<WidthIncompatibilityData> exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
    if (exceptions == null || exceptions.isEmpty()) {
        viewport.setWidthMessage(null);
        return;
    }
    Rectangle viewableBase;
    Rectangle viewable;
    if (canvasPane != null) {
        viewableBase = canvasPane.getViewport().getViewRect();
    } else {
        Bounds bds = proj.getCurrentCircuit().getBounds();
        viewableBase = new Rectangle(0, 0, bds.getWidth(), bds.getHeight());
    }
    double zoom = getZoomFactor();
    if (zoom == 1.0) {
        viewable = viewableBase;
    } else {
        viewable = new Rectangle((int) (viewableBase.x / zoom), (int) (viewableBase.y / zoom), (int) (viewableBase.width / zoom), (int) (viewableBase.height / zoom));
    }
    viewport.setWidthMessage(Strings.get("canvasWidthError") + (exceptions.size() == 1 ? "" : " (" + exceptions.size() + ")"));
    for (WidthIncompatibilityData ex : exceptions) {
        // See whether any of the points are on the canvas.
        boolean isWithin = false;
        for (int i = 0; i < ex.size(); i++) {
            Location p = ex.getPoint(i);
            int x = p.getX();
            int y = p.getY();
            if (x >= viewable.x && x < viewable.x + viewable.width && y >= viewable.y && y < viewable.y + viewable.height) {
                isWithin = true;
                break;
            }
        }
        // If none are, insert an arrow.
        if (!isWithin) {
            Location p = ex.getPoint(0);
            int x = p.getX();
            int y = p.getY();
            boolean isWest = x < viewable.x;
            boolean isEast = x >= viewable.x + viewable.width;
            boolean isNorth = y < viewable.y;
            boolean isSouth = y >= viewable.y + viewable.height;
            if (isNorth) {
                if (isEast) {
                    viewport.setNortheast(true);
                } else if (isWest) {
                    viewport.setNorthwest(true);
                } else {
                    viewport.setNorth(true);
                }
            } else if (isSouth) {
                if (isEast) {
                    viewport.setSoutheast(true);
                } else if (isWest) {
                    viewport.setSouthwest(true);
                } else {
                    viewport.setSouth(true);
                }
            } else {
                if (isEast) {
                    viewport.setEast(true);
                } else if (isWest) {
                    viewport.setWest(true);
                }
            }
        }
    }
}
Also used : WidthIncompatibilityData(com.cburch.logisim.circuit.WidthIncompatibilityData) Bounds(com.cburch.logisim.data.Bounds) Rectangle(java.awt.Rectangle) Location(com.cburch.logisim.data.Location)

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

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