Search in sources :

Example 6 with Location

use of com.cburch.logisim.data.Location 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 7 with Location

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

the class EditTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
    boolean wire = updateLocation(canvas, e);
    Location oldWireLoc = wireLoc;
    wireLoc = NULL_LOCATION;
    lastX = Integer.MIN_VALUE;
    if (wire) {
        current = wiring;
        Selection sel = canvas.getSelection();
        Circuit circ = canvas.getCircuit();
        Collection<Component> selected = sel.getAnchoredComponents();
        ArrayList<Component> suppress = null;
        for (Wire w : circ.getWires()) {
            if (selected.contains(w)) {
                if (w.contains(oldWireLoc)) {
                    if (suppress == null)
                        suppress = new ArrayList<Component>();
                    suppress.add(w);
                }
            }
        }
        sel.setSuppressHandles(suppress);
    } else {
        current = select;
    }
    pressX = e.getX();
    pressY = e.getY();
    current.mousePressed(canvas, g, e);
}
Also used : Selection(com.cburch.logisim.gui.main.Selection) ArrayList(java.util.ArrayList) Circuit(com.cburch.logisim.circuit.Circuit) Component(com.cburch.logisim.comp.Component) Wire(com.cburch.logisim.circuit.Wire) Location(com.cburch.logisim.data.Location)

Example 8 with Location

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

the class EditTool method updateLocation.

private boolean updateLocation(Canvas canvas, int mx, int my, int mods) {
    int snapx = Canvas.snapXToGrid(mx);
    int snapy = Canvas.snapYToGrid(my);
    int dx = mx - snapx;
    int dy = my - snapy;
    boolean isEligible = dx * dx + dy * dy < 36;
    if ((mods & MouseEvent.ALT_DOWN_MASK) != 0)
        isEligible = true;
    if (!isEligible) {
        snapx = -1;
        snapy = -1;
    }
    boolean modsSame = lastMods == mods;
    lastCanvas = canvas;
    lastRawX = mx;
    lastRawY = my;
    lastMods = mods;
    if (lastX == snapx && lastY == snapy && modsSame) {
        // already computed
        return wireLoc != NULL_LOCATION;
    } else {
        Location snap = Location.create(snapx, snapy);
        if (modsSame) {
            Object o = cache.get(snap);
            if (o != null) {
                lastX = snapx;
                lastY = snapy;
                canvas.repaint();
                boolean ret = ((Boolean) o).booleanValue();
                wireLoc = ret ? snap : NULL_LOCATION;
                return ret;
            }
        } else {
            cache.clear();
        }
        boolean ret = isEligible && isWiringPoint(canvas, snap, mods);
        wireLoc = ret ? snap : NULL_LOCATION;
        cache.put(snap, Boolean.valueOf(ret));
        int toRemove = cache.size() - CACHE_MAX_SIZE;
        Iterator<Location> it = cache.keySet().iterator();
        while (it.hasNext() && toRemove > 0) {
            it.next();
            it.remove();
            toRemove--;
        }
        lastX = snapx;
        lastY = snapy;
        canvas.repaint();
        return ret;
    }
}
Also used : Location(com.cburch.logisim.data.Location)

Example 9 with Location

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

the class EditTool method draw.

@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
    Location loc = wireLoc;
    if (loc != NULL_LOCATION && current != wiring) {
        int x = loc.getX();
        int y = loc.getY();
        Graphics g = context.getGraphics();
        g.setColor(Value.TRUE_COLOR);
        GraphicsUtil.switchToWidth(g, 2);
        g.drawOval(x - 5, y - 5, 10, 10);
        g.setColor(Color.BLACK);
        GraphicsUtil.switchToWidth(g, 1);
    }
    current.draw(canvas, context);
}
Also used : Graphics(java.awt.Graphics) Location(com.cburch.logisim.data.Location)

Example 10 with Location

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

the class PullResistor method paintInstance.

@Override
public void paintInstance(InstancePainter painter) {
    Location loc = painter.getLocation();
    int x = loc.getX();
    int y = loc.getY();
    Graphics g = painter.getGraphics();
    g.translate(x, y);
    Value pull = getPullValue(painter.getAttributeSet());
    Value actual = painter.getPortValue(0);
    paintBase(painter, pull, pull.getColor(), actual.getColor());
    g.translate(-x, -y);
    painter.drawPorts();
}
Also used : Graphics(java.awt.Graphics) Value(com.cburch.logisim.data.Value) Location(com.cburch.logisim.data.Location)

Aggregations

Location (com.cburch.logisim.data.Location)169 Direction (com.cburch.logisim.data.Direction)39 Graphics (java.awt.Graphics)35 Component (com.cburch.logisim.comp.Component)26 Bounds (com.cburch.logisim.data.Bounds)24 ArrayList (java.util.ArrayList)23 CanvasObject (com.cburch.draw.model.CanvasObject)17 BitWidth (com.cburch.logisim.data.BitWidth)16 Wire (com.cburch.logisim.circuit.Wire)13 HashMap (java.util.HashMap)10 Handle (com.cburch.draw.model.Handle)9 AttributeSet (com.cburch.logisim.data.AttributeSet)9 Value (com.cburch.logisim.data.Value)9 Instance (com.cburch.logisim.instance.Instance)9 Port (com.cburch.logisim.instance.Port)9 Color (java.awt.Color)9 Graphics2D (java.awt.Graphics2D)9 HashSet (java.util.HashSet)9 Circuit (com.cburch.logisim.circuit.Circuit)8 EndData (com.cburch.logisim.comp.EndData)7