use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class ComponentDrawContext method drawPin.
public void drawPin(Component comp, int i, String label, Direction dir) {
Color curColor = g.getColor();
if (i < 0 || i >= comp.getEnds().size())
return;
EndData e = comp.getEnd(i);
Location pt = e.getLocation();
int x = pt.getX();
int y = pt.getY();
if (getShowState()) {
CircuitState state = getCircuitState();
g.setColor(state.getValue(pt).getColor());
} else {
g.setColor(Color.BLACK);
}
g.fillOval(x - PIN_OFFS, y - PIN_OFFS, PIN_RAD, PIN_RAD);
g.setColor(curColor);
if (dir == Direction.EAST) {
GraphicsUtil.drawText(g, label, x + 3, y, GraphicsUtil.H_LEFT, GraphicsUtil.V_CENTER);
} else if (dir == Direction.WEST) {
GraphicsUtil.drawText(g, label, x - 3, y, GraphicsUtil.H_RIGHT, GraphicsUtil.V_CENTER);
} else if (dir == Direction.SOUTH) {
GraphicsUtil.drawText(g, label, x, y - 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_BASELINE);
} else if (dir == Direction.NORTH) {
GraphicsUtil.drawText(g, label, x, y + 3, GraphicsUtil.H_CENTER, GraphicsUtil.V_TOP);
}
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class Project method setCurrentCircuit.
public void setCurrentCircuit(Circuit circuit) {
CircuitState circState = stateMap.get(circuit);
if (circState == null) {
circState = new CircuitState(this, circuit);
}
setCircuitState(circState);
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class CanvasPainter method drawWithUserState.
private void drawWithUserState(Graphics base, Graphics g, Project proj) {
Circuit circ = proj.getCurrentCircuit();
Selection sel = proj.getSelection();
Set<Component> hidden;
Tool dragTool = canvas.getDragTool();
if (dragTool == null) {
hidden = NO_COMPONENTS;
} else {
hidden = dragTool.getHiddenComponents(canvas);
if (hidden == null)
hidden = NO_COMPONENTS;
}
// draw halo around component whose attributes we are viewing
boolean showHalo = AppPreferences.ATTRIBUTE_HALO.getBoolean();
if (showHalo && haloedComponent != null && haloedCircuit == circ && !hidden.contains(haloedComponent)) {
GraphicsUtil.switchToWidth(g, 3);
g.setColor(Canvas.HALO_COLOR);
Bounds bds = haloedComponent.getBounds(g).expand(5);
int w = bds.getWidth();
int h = bds.getHeight();
double a = Canvas.SQRT_2 * w;
double b = Canvas.SQRT_2 * h;
g.drawOval((int) Math.round(bds.getX() + w / 2.0 - a / 2.0), (int) Math.round(bds.getY() + h / 2.0 - b / 2.0), (int) Math.round(a), (int) Math.round(b));
GraphicsUtil.switchToWidth(g, 1);
g.setColor(Color.BLACK);
}
// draw circuit and selection
CircuitState circState = proj.getCircuitState();
boolean printerView = AppPreferences.PRINTER_VIEW.getBoolean();
ComponentDrawContext context = new ComponentDrawContext(canvas, circ, circState, base, g, printerView);
context.setHighlightedWires(highlightedWires);
circ.draw(context, hidden);
sel.draw(context, hidden);
// draw tool
Tool tool = dragTool != null ? dragTool : proj.getTool();
if (tool != null && !canvas.isPopupMenuUp()) {
Graphics gCopy = g.create();
context.setGraphics(gCopy);
tool.draw(canvas, context);
gCopy.dispose();
}
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class CanvasPainter method paintContents.
//
// painting methods
//
void paintContents(Graphics g, Project proj) {
Rectangle clip = g.getClipBounds();
Dimension size = canvas.getSize();
double zoomFactor = canvas.getZoomFactor();
if (canvas.ifPaintDirtyReset() || clip == null) {
clip = new Rectangle(0, 0, size.width, size.height);
}
// YSY removed to don't overwrite background image
// g.setColor(Color.magenta);
// g.fillRect(clip.x, clip.y, clip.width, clip.height);
grid.paintGrid(g);
g.setColor(Color.black);
Graphics gScaled = g.create();
if (zoomFactor != 1.0 && gScaled instanceof Graphics2D) {
((Graphics2D) gScaled).scale(zoomFactor, zoomFactor);
}
drawWithUserState(g, gScaled, proj);
drawWidthIncompatibilityData(g, gScaled, proj);
Circuit circ = proj.getCurrentCircuit();
CircuitState circState = proj.getCircuitState();
ComponentDrawContext ptContext = new ComponentDrawContext(canvas, circ, circState, g, gScaled);
ptContext.setHighlightedWires(highlightedWires);
gScaled.setColor(Color.RED);
circState.drawOscillatingPoints(ptContext);
gScaled.setColor(Color.BLUE);
proj.getSimulator().drawStepPoints(ptContext);
gScaled.dispose();
}
use of com.cburch.logisim.circuit.CircuitState in project logisim-evolution by reds-heig.
the class AppearanceCanvas method computeSize.
private void computeSize(boolean immediate) {
hidePopup();
Bounds bounds;
CircuitState circState = circuitState;
if (circState == null) {
bounds = Bounds.create(0, 0, 50, 50);
} else {
bounds = circState.getCircuit().getAppearance().getAbsoluteBounds();
}
int width = bounds.getX() + bounds.getWidth() + BOUNDS_BUFFER;
int height = bounds.getY() + bounds.getHeight() + BOUNDS_BUFFER;
Dimension dim;
if (canvasPane == null) {
dim = new Dimension(width, height);
} else {
dim = canvasPane.supportPreferredSize(width, height);
}
if (!immediate) {
Bounds old = oldPreferredSize;
if (old != null && Math.abs(old.getWidth() - dim.width) < THRESH_SIZE_UPDATE && Math.abs(old.getHeight() - dim.height) < THRESH_SIZE_UPDATE) {
return;
}
}
oldPreferredSize = Bounds.create(0, 0, dim.width, dim.height);
setPreferredSize(dim);
revalidate();
}
Aggregations