From 96fa22660010e04fcef2b362a6ce41518755b8a1 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 23 Mar 2020 10:18:45 +0100 Subject: [PATCH] canvas clear --- src/client/widgets/pads/canvas.js | 81 +++---------------------------- 1 file changed, 6 insertions(+), 75 deletions(-) diff --git a/src/client/widgets/pads/canvas.js b/src/client/widgets/pads/canvas.js index 36de98a0..5337e835 100644 --- a/src/client/widgets/pads/canvas.js +++ b/src/client/widgets/pads/canvas.js @@ -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 { `}) - 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