Skip to content
Snippets Groups Projects
Commit c70b3b24 authored by srosse's avatar srosse
Browse files

OO-3100: adapt the drawing interaction to touch device

parent 61b1f850
No related branches found
No related tags found
No related merge requests found
...@@ -82,13 +82,18 @@ ...@@ -82,13 +82,18 @@
}); });
/* Mouse Capturing Work */ /* Mouse Capturing Work */
jQuery(tmp_canvas).on('mousemove', function(e) { jQuery(tmp_canvas).on('mousemove touchmove', function(e) {
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX; if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') {
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY; mouse.x = e.originalEvent.layerX;
mouse.y = e.originalEvent.layerY;
} else {
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX;
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY;
}
}); });
/* Mouse Capturing Work out of the canvas */ /* Mouse Capturing Work out of the canvas */
jQuery(document).on('mousemove', function(e) { jQuery(document).on('mousemove touchmove', function(e) {
if(mouse.leave) { if(mouse.leave) {
var rect = tmp_canvas.getBoundingClientRect(); var rect = tmp_canvas.getBoundingClientRect();
mouse.out_x = e.clientX - rect.left; mouse.out_x = e.clientX - rect.left;
...@@ -96,9 +101,14 @@ ...@@ -96,9 +101,14 @@
} }
}); });
jQuery(this.canvas).on('mousemove', function(e) { jQuery(this.canvas).on('mousemove touchmove', function(e) {
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX; if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') {
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY; mouse.x = e.originalEvent.layerX;
mouse.y = e.originalEvent.layerY;
} else {
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX;
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY;
}
}); });
//NEWTHING //NEWTHING
...@@ -130,11 +140,20 @@ ...@@ -130,11 +140,20 @@
empty_canv = this.canvas.toDataURL(); //NEWTHING empty_canv = this.canvas.toDataURL(); //NEWTHING
undo_arr.push(empty_canv); //NEWTHING undo_arr.push(empty_canv); //NEWTHING
jQuery(tmp_canvas).on('mousedown', function(e) { jQuery(tmp_canvas).on('mousedown touchstart', function(e) {
jQuery(tmp_canvas).on('mousemove', onPaint); if(isDoubleTouch(e)) {
return;
}
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX; jQuery(tmp_canvas).on('mousemove touchmove', onPaint);
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY;
if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') {
mouse.x = e.originalEvent.layerX;
mouse.y = e.originalEvent.layerY;
} else {
mouse.x = typeof e.offsetX !== 'undefined' ? e.offsetX : e.layerX;
mouse.y = typeof e.offsetY !== 'undefined' ? e.offsetY : e.layerY;
}
mouse.paint = true; mouse.paint = true;
start_mouse.x = mouse.x; start_mouse.x = mouse.x;
...@@ -145,14 +164,14 @@ ...@@ -145,14 +164,14 @@
//spraying tool. //spraying tool.
sprayIntervalID = setInterval(onPaint, 50); sprayIntervalID = setInterval(onPaint, 50);
onPaint(); onPaint(e);
}).on('mousedown', {formId: formDispatchFieldId}, setFlexiFormDirtyByListener); }).on('mousedown touchstart', {formId: formDispatchFieldId}, setFlexiFormDirtyByListener);
jQuery(tmp_canvas).on('mouseup click', function() { jQuery(tmp_canvas).on('mouseup click touchend', function() {
stopPainting(); stopPainting();
}); });
jQuery(tmp_canvas).on('dragstart', function() { jQuery(tmp_canvas).on('dragstart scroll', function() {
return false; return false;
}); });
...@@ -162,18 +181,18 @@ ...@@ -162,18 +181,18 @@
ppts.push({x: -1, y: -1}); ppts.push({x: -1, y: -1});
} }
jQuery(document).on("mouseup", function(e){ jQuery(document).on("mouseup touchend", function(e){
stopPainting(); stopPainting();
}); });
}); });
jQuery(tmp_canvas).on('mouseenter', function(e) { jQuery(tmp_canvas).on('mouseenter', function(e) {
mouse.leave = false; mouse.leave = false;
jQuery(document).off("mouseup"); jQuery(document).off("mouseup touchend");
}); });
var stopPainting = function() { var stopPainting = function() {
jQuery(tmp_canvas).off('mousemove', onPaint); jQuery(tmp_canvas).off('mousemove touchmove', onPaint);
// for erasing // for erasing
ctx.globalCompositeOperation = 'source-over'; ctx.globalCompositeOperation = 'source-over';
...@@ -444,8 +463,27 @@ ...@@ -444,8 +463,27 @@
ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height); ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height);
ctx.drawImage(undo_img, 0, 0); ctx.drawImage(undo_img, 0, 0);
}; };
function isDoubleTouch(e) {
try {
if(!(typeof e == "undefined")
&& !(typeof e.originalEvent.touches == "undefined")
&& e.originalEvent.touches.length > 1) {
return true;
}
} catch(ex) {
if(window.console) console.log(ex);
}
return false;
}
var onPaint = function() { function onPaint(e) {
if(!(typeof e == "undefined")) {
if(isDoubleTouch(e)) {
return;
}
e.preventDefault();
}
if ( tool == 'brush' ) { if ( tool == 'brush' ) {
onPaintBrush(); onPaintBrush();
} else if ( tool == 'circle' ) { } else if ( tool == 'circle' ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment