Search in sources :

Example 46 with Bounds

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

the class Switch method paint.

private void paint(InstancePainter painter, boolean ghost) {
    // draw
    Bounds bds = painter.getBounds();
    // x position
    int x = bds.getX();
    // y position
    int y = bds.getY();
    // width
    int w = bds.getWidth();
    // height
    int h = bds.getHeight();
    // 0 symbol radius
    byte circle = 4;
    int[] xp;
    int[] yp;
    int[] xr;
    int[] yr;
    Direction facing = painter.getAttributeValue(StdAttr.FACING);
    if (!ghost)
        // draw the first port here because it has to be under the drawing
        painter.drawPort((facing == Direction.SOUTH || facing == Direction.EAST ? 0 : 1));
    boolean active = false;
    if (painter.getShowState() && !ghost) {
        InstanceDataSingleton data = (InstanceDataSingleton) painter.getData();
        active = data != null && (Boolean) data.getValue();
    }
    Color color = painter.getAttributeValue(IoLibrary.ATTR_COLOR);
    if (!painter.shouldDrawColor()) {
        int hue = (color.getRed() + color.getGreen() + color.getBlue()) / 3;
        color = new Color(hue, hue, hue);
    }
    Graphics g = painter.getGraphics();
    if (active) {
        // case true output
        if (facing == Direction.NORTH || facing == Direction.WEST) {
            Location p = painter.getLocation();
            int px = p.getX();
            int py = p.getY();
            GraphicsUtil.switchToWidth(g, Wire.WIDTH);
            g.setColor(Value.trueColor);
            if (facing == Direction.NORTH)
                g.drawLine(px, py, px, py + 10);
            else
                g.drawLine(px, py, px + 10, py);
            GraphicsUtil.switchToWidth(g, 1);
        }
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            // horizontal
            // grey polygon x points
            xp = new int[] { x, x + w - DEPTH, x + w, x + w, x };
            // grey polygon y points
            yp = new int[] { y + DEPTH, y, y + DEPTH, y + h, y + h };
            // white polygon x points
            xr = new int[] { x, x + w - DEPTH, x + w - DEPTH, x };
            // white polygon y points
            yr = new int[] { y + DEPTH, y, y + h - DEPTH, y + h };
        } else {
            // vertical
            xp = new int[] { x + DEPTH, x + w, x + w, x + DEPTH, x };
            yp = new int[] { y, y, y + h, y + h, y + DEPTH };
            xr = new int[] { x, x + w - DEPTH, x + w, x + DEPTH };
            yr = new int[] { y + DEPTH, y + DEPTH, y + h, y + h };
        }
        if (!ghost) {
            g.setColor(color.darker());
            g.fillPolygon(xp, yp, xp.length);
            g.setColor(color);
            g.fillPolygon(xr, yr, xr.length);
            g.setColor(Color.BLACK);
        }
        g.drawPolygon(xp, yp, xp.length);
        g.drawPolygon(xr, yr, xr.length);
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            g.drawLine(x + ((w - DEPTH) / 2), y + (DEPTH / 2) + 1, x + ((w - DEPTH) / 2), y + h - (DEPTH / 2) - 1);
            g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
            g.drawLine(x + ((w - DEPTH) / 6), y + ((h - DEPTH) / 2) + (DEPTH - DEPTH / 6), x + ((w - DEPTH) / 3), y + ((h - DEPTH) / 2) + (DEPTH - DEPTH / 3));
            g.drawOval(x + ((w - DEPTH) * 3 / 4) - (circle / 2), y + ((h - DEPTH) / 2 - (circle / 2)) + 1 + (DEPTH / 4), circle, circle - 1);
        } else {
            g.drawLine(x + w - DEPTH, y + DEPTH, x + w, y);
            g.drawLine(x + (DEPTH / 2) + 1, y + ((h - DEPTH) / 2) + DEPTH, x + w - (DEPTH / 2) - 1, y + ((h - DEPTH) / 2) + DEPTH);
            g.drawLine(x + ((w - DEPTH) / 2) + (DEPTH - DEPTH / 6), y + ((h - DEPTH) * 5 / 6) + DEPTH, x + ((w - DEPTH) / 2) + (DEPTH - DEPTH / 3), y + ((h - DEPTH) * 2 / 3) + DEPTH);
            g.drawOval(x + (DEPTH / 4) + ((w - DEPTH - circle) / 2) + 1, y + ((h - DEPTH) / 4 - (circle / 2)) + DEPTH, circle - 1, circle);
        }
    } else {
        // case false output
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            xp = new int[] { x, x + DEPTH, x + w, x + w, x };
            yp = new int[] { y + DEPTH, y, y + DEPTH, y + h, y + h };
            xr = new int[] { x + DEPTH, x + w, x + w, x + DEPTH };
            yr = new int[] { y, y + DEPTH, y + h, y + h - DEPTH };
        } else {
            xp = new int[] { x + DEPTH, x + w, x + w, x + DEPTH, x };
            yp = new int[] { y, y, y + h, y + h, y + h - DEPTH };
            xr = new int[] { x + DEPTH, x + w, x + w - DEPTH, x };
            yr = new int[] { y, y, y + h - DEPTH, y + h - DEPTH };
        }
        if (!ghost) {
            g.setColor(color.darker());
            g.fillPolygon(xp, yp, xp.length);
            g.setColor(color);
            g.fillPolygon(xr, yr, xr.length);
            g.setColor(Color.BLACK);
        }
        g.drawPolygon(xp, yp, xp.length);
        g.drawPolygon(xr, yr, xr.length);
        if (facing == Direction.NORTH || facing == Direction.SOUTH) {
            // diagonal line inside gray polygon
            g.drawLine(x + DEPTH, y + h - DEPTH, x, y + h);
            g.drawLine(x + ((w - DEPTH) / 2) + DEPTH, y + (DEPTH / 2) + 1, x + ((w - DEPTH) / 2) + DEPTH, y + h - (DEPTH / 2) - 1);
            g.drawLine(x + DEPTH + (w / 6), y + ((h - DEPTH) / 2) + (DEPTH / 6), x + DEPTH + (w / 3), y + ((h - DEPTH) / 2) + (DEPTH / 3));
            g.drawOval(x + ((w - DEPTH) * 3 / 4) - (circle / 2) + DEPTH, y + ((h - DEPTH) / 2 - (circle / 2)) + (DEPTH * 3 / 4) + 1, circle, circle - 1);
        } else {
            g.drawLine(x + (DEPTH / 2) + 1, y + ((h - DEPTH) / 2), x + w - (DEPTH / 2) - 1, y + ((h - DEPTH) / 2));
            g.drawLine(x + w - DEPTH, y + h - DEPTH, x + w, y + h);
            g.drawLine(x + ((w - DEPTH) / 2) + (DEPTH / 6), y + ((h - DEPTH) * 5 / 6), x + ((w - DEPTH) / 2) + (DEPTH / 3), y + ((h - DEPTH) * 2 / 3));
            g.drawOval(x + (DEPTH * 3 / 4) + ((w - DEPTH - circle) / 2) + 1, y + ((h - DEPTH) / 4 - (circle / 2)), circle - 1, circle);
        }
    }
    if (!ghost) {
        painter.drawLabel();
        painter.drawPort((facing == Direction.SOUTH || facing == Direction.EAST ? 1 : 0));
    }
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Color(java.awt.Color) Direction(com.cburch.logisim.data.Direction) InstanceDataSingleton(com.cburch.logisim.instance.InstanceDataSingleton) Location(com.cburch.logisim.data.Location)

Example 47 with Bounds

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

the class Buzzer method configureNewInstance.

@Override
protected void configureNewInstance(Instance instance) {
    Bounds b = instance.getBounds();
    updateports(instance);
    instance.addAttributeListener();
    instance.setTextField(StdAttr.LABEL, StdAttr.LABEL_FONT, b.getX() + b.getWidth() / 2, b.getY() - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BOTTOM);
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Example 48 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 49 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 50 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)

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