forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDial_Display.js
More file actions
67 lines (56 loc) · 2.03 KB
/
Copy pathDial_Display.js
File metadata and controls
67 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function DialDisplay(options) {
const SCREEN_W = g.getWidth();
const SCREEN_H = g.getHeight();
this.options = Object.assign(
{
stepsPerWholeTurn : 7, // 7 chosen as it felt the best in use.
dialRect : {
x: 0,
y: 0,
w: SCREEN_W,
h: SCREEN_H,
},
}, options);
this.value = 0;
this.isFullDraw = true;
}
DialDisplay.prototype.queueRedraw = function() {
this.isFullDraw = true;
this.prevDrawnValue = null;
};
DialDisplay.prototype.set = function(value) {
this.value = value;
};
DialDisplay.prototype.step = function(step) {
"ram";
this.value += step;
//g.setFont("Vector:30");
//g.drawString(this.value);
const DIAL_RECT = this.options.dialRect;
const CENTER = {
x: DIAL_RECT.x + DIAL_RECT.w / 2,
y: DIAL_RECT.y + DIAL_RECT.h / 2,
};
let drawCircle = (value, R, G, B, rad, isFill)=>{
let x = CENTER.x+27*Math.sin(value*(2*Math.PI/this.options.stepsPerWholeTurn));
let y = CENTER.y-27*Math.cos(value*(2*Math.PI/this.options.stepsPerWholeTurn));
g.setColor(R,G,B)
if (!isFill) g.drawCircle(x, y, rad);
if (isFill) g.fillCircle(x, y, rad);
}
if (this.isFullDraw) {
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 25);
g.setColor(1,1,1).drawCircle(CENTER.x, CENTER.y, 25);
for (let i=0; i<this.options.stepsPerWholeTurn; i++) {
drawCircle(i, 1, 1, 1, 1, true);
}
this.isFullDraw = false;
}
//drawCircle(this.value, 1, 1, 1, 2, false);
//drawCircle(prevValue, 0, 0, 0, 2, false);
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)));
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)));
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9);
this.prevDrawnValue = this.value;
};
exports = DialDisplay;