pads: inherit from canvas base class and xy: cancel faders drawing, use a dedicated, simple draw

This commit is contained in:
jean-emmanuel 2016-10-20 18:51:02 +02:00
parent 5acb8414c8
commit ea56f48388
4 changed files with 49 additions and 13 deletions

View file

@ -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(){}

View file

@ -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

View file

@ -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) {