Search in sources :

Example 6 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Line method paint.

@Override
public void paint(Graphics g, HandleGesture gesture) {
    if (setForStroke(g)) {
        int x0 = this.x0;
        int y0 = this.y0;
        int x1 = this.x1;
        int y1 = this.y1;
        Handle h = gesture.getHandle();
        if (h.isAt(x0, y0)) {
            x0 += gesture.getDeltaX();
            y0 += gesture.getDeltaY();
        }
        if (h.isAt(x1, y1)) {
            x1 += gesture.getDeltaX();
            y1 += gesture.getDeltaY();
        }
        g.drawLine(x0, y0, x1, y1);
    }
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 7 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Poly method getPath.

private GeneralPath getPath() {
    GeneralPath p = path;
    if (p == null) {
        p = new GeneralPath();
        Handle[] hs = handles;
        if (hs.length > 0) {
            boolean first = true;
            for (Handle h : hs) {
                if (first) {
                    p.moveTo(h.getX(), h.getY());
                    first = false;
                } else {
                    p.lineTo(h.getX(), h.getY());
                }
            }
        }
        path = p;
    }
    return p;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Handle(com.cburch.draw.model.Handle)

Example 8 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Poly method getHandles.

@Override
public List<Handle> getHandles(HandleGesture gesture) {
    Handle[] hs = handles;
    if (gesture == null) {
        return UnmodifiableList.create(hs);
    } else {
        Handle g = gesture.getHandle();
        Handle[] ret = new Handle[hs.length];
        for (int i = 0, n = hs.length; i < n; i++) {
            Handle h = hs[i];
            if (h.equals(g)) {
                int x = h.getX() + gesture.getDeltaX();
                int y = h.getY() + gesture.getDeltaY();
                Location r;
                if (gesture.isShiftDown()) {
                    Location prev = hs[(i + n - 1) % n].getLocation();
                    Location next = hs[(i + 1) % n].getLocation();
                    if (!closed) {
                        if (i == 0)
                            prev = null;
                        if (i == n - 1)
                            next = null;
                    }
                    if (prev == null) {
                        r = LineUtil.snapTo8Cardinals(next, x, y);
                    } else if (next == null) {
                        r = LineUtil.snapTo8Cardinals(prev, x, y);
                    } else {
                        Location to = Location.create(x, y);
                        Location a = LineUtil.snapTo8Cardinals(prev, x, y);
                        Location b = LineUtil.snapTo8Cardinals(next, x, y);
                        int ad = a.manhattanDistanceTo(to);
                        int bd = b.manhattanDistanceTo(to);
                        r = ad < bd ? a : b;
                    }
                } else {
                    r = Location.create(x, y);
                }
                ret[i] = new Handle(this, r);
            } else {
                ret[i] = h;
            }
        }
        return UnmodifiableList.create(ret);
    }
}
Also used : Handle(com.cburch.draw.model.Handle) Location(com.cburch.logisim.data.Location)

Example 9 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Poly method paint.

@Override
public void paint(Graphics g, HandleGesture gesture) {
    List<Handle> hs = getHandles(gesture);
    int[] xs = new int[hs.size()];
    int[] ys = new int[hs.size()];
    int i = -1;
    for (Handle h : hs) {
        i++;
        xs[i] = h.getX();
        ys[i] = h.getY();
    }
    if (setForFill(g)) {
        g.fillPolygon(xs, ys, xs.length);
    }
    if (setForStroke(g)) {
        if (closed)
            g.drawPolygon(xs, ys, xs.length);
        else
            g.drawPolyline(xs, ys, xs.length);
    }
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 10 with Handle

use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.

the class Poly method deleteHandle.

@Override
public Handle deleteHandle(Handle handle) {
    Handle[] hs = handles;
    int n = hs.length;
    Handle[] is = new Handle[n - 1];
    Handle previous = null;
    boolean deleted = false;
    for (int i = 0; i < n; i++) {
        if (deleted) {
            is[i - 1] = hs[i];
        } else if (hs[i].equals(handle)) {
            if (previous == null) {
                previous = hs[n - 1];
            }
            deleted = true;
        } else {
            previous = hs[i];
            is[i] = hs[i];
        }
    }
    setHandles(is);
    return previous;
}
Also used : Handle(com.cburch.draw.model.Handle)

Aggregations

Handle (com.cburch.draw.model.Handle)39 CanvasObject (com.cburch.draw.model.CanvasObject)9 Location (com.cburch.logisim.data.Location)9 Selection (com.cburch.draw.canvas.Selection)7 HandleGesture (com.cburch.draw.model.HandleGesture)7 Bounds (com.cburch.logisim.data.Bounds)5 ModelDeleteHandleAction (com.cburch.draw.actions.ModelDeleteHandleAction)1 ModelInsertHandleAction (com.cburch.draw.actions.ModelInsertHandleAction)1 ModelMoveHandleAction (com.cburch.draw.actions.ModelMoveHandleAction)1 ModelTranslateAction (com.cburch.draw.actions.ModelTranslateAction)1 CanvasModel (com.cburch.draw.model.CanvasModel)1 Circuit (com.cburch.logisim.circuit.Circuit)1 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)1 Project (com.cburch.logisim.proj.Project)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1 GeneralPath (java.awt.geom.GeneralPath)1 Map (java.util.Map)1 Element (org.w3c.dom.Element)1