Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Touch pan and zoom for non-apple #132

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions html/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
left: 0;
bottom: 45px;
right: 0;
touch-action: pan-x pan-y;
}

#pedalboard-dashboard.dev_api:after {
Expand Down
1 change: 1 addition & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

<script type="text/javascript" src="js/lib/jquery-1.9.1.min.js?v={{version}}"></script>
<script type="text/javascript" src="js/lib/jquery-ui-1.10.1.custom.min.js?v={{version}}"></script>
<script> if (! ("ontouchend" in document)){document.ontouchend=''}</script>
<script type="text/javascript" src="js/lib/jquery.ui.touch-punch.min.js?v={{version}}"></script>
<script type="text/javascript" src="js/lib/jquery.ba-resize.min.js?v={{version}}"></script>
<script type="text/javascript" src="js/lib/mustache.js?v={{version}}"></script>
Expand Down
2 changes: 1 addition & 1 deletion html/js/desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,9 @@ function Desktop(elements) {
var prevent = function (ev) {
ev.preventDefault()
}

$('body')[0].addEventListener('gesturestart', prevent)
$('body')[0].addEventListener('gesturechange', prevent)
$('body')[0].addEventListener('touchmove', prevent)
$('body')[0].addEventListener('dblclick', prevent)
}

Expand Down
47 changes: 28 additions & 19 deletions html/js/pedalboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ JqueryClass('pedalboard', {
}});

// Dragging the pedalboard move the view area
self.mousedown(function (e) {
self.bind('mousedown touchstart', function (e) {
self.pedalboard('drag', e)
})

Expand Down Expand Up @@ -812,33 +812,42 @@ JqueryClass('pedalboard', {
// Moves the viewable area of the pedalboard
drag: function (start) {
Copy link
Author

@xko xko Feb 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can also handle gesturestart and gesturechage here and remove initGestures, but I don't have apple device to test this

var self = $(this)

self.trigger('dragStart')

var scale = self.data('scale')

function shape(e) {
if (!e.type.startsWith('touch')) return { pageX: e.pageX, pageY: e.pageY, pageD: 0.0001 }
var touches = e.originalEvent.touches
if (touches.length == 1) return { pageX: touches[0].pageX, pageY: touches[0].pageY, pageD: 0.0001 }
var [ x0, x1, y0, y1 ] = [ touches[0].pageX, touches[1].pageX, touches[0].pageY, touches[1].pageY ]
return {
pageX: Math.round(x0+(x1-x0)*0.50),
pageY: Math.round(y0+(y1-y0)*0.50),
pageD: Math.hypot(x0 - x1, y0 - y1)
}
}

start = shape(start)
var canvasX = (start.pageX - self.offset().left) / scale
var canvasY = (start.pageY - self.offset().top) / scale
var screenX = start.pageX - self.parent().offset().left
var screenY = start.pageY - self.parent().offset().top

var moveHandler = function (e) {
if (self.data('preventDrag'))
return

self.pedalboard('zoom', scale, canvasX, canvasY,
screenX + e.pageX - start.pageX,
screenY + e.pageY - start.pageY,
0)
if (self.data('preventDrag')) return
e = shape(e)
var newScale = scale * e.pageD / start.pageD
newScale = Math.min(self.data('maxScale'), newScale)
newScale = Math.max(self.data('minScale'), newScale)
self.pedalboard( 'zoom', newScale, canvasX, canvasY,
e.pageX - self.parent().offset().left, e.pageY - self.parent().offset().top, 0 )
}

var upHandler = function (e) {
$(document).unbind('mouseup', upHandler)
$(document).unbind('mousemove', moveHandler)
$(document).unbind('mouseup touchend', upHandler)
$(document).unbind('mousemove touchmove', moveHandler)
}

$(document).bind('mousemove', moveHandler)
$(document).bind('mouseup', upHandler)
$(document).bind('mousemove touchmove', moveHandler)
$(document).bind('mouseup touchend', upHandler)
},

// Changes the viewing scale of the pedalboard and position it in a way that
Expand Down Expand Up @@ -1494,13 +1503,13 @@ JqueryClass('pedalboard', {
}
}

icon.mousedown(function () {
icon.bind('mousedown touchstart', function () {
self.pedalboard('preventDrag', true)
var upHandler = function () {
self.pedalboard('preventDrag', false)
$('body').unbind('mouseup', upHandler)
$('body').unbind('mouseup touchend', upHandler)
}
$('body').bind('mouseup', upHandler)
$('body').bind('mouseup touchend', upHandler)
})

var actions = $('<div>').addClass('ignore-arrive').addClass('mod-actions').appendTo(icon)
Expand Down