use of com.cburch.draw.shapes.Curve in project logisim-evolution by reds-heig.
the class DefaultAppearance method old_build.
private static List<CanvasObject> old_build(Collection<Instance> pins) {
Map<Direction, List<Instance>> edge;
edge = new HashMap<Direction, List<Instance>>();
edge.put(Direction.NORTH, new ArrayList<Instance>());
edge.put(Direction.SOUTH, new ArrayList<Instance>());
edge.put(Direction.EAST, new ArrayList<Instance>());
edge.put(Direction.WEST, new ArrayList<Instance>());
for (Instance pin : pins) {
Direction pinFacing = pin.getAttributeValue(StdAttr.FACING);
Direction pinEdge = pinFacing.reverse();
List<Instance> e = edge.get(pinEdge);
e.add(pin);
}
for (Map.Entry<Direction, List<Instance>> entry : edge.entrySet()) {
sortPinList(entry.getValue(), entry.getKey());
}
int numNorth = edge.get(Direction.NORTH).size();
int numSouth = edge.get(Direction.SOUTH).size();
int numEast = edge.get(Direction.EAST).size();
int numWest = edge.get(Direction.WEST).size();
int maxVert = Math.max(numNorth, numSouth);
int maxHorz = Math.max(numEast, numWest);
int offsNorth = computeOffset(numNorth, numSouth, maxHorz);
int offsSouth = computeOffset(numSouth, numNorth, maxHorz);
int offsEast = computeOffset(numEast, numWest, maxVert);
int offsWest = computeOffset(numWest, numEast, maxVert);
int width = computeDimension(maxVert, maxHorz);
int height = computeDimension(maxHorz, maxVert);
// compute position of anchor relative to top left corner of box
int ax;
int ay;
if (numEast > 0) {
// anchor is on east side
ax = width;
ay = offsEast;
} else if (numNorth > 0) {
// anchor is on north side
ax = offsNorth;
ay = 0;
} else if (numWest > 0) {
// anchor is on west side
ax = 0;
ay = offsWest;
} else if (numSouth > 0) {
// anchor is on south side
ax = offsSouth;
ay = height;
} else {
// anchor is top left corner
ax = 0;
ay = 0;
}
// place rectangle so anchor is on the grid
int rx = OFFS + (9 - (ax + 9) % 10);
int ry = OFFS + (9 - (ay + 9) % 10);
Location e0 = Location.create(rx + (width - 8) / 2, ry + 1);
Location e1 = Location.create(rx + (width + 8) / 2, ry + 1);
Location ct = Location.create(rx + width / 2, ry + 11);
Curve notch = new Curve(e0, e1, ct);
notch.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
notch.setValue(DrawAttr.STROKE_COLOR, Color.GRAY);
Rectangle rect = new Rectangle(rx, ry, width, height);
rect.setValue(DrawAttr.STROKE_WIDTH, Integer.valueOf(2));
List<CanvasObject> ret = new ArrayList<CanvasObject>();
ret.add(notch);
ret.add(rect);
placePins(ret, edge.get(Direction.WEST), rx, ry + offsWest, 0, 10);
placePins(ret, edge.get(Direction.EAST), rx + width, ry + offsEast, 0, 10);
placePins(ret, edge.get(Direction.NORTH), rx + offsNorth, ry, 10, 0);
placePins(ret, edge.get(Direction.SOUTH), rx + offsSouth, ry + height, 10, 0);
ret.add(new AppearanceAnchor(Location.create(rx + ax, ry + ay)));
return ret;
}
use of com.cburch.draw.shapes.Curve in project logisim-evolution by reds-heig.
the class CurveTool method mouseReleased.
@Override
public void mouseReleased(Canvas canvas, MouseEvent e) {
Curve c = updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
mouseDown = false;
if (state == CONTROL_DRAG) {
if (c != null) {
attrs.applyTo(c);
CanvasModel model = canvas.getModel();
canvas.doAction(new ModelAddAction(model, c));
canvas.toolGestureComplete(this, c);
}
state = BEFORE_CREATION;
}
repaintArea(canvas);
}
use of com.cburch.draw.shapes.Curve in project logisim-evolution by reds-heig.
the class CurveTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
int mx = e.getX();
int my = e.getY();
lastMouseX = mx;
lastMouseY = my;
mouseDown = true;
int mods = e.getModifiersEx();
if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
mx = canvas.snapX(mx);
my = canvas.snapY(my);
}
switch(state) {
case BEFORE_CREATION:
case CONTROL_DRAG:
end0 = Location.create(mx, my);
end1 = end0;
state = ENDPOINT_DRAG;
break;
case ENDPOINT_DRAG:
curCurve = new Curve(end0, end1, Location.create(mx, my));
state = CONTROL_DRAG;
break;
default:
break;
}
repaintArea(canvas);
}
use of com.cburch.draw.shapes.Curve in project logisim-evolution by reds-heig.
the class CurveTool method updateMouse.
private Curve updateMouse(Canvas canvas, int mx, int my, int mods) {
lastMouseX = mx;
lastMouseY = my;
boolean shiftDown = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
boolean ctrlDown = (mods & MouseEvent.CTRL_DOWN_MASK) != 0;
boolean altDown = (mods & MouseEvent.ALT_DOWN_MASK) != 0;
Curve ret = null;
switch(state) {
case ENDPOINT_DRAG:
if (mouseDown) {
if (shiftDown) {
Location p = LineUtil.snapTo8Cardinals(end0, mx, my);
mx = p.getX();
my = p.getY();
}
if (ctrlDown) {
mx = canvas.snapX(mx);
my = canvas.snapY(my);
}
end1 = Location.create(mx, my);
}
break;
case CONTROL_DRAG:
if (mouseDown) {
int cx = mx;
int cy = my;
if (ctrlDown) {
cx = canvas.snapX(cx);
cy = canvas.snapY(cy);
}
if (shiftDown) {
double x0 = end0.getX();
double y0 = end0.getY();
double x1 = end1.getX();
double y1 = end1.getY();
double midx = (x0 + x1) / 2;
double midy = (y0 + y1) / 2;
double dx = x1 - x0;
double dy = y1 - y0;
double[] p = LineUtil.nearestPointInfinite(cx, cy, midx, midy, midx - dy, midy + dx);
cx = (int) Math.round(p[0]);
cy = (int) Math.round(p[1]);
}
if (altDown) {
double[] e0 = { end0.getX(), end0.getY() };
double[] e1 = { end1.getX(), end1.getY() };
double[] mid = { cx, cy };
double[] ct = CurveUtil.interpolate(e0, e1, mid);
cx = (int) Math.round(ct[0]);
cy = (int) Math.round(ct[1]);
}
ret = new Curve(end0, end1, Location.create(cx, cy));
curCurve = ret;
}
break;
default:
break;
}
return ret;
}
Aggregations