Search in sources :

Example 31 with Handle

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

the class PolyUtil method getClosestPoint.

public static ClosestResult getClosestPoint(Location loc, boolean closed, Handle[] hs) {
    int xq = loc.getX();
    int yq = loc.getY();
    ClosestResult ret = new ClosestResult();
    ret.dist = Double.MAX_VALUE;
    if (hs.length > 0) {
        Handle h0 = hs[0];
        int x0 = h0.getX();
        int y0 = h0.getY();
        int stop = closed ? hs.length : (hs.length - 1);
        for (int i = 0; i < stop; i++) {
            Handle h1 = hs[(i + 1) % hs.length];
            int x1 = h1.getX();
            int y1 = h1.getY();
            double d = LineUtil.ptDistSqSegment(x0, y0, x1, y1, xq, yq);
            if (d < ret.dist) {
                ret.dist = d;
                ret.prevHandle = h0;
                ret.nextHandle = h1;
            }
            h0 = h1;
            x0 = x1;
            y0 = y1;
        }
    }
    if (ret.dist == Double.MAX_VALUE) {
        return null;
    } else {
        Handle h0 = ret.prevHandle;
        Handle h1 = ret.nextHandle;
        double[] p = LineUtil.nearestPointSegment(xq, yq, h0.getX(), h0.getY(), h1.getX(), h1.getY());
        ret.loc = Location.create((int) Math.round(p[0]), (int) Math.round(p[1]));
        return ret;
    }
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 32 with Handle

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

the class Text method getHandles.

public List<Handle> getHandles() {
    Bounds bds = label.getBounds();
    int x = bds.getX();
    int y = bds.getY();
    int w = bds.getWidth();
    int h = bds.getHeight();
    return UnmodifiableList.create(new Handle[] { new Handle(this, x, y), new Handle(this, x + w, y), new Handle(this, x + w, y + h), new Handle(this, x, y + h) });
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Handle(com.cburch.draw.model.Handle)

Example 33 with Handle

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

the class AppearanceEditHandler method addControlPoint.

@Override
public void addControlPoint() {
    Selection sel = canvas.getSelection();
    Handle handle = sel.getSelectedHandle();
    canvas.doAction(new ModelInsertHandleAction(canvas.getModel(), handle));
}
Also used : ModelInsertHandleAction(com.cburch.draw.actions.ModelInsertHandleAction) Selection(com.cburch.draw.canvas.Selection) Handle(com.cburch.draw.model.Handle)

Example 34 with Handle

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

the class AppearanceEditHandler method removeControlPoint.

@Override
public void removeControlPoint() {
    Selection sel = canvas.getSelection();
    Handle handle = sel.getSelectedHandle();
    canvas.doAction(new ModelDeleteHandleAction(canvas.getModel(), handle));
}
Also used : ModelDeleteHandleAction(com.cburch.draw.actions.ModelDeleteHandleAction) Selection(com.cburch.draw.canvas.Selection) Handle(com.cburch.draw.model.Handle)

Example 35 with Handle

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

the class Selection method modelChanged.

void modelChanged(CanvasModelEvent event) {
    int action = event.getAction();
    switch(action) {
        case CanvasModelEvent.ACTION_REMOVED:
            Collection<? extends CanvasObject> affected = event.getAffected();
            if (affected != null) {
                selected.removeAll(affected);
                suppressed.keySet().removeAll(affected);
                Handle h = selectedHandle;
                if (h != null && affected.contains(h.getObject())) {
                    setHandleSelected(null);
                }
            }
            break;
        case CanvasModelEvent.ACTION_HANDLE_DELETED:
            if (event.getHandle().equals(selectedHandle)) {
                setHandleSelected(null);
            }
            break;
        case CanvasModelEvent.ACTION_HANDLE_MOVED:
            HandleGesture gesture = event.getHandleGesture();
            if (gesture.getHandle().equals(selectedHandle)) {
                setHandleSelected(gesture.getResultingHandle());
            }
            break;
        default:
            break;
    }
}
Also used : HandleGesture(com.cburch.draw.model.HandleGesture) 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