use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class Canvas method computeViewportContents.
private void computeViewportContents() {
Set<WidthIncompatibilityData> exceptions = proj.getCurrentCircuit().getWidthIncompatibilityData();
if (exceptions == null || exceptions.isEmpty()) {
viewport.setWidthMessage(null);
return;
}
Rectangle viewableBase;
Rectangle viewable;
if (canvasPane != null) {
viewableBase = canvasPane.getViewport().getViewRect();
} else {
Bounds bds = proj.getCurrentCircuit().getBounds();
viewableBase = new Rectangle(0, 0, bds.getWidth(), bds.getHeight());
}
double zoom = getZoomFactor();
if (zoom == 1.0) {
viewable = viewableBase;
} else {
viewable = new Rectangle((int) (viewableBase.x / zoom), (int) (viewableBase.y / zoom), (int) (viewableBase.width / zoom), (int) (viewableBase.height / zoom));
}
viewport.setWidthMessage(Strings.get("canvasWidthError") + (exceptions.size() == 1 ? "" : " (" + exceptions.size() + ")"));
for (WidthIncompatibilityData ex : exceptions) {
// See whether any of the points are on the canvas.
boolean isWithin = false;
for (int i = 0; i < ex.size(); i++) {
Location p = ex.getPoint(i);
int x = p.getX();
int y = p.getY();
if (x >= viewable.x && x < viewable.x + viewable.width && y >= viewable.y && y < viewable.y + viewable.height) {
isWithin = true;
break;
}
}
// If none are, insert an arrow.
if (!isWithin) {
Location p = ex.getPoint(0);
int x = p.getX();
int y = p.getY();
boolean isWest = x < viewable.x;
boolean isEast = x >= viewable.x + viewable.width;
boolean isNorth = y < viewable.y;
boolean isSouth = y >= viewable.y + viewable.height;
if (isNorth) {
if (isEast) {
viewport.setNortheast(true);
} else if (isWest) {
viewport.setNorthwest(true);
} else {
viewport.setNorth(true);
}
} else if (isSouth) {
if (isEast) {
viewport.setSoutheast(true);
} else if (isWest) {
viewport.setSouthwest(true);
} else {
viewport.setSouth(true);
}
} else {
if (isEast) {
viewport.setEast(true);
} else if (isWest) {
viewport.setWest(true);
}
}
}
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class EditTool method mousePressed.
@Override
public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) {
boolean wire = updateLocation(canvas, e);
Location oldWireLoc = wireLoc;
wireLoc = NULL_LOCATION;
lastX = Integer.MIN_VALUE;
if (wire) {
current = wiring;
Selection sel = canvas.getSelection();
Circuit circ = canvas.getCircuit();
Collection<Component> selected = sel.getAnchoredComponents();
ArrayList<Component> suppress = null;
for (Wire w : circ.getWires()) {
if (selected.contains(w)) {
if (w.contains(oldWireLoc)) {
if (suppress == null)
suppress = new ArrayList<Component>();
suppress.add(w);
}
}
}
sel.setSuppressHandles(suppress);
} else {
current = select;
}
pressX = e.getX();
pressY = e.getY();
current.mousePressed(canvas, g, e);
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class EditTool method updateLocation.
private boolean updateLocation(Canvas canvas, int mx, int my, int mods) {
int snapx = Canvas.snapXToGrid(mx);
int snapy = Canvas.snapYToGrid(my);
int dx = mx - snapx;
int dy = my - snapy;
boolean isEligible = dx * dx + dy * dy < 36;
if ((mods & MouseEvent.ALT_DOWN_MASK) != 0)
isEligible = true;
if (!isEligible) {
snapx = -1;
snapy = -1;
}
boolean modsSame = lastMods == mods;
lastCanvas = canvas;
lastRawX = mx;
lastRawY = my;
lastMods = mods;
if (lastX == snapx && lastY == snapy && modsSame) {
// already computed
return wireLoc != NULL_LOCATION;
} else {
Location snap = Location.create(snapx, snapy);
if (modsSame) {
Object o = cache.get(snap);
if (o != null) {
lastX = snapx;
lastY = snapy;
canvas.repaint();
boolean ret = ((Boolean) o).booleanValue();
wireLoc = ret ? snap : NULL_LOCATION;
return ret;
}
} else {
cache.clear();
}
boolean ret = isEligible && isWiringPoint(canvas, snap, mods);
wireLoc = ret ? snap : NULL_LOCATION;
cache.put(snap, Boolean.valueOf(ret));
int toRemove = cache.size() - CACHE_MAX_SIZE;
Iterator<Location> it = cache.keySet().iterator();
while (it.hasNext() && toRemove > 0) {
it.next();
it.remove();
toRemove--;
}
lastX = snapx;
lastY = snapy;
canvas.repaint();
return ret;
}
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class EditTool method draw.
@Override
public void draw(Canvas canvas, ComponentDrawContext context) {
Location loc = wireLoc;
if (loc != NULL_LOCATION && current != wiring) {
int x = loc.getX();
int y = loc.getY();
Graphics g = context.getGraphics();
g.setColor(Value.TRUE_COLOR);
GraphicsUtil.switchToWidth(g, 2);
g.drawOval(x - 5, y - 5, 10, 10);
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 1);
}
current.draw(canvas, context);
}
use of com.cburch.logisim.data.Location in project logisim-evolution by reds-heig.
the class PullResistor method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Location loc = painter.getLocation();
int x = loc.getX();
int y = loc.getY();
Graphics g = painter.getGraphics();
g.translate(x, y);
Value pull = getPullValue(painter.getAttributeSet());
Value actual = painter.getPortValue(0);
paintBase(painter, pull, pull.getColor(), actual.getColor());
g.translate(-x, -y);
painter.drawPorts();
}
Aggregations