use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class AddTool method expose.
private void expose(java.awt.Component c, int x, int y) {
Bounds bds = getBounds();
c.repaint(x + bds.getX(), y + bds.getY(), bds.getWidth(), bds.getHeight());
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class AddTool method getBounds.
private Bounds getBounds() {
Bounds ret = bounds;
if (ret == null) {
ComponentFactory source = getFactory();
if (source == null) {
ret = Bounds.EMPTY_BOUNDS;
} else {
AttributeSet base = getBaseAttributes();
ret = source.getOffsetBounds(base).expand(5);
}
bounds = ret;
}
return ret;
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class Tunnel method paintGhost.
//
// graphics methods
//
@Override
public void paintGhost(InstancePainter painter) {
TunnelAttributes attrs = (TunnelAttributes) painter.getAttributeSet();
Direction facing = attrs.getFacing();
String label = attrs.getLabel();
Graphics g = painter.getGraphics();
g.setFont(attrs.getFont());
FontMetrics fm = g.getFontMetrics();
Bounds bds = computeBounds(attrs, fm.stringWidth(label), fm.getAscent() + fm.getDescent(), g, label);
if (attrs.setOffsetBounds(bds)) {
Instance instance = painter.getInstance();
if (instance != null)
instance.recomputeBounds();
}
int x0 = bds.getX();
int y0 = bds.getY();
int x1 = x0 + bds.getWidth();
int y1 = y0 + bds.getHeight();
int mw = ARROW_MAX_WIDTH / 2;
int[] xp;
int[] yp;
if (facing == Direction.NORTH) {
int yb = y0 + ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, 0, x1, x1, x0 };
yp = new int[] { yb, y0, yb, y1, y1 };
} else {
xp = new int[] { x0, -mw, 0, mw, x1, x1, x0 };
yp = new int[] { yb, yb, y0, yb, yb, y1, y1 };
}
} else if (facing == Direction.SOUTH) {
int yb = y1 - ARROW_DEPTH;
if (x1 - x0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, x1, x1, 0, x0 };
yp = new int[] { y0, y0, yb, y1, yb };
} else {
xp = new int[] { x0, x1, x1, mw, 0, -mw, x0 };
yp = new int[] { y0, y0, yb, yb, y1, yb, yb };
}
} else if (facing == Direction.EAST) {
int xb = x1 - ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { x0, xb, x1, xb, x0 };
yp = new int[] { y0, y0, 0, y1, y1 };
} else {
xp = new int[] { x0, xb, xb, x1, xb, xb, x0 };
yp = new int[] { y0, y0, -mw, 0, mw, y1, y1 };
}
} else {
int xb = x0 + ARROW_DEPTH;
if (y1 - y0 <= ARROW_MAX_WIDTH) {
xp = new int[] { xb, x1, x1, xb, x0 };
yp = new int[] { y0, y0, y1, y1, 0 };
} else {
xp = new int[] { xb, x1, x1, xb, xb, x0, xb };
yp = new int[] { y0, y0, y1, y1, mw, 0, -mw };
}
}
GraphicsUtil.switchToWidth(g, 2);
g.drawPolygon(xp, yp, xp.length);
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class SelectTool method computeDxDy.
private void computeDxDy(Project proj, MouseEvent e, Graphics g) {
Bounds bds = proj.getSelection().getBounds(g);
int dx;
int dy;
if (bds == Bounds.EMPTY_BOUNDS) {
dx = e.getX() - start.getX();
dy = e.getY() - start.getY();
} else {
dx = Math.max(e.getX() - start.getX(), -bds.getX());
dy = Math.max(e.getY() - start.getY(), -bds.getY());
}
Selection sel = proj.getSelection();
if (sel.shouldSnap()) {
dx = Canvas.snapXToGrid(dx);
dy = Canvas.snapYToGrid(dy);
}
curDx = dx;
curDy = dy;
}
use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class PropagationPoints method draw.
void draw(ComponentDrawContext context) {
if (data.isEmpty())
return;
CircuitState state = context.getCircuitState();
HashMap<CircuitState, CircuitState> stateMap = new HashMap<CircuitState, CircuitState>();
for (CircuitState s : state.getSubstates()) {
addSubstates(stateMap, s, s);
}
Graphics g = context.getGraphics();
GraphicsUtil.switchToWidth(g, 2);
for (Entry e : data) {
if (e.state == state) {
Location p = e.loc;
g.drawOval(p.getX() - 4, p.getY() - 4, 8, 8);
} else if (stateMap.containsKey(e.state)) {
CircuitState substate = stateMap.get(e.state);
Component subcirc = substate.getSubcircuit();
Bounds b = subcirc.getBounds();
g.drawRect(b.getX(), b.getY(), b.getWidth(), b.getHeight());
}
}
GraphicsUtil.switchToWidth(g, 1);
}
Aggregations