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

OO-4296: adapt drawing interaction to android devices

parent c4ef737c
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* @date Mar. 2016 * @date Mar. 2016
*/ */
(function($) { (function($) {
"use strict";
$.fn.paint = function(options) { $.fn.paint = function(options) {
var paint = this.data("data-oo-paint"); var paint = this.data("data-oo-paint");
if(typeof paint === "undefined") { if(typeof paint === "undefined") {
...@@ -32,7 +33,6 @@ ...@@ -32,7 +33,6 @@
var sketchId = jQuery(this.divPanel).attr('id'); var sketchId = jQuery(this.divPanel).attr('id');
var sketch = document.querySelector('#' + sketchId); var sketch = document.querySelector('#' + sketchId);
var sketch_style = getComputedStyle(sketch);
var canvas_small = document.getElementById('brush_size'); var canvas_small = document.getElementById('brush_size');
var context_small = canvas_small.getContext('2d'); var context_small = canvas_small.getContext('2d');
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
var mouse = { x: 0, y: 0, out_x: 0, out_y: 0, paint: false, leave: false}; var mouse = { x: 0, y: 0, out_x: 0, out_y: 0, paint: false, leave: false};
var start_mouse = {x: 0, y: 0}; var start_mouse = {x: 0, y: 0};
var last_mouse = {x: 0, y: 0};
var sprayIntervalID; var sprayIntervalID;
...@@ -59,7 +58,6 @@ ...@@ -59,7 +58,6 @@
var ppts = []; var ppts = [];
//undo array //undo array
var undo_arr = [];// NEWTHING
var undo_count = 0;// NEWTHING var undo_count = 0;// NEWTHING
var empty_canv; // NEWTHING var empty_canv; // NEWTHING
...@@ -83,13 +81,7 @@ ...@@ -83,13 +81,7 @@
/* Mouse Capturing Work */ /* Mouse Capturing Work */
jQuery(tmp_canvas).on('mousemove touchmove', function(e) { jQuery(tmp_canvas).on('mousemove touchmove', function(e) {
if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') { copyEventCoordinateToMouse(e, tmp_canvas);
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 */
...@@ -102,13 +94,7 @@ ...@@ -102,13 +94,7 @@
}); });
jQuery(this.canvas).on('mousemove touchmove', function(e) { jQuery(this.canvas).on('mousemove touchmove', function(e) {
if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') { copyEventCoordinateToMouse(e, this.canvas);
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
...@@ -138,22 +124,15 @@ ...@@ -138,22 +124,15 @@
drawBrush(); drawBrush();
empty_canv = this.canvas.toDataURL(); //NEWTHING empty_canv = this.canvas.toDataURL(); //NEWTHING
undo_arr.push(empty_canv); //NEWTHING
jQuery(tmp_canvas).on('mousedown touchstart', function(e) { jQuery(tmp_canvas).on('mousedown touchstart', function(e) {
if(isDoubleTouch(e) || isRightClick(e)) { if(isDoubleTouch(e) || isRightClick(e)) {
return; return;
} }
jQuery(tmp_canvas).on('mousemove touchmove', onPaint); jQuery(tmp_canvas).on('mousemove touchmove', onPaint);
if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') { copyEventCoordinateToMouse(e, tmp_canvas);
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;
...@@ -191,6 +170,23 @@ ...@@ -191,6 +170,23 @@
jQuery(document).off("mouseup touchend"); jQuery(document).off("mouseup touchend");
}); });
var copyEventCoordinateToMouse = function(e, canvasElement) {
if(typeof e.offsetX == 'undefined' && typeof e.layerX == 'undefined') {
if((typeof e.originalEvent.layerX == 'undefined') && e.originalEvent.touches !== 'undefined' && e.originalEvent.touches.length > 0) {
var te = e.originalEvent.touches[0];
var canvasOffset = jQuery(canvasElement).offset();
mouse.x = te.pageX - canvasOffset.left;
mouse.y = te.pageY - canvasOffset.top;
} else {
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;
}
}
var stopPainting = function() { var stopPainting = function() {
jQuery(tmp_canvas).off('mousemove touchmove', onPaint); jQuery(tmp_canvas).off('mousemove touchmove', onPaint);
...@@ -209,7 +205,6 @@ ...@@ -209,7 +205,6 @@
var image = canvas.toDataURL(); var image = canvas.toDataURL();
jQuery('#' + inputHolderId).val(image); jQuery('#' + inputHolderId).val(image);
undo_arr.push(image);
undo_count = 0; //NEWTHING undo_count = 0; //NEWTHING
} }
...@@ -289,6 +284,7 @@ ...@@ -289,6 +284,7 @@
return; return;
} }
// Tmp canvas is always cleared up before drawing. // Tmp canvas is always cleared up before drawing.
tmp_ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height); tmp_ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height);
...@@ -311,7 +307,7 @@ ...@@ -311,7 +307,7 @@
var c = (ptx + nextPtx) / 2; var c = (ptx + nextPtx) / 2;
var d = (pty + nextPty) / 2; var d = (pty + nextPty) / 2;
tmp_ctx.quadraticCurveTo(ptx, pty, c, d); tmp_ctx.quadraticCurveTo(ptx, pty, c, d);
stopped = false;
} else { } else {
tmp_ctx.stroke(); tmp_ctx.stroke();
stopped = true; stopped = true;
...@@ -390,7 +386,7 @@ ...@@ -390,7 +386,7 @@
tmp_ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); tmp_ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
tmp_ctx.closePath(); tmp_ctx.closePath();
tmp_ctx.stroke(); tmp_ctx.stroke();
}; }
var onErase = function() { var onErase = function() {
// Saving all the points in an array // Saving all the points in an array
...@@ -452,17 +448,6 @@ ...@@ -452,17 +448,6 @@
tmp_ctx.fillRect(x, y, 1, 1); tmp_ctx.fillRect(x, y, 1, 1);
} }
}; };
var UndoFunc = function(count) {
var number = undo_arr.length;
var img_data = undo_arr[number - (count + 1)];
var undo_img = new Image();
undo_img.src = img_data.toString();
ctx.clearRect(0, 0, tmp_canvas.width, tmp_canvas.height);
ctx.drawImage(undo_img, 0, 0);
};
function isDoubleTouch(e) { function isDoubleTouch(e) {
try { try {
...@@ -479,7 +464,6 @@ ...@@ -479,7 +464,6 @@
function isRightClick(e) { function isRightClick(e) {
try { try {
console.log(e);
if(!(typeof e == "undefined") if(!(typeof e == "undefined")
&& !(typeof e.which == "undefined") && !(typeof e.which == "undefined")
&& (e.which == 2 || e.which == 3)) { && (e.which == 2 || e.which == 3)) {
...@@ -513,6 +497,6 @@ ...@@ -513,6 +497,6 @@
} else if ( tool == 'spray' ) { } else if ( tool == 'spray' ) {
generateSprayParticles(); generateSprayParticles();
} }
}; }
} }
}(jQuery)); }(jQuery));
\ No newline at end of file
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