Search in sources :

Example 81 with Location

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

the class SvgCreator method createLine.

public static Element createLine(Document doc, Line line) {
    Element elt = doc.createElement("line");
    Location v1 = line.getEnd0();
    Location v2 = line.getEnd1();
    elt.setAttribute("x1", "" + v1.getX());
    elt.setAttribute("y1", "" + v1.getY());
    elt.setAttribute("x2", "" + v2.getX());
    elt.setAttribute("y2", "" + v2.getY());
    populateStroke(elt, line);
    return elt;
}
Also used : Element(org.w3c.dom.Element) Location(com.cburch.logisim.data.Location)

Example 82 with Location

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

the class AbstractCanvasObject method overlaps.

public boolean overlaps(CanvasObject other) {
    Bounds a = this.getBounds();
    Bounds b = other.getBounds();
    Bounds c = a.intersect(b);
    Random rand = new Random();
    if (c.getWidth() == 0 || c.getHeight() == 0) {
        return false;
    } else if (other instanceof AbstractCanvasObject) {
        AbstractCanvasObject that = (AbstractCanvasObject) other;
        for (int i = 0; i < OVERLAP_TRIES; i++) {
            if (i % 2 == 0) {
                Location loc = this.getRandomPoint(c, rand);
                if (loc != null && that.contains(loc, false))
                    return true;
            } else {
                Location loc = that.getRandomPoint(c, rand);
                if (loc != null && this.contains(loc, false))
                    return true;
            }
        }
        return false;
    } else {
        for (int i = 0; i < OVERLAP_TRIES; i++) {
            Location loc = this.getRandomPoint(c, rand);
            if (loc != null && other.contains(loc, false))
                return true;
        }
        return false;
    }
}
Also used : Random(java.util.Random) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 83 with Location

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

the class Curve method getHandleArray.

private Handle[] getHandleArray(HandleGesture gesture) {
    if (gesture == null) {
        return new Handle[] { new Handle(this, p0), new Handle(this, p1), new Handle(this, p2) };
    } else {
        Handle g = gesture.getHandle();
        int gx = g.getX() + gesture.getDeltaX();
        int gy = g.getY() + gesture.getDeltaY();
        Handle[] ret = { new Handle(this, p0), new Handle(this, p1), new Handle(this, p2) };
        if (g.isAt(p0)) {
            if (gesture.isShiftDown()) {
                Location p = LineUtil.snapTo8Cardinals(p2, gx, gy);
                ret[0] = new Handle(this, p);
            } else {
                ret[0] = new Handle(this, gx, gy);
            }
        } else if (g.isAt(p2)) {
            if (gesture.isShiftDown()) {
                Location p = LineUtil.snapTo8Cardinals(p0, gx, gy);
                ret[2] = new Handle(this, p);
            } else {
                ret[2] = new Handle(this, gx, gy);
            }
        } else if (g.isAt(p1)) {
            if (gesture.isShiftDown()) {
                double x0 = p0.getX();
                double y0 = p0.getY();
                double x1 = p2.getX();
                double y1 = p2.getY();
                double midx = (x0 + x1) / 2;
                double midy = (y0 + y1) / 2;
                double dx = x1 - x0;
                double dy = y1 - y0;
                double[] p = LineUtil.nearestPointInfinite(gx, gy, midx, midy, midx - dy, midy + dx);
                gx = (int) Math.round(p[0]);
                gy = (int) Math.round(p[1]);
            }
            if (gesture.isAltDown()) {
                double[] e0 = { p0.getX(), p0.getY() };
                double[] e1 = { p2.getX(), p2.getY() };
                double[] mid = { gx, gy };
                double[] ct = CurveUtil.interpolate(e0, e1, mid);
                gx = (int) Math.round(ct[0]);
                gy = (int) Math.round(ct[1]);
            }
            ret[1] = new Handle(this, gx, gy);
        }
        return ret;
    }
}
Also used : Handle(com.cburch.draw.model.Handle) Location(com.cburch.logisim.data.Location)

Example 84 with Location

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

the class InstanceTextField method getTextCaret.

public Caret getTextCaret(ComponentUserEvent event) {
    canvas = event.getCanvas();
    Graphics g = canvas.getGraphics();
    // and if it is empty, just return a caret at its beginning
    if (field == null)
        createField(comp.getAttributeSet(), "");
    String text = field.getText();
    if (text == null || text.equals(""))
        return field.getCaret(g, 0);
    Bounds bds = field.getBounds(g);
    if (bds.getWidth() < 4 || bds.getHeight() < 4) {
        Location loc = comp.getLocation();
        bds = bds.add(Bounds.create(loc).expand(2));
    }
    int x = event.getX();
    int y = event.getY();
    if (bds.contains(x, y))
        return field.getCaret(g, x, y);
    else
        return null;
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 85 with Location

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

the class InstanceComponent method contains.

public boolean contains(Location pt) {
    Location translated = pt.translate(-loc.getX(), -loc.getY());
    InstanceFactory factory = instance.getFactory();
    return factory.contains(translated, instance.getAttributeSet());
}
Also used : 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