Search in sources :

Example 1 with ComponentDrawContext

use of com.cburch.logisim.comp.ComponentDrawContext 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 2 with ComponentDrawContext

use of com.cburch.logisim.comp.ComponentDrawContext in project logisim-evolution by reds-heig.

the class InstancePokerAdapter method getPokeCaret.

public Caret getPokeCaret(ComponentUserEvent event) {
    if (poker == null) {
        return null;
    } else {
        canvas = event.getCanvas();
        CircuitState circState = event.getCircuitState();
        InstanceStateImpl state = new InstanceStateImpl(circState, comp);
        MouseEvent e = new MouseEvent(event.getCanvas(), MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, event.getX(), event.getY(), 1, false);
        boolean isAccepted = poker.init(state, e);
        if (isAccepted) {
            this.state = state;
            this.context = new ComponentDrawContext(event.getCanvas(), event.getCanvas().getCircuit(), circState, null, null);
            mousePressed(e);
            return this;
        } else {
            poker = null;
            return null;
        }
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) MouseEvent(java.awt.event.MouseEvent) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext)

Example 3 with ComponentDrawContext

use of com.cburch.logisim.comp.ComponentDrawContext in project logisim-evolution by reds-heig.

the class CanvasPainter method drawWithUserState.

private void drawWithUserState(Graphics base, Graphics g, Project proj) {
    Circuit circ = proj.getCurrentCircuit();
    Selection sel = proj.getSelection();
    Set<Component> hidden;
    Tool dragTool = canvas.getDragTool();
    if (dragTool == null) {
        hidden = NO_COMPONENTS;
    } else {
        hidden = dragTool.getHiddenComponents(canvas);
        if (hidden == null)
            hidden = NO_COMPONENTS;
    }
    // draw halo around component whose attributes we are viewing
    boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
    if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
        GraphicsUtil.switchToWidth(g, 3);
        g.setColor(Canvas.HALO_COLOR);
        Bounds bds = haloedComponent.getBounds(g).expand(5);
        int w = bds.getWidth();
        int h = bds.getHeight();
        double a = Canvas.SQRT_2 * w;
        double b = Canvas.SQRT_2 * h;
        g.drawOval((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));
        GraphicsUtil.switchToWidth(g, 1);
        g.setColor(Color.BLACK);
    }
    // draw circuit and selection
    CircuitState circState = proj.getCircuitState();
    boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
    ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
    context.setHighlightedWires(highlightedWires);
    circ.draw(context, hidden);
    sel.draw(context, hidden);
    // draw tool
    Tool tool = dragTool != null ? dragTool : proj.getTool();
    if (tool != null && !canvas.isPopupMenuUp()) {
        Graphics gCopy = g.create();
        context.setGraphics(gCopy);
        tool.draw(canvas, context);
        gCopy.dispose();
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Bounds(com.cburch.logisim.data.Bounds) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Tool(com.cburch.logisim.tools.Tool)

Example 4 with ComponentDrawContext

use of com.cburch.logisim.comp.ComponentDrawContext in project logisim-evolution by reds-heig.

the class CanvasPainter method paintContents.

// 
// painting methods
// 
void paintContents(Graphics g, Project proj) {
    Rectangle clip = g.getClipBounds();
    Dimension size = canvas.getSize();
    double zoomFactor = canvas.getZoomFactor();
    if (canvas.ifPaintDirtyReset() || clip == null) {
        clip = new Rectangle(0, 0, size.width, size.height);
    }
    // YSY removed to don't overwrite background image
    // g.setColor(Color.magenta);
    // g.fillRect(clip.x, clip.y, clip.width, clip.height);
    grid.paintGrid(g);
    g.setColor(Color.black);
    Graphics gScaled = g.create();
    if (zoomFactor != 1.0 && gScaled instanceof Graphics2D) {
        ((Graphics2D) gScaled).scale(zoomFactor, zoomFactor);
    }
    drawWithUserState(g, gScaled, proj);
    drawWidthIncompatibilityData(g, gScaled, proj);
    Circuit circ = proj.getCurrentCircuit();
    CircuitState circState = proj.getCircuitState();
    ComponentDrawContext ptContext = new ComponentDrawContext(canvas, circ, circState, g, gScaled);
    ptContext.setHighlightedWires(highlightedWires);
    gScaled.setColor(Color.RED);
    circState.drawOscillatingPoints(ptContext);
    gScaled.setColor(Color.BLUE);
    proj.getSimulator().drawStepPoints(ptContext);
    gScaled.dispose();
}
Also used : Graphics(java.awt.Graphics) CircuitState(com.cburch.logisim.circuit.CircuitState) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext) Rectangle(java.awt.Rectangle) Circuit(com.cburch.logisim.circuit.Circuit) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 5 with ComponentDrawContext

use of com.cburch.logisim.comp.ComponentDrawContext in project logisim-evolution by reds-heig.

the class ComponentIcon method paintIcon.

public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
    // draw tool icon
    Graphics gIcon = g.create();
    ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon);
    comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet());
    gIcon.dispose();
    if (triangleState != TRIANGLE_NONE) {
        int[] xp;
        int[] yp;
        if (triangleState == TRIANGLE_CLOSED) {
            xp = new int[] { x + 13, x + 13, x + 17 };
            yp = new int[] { y + 11, y + 19, y + 15 };
        } else {
            xp = new int[] { x + 11, x + 19, x + 15 };
            yp = new int[] { y + 13, y + 13, y + 17 };
        }
        g.setColor(Color.LIGHT_GRAY);
        g.fillPolygon(xp, yp, 3);
        g.setColor(Color.DARK_GRAY);
        g.drawPolygon(xp, yp, 3);
    }
}
Also used : Graphics(java.awt.Graphics) ComponentDrawContext(com.cburch.logisim.comp.ComponentDrawContext)

Aggregations

ComponentDrawContext (com.cburch.logisim.comp.ComponentDrawContext)5 Graphics (java.awt.Graphics)4 Circuit (com.cburch.logisim.circuit.Circuit)3 CircuitState (com.cburch.logisim.circuit.CircuitState)3 Bounds (com.cburch.logisim.data.Bounds)2 Dimension (java.awt.Dimension)2 Graphics2D (java.awt.Graphics2D)2 Component (com.cburch.logisim.comp.Component)1 Instance (com.cburch.logisim.instance.Instance)1 Tool (com.cburch.logisim.tools.Tool)1 Rectangle (java.awt.Rectangle)1 MouseEvent (java.awt.event.MouseEvent)1