Skip to content

Commit 9cae2a9

Browse files
author
thyttan
committed
Dial_Display: tweak logic and docs
1 parent 21dcbea commit 9cae2a9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

modules/Dial_Display.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ let dialDisplayGenerator = function(options) {
2020
y: DIAL_RECT.y + DIAL_RECT.h / 2,
2121
};
2222

23-
let dialDisplay = function(step, value) {
23+
let dialDisplay = function(step, value, isReinit) {
2424
let prevValue = this.value;
25-
if (value) this.value = value;
25+
if (value!==undefined) this.value = value;
2626
if (!this.value) this.value = 0;
27-
if (this.isFirstDraw===undefined) this.isFirstDraw = true;
27+
if (this.isFirstDraw===undefined || isReinit) this.isFirstDraw = true;
2828
this.value += step;
2929
//g.setFont("Vector:30");
3030
//g.drawString(this.value);
@@ -37,7 +37,7 @@ let dialDisplayGenerator = function(options) {
3737
if (isFill) g.fillCircle(x, y, rad);
3838
}
3939
if (this.isFirstDraw) {
40-
g.clear();
40+
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 25);
4141
g.setColor(1,1,1).drawCircle(CENTER.x, CENTER.y, 25);
4242
for (let i=0; i<options.stepsPerWholeTurn; i++) {
4343
drawCircle(i, 1, 1, 1, 1, true);
@@ -47,8 +47,8 @@ let dialDisplayGenerator = function(options) {
4747

4848
//drawCircle(this.value, 1, 1, 1, 2, false);
4949
//drawCircle(prevValue, 0, 0, 0, 2, false);
50-
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/options.stepsPerWholeTurn)));
5150
g.setColor(0,0,0).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(prevValue*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(prevValue*(2*Math.PI/options.stepsPerWholeTurn)));
51+
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/options.stepsPerWholeTurn)));
5252
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9);
5353

5454
return this.value;

modules/Dial_Display.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Usage
1010
```JS
1111
var DialDisplay = require("Dial_Display");
1212
var dialDisplay = new DialDisplay(options);
13+
var value = dialDisplay(-1, 0, true)
1314
```
1415

1516
For example in use with the Dial module:
@@ -29,7 +30,7 @@ var DialDisplay = require("Dial_Display");
2930
var dialDisplay = new DialDisplay(options);
3031

3132
var cb = (step)=>{
32-
var value = dialDisplay(step);
33+
var value = dialDisplay(step, undefined, true);
3334
};
3435

3536
var Dial = require("Dial");
@@ -54,3 +55,7 @@ Defaults:
5455
}
5556
```
5657

58+
The generated function takes three arguments:
59+
`step` - +1 or -1
60+
`value` - the previous value the step acts on.
61+
`isReinit` - true/false, whether to draw all of the dial or just the indicator.

0 commit comments

Comments
 (0)