Search in sources :

Example 91 with Location

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

the class PolyTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
        mouseDown = false;
        int size = locations.size();
        if (size >= 3) {
            Location first = locations.get(0);
            Location last = locations.get(size - 1);
            if (first.manhattanDistanceTo(last) <= CLOSE_TOLERANCE) {
                locations.remove(size - 1);
                CanvasObject add = commit(canvas);
                canvas.toolGestureComplete(this, add);
            }
        }
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Location(com.cburch.logisim.data.Location)

Example 92 with Location

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

the class PolyTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
    int mx = e.getX();
    int my = e.getY();
    lastMouseX = mx;
    lastMouseY = my;
    int mods = e.getModifiersEx();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        mx = canvas.snapX(mx);
        my = canvas.snapY(my);
    }
    if (active && e.getClickCount() > 1) {
        CanvasObject add = commit(canvas);
        canvas.toolGestureComplete(this, add);
        return;
    }
    Location loc = Location.create(mx, my);
    List<Location> locs = locations;
    if (!active) {
        locs.clear();
        locs.add(loc);
    }
    locs.add(loc);
    mouseDown = true;
    active = canvas.getModel() != null;
    repaintArea(canvas);
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) Location(com.cburch.logisim.data.Location)

Example 93 with Location

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

the class RectangularTool method computeBounds.

private Bounds computeBounds(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    if (!active) {
        return Bounds.EMPTY_BOUNDS;
    } else {
        Location start = dragStart;
        int x0 = start.getX();
        int y0 = start.getY();
        int x1 = mx;
        int y1 = my;
        if (x0 == x1 && y0 == y1) {
            return Bounds.EMPTY_BOUNDS;
        }
        boolean ctrlDown = (mods & MouseEvent.CTRL_DOWN_MASK) != 0;
        if (ctrlDown) {
            x0 = canvas.snapX(x0);
            y0 = canvas.snapY(y0);
            x1 = canvas.snapX(x1);
            y1 = canvas.snapY(y1);
        }
        boolean altDown = (mods & MouseEvent.ALT_DOWN_MASK) != 0;
        boolean shiftDown = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
        if (altDown) {
            if (shiftDown) {
                int r = Math.min(Math.abs(x0 - x1), Math.abs(y0 - y1));
                x1 = x0 + r;
                y1 = y0 + r;
                x0 -= r;
                y0 -= r;
            } else {
                x0 = x0 - (x1 - x0);
                y0 = y0 - (y1 - y0);
            }
        } else {
            if (shiftDown) {
                int r = Math.min(Math.abs(x0 - x1), Math.abs(y0 - y1));
                y1 = y1 < y0 ? y0 - r : y0 + r;
                x1 = x1 < x0 ? x0 - r : x0 + r;
            }
        }
        int x = x0;
        int y = y0;
        int w = x1 - x0;
        int h = y1 - y0;
        if (w < 0) {
            x = x1;
            w = -w;
        }
        if (h < 0) {
            y = y1;
            h = -h;
        }
        return Bounds.create(x, y, w, h);
    }
}
Also used : Location(com.cburch.logisim.data.Location)

Example 94 with Location

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

the class SelectTool method draw.

@Override
public void draw(Canvas canvas, Graphics g) {
    Selection selection = canvas.getSelection();
    int action = curAction;
    Location start = dragStart;
    Location end = dragEnd;
    HandleGesture gesture = null;
    boolean drawHandles;
    switch(action) {
        case MOVE_ALL:
            drawHandles = !dragEffective;
            break;
        case MOVE_HANDLE:
            drawHandles = !dragEffective;
            if (dragEffective)
                gesture = curGesture;
            break;
        default:
            drawHandles = true;
    }
    CanvasObject moveHandleObj = null;
    if (gesture != null)
        moveHandleObj = gesture.getHandle().getObject();
    if (drawHandles) {
        // unscale the coordinate system so that the stroke width isn't
        // scaled
        double zoom = 1.0;
        Graphics gCopy = g.create();
        if (gCopy instanceof Graphics2D) {
            zoom = canvas.getZoomFactor();
            if (zoom != 1.0) {
                ((Graphics2D) gCopy).scale(1.0 / zoom, 1.0 / zoom);
            }
        }
        GraphicsUtil.switchToWidth(gCopy, 1);
        int size = (int) Math.ceil(HANDLE_SIZE * Math.sqrt(zoom));
        int offs = size / 2;
        for (CanvasObject obj : selection.getSelected()) {
            List<Handle> handles;
            if (action == MOVE_HANDLE && obj == moveHandleObj) {
                handles = obj.getHandles(gesture);
            } else {
                handles = obj.getHandles(null);
            }
            for (Handle han : handles) {
                int x = han.getX();
                int y = han.getY();
                if (action == MOVE_ALL && dragEffective) {
                    Location delta = selection.getMovingDelta();
                    x += delta.getX();
                    y += delta.getY();
                }
                x = (int) Math.round(zoom * x);
                y = (int) Math.round(zoom * y);
                gCopy.clearRect(x - offs, y - offs, size, size);
                gCopy.drawRect(x - offs, y - offs, size, size);
            }
        }
        Handle selHandle = selection.getSelectedHandle();
        if (selHandle != null) {
            int x = selHandle.getX();
            int y = selHandle.getY();
            if (action == MOVE_ALL && dragEffective) {
                Location delta = selection.getMovingDelta();
                x += delta.getX();
                y += delta.getY();
            }
            x = (int) Math.round(zoom * x);
            y = (int) Math.round(zoom * y);
            int[] xs = { x - offs, x, x + offs, x };
            int[] ys = { y, y - offs, y, y + offs };
            gCopy.setColor(Color.WHITE);
            gCopy.fillPolygon(xs, ys, 4);
            gCopy.setColor(Color.BLACK);
            gCopy.drawPolygon(xs, ys, 4);
        }
    }
    switch(action) {
        case RECT_SELECT:
        case RECT_TOGGLE:
            if (dragEffective) {
                // find rectangle currently to show
                int x0 = start.getX();
                int y0 = start.getY();
                int x1 = end.getX();
                int y1 = end.getY();
                if (x1 < x0) {
                    int t = x0;
                    x0 = x1;
                    x1 = t;
                }
                if (y1 < y0) {
                    int t = y0;
                    y0 = y1;
                    y1 = t;
                }
                // make the region that's not being selected darker
                int w = canvas.getWidth();
                int h = canvas.getHeight();
                g.setColor(RECT_SELECT_BACKGROUND);
                g.fillRect(0, 0, w, y0);
                g.fillRect(0, y0, x0, y1 - y0);
                g.fillRect(x1, y0, w - x1, y1 - y0);
                g.fillRect(0, y1, w, h - y1);
                // now draw the rectangle
                g.setColor(Color.GRAY);
                g.drawRect(x0, y0, x1 - x0, y1 - y0);
            }
            break;
        default:
            break;
    }
}
Also used : Graphics(java.awt.Graphics) HandleGesture(com.cburch.draw.model.HandleGesture) CanvasObject(com.cburch.draw.model.CanvasObject) Selection(com.cburch.draw.canvas.Selection) Location(com.cburch.logisim.data.Location) Graphics2D(java.awt.Graphics2D) Handle(com.cburch.draw.model.Handle)

Example 95 with Location

use of com.cburch.logisim.data.Location 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)

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