use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Line method paint.
@Override
public void paint(Graphics g, HandleGesture gesture) {
if (setForStroke(g)) {
int x0 = this.x0;
int y0 = this.y0;
int x1 = this.x1;
int y1 = this.y1;
Handle h = gesture.getHandle();
if (h.isAt(x0, y0)) {
x0 += gesture.getDeltaX();
y0 += gesture.getDeltaY();
}
if (h.isAt(x1, y1)) {
x1 += gesture.getDeltaX();
y1 += gesture.getDeltaY();
}
g.drawLine(x0, y0, x1, y1);
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method getPath.
private GeneralPath getPath() {
GeneralPath p = path;
if (p == null) {
p = new GeneralPath();
Handle[] hs = handles;
if (hs.length > 0) {
boolean first = true;
for (Handle h : hs) {
if (first) {
p.moveTo(h.getX(), h.getY());
first = false;
} else {
p.lineTo(h.getX(), h.getY());
}
}
}
path = p;
}
return p;
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method getHandles.
@Override
public List<Handle> getHandles(HandleGesture gesture) {
Handle[] hs = handles;
if (gesture == null) {
return UnmodifiableList.create(hs);
} else {
Handle g = gesture.getHandle();
Handle[] ret = new Handle[hs.length];
for (int i = 0, n = hs.length; i < n; i++) {
Handle h = hs[i];
if (h.equals(g)) {
int x = h.getX() + gesture.getDeltaX();
int y = h.getY() + gesture.getDeltaY();
Location r;
if (gesture.isShiftDown()) {
Location prev = hs[(i + n - 1) % n].getLocation();
Location next = hs[(i + 1) % n].getLocation();
if (!closed) {
if (i == 0)
prev = null;
if (i == n - 1)
next = null;
}
if (prev == null) {
r = LineUtil.snapTo8Cardinals(next, x, y);
} else if (next == null) {
r = LineUtil.snapTo8Cardinals(prev, x, y);
} else {
Location to = Location.create(x, y);
Location a = LineUtil.snapTo8Cardinals(prev, x, y);
Location b = LineUtil.snapTo8Cardinals(next, x, y);
int ad = a.manhattanDistanceTo(to);
int bd = b.manhattanDistanceTo(to);
r = ad < bd ? a : b;
}
} else {
r = Location.create(x, y);
}
ret[i] = new Handle(this, r);
} else {
ret[i] = h;
}
}
return UnmodifiableList.create(ret);
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method paint.
@Override
public void paint(Graphics g, HandleGesture gesture) {
List<Handle> hs = getHandles(gesture);
int[] xs = new int[hs.size()];
int[] ys = new int[hs.size()];
int i = -1;
for (Handle h : hs) {
i++;
xs[i] = h.getX();
ys[i] = h.getY();
}
if (setForFill(g)) {
g.fillPolygon(xs, ys, xs.length);
}
if (setForStroke(g)) {
if (closed)
g.drawPolygon(xs, ys, xs.length);
else
g.drawPolyline(xs, ys, xs.length);
}
}
use of com.cburch.draw.model.Handle in project logisim-evolution by reds-heig.
the class Poly method deleteHandle.
@Override
public Handle deleteHandle(Handle handle) {
Handle[] hs = handles;
int n = hs.length;
Handle[] is = new Handle[n - 1];
Handle previous = null;
boolean deleted = false;
for (int i = 0; i < n; i++) {
if (deleted) {
is[i - 1] = hs[i];
} else if (hs[i].equals(handle)) {
if (previous == null) {
previous = hs[n - 1];
}
deleted = true;
} else {
previous = hs[i];
is[i] = hs[i];
}
}
setHandles(is);
return previous;
}
Aggregations