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;
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations