widgets: continue oop rewriting, fader ok, now using canvas
Addded 'origin' option to fader
This commit is contained in:
parent
a7db945999
commit
90db937a9e
11 changed files with 1084 additions and 1009 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1,6 +1,6 @@
|
|||
var widgets = {
|
||||
// sliders
|
||||
fader: require('./widgets/fader'),
|
||||
fader: require('./widgets/sliders/fader'),
|
||||
knob: require('./widgets/knob'),
|
||||
|
||||
// buttons
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@ var _canvas_base = module.exports = function() {
|
|||
|
||||
this.canvas = this.widget.find('canvas')
|
||||
this.ctx = this.canvas[0].getContext('2d')
|
||||
|
||||
|
||||
this.height = undefined
|
||||
this.width = undefined
|
||||
|
||||
this.visible = false
|
||||
|
||||
this.linecolor = undefined
|
||||
this.colors = {}
|
||||
this.textColor = getComputedStyle(document.documentElement).getPropertyValue('--color-text-fade')
|
||||
|
||||
|
||||
|
|
@ -46,9 +46,18 @@ _canvas_base.prototype.resizeHandle = function(){
|
|||
|
||||
if (!self.visible) {
|
||||
this.visible = true
|
||||
this.lineColor = getComputedStyle(this.widget[0]).getPropertyValue('--color-custom')
|
||||
this.colors.custom = getComputedStyle(this.widget[0]).getPropertyValue('--color-custom')
|
||||
this.colors.text = getComputedStyle(this.widget[0]).getPropertyValue('--color-text')
|
||||
this.colors.raised = getComputedStyle(this.widget[0]).getPropertyValue('--color-raised')
|
||||
this.colors.bg = getComputedStyle(this.widget[0]).getPropertyValue('--color-bg')
|
||||
this.colors.fg = getComputedStyle(this.widget[0]).getPropertyValue('--color-fg')
|
||||
this.colors.faded = getComputedStyle(this.widget[0]).getPropertyValue('--color-faded')
|
||||
}
|
||||
|
||||
requestAnimationFrame(this._draw.bind(this))
|
||||
requestAnimationFrame(this.draw.bind(this))
|
||||
|
||||
}
|
||||
|
||||
_canvas_base.prototype.draw = function(){
|
||||
//
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,299 +0,0 @@
|
|||
var utils = require('./utils'),
|
||||
clip = utils.clip,
|
||||
mapToScale = utils.mapToScale,
|
||||
sendOsc = utils.sendOsc
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
module.exports.create = function(widgetData,container) {
|
||||
var widget = $(`
|
||||
<div class="fader-wrapper-outer">
|
||||
<div class="fader-wrapper">
|
||||
<div class="fader">
|
||||
<div class="gauge"></div>
|
||||
<div class="knob"></div>
|
||||
<div class="pips"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`),
|
||||
gauge = widget.find('.gauge'),
|
||||
knob = widget.find('.knob'),
|
||||
wrapper = widget.find('.fader-wrapper'),
|
||||
fader = widget.find('.fader'),
|
||||
pips = widget.find('.pips'),
|
||||
input = widget.find('.input').fakeInput({align:'center'}),
|
||||
unit = widgetData.unit?' '+widgetData.unit.trim(): '',
|
||||
dimension = widgetData.horizontal?'width':'height',
|
||||
snap = widgetData.snap,
|
||||
logScale = widgetData.logScale,
|
||||
roundFactor = Math.pow(10,widgetData.precision)
|
||||
|
||||
|
||||
if (widgetData.horizontal) {
|
||||
container.addClass('horizontal')
|
||||
} else {
|
||||
if (widgetData.alignRight) container.addClass('align-right')
|
||||
}
|
||||
|
||||
if (widgetData.compact) container.addClass('compact')
|
||||
if (widgetData.noPip) wrapper.addClass('no-pip')
|
||||
|
||||
gauge.size = 0
|
||||
fader.size = 0
|
||||
wrapper.size = 0
|
||||
widget.value = undefined
|
||||
|
||||
if (widgetData.meter) {
|
||||
var parsewidgets = require('../parser').widgets
|
||||
var data = {
|
||||
type:'meter',
|
||||
id: widgetData.id + '/meter',
|
||||
label:false,
|
||||
horizontal:widgetData.horizontal,
|
||||
range:widgetData.range,
|
||||
logScale:widgetData.logScale,
|
||||
path:widgetData.path + '/meter',
|
||||
preArgs:widgetData.preArgs,
|
||||
color:widgetData.color
|
||||
}
|
||||
var element = parsewidgets([data],fader)
|
||||
element[0].classList.add('not-editable')
|
||||
widget[0].classList.add('has-meter')
|
||||
}
|
||||
|
||||
|
||||
var rangeKeys = [],
|
||||
rangeVals = [],
|
||||
rangeLabels = []
|
||||
|
||||
for (k in widgetData.range) {
|
||||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||||
val = typeof widgetData.range[k] == 'object'?
|
||||
widgetData.range[k][Object.keys(widgetData.range[k])[0]]:
|
||||
widgetData.range[k],
|
||||
label = typeof widgetData.range[k] == 'object'?
|
||||
Object.keys(widgetData.range[k])[0]:
|
||||
val
|
||||
|
||||
rangeKeys.push(key)
|
||||
rangeVals.push(val)
|
||||
rangeLabels.push(label)
|
||||
}
|
||||
|
||||
var rangeValsMax = Math.max.apply(Math, rangeVals),
|
||||
rangeValsMin = Math.min.apply(Math, rangeVals)
|
||||
|
||||
if (!widgetData.noPip&&!widgetData.compact) {
|
||||
var pipTexts = {}
|
||||
for (k in rangeKeys) {
|
||||
pipTexts[rangeKeys[k]]=rangeLabels[k]
|
||||
}
|
||||
|
||||
var pipsInner = ''
|
||||
for (var i=0;i<=100;i++) {
|
||||
if (pipTexts[i]==undefined) continue
|
||||
|
||||
var pos = dimension=='height'?'bottom':'left';
|
||||
|
||||
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
|
||||
|
||||
var add = `
|
||||
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
|
||||
`
|
||||
pipsInner = pipsInner + add
|
||||
}
|
||||
pips[0].innerHTML = pipsInner
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fader.resize(function(){
|
||||
fader.size= dimension=='height'?fader.outerHeight():fader.outerWidth()
|
||||
wrapper.size = dimension=='height'?wrapper.outerHeight():wrapper.outerWidth()
|
||||
widget.updateUi(gauge.size)
|
||||
})
|
||||
|
||||
wrapper.on('fake-right-click',function(e){
|
||||
if (!EDITING) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
input.focus()
|
||||
}
|
||||
})
|
||||
|
||||
wrapper.on('mousewheel',function(e){
|
||||
if (e.originalEvent.wheelDeltaX) return
|
||||
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var divider = e.ctrlKey?4:.25
|
||||
gauge.size = clip(gauge.size+e.originalEvent.wheelDelta/(fader.size*divider),[0,100])
|
||||
|
||||
widget.updateUi(gauge.size)
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
})
|
||||
|
||||
var off = 0
|
||||
wrapper.on('draginit',function(e,data,traversing){
|
||||
if (snap || traversing) {
|
||||
|
||||
var d = (dimension=='height')?
|
||||
((fader.size-data.offsetY+(wrapper.size-fader.size)/2) * 100 / fader.size):
|
||||
(data.offsetX - (wrapper.size-fader.size)/2) * 100 / fader.size
|
||||
d = clip(d,[0,100])
|
||||
|
||||
widget.updateUi(d)
|
||||
gauge.size = d
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
off = gauge.size
|
||||
|
||||
})
|
||||
|
||||
|
||||
wrapper.on('drag',function(e,data){
|
||||
|
||||
var d = (dimension=='height')?-data.deltaY:data.deltaX
|
||||
d = clip(d*100/fader.size+off,[0,100])
|
||||
|
||||
widget.updateUi(d)
|
||||
|
||||
gauge.size = d
|
||||
|
||||
var v = widget.getValue()
|
||||
|
||||
if (v!=widget.value) {
|
||||
widget.value = v
|
||||
|
||||
widget.sendValue(v)
|
||||
widget.showValue(v)
|
||||
|
||||
widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
widget.updateUi = function(v){
|
||||
var s = v/100,
|
||||
t = dimension=='height'?
|
||||
['1,'+s+',1','0,'+ Math.round(-s*fader.size) +'px,0']
|
||||
:[s+',1,1',Math.round(s*fader.size) +'px,0,0']
|
||||
gauge[0].setAttribute('style','transform:scale3d('+t[0]+')')
|
||||
knob[0].setAttribute('style','transform:translate3d('+t[1]+')')
|
||||
}
|
||||
|
||||
widget.getValue = function(){
|
||||
var h = clip(gauge.size,[0,100])
|
||||
for (var i=0;i<rangeKeys.length-1;i++) {
|
||||
if (h <= rangeKeys[i+1] && h >= rangeKeys[i]) {
|
||||
return mapToScale(h,[rangeKeys[i],rangeKeys[i+1]],[rangeVals[i],rangeVals[i+1]],widgetData.precision,logScale)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
widget.setValue = function(v,send,sync) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
var h,
|
||||
v = clip(Math.round(v*roundFactor)/roundFactor,[rangeValsMin,rangeValsMax])
|
||||
for (var i=0;i<rangeVals.length-1;i++) {
|
||||
if (v <= rangeVals[i+1] && v >= rangeVals[i]) {
|
||||
h = mapToScale(v,[rangeVals[i],rangeVals[i+1]],[rangeKeys[i],rangeKeys[i+1]],false,logScale,true)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
widget.updateUi(h)
|
||||
|
||||
gauge.size = h
|
||||
|
||||
widget.value = v
|
||||
widget.showValue(v)
|
||||
|
||||
|
||||
if (sync) widget.trigger('sync',[widgetData.id,widget,widgetData.linkId])
|
||||
if (send) widget.sendValue(v)
|
||||
}
|
||||
|
||||
widget.sendValue = function(v) {
|
||||
var args = widgetData.preArgs.concat(v)
|
||||
|
||||
sendOsc({
|
||||
target:widgetData.target,
|
||||
path:widgetData.path,
|
||||
precision:widgetData.precision,
|
||||
args:args
|
||||
})
|
||||
}
|
||||
|
||||
widget.showValue = function(v) {
|
||||
input.val(v+unit)
|
||||
}
|
||||
|
||||
input.change(function(){
|
||||
widget.setValue(parseFloat(input.val()),true,true)
|
||||
})
|
||||
|
||||
widget.setValue(rangeVals[0])
|
||||
|
||||
return widget
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ _plots_base.prototype.syncHandleProxy = function() {
|
|||
_plots_base.prototype.syncHandle = function(e,id,w) {
|
||||
if (this.linkedWidgets.indexOf(id)==-1 || !WIDGETS[id]) return
|
||||
this.updateData()
|
||||
requestAnimationFrame(this._draw.bind(this))
|
||||
requestAnimationFrame(this.draw.bind(this))
|
||||
}
|
||||
|
||||
_plots_base.prototype.resizeHandle = function(){
|
||||
|
|
@ -50,19 +50,19 @@ _plots_base.prototype.resizeHandle = function(){
|
|||
_canvas_base.prototype.resizeHandle.call(this)
|
||||
}
|
||||
|
||||
_plots_base.prototype._draw = function() {
|
||||
_plots_base.prototype.draw = function() {
|
||||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
this.ctx.beginPath()
|
||||
|
||||
this.draw()
|
||||
this.draw_data()
|
||||
|
||||
this.ctx.lineWidth = 1*PXSCALE
|
||||
this.ctx.strokeStyle = this.lineColor
|
||||
this.ctx.strokeStyle = this.colors.custom
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.font = PXSCALE * 10 + 'px sans-serif'
|
||||
this.ctx.fillStyle = this.textColor
|
||||
this.ctx.fillStyle = this.colors.text
|
||||
|
||||
|
||||
this.ctx.textBaseline = "bottom"
|
||||
|
|
@ -85,7 +85,7 @@ _plots_base.prototype._draw = function() {
|
|||
|
||||
}
|
||||
|
||||
_plots_base.prototype.draw = function() {
|
||||
_plots_base.prototype.draw_data = function() {
|
||||
var first = true
|
||||
var point = []
|
||||
for (i in this.data) {
|
||||
|
|
@ -118,7 +118,7 @@ _plots_base.prototype.draw = function() {
|
|||
|
||||
_plots_base.prototype.setValue = function(v) {
|
||||
this.data = v
|
||||
requestAnimationFrame(this._draw.bind(this))
|
||||
requestAnimationFrame(this.draw.bind(this))
|
||||
}
|
||||
|
||||
_plots_base.prototype.updateData = function(){
|
||||
|
|
|
|||
|
|
@ -67,12 +67,12 @@ Visualizer.prototype.startLoop = function(){
|
|||
|
||||
this.loop = setInterval(function(){
|
||||
this.updateData()
|
||||
this._draw()
|
||||
this.draw()
|
||||
}.bind(this),1000*this.widgetData.duration/this.length)
|
||||
}
|
||||
|
||||
|
||||
Visualizer.prototype.draw = function(){
|
||||
Visualizer.prototype.draw_data = function(){
|
||||
|
||||
var first = true
|
||||
var point = []
|
||||
|
|
|
|||
173
browser/js/app/widgets/sliders/_sliders_base.js
Normal file
173
browser/js/app/widgets/sliders/_sliders_base.js
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
var {clip, mapToScale, sendOsc} = require('../utils')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
var _sliders_base = module.exports = function(){
|
||||
|
||||
this.widget = $(`
|
||||
<div class="slider">
|
||||
<div class="wrapper">
|
||||
<canvas></canvas>
|
||||
</div>
|
||||
<div class="input"></div>
|
||||
</div>
|
||||
`)
|
||||
|
||||
_canvas_base.apply(this, arguments)
|
||||
|
||||
this.input = this.widget.find('.input').fakeInput({align:'center'})
|
||||
this.roundFactor = Math.pow(10,this.widgetData.precision)
|
||||
this.value = undefined
|
||||
this.percent = 0
|
||||
|
||||
|
||||
this.rangeKeys = []
|
||||
this.rangeVals = []
|
||||
this.rangeLabels = []
|
||||
|
||||
for (k in this.widgetData.range) {
|
||||
var key = k=='min'?0:k=='max'?100:parseInt(k),
|
||||
val = typeof this.widgetData.range[k] == 'object'?
|
||||
this.widgetData.range[k][Object.keys(this.widgetData.range[k])[0]]:
|
||||
this.widgetData.range[k],
|
||||
label = typeof this.widgetData.range[k] == 'object'?
|
||||
Object.keys(this.widgetData.range[k])[0]:
|
||||
val
|
||||
|
||||
this.rangeKeys.push(key)
|
||||
this.rangeVals.push(val)
|
||||
this.rangeLabels.push(label)
|
||||
}
|
||||
this.rangeValsMax = Math.max.apply(Math, this.rangeVals),
|
||||
this.rangeValsMin = Math.min.apply(Math, this.rangeVals)
|
||||
|
||||
this.originValue = this.widgetData.origin=='auto'?
|
||||
this.rangeValsMin:
|
||||
clip(this.widgetData.origin,[this.rangeValsMin,this.rangeValsMax])
|
||||
|
||||
|
||||
|
||||
this.widget.on('fake-right-click',function(e){
|
||||
if (!EDITING) {
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
this.input.focus()
|
||||
}
|
||||
}.bind(this))
|
||||
|
||||
this.widget.on('mousewheel',this.mousewheelHandleProxy.bind(this))
|
||||
this.canvas.on('draginit',this.draginitHandleProxy.bind(this))
|
||||
this.canvas.on('drag',this.dragHandleProxy.bind(this))
|
||||
|
||||
this.input.change(function(){
|
||||
this.widget.setValue(parseFloat(this.input.val()),true,true)
|
||||
}.bind(this))
|
||||
|
||||
this.widget.getValue = function(){
|
||||
return this.value
|
||||
}.bind(this)
|
||||
|
||||
this.widget.setValue = this.setValue.bind(this)
|
||||
|
||||
this.setValue(this.originValue)
|
||||
|
||||
}
|
||||
|
||||
_sliders_base.prototype = Object.create(_canvas_base.prototype)
|
||||
|
||||
_sliders_base.prototype.constructor = _sliders_base
|
||||
|
||||
|
||||
_sliders_base.prototype.mousewheelHandleProxy = function() {
|
||||
this.mousewheelHandle.apply(this,arguments)
|
||||
}
|
||||
|
||||
_sliders_base.prototype.draginitHandleProxy = function() {
|
||||
this.draginitHandle.apply(this,arguments)
|
||||
}
|
||||
|
||||
_sliders_base.prototype.dragHandleProxy = function() {
|
||||
this.dragHandle.apply(this,arguments)
|
||||
}
|
||||
|
||||
|
||||
_sliders_base.prototype.mousewheelHandle = function(e, data, traversing) {
|
||||
if (e.originalEvent.wheelDeltaX) return
|
||||
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var direction = e.originalEvent.wheelDelta / Math.abs(e.originalEvent.wheelDelta),
|
||||
increment = e.ctrlKey?0.25:1
|
||||
|
||||
this.percent = clip(this.percent + Math.max(increment,100/Math.pow(10,this.widgetData.precision)) * direction ,[0,100])
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true)
|
||||
|
||||
|
||||
}
|
||||
|
||||
_sliders_base.prototype.draginitHandle = function(e, data, traversing) {
|
||||
|
||||
}
|
||||
|
||||
_sliders_base.prototype.dragHandle = function(e, data, traversing) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
_sliders_base.prototype.resizeHandle = function() {
|
||||
if (!self.visible) {
|
||||
this.colors.track = getComputedStyle(this.widget[0]).getPropertyValue('--color-track')
|
||||
this.colors.gauge = getComputedStyle(this.widget[0]).getPropertyValue('--color-gauge')
|
||||
this.colors.knob = getComputedStyle(this.widget[0]).getPropertyValue('--color-knob')
|
||||
}
|
||||
_canvas_base.prototype.resizeHandle.call(this)
|
||||
}
|
||||
|
||||
|
||||
_sliders_base.prototype.percentToValue = function(percent) {
|
||||
var h = clip(percent,[0,100])
|
||||
for (var i=0;i<this.rangeKeys.length-1;i++) {
|
||||
if (h <= this.rangeKeys[i+1] && h >= this.rangeKeys[i]) {
|
||||
return mapToScale(h,[this.rangeKeys[i],this.rangeKeys[i+1]],[this.rangeVals[i],this.rangeVals[i+1]],this.widgetData.precision,this.widgetData.logScale)
|
||||
}
|
||||
}
|
||||
}
|
||||
_sliders_base.prototype.valueToPercent = function(value) {
|
||||
for (var i=0;i<this.rangeVals.length-1;i++) {
|
||||
if (value <= this.rangeVals[i+1] && value >= this.rangeVals[i]) {
|
||||
return mapToScale(value,[this.rangeVals[i],this.rangeVals[i+1]],[this.rangeKeys[i],this.rangeKeys[i+1]],false,this.widgetData.logScale,true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_sliders_base.prototype.setValue = function(v,send,sync, dragged) {
|
||||
if (typeof v != 'number') return
|
||||
|
||||
this.value = clip(Math.round(v*this.roundFactor)/this.roundFactor,[this.rangeValsMin,this.rangeValsMax])
|
||||
|
||||
if (!dragged) this.percent = this.valueToPercent(this.value)
|
||||
|
||||
this.draw()
|
||||
|
||||
this.showValue()
|
||||
|
||||
if (sync) this.widget.trigger('sync',[this.widgetData.id,this.widget,this.widgetData.linkId])
|
||||
if (send) this.sendValue(v)
|
||||
}
|
||||
|
||||
_sliders_base.prototype.sendValue = function(value) {
|
||||
var args = this.widgetData.preArgs.concat(value)
|
||||
|
||||
sendOsc({
|
||||
target:this.widgetData.target,
|
||||
path:this.widgetData.path,
|
||||
precision:this.widgetData.precision,
|
||||
args:args
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
_sliders_base.prototype.showValue = function() {
|
||||
this.input.val(this.value + ' ' + this.widgetData.unit)
|
||||
}
|
||||
262
browser/js/app/widgets/sliders/fader.js
Normal file
262
browser/js/app/widgets/sliders/fader.js
Normal file
|
|
@ -0,0 +1,262 @@
|
|||
var {clip, mapToScale, sendOsc} = require('../utils'),
|
||||
_sliders_base = require('./_sliders_base')
|
||||
|
||||
var Fader = function(widgetData){
|
||||
|
||||
_sliders_base.apply(this,arguments)
|
||||
this.widget.addClass('fader-v2')
|
||||
this.margin = 20
|
||||
|
||||
|
||||
if (widgetData.horizontal) {
|
||||
this.widget.addClass('horizontal')
|
||||
}
|
||||
|
||||
if (widgetData.compact) {
|
||||
this.widget.addClass('compact')
|
||||
this.margin = 0
|
||||
}
|
||||
|
||||
if (widgetData.alignRight && !widgetData.horizontal) {
|
||||
this.widget.addClass('align-right')
|
||||
}
|
||||
|
||||
if (!widgetData.noPip&&!widgetData.compact) {
|
||||
|
||||
this.widget.addClass('has-pips')
|
||||
|
||||
var pips = $('<div class="pips"></div>').appendTo(this.widget.find('.wrapper'))
|
||||
var pipTexts = {}
|
||||
for (k in this.rangeKeys) {
|
||||
pipTexts[this.rangeKeys[k]]=this.rangeLabels[k]
|
||||
}
|
||||
|
||||
var pipsInner = ''
|
||||
for (var i=0;i<=100;i++) {
|
||||
if (pipTexts[i]==undefined) continue
|
||||
|
||||
var pos = widgetData.horizontal?'left':'bottom';
|
||||
|
||||
var piptext = `<span>${Math.abs(pipTexts[i])>=1000?pipTexts[i]/1000+'k':pipTexts[i]}</span>`
|
||||
|
||||
var add = `
|
||||
<div class="pip val" style="${pos}:${i}%">${piptext}</div>
|
||||
`
|
||||
pipsInner = pipsInner + add
|
||||
}
|
||||
pips[0].innerHTML = pipsInner
|
||||
}
|
||||
|
||||
|
||||
if (widgetData.meter) {
|
||||
var parsewidgets = require('../../parser').widgets
|
||||
var data = {
|
||||
type:'meter',
|
||||
id: widgetData.id + '/meter',
|
||||
label:false,
|
||||
horizontal:widgetData.horizontal,
|
||||
range:widgetData.range,
|
||||
logScale:widgetData.logScale,
|
||||
path:widgetData.path + '/meter',
|
||||
preArgs:widgetData.preArgs,
|
||||
color:widgetData.color
|
||||
}
|
||||
var element = parsewidgets([data],this.widget.find('.wrapper'))
|
||||
element[0].classList.add('not-editable')
|
||||
this.widget[0].classList.add('has-meter')
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Fader.prototype = Object.create(_sliders_base.prototype)
|
||||
|
||||
Fader.prototype.constructor = Fader
|
||||
|
||||
Fader.prototype.draginitHandle = function(e, data, traversing){
|
||||
|
||||
this.percent = clip(this.percent,[0,100])
|
||||
|
||||
if (!(traversing || this.widgetData.snap)) return
|
||||
|
||||
this.percent = this.widgetData.horizontal?
|
||||
(data.offsetX - this.margin * PXSCALE) / (this.width - (this.margin * PXSCALE * 2)) * 100:
|
||||
(this.height - data.offsetY - this.margin * PXSCALE) / (this.height - (this.margin * PXSCALE * 2)) * 100
|
||||
|
||||
// this.percent = clip(this.percent,[0,100])
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Fader.prototype.dragHandle = function(e, data) {
|
||||
|
||||
this.percent = this.widgetData.horizontal?
|
||||
this.percent + ( data.speedX/(this.width - this.margin * PXSCALE * 2)) * 100:
|
||||
this.percent + (-data.speedY/(this.height - this.margin * PXSCALE * 2)) * 100
|
||||
|
||||
this.percent = this.percent,[0,100]
|
||||
|
||||
this.setValue(this.percentToValue(this.percent), true, true, true)
|
||||
|
||||
}
|
||||
|
||||
Fader.prototype.percentToCoord = function(percent) {
|
||||
if (this.widgetData.horizontal) {
|
||||
return clip(percent / 100,[0,1]) * (this.width - 2 * PXSCALE * this.margin)
|
||||
} else {
|
||||
return (this.height - this.margin * PXSCALE) - clip(percent / 100, [0,1]) * (this.height - 2 * PXSCALE * this.margin)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Fader.prototype.draw = function(){
|
||||
|
||||
var d = this.percentToCoord(this.percent),
|
||||
o = this.percentToCoord(this.valueToPercent(this.originValue))
|
||||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
|
||||
if (this.widgetData.horizontal) {
|
||||
if (this.widgetData.compact) {
|
||||
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.beginPath()
|
||||
this.ctx.moveTo(d, this.height / 2)
|
||||
this.ctx.lineTo(o, this.height / 2)
|
||||
this.ctx.lineWidth = this.height
|
||||
this.ctx.stroke()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.rect(Math.min(d,this.width-PXSCALE), 0, PXSCALE, this.height)
|
||||
this.ctx.fill()
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.track
|
||||
this.ctx.rect(this.margin * PXSCALE, this.height / 2 - 1 * PXSCALE, this.width - this.margin * 2 * PXSCALE, 2 * PXSCALE)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.moveTo(d + this.margin * PXSCALE, this.height / 2)
|
||||
this.ctx.lineTo(o + this.margin * PXSCALE, this.height / 2)
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(d + this.margin * PXSCALE, this.height / 2, 4 * PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if (this.widgetData.compact) {
|
||||
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.beginPath()
|
||||
this.ctx.moveTo(this.width / 2, d)
|
||||
this.ctx.lineTo(this.width / 2, o)
|
||||
this.ctx.lineWidth = this.width
|
||||
this.ctx.stroke()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.rect(0, Math.min(d,this.height-PXSCALE), this.width, PXSCALE)
|
||||
this.ctx.fill()
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.track
|
||||
this.ctx.rect(this.width / 2 - 1 * PXSCALE, this.margin * PXSCALE, 2 * PXSCALE, this.height - this.margin *2 * PXSCALE)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.strokeStyle = this.colors.gauge
|
||||
this.ctx.moveTo(this.width / 2, d)
|
||||
this.ctx.lineTo(this.width / 2, o)
|
||||
this.ctx.lineWidth = 2 * PXSCALE
|
||||
this.ctx.stroke()
|
||||
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.fillStyle = this.colors.knob
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
this.ctx.arc(this.width / 2, d, 10 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(this.width / 2, d, 4 *PXSCALE, Math.PI * 2,false)
|
||||
this.ctx.fill()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
module.exports.options = {
|
||||
type:'fader',
|
||||
id:'auto',
|
||||
linkId:'',
|
||||
|
||||
separator1:'style',
|
||||
|
||||
label:'auto',
|
||||
unit:'',
|
||||
left:'auto',
|
||||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
alignRight:false,
|
||||
horizontal:false,
|
||||
noPip:false,
|
||||
compact:false,
|
||||
color:'auto',
|
||||
css:'',
|
||||
|
||||
separator2:'behaviour',
|
||||
|
||||
snap:false,
|
||||
|
||||
separator3:'osc',
|
||||
|
||||
range:{min:0,max:1},
|
||||
origin: 'auto',
|
||||
logScale:false,
|
||||
precision:2,
|
||||
meter:false,
|
||||
path:'auto',
|
||||
preArgs:[],
|
||||
target:[]
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData,container) {
|
||||
|
||||
var fader = new Fader(widgetData, container)
|
||||
return fader.widget
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -41,6 +41,7 @@
|
|||
width: 100%;
|
||||
background: var(--color-raised);
|
||||
border-bottom:1rem solid var(--color-bg);
|
||||
flex-shrink: 0;
|
||||
|
||||
&.accent {
|
||||
color:var(--color-accent);
|
||||
|
|
|
|||
|
|
@ -1,211 +1,53 @@
|
|||
.fader-container {
|
||||
--color-pips: var(--color-text-fade);
|
||||
--color-gauge: var(--color-custom);
|
||||
--color-knob: var(--color-custom);
|
||||
|
||||
|
||||
|
||||
width:100rem;
|
||||
min-height: 200rem;
|
||||
.fader-v2 {
|
||||
height:100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
|
||||
&.align-right {
|
||||
|
||||
.fader-wrapper {
|
||||
.fader {
|
||||
margin-left:calc(50% + 10rem);
|
||||
}
|
||||
.meter-container {
|
||||
right:auto;
|
||||
left:-13rem!important;
|
||||
}
|
||||
.pips {
|
||||
margin-left: -20rem;
|
||||
.pip {
|
||||
right:0;
|
||||
left:auto;
|
||||
span {
|
||||
right:3rem;
|
||||
left:auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.compact {
|
||||
.fader-wrapper-outer .fader-wrapper .fader{
|
||||
.meter-container {
|
||||
left:0!important;
|
||||
right: auto!important;
|
||||
}
|
||||
}
|
||||
.has-meter {
|
||||
.input {
|
||||
left:calc(50% + 2rem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
&.compact {
|
||||
.fader-wrapper-outer {
|
||||
.input {
|
||||
position: absolute;
|
||||
top:50%;
|
||||
transform: rotate(-90deg);
|
||||
pointer-events: none;
|
||||
width: 100rem;
|
||||
margin-left: -50rem;
|
||||
left:50%;
|
||||
z-index: 3;
|
||||
}
|
||||
.fader-wrapper {
|
||||
padding:1rem 0 0!important;
|
||||
background:var(--color-faded);
|
||||
.fader {
|
||||
width:100%;
|
||||
margin: 0;
|
||||
&:before {
|
||||
content:none;
|
||||
}
|
||||
.gauge {
|
||||
opacity: .3;
|
||||
}
|
||||
.knob {
|
||||
&:before, &:after {
|
||||
display:none;
|
||||
}
|
||||
width:100%;
|
||||
height:1rem;
|
||||
background:var(--color-knob);
|
||||
}
|
||||
.pips {
|
||||
display: none;
|
||||
}
|
||||
.meter-container {
|
||||
right:-1rem!important;
|
||||
left: auto!important;
|
||||
width: 4rem;
|
||||
top:-2rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.has-meter {
|
||||
.input {
|
||||
left:calc(50% - 2rem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
margin-top:-5rem;
|
||||
}
|
||||
|
||||
.fader-wrapper-outer {
|
||||
.wrapper {
|
||||
overflow: hidden;
|
||||
flex:1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex:1;
|
||||
}
|
||||
|
||||
.fader-wrapper {
|
||||
padding:20rem;
|
||||
flex:1;
|
||||
overflow:hidden;
|
||||
max-height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
cursor: -webkit-grab;
|
||||
&:active {
|
||||
cursor: -webkit-grabbing;
|
||||
}
|
||||
.fader {
|
||||
width:2rem;
|
||||
position: relative;
|
||||
margin:0 auto;
|
||||
margin-right:calc(50% + 15rem);
|
||||
|
||||
pointer-events: none;
|
||||
canvas {
|
||||
flex:1;
|
||||
&:before {
|
||||
content:"";
|
||||
width:100%;
|
||||
height:100%;
|
||||
background:var(--color-track);
|
||||
// z-index: 1;
|
||||
display:block;
|
||||
position: absolute;
|
||||
}
|
||||
.gauge {
|
||||
position: absolute;
|
||||
bottom:0!important;
|
||||
top:0!important;
|
||||
width:100%;
|
||||
height:100%;
|
||||
transform-origin: bottom;
|
||||
max-height:100%;
|
||||
max-width:100%;
|
||||
background:var(--color-gauge);
|
||||
z-index: 1;
|
||||
max-height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
}
|
||||
.knob {
|
||||
position: absolute;
|
||||
bottom:0;
|
||||
width:0;
|
||||
height:0;
|
||||
z-index: 2;
|
||||
&:before {
|
||||
content:"";
|
||||
position: absolute;
|
||||
top:-4rem;
|
||||
left:-3rem;
|
||||
height:8rem;
|
||||
width:8rem;
|
||||
background:var(--color-knob);
|
||||
border:none!important;
|
||||
border-radius: 100%!important;
|
||||
}
|
||||
&:after {
|
||||
content:"";
|
||||
position: absolute;
|
||||
top:-10rem;
|
||||
left:-9rem;
|
||||
height:20rem;
|
||||
width:20rem;
|
||||
border:none!important;
|
||||
border-radius: 100%!important;
|
||||
background:var(--color-knob);
|
||||
opacity: .2;
|
||||
}
|
||||
}
|
||||
.meter-container {
|
||||
position: absolute;
|
||||
z-index: 2;
|
||||
left:auto;
|
||||
right:-15rem;
|
||||
bottom:0;
|
||||
top:0;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
width: 4rem;
|
||||
background: var(--color-bg);
|
||||
height:auto;
|
||||
.meter {
|
||||
margin:0;
|
||||
}
|
||||
}
|
||||
.meter-container {
|
||||
pointer-events: none;
|
||||
|
||||
position: absolute;
|
||||
top:20rem;
|
||||
bottom:19rem;
|
||||
left:50%;
|
||||
height: auto;
|
||||
width:3rem;
|
||||
min-width: 3rem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
&.has-pips {
|
||||
|
||||
.wrapper canvas {
|
||||
padding-right: 28rem;
|
||||
}
|
||||
|
||||
.pips {
|
||||
pointer-events: none;
|
||||
|
||||
position: absolute;
|
||||
top:0;
|
||||
bottom:0;
|
||||
top:20rem;
|
||||
bottom:20rem;
|
||||
left:50%;
|
||||
z-index: 0;
|
||||
width: 4rem;
|
||||
margin-left: 17rem;
|
||||
margin-left: 7rem;
|
||||
background: linear-gradient(to bottom, transparent 0, transparent 2px, var(--color-pips) 2px, var(--color-pips) 3px, transparent 3px, transparent 5px);
|
||||
background-size: 100% 5px;
|
||||
background-repeat: repeat-y;
|
||||
|
|
@ -240,131 +82,111 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.no-pip {
|
||||
.pips {
|
||||
display: none!important;
|
||||
&.horizontal {
|
||||
.wrapper canvas {
|
||||
padding-right:0;
|
||||
padding-bottom: 20rem;
|
||||
}
|
||||
.fader {
|
||||
margin:0 auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.fader-container.horizontal {
|
||||
min-height: 80rem;
|
||||
height: auto;
|
||||
width:300rem;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.compact .fader-wrapper-outer {
|
||||
|
||||
.input {
|
||||
transform: none;
|
||||
top:50%;
|
||||
margin-top:-15rem;
|
||||
}
|
||||
.fader-wrapper {
|
||||
display:flex;
|
||||
flex:1;
|
||||
padding:0 1rem 0 0!important;
|
||||
}
|
||||
.fader {
|
||||
height:100%;
|
||||
top:0;
|
||||
.knob {
|
||||
width:1rem;
|
||||
height:100%;
|
||||
margin-bottom:0;
|
||||
bottom:0;
|
||||
}
|
||||
.meter-container {
|
||||
top:0;
|
||||
left:0!important;
|
||||
right:-1px!important;
|
||||
.wrapper .meter-container {
|
||||
left:20rem;
|
||||
right:20rem;
|
||||
height: 3rem;
|
||||
min-height: 3rem;
|
||||
width: auto;
|
||||
height: 4rem;
|
||||
top:50%;
|
||||
margin-top: 3rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.fader-wrapper-outer {
|
||||
position: relative;
|
||||
top:auto;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
.fader-wrapper {
|
||||
padding:20rem 20rem 40rem;
|
||||
display: block;
|
||||
flex:0;
|
||||
flex-shrink: 0;
|
||||
&.no-pip {
|
||||
padding: 20rem;
|
||||
}
|
||||
}
|
||||
.fader {
|
||||
width:100%;
|
||||
left:auto;
|
||||
top:50%;
|
||||
height:2rem;
|
||||
&:before {
|
||||
box-shadow:none;
|
||||
}
|
||||
.gauge {
|
||||
transform-origin: left;
|
||||
}
|
||||
.meter-container {
|
||||
top:-15rem;
|
||||
left:0;
|
||||
right:0;
|
||||
bottom:auto;
|
||||
height:1rem;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
.pips {
|
||||
top:50%;
|
||||
left:20rem;
|
||||
right:20rem;
|
||||
font-size: 0;
|
||||
height:4rem;
|
||||
width:auto;
|
||||
height: 4rem;
|
||||
}
|
||||
.knob {
|
||||
bottom:1px;
|
||||
margin:0;
|
||||
margin-top: 10rem;
|
||||
background: linear-gradient(to right, transparent 0, transparent 2px, var(--color-pips) 2px, var(--color-pips) 3px, transparent 3px, transparent 5px);
|
||||
background-size: 5px 100%;
|
||||
background-repeat: repeat-x;
|
||||
.pip {
|
||||
width:1px;
|
||||
height:6rem;
|
||||
margin: 0;
|
||||
&:before {
|
||||
top:0;
|
||||
bottom:0;
|
||||
left:-4px;
|
||||
right:-4px;
|
||||
}
|
||||
span {
|
||||
top:15rem;
|
||||
left:-15rem!important;
|
||||
right:auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.pips {
|
||||
top:15rem;left:0;
|
||||
right:0;
|
||||
font-size: 0;
|
||||
height:4rem;
|
||||
width:100%;
|
||||
margin:0;
|
||||
background: linear-gradient(to right, transparent 0, transparent 2px, var(--color-pips) 2px, var(--color-pips) 3px, transparent 3px, transparent 5px);
|
||||
background-size: 5px 100%;
|
||||
background-repeat: repeat-x;
|
||||
}
|
||||
.pip {
|
||||
width:1px;
|
||||
height:6rem;
|
||||
margin: 0;
|
||||
&:before {
|
||||
top:0;
|
||||
bottom:0;
|
||||
left:-4px;
|
||||
right:-4px;
|
||||
|
||||
&.align-right {
|
||||
.wrapper canvas {
|
||||
padding-right: 0;
|
||||
padding-left: 28rem;
|
||||
}
|
||||
span {
|
||||
top:15rem;
|
||||
left:-15rem!important;
|
||||
right:auto;
|
||||
.wrapper .meter-container {
|
||||
left: auto;
|
||||
right:50%;
|
||||
margin-left: 0;
|
||||
}
|
||||
.pips {
|
||||
margin-left: 0;
|
||||
margin-right: 7rem;
|
||||
left:auto;
|
||||
right:50%;
|
||||
.pip {
|
||||
right:0;
|
||||
left:auto;
|
||||
span {
|
||||
right:3rem;
|
||||
left:auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
&.compact .has-meter {
|
||||
&.compact {
|
||||
.input {
|
||||
top:calc(50% + 2rem)
|
||||
overflow: hidden;
|
||||
position: absolute;
|
||||
top:50%;
|
||||
transform: rotate(-90deg);
|
||||
pointer-events: none;
|
||||
width: 100rem;
|
||||
margin-left: -50rem;
|
||||
left:50%;
|
||||
z-index: 3;
|
||||
margin-top: -15rem;
|
||||
}
|
||||
.meter-container {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: auto;
|
||||
right:0;
|
||||
}
|
||||
&.horizontal {
|
||||
.meter-container {
|
||||
top: auto;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right:0;
|
||||
height: 3rem;
|
||||
min-height: 3rem;
|
||||
width: auto;
|
||||
}
|
||||
.input {
|
||||
transform: none;
|
||||
top:50%;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue