diff options
Diffstat (limited to 'js/ui')
| -rw-r--r-- | js/ui/brush.js | 3 | ||||
| -rw-r--r-- | js/ui/canvas.js | 41 |
2 files changed, 41 insertions, 3 deletions
diff --git a/js/ui/brush.js b/js/ui/brush.js index 4b2db3c..ae1e36e 100644 --- a/js/ui/brush.js +++ b/js/ui/brush.js @@ -52,9 +52,6 @@ var brush = (function(){ lex.focus() }) }) - window.addEventListener("mouseup", function(){ - dragging = false - }) } brush.expand = function(i){ diff --git a/js/ui/canvas.js b/js/ui/canvas.js index 62bd4c3..b656f5d 100644 --- a/js/ui/canvas.js +++ b/js/ui/canvas.js @@ -20,6 +20,7 @@ var canvas = current_canvas = (function(){ e.preventDefault() }) lex.span.addEventListener('mousedown', function(e){ + if (is_mobile) return e.preventDefault() dragging = true current_canvas = canvas @@ -46,7 +47,9 @@ var canvas = current_canvas = (function(){ } lex.focus() }) + lex.span.addEventListener("mousemove", function(e){ + if (is_mobile) return if (! dragging) return if (drawing) { draw.move(e, lex, point) @@ -58,6 +61,44 @@ var canvas = current_canvas = (function(){ }) }) + + if (is_mobile) { + exports.rapper.addEventListener('touchstart', function(e){ + e.preventDefault() + var x, y, point, lex + x = (e.touches[0].pageX - exports.rapper.offsetTop) / exports.aa[0][0].span.offsetWidth + y = (e.touches[0].pageY - exports.rapper.offsetTop) / exports.aa[0][0].span.offsetHeight + x = ~~clamp(x, 0, exports.aa[0].length-1) + y = ~~clamp(y, 0, exports.aa.length-1) + point = [x,y] + lex = exports.aa[y][x] + dragging = true + if (drawing) { + draw.down(e, lex, point) + } + else if (filling) { + draw.fill(brush, x, y) + } + lex.focus() + }) + exports.rapper.addEventListener("touchmove", function(e){ + e.preventDefault() + var x, y, point, lex + x = (e.touches[0].pageX - exports.rapper.offsetTop) / exports.aa[0][0].span.offsetWidth + y = (e.touches[0].pageY - exports.rapper.offsetTop) / exports.aa[0][0].span.offsetHeight + x = ~~clamp(x, 0, exports.aa[0].length-1) + y = ~~clamp(y, 0, exports.aa.length-1) + point = [x,y] + lex = exports.aa[y][x] + if (! dragging) return + shader_el.innerHTML = point.join(",") + if (drawing) { + draw.move(e, lex, point) + } + lex.focus() + }) + } + } return exports |
