Skip to content

Commit

Permalink
adjust mouse wheel sensitivity (sharpie7#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalstad committed Dec 9, 2024
1 parent 76da2e8 commit 11fc892
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
13 changes: 12 additions & 1 deletion src/com/lushprojects/circuitjs1/client/CirSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public class CirSim implements MouseDownHandler, MouseMoveHandler, MouseUpHandle
double maxTimeStep;
double minTimeStep;

double wheelSensitivity = 1;

// accumulated time since we incremented timeStepCount
double timeStepAccum;

Expand Down Expand Up @@ -827,6 +829,7 @@ public void onBrowserEvent(Event event) {
scopePopupMenu = new ScopePopupMenu();

setColors(positiveColor, negativeColor, neutralColor, selectColor, currentColor);
setWheelSensitivity();

if (startCircuitText != null) {
getSetupList(false);
Expand Down Expand Up @@ -922,6 +925,14 @@ else if (getOptionFromStorage("alternativeColor", false))
CircuitElm.setColorScale();
}

void setWheelSensitivity() {
wheelSensitivity = 1;
try {
Storage stor = Storage.getLocalStorageIfSupported();
wheelSensitivity = Double.parseDouble(stor.getItem("wheelSensitivity"));
} catch (Exception e) {}
}

MenuItem menuItemWithShortcut(String icon, String text, String shortcut, MyCommand cmd) {
final String edithtml="<div style=\"white-space:nowrap\"><div style=\"display:inline-block;width:100%;\"><i class=\"cirjsicon-";
String nbsp = "&nbsp;";
Expand Down Expand Up @@ -5026,7 +5037,7 @@ else if (scopeSelected != -1 && !zoomOnly)
else if (!dialogIsShowing()) {
mouseCursorX=e.getX();
mouseCursorY=e.getY();
zoomCircuit(-e.getDeltaY(), false);
zoomCircuit(-e.getDeltaY()*wheelSensitivity, false);
zoomTime = System.currentTimeMillis();
}
repaint();
Expand Down
16 changes: 12 additions & 4 deletions src/com/lushprojects/circuitjs1/client/EditOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ public EditInfo getEditInfo(int n) {
}
if (n == 11)
return new EditInfo("Minimum Target Frame Rate", sim.minFrameRate);
if (n == 12) {
if (n == 12)
return new EditInfo("Mouse Wheel Sensitivity", sim.wheelSensitivity);
if (n == 13) {
EditInfo ei = new EditInfo("", 0, -1, -1);
ei.checkbox = new Checkbox("Auto-Adjust Timestep", sim.adjustTimeStep);
return ei;
}
if (n == 13 && sim.adjustTimeStep)
if (n == 14 && sim.adjustTimeStep)
return new EditInfo("Minimum time step size (s)", sim.minTimeStep, 0, 0);

return null;
Expand Down Expand Up @@ -153,11 +155,17 @@ public void setEditValue(int n, EditInfo ei) {
sim.developerMode = ei.checkbox.getState();
if (n == 11 && ei.value > 0)
sim.minFrameRate = ei.value;
if (n == 12) {
if (n == 12 && ei.value > 0) {
sim.wheelSensitivity = ei.value;
Storage stor = Storage.getLocalStorageIfSupported();
if (stor != null)
stor.setItem("wheelSensitivity", Double.toString(sim.wheelSensitivity));
}
if (n == 13) {
sim.adjustTimeStep = ei.checkbox.getState();
ei.newDialog = true;
}
if (n == 13 && ei.value > 0)
if (n == 14 && ei.value > 0)
sim.minTimeStep = ei.value;
}

Expand Down
6 changes: 3 additions & 3 deletions src/com/lushprojects/circuitjs1/client/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Scope {
double scale[]; // Max value to scale the display to show - indexed for each value of UNITS - e.g. UNITS_V, UNITS_A etc.
boolean reduceRange[];
double scaleX, scaleY; // for X-Y plots
int wheelDeltaY;
double wheelDeltaY;
int selectedPlot;
ScopePropertiesDialog properties;
String curColor, voltColor;
Expand Down Expand Up @@ -2124,14 +2124,14 @@ void selectY() {
}

void onMouseWheel(MouseWheelEvent e) {
wheelDeltaY += e.getDeltaY();
wheelDeltaY += e.getDeltaY()*sim.wheelSensitivity;
if (wheelDeltaY > 5) {
slowDown();
wheelDeltaY = 0;
}
if (wheelDeltaY < -5) {
speedUp();
wheelDeltaY = 0;
wheelDeltaY = 0;
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/com/lushprojects/circuitjs1/client/ScrollValuePopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ScrollValuePopup extends PopupPanel implements MouseOutHandler, Mou
VerticalPanel vp;
CircuitElm myElm;
Label labels[];
int deltaY;
double deltaY;
String name;
EditInfo inf;
CirSim sim;
Expand Down Expand Up @@ -187,11 +187,7 @@ public void onMouseDown(MouseDownEvent e) {
static final int scale = 6;

public void doDeltaY(int dy) {
deltaY += (int) (dy/getDevicePixelRatio());
if (currentidx+deltaY/scale < 0)
deltaY=-scale*currentidx;
if (currentidx+deltaY/scale>=nvalues)
deltaY= (nvalues-currentidx-1)*scale;
deltaY += (dy/(double) getDevicePixelRatio());
setElmValue();
setupLabels();
}
Expand All @@ -215,7 +211,7 @@ public void setElmValue(int i) {

public int getSelIdx() {
int r;
r=currentidx+deltaY/scale;
r = currentidx + (int)Math.round(sim.wheelSensitivity*deltaY/scale);
if (r<0)
r=0;
if (r>=nvalues)
Expand Down

0 comments on commit 11fc892

Please sign in to comment.