use of com.cburch.draw.model.Handle 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.draw.model.Handle in project logisim-evolution by reds-heig.
the class Line method moveHandle.
@Override
public Handle moveHandle(HandleGesture gesture) {
Handle h = gesture.getHandle();
int dx = gesture.getDeltaX();
int dy = gesture.getDeltaY();
Handle ret = null;
if (h.isAt(x0, y0)) {
x0 += dx;
y0 += dy;
ret = new Handle(this, x0, y0);
}
if (h.isAt(x1, y1)) {
x1 += dx;
y1 += dy;
ret = new Handle(this, x1, y1);
}
bounds = Bounds.create(x0, y0, 0, 0).add(x1, y1);
return ret;
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method insertHandle.
@Override
public void insertHandle(Handle desired, Handle previous) {
Location loc = desired.getLocation();
Handle[] hs = handles;
Handle prev;
if (previous == null) {
PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc, closed, hs);
prev = result.getPreviousHandle();
} else {
prev = previous;
}
Handle[] is = new Handle[hs.length + 1];
boolean inserted = false;
for (int i = 0; i < hs.length; i++) {
if (inserted) {
is[i + 1] = hs[i];
} else if (hs[i].equals(prev)) {
inserted = true;
is[i] = hs[i];
is[i + 1] = desired;
} else {
is[i] = hs[i];
}
}
if (!inserted) {
throw new IllegalArgumentException("no such handle");
}
setHandles(is);
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method moveHandle.
@Override
public Handle moveHandle(HandleGesture gesture) {
List<Handle> hs = getHandles(gesture);
Handle[] is = new Handle[hs.size()];
Handle ret = null;
int i = -1;
for (Handle h : hs) {
i++;
is[i] = h;
}
setHandles(is);
return ret;
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method clone.
/**
* Clone function taken from Cornell's version of Logisim:
* http://www.cs.cornell.edu/courses/cs3410/2015sp/
*/
public Poly clone() {
Poly ret = (Poly) super.clone();
Handle[] hs = this.handles.clone();
for (int i = 0, n = hs.length; i < n; ++i) {
Handle oldHandle = hs[i];
hs[i] = new Handle(ret, oldHandle.getX(), oldHandle.getY());
}
ret.handles = hs;
return (ret);
}
Aggregations