knob/encoder: some swag fix

This commit is contained in:
jean-emmanuel 2017-04-27 10:04:31 +02:00
parent aeac77ed40
commit 4219694389
3 changed files with 91 additions and 29 deletions

View file

@ -166,3 +166,50 @@ range: {
--color-knob:color;
--color-pips:color;
```
## Encoder
An endless knob that only responds to rotative gestures.
```js
{
type:'encoder',
// etc
}
```
#### `ticks`
- type: `number`
- default: `360`
- usage: defines the granularity / verbosity of the encoder (number of step for a 360° arc)
#### `back`
- type: `string|number|object`
- default: `-1`
- usage: defines which value is sent when rotating the encoder anticlockwise
- can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs))
#### `forth`
- type: `string|number|object`
- default: `1`
- usage: defines which value is sent when rotating the encoder clockwise
- can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs))
#### `release`
- type: `string|number|object`
- default: `empty`
- usage: defines which value is sent when releasing the encoder
- set to `null` to send send no argument in the osc message
- can be an `object` if the type needs to be specified (see [preArgs](../widgets-generics.md#preargs))
#### `snap`
- type: `boolean`
- default: `false`
- usage: by default, dragging the widget will modify it's value starting from its last value. Setting this to `true` will make it snap directly to the mouse/touch position.
#### `css`
```
--color-knob:color;
```

View file

@ -2,6 +2,41 @@ var {clip, mapToScale} = require('../utils'),
Knob = require('./knob'),
_widgets_base = require('../common/_widgets_base')
var EncoderKnob = class extends Knob {
draginitHandle(e, data, traversing) {
this.percent = clip(this.percent,[0,100])
this.lastOffsetX = data.offsetX
this.lastOffsetY = data.offsetY
if (!(traversing || this.widgetData.snap)) return
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true, draginit:true})
}
mousewheelHandle(){}
}
var DisplayKnob = class extends Knob {
draw(){
super.draw()
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.strokeStyle = this.colors.raised
this.ctx.arc(this.width / 2, this.height / 2, this.minDimension / 2 - this.gaugeWidth * 1.5 * PXSCALE - 2 * PXSCALE, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.globalAlpha = 0.3
this.ctx.lineWidth = 1.1 * PXSCALE
this.ctx.stroke()
this.ctx.globalAlpha = 1
}
}
module.exports = class Encoder extends _widgets_base {
static options() {
@ -52,7 +87,7 @@ module.exports = class Encoder extends _widgets_base {
this.wrapper = this.widget.find('.wrapper')
this.ticks = Math.abs(parseInt(widgetData.ticks))
this.knob = new Knob({
this.knob = new EncoderKnob({
label:false,
angle:360,
snap:true,
@ -62,7 +97,7 @@ module.exports = class Encoder extends _widgets_base {
this.knob.noDraw = true
this.display = new Knob({
this.display = new DisplayKnob({
label:false,
angle:360,
range:{min:0,max:this.ticks},
@ -78,22 +113,6 @@ module.exports = class Encoder extends _widgets_base {
this.previousValue = this.ticks/2
this.knob.mousewheelHandle = ()=>{}
this.knob.draginitHandle = function(e, data, traversing) {
this.percent = clip(this.percent,[0,100])
this.lastOffsetX = data.offsetX
this.lastOffsetY = data.offsetY
if (!(traversing || this.widgetData.snap)) return
this.percent = this.angleToPercent(this.coordsToAngle(data.offsetX, data.offsetY))
this.setValue(this.percentToValue(this.percent), {send:true,sync:true,dragged:true, draginit:true})
}
this.wrapper.on('sync',(e)=>{
e.stopPropagation()

View file

@ -212,19 +212,15 @@ module.exports = class Knob extends _sliders_base {
this.ctx.beginPath()
this.ctx.fillStyle = this.colors.raised
this.ctx.strokeStyle = this.colors.raised
this.ctx.arc(this.width / 2, this.height / 2, r, 0, Math.PI * 2)
this.ctx.fill()
if ( this.colors.raised){
var grd=this.ctx.createRadialGradient(this.width / 2, this.height / 2, Math.max(r - 4 * PXSCALE, PXSCALE), this.width / 2, this.height / 2, r)
grd.addColorStop(0, 'transparent')
grd.addColorStop(1, this.colors.raised)
}
this.ctx.beginPath()
this.ctx.fillStyle = grd
this.ctx.arc(this.width / 2, this.height / 2, r, 0, Math.PI * 2)
this.ctx.fill()
this.ctx.lineWidth = 1 * PXSCALE
this.ctx.stroke()
this.ctx.globalAlpha = 0.3
this.ctx.lineWidth = 1.1 * PXSCALE
this.ctx.stroke()
this.ctx.globalAlpha = 1
this.ctx.lineWidth = 2 * PXSCALE