use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class LineTool method updateMouse.
private void updateMouse(Canvas canvas, int mx, int my, int mods) {
if (active) {
boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
Location newEnd;
if (shift) {
newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
} else {
newEnd = Location.create(mx, my);
}
if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
int x = newEnd.getX();
int y = newEnd.getY();
x = canvas.snapX(x);
y = canvas.snapY(y);
newEnd = Location.create(x, y);
}
if (!newEnd.equals(mouseEnd)) {
mouseEnd = newEnd;
repaintArea(canvas);
}
}
lastMouseX = mx;
lastMouseY = my;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PolyTool method updateMouse.
private void updateMouse(Canvas canvas, int mx, int my, int mods) {
lastMouseX = mx;
lastMouseY = my;
if (active) {
int index = locations.size() - 1;
Location last = locations.get(index);
Location newLast;
if ((mods & MouseEvent.SHIFT_DOWN_MASK) != 0 && index > 0) {
Location nextLast = locations.get(index - 1);
newLast = LineUtil.snapTo8Cardinals(nextLast, mx, my);
} else {
newLast = Location.create(mx, my);
}
if ((mods & MouseEvent.CTRL_DOWN_MASK) != 0) {
int lastX = newLast.getX();
int lastY = newLast.getY();
lastX = canvas.snapX(lastX);
lastY = canvas.snapY(lastY);
newLast = Location.create(lastX, lastY);
}
if (!newLast.equals(last)) {
locations.set(index, newLast);
repaintArea(canvas);
}
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PolyTool method commit.
private CanvasObject commit(Canvas canvas) {
if (!active)
return null;
CanvasObject add = null;
active = false;
List<Location> locs = locations;
for (int i = locs.size() - 2; i >= 0; i--) {
if (locs.get(i).equals(locs.get(i + 1)))
locs.remove(i);
}
if (locs.size() > 1) {
CanvasModel model = canvas.getModel();
add = new Poly(closed, locs);
canvas.doAction(new ModelAddAction(model, add));
repaintArea(canvas);
}
locs.clear();
return add;
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PolyTool method draw.
@Override
public void draw(Canvas canvas, Graphics g) {
if (active) {
g.setColor(Color.GRAY);
int size = locations.size();
int[] xs = new int[size];
int[] ys = new int[size];
for (int i = 0; i < size; i++) {
Location loc = locations.get(i);
xs[i] = loc.getX();
ys[i] = loc.getY();
}
g.drawPolyline(xs, ys, size);
int lastX = xs[xs.length - 1];
int lastY = ys[ys.length - 1];
g.fillOval(lastX - 2, lastY - 2, 4, 4);
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class RectangularTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, MouseEvent e) {
Location loc = Location.create(e.getX(), e.getY());
Bounds bds = Bounds.create(loc);
dragStart = loc;
lastMouseX = loc.getX();
lastMouseY = loc.getY();
active = canvas.getModel() != null;
repaintArea(canvas, bds);
}
Aggregations