pads: inherit from canvas base class and xy: cancel faders drawing, use a dedicated, simple draw
This commit is contained in:
parent
5acb8414c8
commit
ea56f48388
4 changed files with 49 additions and 13 deletions
|
|
@ -11,3 +11,5 @@ _fake_fader.prototype = Object.create(Fader.prototype)
|
|||
_fake_fader.prototype.constructor = _fake_fader
|
||||
|
||||
_fake_fader.prototype.sendValue = function(){}
|
||||
|
||||
_fake_fader.prototype.draw = function(){}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
var Fader = require('../sliders/fader')
|
||||
var _widgets_base = require('../common/_widgets_base')
|
||||
var _canvas_base = require('../common/_canvas_base')
|
||||
|
||||
var _pads_base = module.exports = function(){
|
||||
|
||||
this.widget = $(`
|
||||
<div class="pad">
|
||||
<div class="wrapper">
|
||||
|
||||
<canvas></canvas>
|
||||
</div>
|
||||
</div>
|
||||
`)
|
||||
this.wrapper = this.widget.find('.wrapper')
|
||||
_widgets_base.apply(this, arguments)
|
||||
_canvas_base.apply(this, arguments)
|
||||
|
||||
|
||||
}
|
||||
|
||||
_pads_base.prototype = Object.create(_widgets_base.prototype)
|
||||
_pads_base.prototype = Object.create(_canvas_base.prototype)
|
||||
|
||||
_pads_base.prototype.constructor = _pads_base
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
var _pads_base = require('./_pads_base'),
|
||||
Fader = require('./_fake_fader')
|
||||
Fader = require('./_fake_fader'),
|
||||
{clip} = require('../utils')
|
||||
|
||||
module.exports.options = {
|
||||
type:'xy',
|
||||
|
|
@ -95,7 +96,7 @@ var Xy = module.exports.Xy = function(widgetData) {
|
|||
|
||||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
|
||||
|
||||
this.draw()
|
||||
})
|
||||
|
||||
this.wrapper.on('draginit',(e, data, traversing)=>{
|
||||
|
|
@ -136,7 +137,41 @@ Xy.prototype.setValue = function(v, options){
|
|||
|
||||
if (options.send) this.sendValue()
|
||||
if (options.sync) this.widget.trigger({type:'sync', id:this.widgetData.id,widget:this.widget, linkId:this.widgetData.linkId, options:options})
|
||||
this.draw()
|
||||
}
|
||||
|
||||
Xy.prototype.draw = function(){
|
||||
|
||||
var x = clip(this.faders.x.percent / 100 * this.width,[0,this.width]),
|
||||
y = clip((1 - this.faders.y.percent / 100) * this.height,[0,this.height])
|
||||
|
||||
this.ctx.clearRect(0,0,this.width,this.height)
|
||||
|
||||
this.ctx.fillStyle = this.faders.x.colors.custom
|
||||
this.ctx.lineWidth = PXSCALE
|
||||
this.ctx.strokeStyle = this.faders.x.colors.custom
|
||||
|
||||
this.ctx.save()
|
||||
this.ctx.globalAlpha = 0.3
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(x, y, 10 * PXSCALE, Math.PI * 2, false)
|
||||
this.ctx.fill()
|
||||
|
||||
this.ctx.globalAlpha = 0.1
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.moveTo(0,y)
|
||||
this.ctx.lineTo(this.width,y)
|
||||
this.ctx.moveTo(x,0)
|
||||
this.ctx.lineTo(x,this.height)
|
||||
this.ctx.stroke()
|
||||
|
||||
this.ctx.restore()
|
||||
|
||||
this.ctx.beginPath()
|
||||
this.ctx.arc(x, y, 4 * PXSCALE, Math.PI * 2, false)
|
||||
this.ctx.fill()
|
||||
}
|
||||
|
||||
module.exports.create = function(widgetData) {
|
||||
|
|
|
|||
|
|
@ -15,18 +15,17 @@
|
|||
height: 100%;
|
||||
width: 100%;
|
||||
background:var(--color-faded);
|
||||
> canvas {
|
||||
width:100%;
|
||||
height:100%;
|
||||
position: absolute;
|
||||
}
|
||||
.fader {
|
||||
--color-gauge:transparent;
|
||||
--color-pips: var(--color-text-fade);
|
||||
--color-knob: var(--color-custom);
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
width:100%;
|
||||
height:100%;
|
||||
opacity: 0.5;
|
||||
.wrapper canvas {
|
||||
background:transparent;
|
||||
}
|
||||
opacity: 0;
|
||||
.input {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue