Skip to content

Commit 681ce21

Browse files
author
thyttan
committed
Dial_Display: more robust clearing of previous position
Dial_Display could loose track of the previously drawn position if `Dial_Display.set()` was called twice or more.
1 parent 3479c79 commit 681ce21

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

modules/Dial_Display.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ function DialDisplay(options) {
1919

2020
DialDisplay.prototype.reset = function() {
2121
this.isFirstDraw = true;
22+
this.prevDrawnValue = null;
2223
};
2324

2425
DialDisplay.prototype.set = function(value) {
25-
this.prevValue = this.value;
2626
this.value = value;
2727
};
2828

2929
DialDisplay.prototype.step = function(step) {
3030
"ram";
31-
let prevValue = this.prevValue != null ? this.prevValue : this.value;
3231
this.value += step;
3332
//g.setFont("Vector:30");
3433
//g.drawString(this.value);
@@ -58,11 +57,11 @@ DialDisplay.prototype.step = function(step) {
5857

5958
//drawCircle(this.value, 1, 1, 1, 2, false);
6059
//drawCircle(prevValue, 0, 0, 0, 2, false);
61-
g.setColor(0,0,0).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(prevValue*(2*Math.PI/this.options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(prevValue*(2*Math.PI/this.options.stepsPerWholeTurn)));
60+
g.setColor(0,0,0).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.prevDrawnValue*(2*Math.PI/this.options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.prevDrawnValue*(2*Math.PI/this.options.stepsPerWholeTurn)));
6261
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/this.options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/this.options.stepsPerWholeTurn)));
6362
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9);
6463

65-
delete this.prevValue;
64+
this.prevDrawnValue = this.value;
6665
};
6766

6867
exports = DialDisplay;

0 commit comments

Comments
 (0)