use of com.cburch.logisim.data.Bounds in project logisim-evolution by reds-heig.
the class LayoutThumbnail method paintComponent.
@Override
protected void paintComponent(Graphics g) {
if (circuitState != null) {
Circuit circuit = circuitState.getCircuit();
Bounds bds = circuit.getBounds(g);
Dimension size = getSize();
double scaleX = (double) (size.width - 2 * BORDER) / bds.getWidth();
double scaleY = (double) (size.height - 2 * BORDER) / bds.getHeight();
double scale = Math.min(1.0, Math.min(scaleX, scaleY));
Graphics gCopy = g.create();
int borderX = (int) ((size.width - bds.getWidth() * scale) / 2);
int borderY = (int) ((size.height - bds.getHeight() * scale) / 2);
gCopy.translate(borderX, borderY);
if (scale != 1.0 && g instanceof Graphics2D) {
((Graphics2D) gCopy).scale(scale, scale);
}
gCopy.translate(-bds.getX(), -bds.getY());
ComponentDrawContext context = new ComponentDrawContext(this, circuit, circuitState, g, gCopy);
context.setShowState(false);
context.setShowColor(false);
circuit.draw(context, Collections.<Component>emptySet());
if (ports != null) {
gCopy.setColor(AppearancePort.COLOR);
int width = Math.max(4, (int) ((2 / scale) + 0.5));
GraphicsUtil.switchToWidth(gCopy, width);
for (Instance port : ports) {
Bounds b = port.getBounds();
int x = b.getX();
int y = b.getY();
int w = b.getWidth();
int h = b.getHeight();
if (Pin.FACTORY.isInputPin(port)) {
gCopy.drawRect(x, y, w, h);
} else {
if (b.getWidth() > 25) {
gCopy.drawRoundRect(x, y, w, h, 4, 4);
} else {
gCopy.drawOval(x, y, w, h);
}
}
}
}
gCopy.dispose();
g.setColor(Color.BLACK);
GraphicsUtil.switchToWidth(g, 2);
g.drawRect(0, 0, size.width - 2, size.height - 2);
}
}
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 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