Search in sources :

Example 96 with Bounds

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

the class InstanceTextField method getTextCaret.

public Caret getTextCaret(ComponentUserEvent event) {
    canvas = event.getCanvas();
    Graphics g = canvas.getGraphics();
    // and if it is empty, just return a caret at its beginning
    if (field == null)
        createField(comp.getAttributeSet(), "");
    String text = field.getText();
    if (text == null || text.equals(""))
        return field.getCaret(g, 0);
    Bounds bds = field.getBounds(g);
    if (bds.getWidth() < 4 || bds.getHeight() < 4) {
        Location loc = comp.getLocation();
        bds = bds.add(Bounds.create(loc).expand(2));
    }
    int x = event.getX();
    int y = event.getY();
    if (bds.contains(x, y))
        return field.getCaret(g, x, y);
    else
        return null;
}
Also used : Graphics(java.awt.Graphics) Bounds(com.cburch.logisim.data.Bounds) Location(com.cburch.logisim.data.Location)

Example 97 with Bounds

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

the class InstanceComponent method expose.

public void expose(ComponentDrawContext context) {
    Bounds b = bounds;
    context.getDestination().repaint(b.getX(), b.getY(), b.getWidth(), b.getHeight());
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Example 98 with Bounds

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

the class RectangularTool method toolDeselected.

@Override
public void toolDeselected(Canvas canvas) {
    Bounds bds = currentBounds;
    active = false;
    repaintArea(canvas, bds);
}
Also used : Bounds(com.cburch.logisim.data.Bounds)

Example 99 with Bounds

use of com.cburch.logisim.data.Bounds 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 100 with Bounds

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

the class Circuit method getBounds.

public Bounds getBounds() {
    Bounds wireBounds = wires.getWireBounds();
    Iterator<Component> it = comps.iterator();
    if (!it.hasNext())
        return wireBounds;
    Component first = it.next();
    Bounds firstBounds = first.getBounds();
    int xMin = firstBounds.getX();
    int yMin = firstBounds.getY();
    int xMax = xMin + firstBounds.getWidth();
    int yMax = yMin + firstBounds.getHeight();
    while (it.hasNext()) {
        Component c = it.next();
        Bounds bds = c.getBounds();
        int x0 = bds.getX();
        int x1 = x0 + bds.getWidth();
        int y0 = bds.getY();
        int y1 = y0 + bds.getHeight();
        if (x0 < xMin)
            xMin = x0;
        if (x1 > xMax)
            xMax = x1;
        if (y0 < yMin)
            yMin = y0;
        if (y1 > yMax)
            yMax = y1;
    }
    Bounds compBounds = Bounds.create(xMin, yMin, xMax - xMin, yMax - yMin);
    if (wireBounds.getWidth() == 0 || wireBounds.getHeight() == 0) {
        return compBounds;
    } else {
        return compBounds.add(wireBounds);
    }
}
Also used : Bounds(com.cburch.logisim.data.Bounds) Component(com.cburch.logisim.comp.Component)

Aggregations

Bounds (com.cburch.logisim.data.Bounds)199 Graphics (java.awt.Graphics)71 Direction (com.cburch.logisim.data.Direction)29 Location (com.cburch.logisim.data.Location)29 BitWidth (com.cburch.logisim.data.BitWidth)20 Graphics2D (java.awt.Graphics2D)20 Font (java.awt.Font)19 Component (com.cburch.logisim.comp.Component)14 Color (java.awt.Color)14 FontMetrics (java.awt.FontMetrics)12 Value (com.cburch.logisim.data.Value)9 Circuit (com.cburch.logisim.circuit.Circuit)7 Port (com.cburch.logisim.instance.Port)7 Instance (com.cburch.logisim.instance.Instance)6 InstanceDataSingleton (com.cburch.logisim.instance.InstanceDataSingleton)6 Handle (com.cburch.draw.model.Handle)5 RadixOption (com.cburch.logisim.circuit.RadixOption)5 CanvasObject (com.cburch.draw.model.CanvasObject)3 Wire (com.cburch.logisim.circuit.Wire)3 ComponentFactory (com.cburch.logisim.comp.ComponentFactory)3