Search in sources :

Example 1 with Handle

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

the class AppearanceEditHandler method computeEnabled.

@Override
public void computeEnabled() {
    Project proj = canvas.getProject();
    Circuit circ = canvas.getCircuit();
    Selection sel = canvas.getSelection();
    boolean selEmpty = sel.isEmpty();
    boolean canChange = proj.getLogisimFile().contains(circ);
    boolean clipExists = !Clipboard.isEmpty();
    boolean selHasRemovable = false;
    for (CanvasObject o : sel.getSelected()) {
        if (!(o instanceof AppearanceElement)) {
            selHasRemovable = true;
        }
    }
    boolean canRaise;
    boolean canLower;
    if (!selEmpty && canChange) {
        Map<CanvasObject, Integer> zs = ZOrder.getZIndex(sel.getSelected(), canvas.getModel());
        int zmin = Integer.MAX_VALUE;
        int zmax = Integer.MIN_VALUE;
        int count = 0;
        for (Map.Entry<CanvasObject, Integer> entry : zs.entrySet()) {
            if (!(entry.getKey() instanceof AppearanceElement)) {
                count++;
                int z = entry.getValue().intValue();
                if (z < zmin)
                    zmin = z;
                if (z > zmax)
                    zmax = z;
            }
        }
        int maxPoss = AppearanceCanvas.getMaxIndex(canvas.getModel());
        if (count > 0 && count <= maxPoss) {
            canRaise = zmin <= maxPoss - count;
            canLower = zmax >= count;
        } else {
            canRaise = false;
            canLower = false;
        }
    } else {
        canRaise = false;
        canLower = false;
    }
    boolean canAddCtrl = false;
    boolean canRemCtrl = false;
    Handle handle = sel.getSelectedHandle();
    if (handle != null && canChange) {
        CanvasObject o = handle.getObject();
        canAddCtrl = o.canInsertHandle(handle.getLocation()) != null;
        canRemCtrl = o.canDeleteHandle(handle.getLocation()) != null;
    }
    setEnabled(LogisimMenuBar.CUT, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.COPY, !selEmpty);
    setEnabled(LogisimMenuBar.PASTE, canChange && clipExists);
    setEnabled(LogisimMenuBar.DELETE, selHasRemovable && canChange);
    setEnabled(LogisimMenuBar.DUPLICATE, !selEmpty && canChange);
    setEnabled(LogisimMenuBar.SELECT_ALL, true);
    setEnabled(LogisimMenuBar.RAISE, canRaise);
    setEnabled(LogisimMenuBar.LOWER, canLower);
    setEnabled(LogisimMenuBar.RAISE_TOP, canRaise);
    setEnabled(LogisimMenuBar.LOWER_BOTTOM, canLower);
    setEnabled(LogisimMenuBar.ADD_CONTROL, canAddCtrl);
    setEnabled(LogisimMenuBar.REMOVE_CONTROL, canRemCtrl);
}
Also used : Project(com.cburch.logisim.proj.Project) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) Circuit(com.cburch.logisim.circuit.Circuit) AppearanceElement(com.cburch.logisim.circuit.appear.AppearanceElement) Map(java.util.Map) Handle(com.cburch.draw.model.Handle)

Example 2 with Handle

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

the class AppearanceAnchor method getHandles.

@Override
public List<Handle> getHandles(HandleGesture gesture) {
    Location c = getLocation();
    Location end = c.translate(facing, RADIUS + INDICATOR_LENGTH);
    return UnmodifiableList.create(new Handle[] { new Handle(this, c), new Handle(this, end) });
}
Also used : Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 3 with Handle

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

the class AppearancePort method getHandles.

@Override
public List<Handle> getHandles(HandleGesture gesture) {
    Location loc = getLocation();
    int r = isInput() ? INPUT_RADIUS : OUTPUT_RADIUS;
    return UnmodifiableList.create(new Handle[] { new Handle(this, loc.translate(-r, -r)), new Handle(this, loc.translate(r, -r)), new Handle(this, loc.translate(r, r)), new Handle(this, loc.translate(-r, r)) });
}
Also used : Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 4 with Handle

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

the class SelectTool method setMouse.

private void setMouse(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
    boolean ctrl = (mods & InputEvent.CTRL_DOWN_MASK) != 0;
    Location newEnd = Location.create(mx, my);
    dragEnd = newEnd;
    Location start = dragStart;
    int dx = newEnd.getX() - start.getX();
    int dy = newEnd.getY() - start.getY();
    if (!dragEffective) {
        if (Math.abs(dx) + Math.abs(dy) > DRAG_TOLERANCE) {
            dragEffective = true;
        } else {
            return;
        }
    }
    switch(curAction) {
        case MOVE_HANDLE:
            HandleGesture gesture = curGesture;
            if (ctrl) {
                Handle h = gesture.getHandle();
                dx = canvas.snapX(h.getX() + dx) - h.getX();
                dy = canvas.snapY(h.getY() + dy) - h.getY();
            }
            curGesture = new HandleGesture(gesture.getHandle(), dx, dy, mods);
            canvas.getSelection().setHandleGesture(curGesture);
            break;
        case MOVE_ALL:
            if (ctrl) {
                int minX = Integer.MAX_VALUE;
                int minY = Integer.MAX_VALUE;
                for (CanvasObject o : canvas.getSelection().getSelected()) {
                    for (Handle handle : o.getHandles(null)) {
                        int x = handle.getX();
                        int y = handle.getY();
                        if (x < minX)
                            minX = x;
                        if (y < minY)
                            minY = y;
                    }
                }
                dx = canvas.snapX(minX + dx) - minX;
                dy = canvas.snapY(minY + dy) - minY;
            }
            if (shift) {
                if (Math.abs(dx) > Math.abs(dy)) {
                    dy = 0;
                } else {
                    dx = 0;
                }
            }
            canvas.getSelection().setMovingDelta(dx, dy);
            break;
        default:
            break;
    }
    repaintArea(canvas);
}
Also used : HandleGesture(com.cburch.draw.model.HandleGesture) CanvasObject(com.cburch.draw.model.CanvasObject) Location(com.cburch.logisim.data.Location) Handle(com.cburch.draw.model.Handle)

Example 5 with Handle

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

the class Line method getHandles.

@Override
public List<Handle> getHandles(HandleGesture gesture) {
    if (gesture == null) {
        return UnmodifiableList.create(new Handle[] { new Handle(this, x0, y0), new Handle(this, x1, y1) });
    } else {
        Handle h = gesture.getHandle();
        int dx = gesture.getDeltaX();
        int dy = gesture.getDeltaY();
        Handle[] ret = new Handle[2];
        ret[0] = new Handle(this, h.isAt(x0, y0) ? Location.create(x0 + dx, y0 + dy) : Location.create(x0, y0));
        ret[1] = new Handle(this, h.isAt(x1, y1) ? Location.create(x1 + dx, y1 + dy) : Location.create(x1, y1));
        return UnmodifiableList.create(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