var xpos, ypos; // mouse pos.
var pressF = 0;
var pressX, pressY;
canvas.addEventListener("mousedown" , mousePressed);
canvas.addEventListener("mouseup" , mouseReleased);
canvas.addEventListener("mousemove" , mouseMoved);
//............................
function mouseMoved(ee) {
//............................
getPos(ee);
if(pressF == 0) return;
xp += xpos - pressX;
yp += ypos - pressY;
paint();
pressX = xpos; pressY = ypos;
}
//............................
function mousePressed(ee) {
//............................
getPos(ee);
pressF = 1; pressX = xpos; pressY = ypos;
paint();
}
//............................
function mouseReleased(ee) {
//............................
getPos(ee);
pressF = 0;
paint();
}
//..........................
function getPos(e) {
//..........................
var rect = e.target.getBoundingClientRect();
xpos = e.clientX - rect.left;
ypos = e.clientY - rect.top;
}