use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class PolyUtil method getClosestPoint.
public static ClosestResult getClosestPoint(Location loc, boolean closed, Handle[] hs) {
int xq = loc.getX();
int yq = loc.getY();
ClosestResult ret = new ClosestResult();
ret.dist = Double.MAX_VALUE;
if (hs.length > 0) {
Handle h0 = hs[0];
int x0 = h0.getX();
int y0 = h0.getY();
int stop = closed ? hs.length : (hs.length - 1);
for (int i = 0; i < stop; i++) {
Handle h1 = hs[(i + 1) % hs.length];
int x1 = h1.getX();
int y1 = h1.getY();
double d = LineUtil.ptDistSqSegment(x0, y0, x1, y1, xq, yq);
if (d < ret.dist) {
ret.dist = d;
ret.prevHandle = h0;
ret.nextHandle = h1;
}
h0 = h1;
x0 = x1;
y0 = y1;
}
}
if (ret.dist == Double.MAX_VALUE) {
return null;
} else {
Handle h0 = ret.prevHandle;
Handle h1 = ret.nextHandle;
double[] p = LineUtil.nearestPointSegment(xq, yq, h0.getX(), h0.getY(), h1.getX(), h1.getY());
ret.loc = Location.create((int) Math.round(p[0]), (int) Math.round(p[1]));
return ret;
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Text method getHandles.
public List<Handle> getHandles() {
Bounds bds = label.getBounds();
int x = bds.getX();
int y = bds.getY();
int w = bds.getWidth();
int h = bds.getHeight();
return UnmodifiableList.create(new Handle[] { new Handle(this, x, y), new Handle(this, x + w, y), new Handle(this, x + w, y + h), new Handle(this, x, y + h) });
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method addControlPoint.
@Override
public void addControlPoint() {
Selection sel = canvas.getSelection();
Handle handle = sel.getSelectedHandle();
canvas.doAction(new ModelInsertHandleAction(canvas.getModel(), handle));
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class AppearanceEditHandler method removeControlPoint.
@Override
public void removeControlPoint() {
Selection sel = canvas.getSelection();
Handle handle = sel.getSelectedHandle();
canvas.doAction(new ModelDeleteHandleAction(canvas.getModel(), handle));
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Selection method modelChanged.
void modelChanged(CanvasModelEvent event) {
int action = event.getAction();
switch(action) {
case CanvasModelEvent.ACTION_REMOVED:
Collection<? extends CanvasObject> affected = event.getAffected();
if (affected != null) {
selected.removeAll(affected);
suppressed.keySet().removeAll(affected);
Handle h = selectedHandle;
if (h != null && affected.contains(h.getObject())) {
setHandleSelected(null);
}
}
break;
case CanvasModelEvent.ACTION_HANDLE_DELETED:
if (event.getHandle().equals(selectedHandle)) {
setHandleSelected(null);
}
break;
case CanvasModelEvent.ACTION_HANDLE_MOVED:
HandleGesture gesture = event.getHandleGesture();
if (gesture.getHandle().equals(selectedHandle)) {
setHandleSelected(gesture.getResultingHandle());
}
break;
default:
break;
}
}
Aggregations