canvas clear

This commit is contained in:
bordun 2020-03-23 10:18:45 +01:00
parent 3ce0a0e6af
commit 96fa226600

View file

@ -2,6 +2,7 @@ var Canvas = require('../common/canvas'),
html = require('nanohtml')
class CanvasWidget extends Canvas {
static description() {
return 'KANVA !'
@ -15,16 +16,8 @@ class CanvasWidget extends Canvas {
_canvas:'canvas',
valueLength: {type: 'number', value: 1, help: ' '},
multiTouch: {type: 'boolean', value: false, help: ' '},
sensitivity: {type: 'number', value: 1, help: ' '},
snap: {type: 'boolean', value: true, help: ' '},
coordsToValue: {type: 'script', value: '', help: ' '},
valueToCoords: {type: 'script', value: '', help: ' '},
draw: {type: 'script', value: '', help: ' '},
autoClear: {type: 'boolean', value: true, help: ' '},
onCreate: {type: 'string', value: '', help: ' '},
onTouch: {type: 'string', value: '', help: ' '},
}, [], {})
@ -38,63 +31,22 @@ class CanvasWidget extends Canvas {
</div>
`})
this.nextTouch = 0
this.value = 1
this.touchMap = {}
this.touchCoords = []
for (var i = 0; i < this.getProp('valueLength'); i++) {
this.touchCoords.push([0,0])
}
this.localContext = {}
this.on('draginit',(e)=>{
if (this.touchMap[e.pointerId] !== undefined) return
this.touchMap[e.pointerId] = this.nextTouch++
if (this.getProp('snap')) this.touchCoords[this.touchMap[e.pointerId]] = [e.offsetX, e.offsetY]
this.touchCallback(e)
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
}, {element: this.widget, multitouch: true})
this.on('drag',(e)=>{
if (this.touchMap[e.pointerId] === undefined) return
console.log(this.touchMap[e.pointerId])
this.touchCoords[this.touchMap[e.pointerId]][0] += e.movementX / e.inertia * this.getProp('sensitivity')
this.touchCoords[this.touchMap[e.pointerId]][1] += e.movementY / e.inertia * this.getProp('sensitivity')
this.touchCallback(e)
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
}, {element: this.widget, multitouch: true})
this.on('dragend',(e)=>{
if (this.touchMap[e.pointerId] === undefined) return
delete this.touchMap[e.pointerId]
this.nextTouch--
this.touchCallback(e)
}, {element: this.widget, multitouch: true})
}, {element: this.widget, multitouch: this.getProp('multiTouch')})
}
touchCallback() {
var value = this.resolveProp('coordsToValue', undefined, false, false, false, {
coords: this.touchCoords,
value: this.value,
width: this.width,
height: this.height,
local: this.localContext
})
if (value !== undefined) this.setValue(value, {send: true, sync: true, dragged: true})
}
@ -145,28 +97,7 @@ class CanvasWidget extends Canvas {
}
CanvasWidget.parsersContexts.coordsToValue = CanvasWidget.parsersContexts.valueToCoords = {
coords: [[]],
value: [],
width: 100,
height: 100,
local: {}
}
CanvasWidget.parsersContexts.draw = {
value: [],
coords: [[]],
colors: {},
width: 100,
height: 100,
ctx: ()=>{}
}
CanvasWidget.dynamicProps = CanvasWidget.prototype.constructor.dynamicProps.concat([
'draw',
'sensitivity'
])
module.exports = CanvasWidget