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