canvas: ios: different touch.force implementation

This commit is contained in:
jean-emmanuel 2022-10-21 13:05:55 +02:00
parent 4984777dd8
commit edb014e1da
5 changed files with 12 additions and 76 deletions

View file

@ -2,7 +2,7 @@
"name": "open-stage-control",
"productName": "Open Stage Control",
"description": "Libre and modular OSC / MIDI controller",
"version": "1.18.2-beta2",
"version": "1.18.2-beta3",
"author": {
"name": "Jean-Emmanuel Doucet",
"email": "jean-emmanuel@ammd.net"

View file

@ -228,9 +228,17 @@ function triggerWidgetEvent(target, name, event) {
// init
DOM.ready(()=>{
if (!iOS) document.addEventListener('pointermove', mouseMoveCapture, true)
if (!iOS) {
document.addEventListener('pointermove', mouseMoveCapture, true)
if ('onwebkitmouseforcechanged' in document) document.addEventListener('webkitmouseforcechanged', mouseMoveCapture, true)
}
if (!iOS) document.addEventListener('pointerup', mouseUpCapture, true)
document.addEventListener('touchmove', touchMoveCapture, true)
if ('ontouchforcechange' in document) document.addEventListener('touchforcechange', touchMoveCapture, true)
DOM.addEventListener(document, 'touchend touchcancel', touchUpCapture, true)
if (!iOS) document.addEventListener('pointerdown', mouseDownCapture)

View file

@ -1,5 +1,4 @@
const Touch = window.Touch || class Touch {}
const iOS = require('../ui/ios')
// const cssTransformCoords = require('./transform-coords')
@ -8,7 +7,7 @@ module.exports = {
fix: function(e) {
var ev = {
return {
target: e.target,
firstTarget: null,
@ -41,23 +40,6 @@ module.exports = {
touchType: e.touchType
}
if (iOS && IOS_TOUCH_POLLING) {
// iOS-specific event properties
ev.touchType = e.touchType
// iOS-pollable event properties
for (let p of ['altitudeAngle', 'azimuthAngle', 'force']) {
Object.defineProperty(ev, 'update_' + p, {
enumerable: false,
value: function(){
var changed = this[p] !== e[p]
if (changed) this[p] = e[p]
return changed
}
})
}
}
return ev
},
normalizeDragEvent: function(event, previousEvent) {

View file

@ -30,8 +30,6 @@ window.DOUBLE_TAP_TIME = ENV.doubletap ? parseInt(ENV.doubletap) : 375
window.CLIENT_SYNC = parseInt(ENV.clientSync) !== 0
window.IOS_TOUCH_POLLING = false
window.TOGGLE_ALT_TRAVERSING = !!ENV.altTraversing

View file

@ -1,9 +1,7 @@
var Canvas = require('../common/canvas'),
Script = require('../scripts/script'),
widgetManager = require('../../managers/widgets'),
html = require('nanohtml'),
iOS = require('../../ui/ios'),
iosEvents = ['altitudeAngle', 'azimuthAngle', 'force']
html = require('nanohtml')
class CanvasWidget extends Canvas {
@ -116,60 +114,16 @@ class CanvasWidget extends Canvas {
this.batchDraw()
}
if (iOS) {
var code = String(this.getProp('onTouch'))
if (iosEvents.some(x=>code.includes(x))) {
this.iosTouch = true
this.iosTouchCache = {}
this.iosTouchPolls = {}
IOS_TOUCH_POLLING = true
// enable data getters in ../../events/utils.js
}
}
this.on('draginit',(e)=>{
touchCb(e, 'start')
if (this.iosTouch) {
// cache touch inforamtions
this.iosTouchCache[e.pointerId] = e
// start polling extra touch inforamtions
this.iosTouchPolls[e.pointerId] = setInterval(()=>{
if (!this.iosTouchCache[e.pointerId]) return
var changed = false
for (var p of iosEvents) {
// update event data
if (this.iosTouchCache[e.pointerId]['update_' + p]()) changed = true
}
if (changed) {
// if polled value has changed, retrig last move event
// reset movement data since this is only relevant when
// the pointer doesn't move
this.iosTouchCache[e.pointerId].movementX = 0
this.iosTouchCache[e.pointerId].movementY = 0
// call touch move callback
touchCb(this.iosTouchCache[e.pointerId], 'move')
}
}, 1000 / 30)
}
}, {element: this.container, multitouch: true})
this.on('drag',(e)=>{
touchCb(e, 'move')
if (this.iosTouch) {
// cache touch inforamtions
this.iosTouchCache[e.pointerId] = e
}
}, {element: this.container, multitouch: true})
this.on('dragend',(e)=>{
touchCb(e, 'stop')
if (this.iosTouch) {
// stop polling extra touch inforamtions
clearInterval(this.iosTouchPolls[e.pointerId])
delete this.iosTouchPolls[e.pointerId]
delete this.iosTouchCache[e.pointerId]
}
}, {element: this.container, multitouch: true})
}
@ -239,12 +193,6 @@ class CanvasWidget extends Canvas {
clearInterval(this.drawInterval)
if (this.iosTouch) {
for (var k in this.iosTouchPolls) {
clearInterval(this.iosTouchPolls[k])
}
}
super.onRemove()
}