Search in sources :

Example 21 with Handle

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

the class SelectTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    beforePressSelection = null;
    beforePressHandle = null;
    setMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
    CanvasModel model = canvas.getModel();
    Selection selection = canvas.getSelection();
    Set<CanvasObject> selected = selection.getSelected();
    int action = curAction;
    curAction = IDLE;
    if (!dragEffective) {
        Location loc = dragEnd;
        CanvasObject o = getObjectAt(model, loc.getX(), loc.getY(), false);
        if (o != null) {
            Handle han = o.canDeleteHandle(loc);
            if (han != null) {
                selection.setHandleSelected(han);
            } else {
                han = o.canInsertHandle(loc);
                if (han != null) {
                    selection.setHandleSelected(han);
                }
            }
        }
    }
    Location start = dragStart;
    int x1 = e.getX();
    int y1 = e.getY();
    switch(action) {
        case MOVE_ALL:
            Location moveDelta = selection.getMovingDelta();
            if (dragEffective && !moveDelta.equals(Location.create(0, 0))) {
                canvas.doAction(new ModelTranslateAction(model, selected, moveDelta.getX(), moveDelta.getY()));
            }
            break;
        case MOVE_HANDLE:
            HandleGesture gesture = curGesture;
            curGesture = null;
            if (dragEffective && gesture != null) {
                ModelMoveHandleAction act;
                act = new ModelMoveHandleAction(model, gesture);
                canvas.doAction(act);
                Handle result = act.getNewHandle();
                if (result != null) {
                    Handle h = result.getObject().canDeleteHandle(result.getLocation());
                    selection.setHandleSelected(h);
                }
            }
            break;
        case RECT_SELECT:
            if (dragEffective) {
                Bounds bds = Bounds.create(start).add(x1, y1);
                selection.setSelected(canvas.getModel().getObjectsIn(bds), true);
            } else {
                CanvasObject clicked;
                clicked = getObjectAt(model, start.getX(), start.getY(), true);
                if (clicked != null) {
                    selection.clearSelected();
                    selection.setSelected(clicked, true);
                }
            }
            break;
        case RECT_TOGGLE:
            if (dragEffective) {
                Bounds bds = Bounds.create(start).add(x1, y1);
                selection.toggleSelected(canvas.getModel().getObjectsIn(bds));
            } else {
                CanvasObject clicked;
                clicked = getObjectAt(model, start.getX(), start.getY(), true);
                selection.setSelected(clicked, !selected.contains(clicked));
            }
            break;
        default:
            break;
    }
    selection.clearDrawsSuppressed();
    repaintArea(canvas);
}
Also used : HandleGesture(com.cburch.draw.model.HandleGesture) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) ModelTranslateAction(com.cburch.draw.actions.ModelTranslateAction) Bounds(com.cburch.logisim.data.Bounds) CanvasModel(com.cburch.draw.model.CanvasModel) ModelMoveHandleAction(com.cburch.draw.actions.ModelMoveHandleAction) Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 22 with Handle

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

the class Line method moveHandle.

@Override
public Handle moveHandle(HandleGesture gesture) {
    Handle h = gesture.getHandle();
    int dx = gesture.getDeltaX();
    int dy = gesture.getDeltaY();
    Handle ret = null;
    if (h.isAt(x0, y0)) {
        x0 += dx;
        y0 += dy;
        ret = new Handle(this, x0, y0);
    }
    if (h.isAt(x1, y1)) {
        x1 += dx;
        y1 += dy;
        ret = new Handle(this, x1, y1);
    }
    bounds = Bounds.create(x0, y0, 0, 0).add(x1, y1);
    return ret;
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 23 with Handle

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

the class Poly method insertHandle.

@Override
public void insertHandle(Handle desired, Handle previous) {
    Location loc = desired.getLocation();
    Handle[] hs = handles;
    Handle prev;
    if (previous == null) {
        PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc, closed, hs);
        prev = result.getPreviousHandle();
    } else {
        prev = previous;
    }
    Handle[] is = new Handle[hs.length + 1];
    boolean inserted = false;
    for (int i = 0; i < hs.length; i++) {
        if (inserted) {
            is[i + 1] = hs[i];
        } else if (hs[i].equals(prev)) {
            inserted = true;
            is[i] = hs[i];
            is[i + 1] = desired;
        } else {
            is[i] = hs[i];
        }
    }
    if (!inserted) {
        throw new IllegalArgumentException("no such handle");
    }
    setHandles(is);
}
Also used : Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 24 with Handle

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

the class Poly method moveHandle.

@Override
public Handle moveHandle(HandleGesture gesture) {
    List<Handle> hs = getHandles(gesture);
    Handle[] is = new Handle[hs.size()];
    Handle ret = null;
    int i = -1;
    for (Handle h : hs) {
        i++;
        is[i] = h;
    }
    setHandles(is);
    return ret;
}
Also used : Handle(com.cburch.draw.model.Handle)

Example 25 with Handle

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

the class Poly method clone.

/**
 * Clone function taken from Cornell's version of Logisim:
 * http://www.cs.cornell.edu/courses/cs3410/2015sp/
 */
public Poly clone() {
    Poly ret = (Poly) super.clone();
    Handle[] hs = this.handles.clone();
    for (int i = 0, n = hs.length; i < n; ++i) {
        Handle oldHandle = hs[i];
        hs[i] = new Handle(ret, oldHandle.getX(), oldHandle.getY());
    }
    ret.handles = hs;
    return (ret);
}
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