Search in sources :

Example 51 with Location

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

the class LineTool method updateMouse.

private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    if (active) {
        boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
        Location newEnd;
        if (shift) {
            newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
        } else {
            newEnd = Location.create(mx, my);
        }
        if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
            int x = newEnd.getX();
            int y = newEnd.getY();
            x = canvas.snapX(x);
            y = canvas.snapY(y);
            newEnd = Location.create(x, y);
        }
        if (!newEnd.equals(mouseEnd)) {
            mouseEnd = newEnd;
            repaintArea(canvas);
        }
    }
    lastMouseX = mx;
    lastMouseY = my;
}
Also used : Location(com.cburch.logisim.data.Location)

Example 52 with Location

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

the class PolyTool method updateMouse.

private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    lastMouseX = mx;
    lastMouseY = my;
    if (active) {
        int index = locations.size() - 1;
        Location last = locations.get(index);
        Location newLast;
        if ((mods & MouseEvent.SHIFT_DOWN_MASK) != 0 && index > 0) {
            Location nextLast = locations.get(index - 1);
            newLast = LineUtil.snapTo8Cardinals(nextLast, mx, my);
        } else {
            newLast = Location.create(mx, my);
        }
        if ((mods & MouseEvent.CTRL_DOWN_MASK) != 0) {
            int lastX = newLast.getX();
            int lastY = newLast.getY();
            lastX = canvas.snapX(lastX);
            lastY = canvas.snapY(lastY);
            newLast = Location.create(lastX, lastY);
        }
        if (!newLast.equals(last)) {
            locations.set(index, newLast);
            repaintArea(canvas);
        }
    }
}
Also used : Location(com.cburch.logisim.data.Location)

Example 53 with Location

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

the class PolyTool method commit.

private CanvasObject commit(Canvas canvas) {
    if (!active)
        return null;
    CanvasObject add = null;
    active = false;
    List<Location> locs = locations;
    for (int i = locs.size() - 2; i >= 0; i--) {
        if (locs.get(i).equals(locs.get(i + 1)))
            locs.remove(i);
    }
    if (locs.size() > 1) {
        CanvasModel model = canvas.getModel();
        add = new Poly(closed, locs);
        canvas.doAction(new ModelAddAction(model, add));
        repaintArea(canvas);
    }
    locs.clear();
    return add;
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ModelAddAction(com.cburch.draw.actions.ModelAddAction) CanvasModel(com.cburch.draw.model.CanvasModel) Poly(com.cburch.draw.shapes.Poly) Location(com.cburch.logisim.data.Location)

Example 54 with Location

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

the class PolyTool method draw.

@Override
public void draw(Canvas canvas, Graphics g) {
    if (active) {
        g.setColor(Color.GRAY);
        int size = locations.size();
        int[] xs = new int[size];
        int[] ys = new int[size];
        for (int i = 0; i < size; i++) {
            Location loc = locations.get(i);
            xs[i] = loc.getX();
            ys[i] = loc.getY();
        }
        g.drawPolyline(xs, ys, size);
        int lastX = xs[xs.length - 1];
        int lastY = ys[ys.length - 1];
        g.fillOval(lastX - 2, lastY - 2, 4, 4);
    }
}
Also used : Location(com.cburch.logisim.data.Location)

Example 55 with Location

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

the class RectangularTool method mousePressed.

@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
    Location loc = Location.create(e.getX(), e.getY());
    Bounds bds = Bounds.create(loc);
    dragStart = loc;
    lastMouseX = loc.getX();
    lastMouseY = loc.getY();
    active = canvas.getModel() != null;
    repaintArea(canvas, bds);
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

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