Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/com/lushprojects/circuitjs1/client/ChipElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ void drawChip(Graphics g) {
hasVertical = true;
break;
}
double threshold = getThreshold();
for (i = 0; i != getPostCount(); i++) {
g.setFont(f);
Pin p = pins[i];
if (p.busZ > 0)
continue;
setVoltageColor(g, volts[i]);
if (isDigitalChip())
setLogicPinColor(g, volts[i], threshold);
else
setVoltageColor(g, volts[i]);
Point a = p.post;
Point b = p.stub;
drawThickLine(g, a, b, p.busWidth > 1 ? 5 : 3);
Expand Down
23 changes: 21 additions & 2 deletions src/com/lushprojects/circuitjs1/client/CircuitElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public abstract class CircuitElm implements Editable {
static final int SCALE_MU = 3;

static int decimalDigits, shortDecimalDigits;


// when true, logic gate/chip pin leads are colored by logical state (high/low)
// rather than by analog voltage
static boolean colorLogicPins;

// initial point where user created element. For simple two-terminal elements, this is the first node/post.
int x, y;

Expand Down Expand Up @@ -1116,7 +1120,22 @@ Color getVoltageColor(Graphics g, double volts) {
void setVoltageColor(Graphics g, double volts) {
g.setColor(getVoltageColor(g, volts));
}


// Set pin color based on logical state (high/low) relative to a threshold.
// Used by logic gates and chips when colorLogicPins is enabled.
// Falls back to normal voltage coloring when the option is off.
void setLogicPinColor(Graphics g, double volts, double threshold) {
if (colorLogicPins) {
if (needsHighlight()) {
g.setColor(selectColor);
return;
}
g.setColor(volts > threshold ? positiveColor : neutralColor);
} else {
setVoltageColor(g, volts);
}
}

// yellow argument is unused, can't remember why it was there
void setPowerColor(Graphics g, boolean yellow) {

Expand Down
5 changes: 4 additions & 1 deletion src/com/lushprojects/circuitjs1/client/DelayBufferElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ void undumpXml(XMLDeserializer xml) {

void draw(Graphics g) {
drawPosts(g);
draw2Leads(g);
setLogicPinColor(g, volts[0], threshold);
drawThickLine(g, point1, lead1);
setLogicPinColor(g, volts[1], threshold);
drawThickLine(g, lead2, point2);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, gatePoly);
if (GateElm.useEuroGates())
Expand Down
13 changes: 11 additions & 2 deletions src/com/lushprojects/circuitjs1/client/EditOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ public EditInfo getEditInfo(int n) {
return ei;
}
if (n == 15) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Color Logic Pins by State", CircuitElm.colorLogicPins);
return ei;
}
if (n == 16) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Auto-Adjust Timestep", sim.adjustTimeStep);
return ei;
}
if (n == 16 && sim.adjustTimeStep)
if (n == 17 && sim.adjustTimeStep)
return new EditInfo("Minimum time step size (s)", sim.minTimeStep, 0, 0).setPositive();

// don't add new options here. they are only visible if sim.adjustTimeStemp is set, and it isn't by default.
Expand Down Expand Up @@ -194,10 +199,14 @@ public void setEditValue(int n, EditInfo ei) {
if (n == 14)
app.autoDCOnReset = ei.checkbox.getState();
if (n == 15) {
CircuitElm.colorLogicPins = ei.checkbox.getState();
app.setOptionInStorage("colorLogicPins", CircuitElm.colorLogicPins);
}
if (n == 16) {
sim.adjustTimeStep = ei.checkbox.getState();
ei.newDialog = true;
}
if (n == 16)
if (n == 17 && ei.value > 0)
sim.minTimeStep = ei.value;
}

Expand Down
5 changes: 3 additions & 2 deletions src/com/lushprojects/circuitjs1/client/GateElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ void drawGatePolygon(Graphics g) {

void draw(Graphics g) {
int i;
double threshold = highVoltage * .5;
for (i = 0; i != inputCount; i++) {
setVoltageColor(g, volts[i]);
setLogicPinColor(g, volts[i], threshold);
drawThickLine(g, inPosts[i], inGates[i]);
}
setVoltageColor(g, volts[inputCount]);
setLogicPinColor(g, volts[inputCount], threshold);
drawThickLine(g, lead2, point2);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
if (useEuroGates()) {
Expand Down
6 changes: 5 additions & 1 deletion src/com/lushprojects/circuitjs1/client/InverterElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ void undumpXml(XMLDeserializer xml) {

void draw(Graphics g) {
drawPosts(g);
draw2Leads(g);
double threshold = highVoltage * .5;
setLogicPinColor(g, volts[0], threshold);
drawThickLine(g, point1, lead1);
setLogicPinColor(g, volts[1], threshold);
drawThickLine(g, lead2, point2);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, gatePoly);
if (GateElm.useEuroGates())
Expand Down
16 changes: 10 additions & 6 deletions src/com/lushprojects/circuitjs1/client/TriStateElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,22 @@ void draw(Graphics g) {
int hs = 16;
setBbox(point1, point2, hs);

// draw control lead underneath the triangle
setVoltageColor(g, volts[2 * busWidth]);
double threshold = highVoltage * .5;
// control lead
setLogicPinColor(g, volts[2 * busWidth], threshold);
drawThickLine(g, point3, lead3);

// draw leads with bus thickness if bus mode
// input/output leads (bus-thick in bus mode)
if (busWidth > 1) {
setVoltageColor(g, volts[0]);
setLogicPinColor(g, volts[0], threshold);
drawThickLine(g, point1, busLead1, 5);
setVoltageColor(g, volts[busWidth]);
setLogicPinColor(g, volts[busWidth], threshold);
drawThickLine(g, lead2, point2, 5);
} else {
draw2Leads(g);
setLogicPinColor(g, volts[0], threshold);
drawThickLine(g, point1, lead1);
setLogicPinColor(g, volts[busWidth], threshold);
drawThickLine(g, lead2, point2);
}

g.setColor(lightGrayColor);
Expand Down
1 change: 1 addition & 0 deletions src/com/lushprojects/circuitjs1/client/UIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ void init() {
getOptionFromStorage("conventionalCurrent", true));
noEditing = !qp.getBooleanValue("editable", true);
mouseWheelEdit = qp.getBooleanValue("mouseWheelEdit", getOptionFromStorage("mouseWheelEdit", true));
CircuitElm.colorLogicPins = getOptionFromStorage("colorLogicPins", false);
positiveColor = qp.getValue("positiveColor");
negativeColor = qp.getValue("negativeColor");
neutralColor = qp.getValue("neutralColor");
Expand Down
Loading