Search in sources :

Example 21 with CanvasObject

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

the class RectangularTool method mouseReleased.

@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
    if (active) {
        final var oldBounds = currentBounds;
        final var bds = computeBounds(canvas, e.getX(), e.getY(), e.getModifiersEx());
        currentBounds = Bounds.EMPTY_BOUNDS;
        active = false;
        CanvasObject add = null;
        if (bds.getWidth() != 0 && bds.getHeight() != 0) {
            final var model = canvas.getModel();
            add = createShape(bds.getX(), bds.getY(), bds.getWidth(), bds.getHeight());
            canvas.doAction(new ModelAddAction(model, add));
            repaintArea(canvas, oldBounds.add(bds));
        }
        canvas.toolGestureComplete(this, add);
    }
}
Also used : CanvasObject(com.cburch.draw.model.CanvasObject) ModelAddAction(com.cburch.draw.actions.ModelAddAction)

Example 22 with CanvasObject

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

the class DrawingAttributeSet method applyTo.

public <E extends CanvasObject> E applyTo(E drawable) {
    AbstractCanvasObject d = (AbstractCanvasObject) drawable;
    // use a for(i...) loop since the attribute list may change as we go on
    for (var i = 0; i < d.getAttributes().size(); i++) {
        Attribute<?> attr = d.getAttributes().get(i);
        @SuppressWarnings("unchecked") Attribute<Object> a = (Attribute<Object>) attr;
        if (attr == DrawAttr.FILL_COLOR && this.containsAttribute(DrawAttr.TEXT_DEFAULT_FILL)) {
            d.setValue(a, this.getValue(DrawAttr.TEXT_DEFAULT_FILL));
        } else if (this.containsAttribute(a)) {
            d.setValue(a, this.getValue(a));
        }
    }
    return drawable;
}
Also used : Attribute(com.cburch.logisim.data.Attribute) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) AbstractCanvasObject(com.cburch.draw.model.AbstractCanvasObject) CanvasObject(com.cburch.draw.model.CanvasObject)

Example 23 with CanvasObject

use of com.cburch.draw.model.CanvasObject 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 24 with CanvasObject

use of com.cburch.draw.model.CanvasObject 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 25 with CanvasObject

use of com.cburch.draw.model.CanvasObject 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)

Aggregations

CanvasObject (com.cburch.draw.model.CanvasObject)45 Location (com.cburch.logisim.data.Location)15 ArrayList (java.util.ArrayList)13 Handle (com.cburch.draw.model.Handle)9 Selection (com.cburch.draw.canvas.Selection)8 ModelAddAction (com.cburch.draw.actions.ModelAddAction)7 Direction (com.cburch.logisim.data.Direction)5 HandleGesture (com.cburch.draw.model.HandleGesture)4 Poly (com.cburch.draw.shapes.Poly)4 Instance (com.cburch.logisim.instance.Instance)4 Map (java.util.Map)4 Rectangle (com.cburch.draw.shapes.Rectangle)3 HashMap (java.util.HashMap)3 AbstractCanvasObject (com.cburch.draw.model.AbstractCanvasObject)2 CanvasModel (com.cburch.draw.model.CanvasModel)2 Circuit (com.cburch.logisim.circuit.Circuit)2 AppearanceElement (com.cburch.logisim.circuit.appear.AppearanceElement)2 AppearancePort (com.cburch.logisim.circuit.appear.AppearancePort)2 Attribute (com.cburch.logisim.data.Attribute)2 Bounds (com.cburch.logisim.data.Bounds)2