Skip to content

Commit

Permalink
多点触屏,画笔颜色、粗细可选
Browse files Browse the repository at this point in the history
  • Loading branch information
jmxhyz committed Aug 11, 2015
1 parent 39ae36d commit a5b29ee
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions assets/js/nodeppt.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,42 @@
}
break;
//上一页
case 66:
//b
$drawBoard.context.strokeStyle = 'rgba(0,0,255,0.5)'; //pen_blue
break;
case 89:
//y
$drawBoard.context.strokeStyle = 'rgba(255,255,0,0.5)'; //pen_yellow
break;
case 82:
//r
$drawBoard.context.strokeStyle = 'rgba(255,0,0,0.5)'; //pen_red
break;
case 71:
//g
$drawBoard.context.strokeStyle = 'rgba(0,255,0,0.5)'; //pen_green
break;
case 77:
//m
$drawBoard.context.strokeStyle = 'rgba(255,0,255,0.5)'; //pen_magenta
break;
case 49:
//1
$drawBoard.context.lineWidth = 3; //画笔粗细
break;
case 50:
//2
$drawBoard.context.lineWidth = 7; //画笔粗细
break;
case 51:
//3
$drawBoard.context.lineWidth = 11; //画笔粗细
break;
case 52:
//4
$drawBoard.context.lineWidth = 15; //画笔粗细
break;
case 33:
// pg up
case 37:
Expand Down Expand Up @@ -651,8 +687,9 @@
$drawBoard.context = $drawBoard.getContext('2d');
var context = $drawBoard.context;
context.lineWidth = 3;
context.lineCap = 'round';
context.strokeStyle = "red";
//context.lineCap = 'round';
context.lineJoin = 'round';
context.strokeStyle = 'rgba(255,0,0,0.5)'; //"red";
}

//显示画板
Expand Down Expand Up @@ -730,6 +767,12 @@
};
var pMouseDown = function (e) {
$drawBoard.isMouseDown = true;
try{ //多点触屏
var touch = e.targetTouches[0];
e = touch;
}
catch(err){
}
// $drawBoard.iLastX = e.clientX - $drawBoard.offsetLeft + ($win.pageXOffset || $doc.body.scrollLeft || $doc.documentElement.scrollLeft);
// $drawBoard.iLastY = e.clientY - $drawBoard.offsetTop + ($win.pageYOffset || $doc.body.scrollTop || $doc.documentElement.scrollTop);
var x = $drawBoard.iLastX = e.layerX || e.offsetX || (e.clientX - $drawBoard.offsetLeft + ($win.pageXOffset || $doc.body.scrollLeft || $doc.documentElement.scrollLeft));
Expand All @@ -738,6 +781,7 @@
x: x,
y: y
});
return false; //兼容手机触屏
};
var pPoints = [];
var pMouseUp = function (e) {
Expand Down Expand Up @@ -767,6 +811,8 @@

var context = $drawBoard.context;
context.beginPath();
context.strokeStyle = data.pencolor; //画笔颜色
context.lineWidth = data.penlineWidth; //画笔粗细
var startX = cOX - (tOX - points[0].x) * iw;
var startY = cOY - (tOY - points[0].y) * ih;
// console.log(startX, points[0].x, startY, iw, wh);
Expand All @@ -778,6 +824,12 @@
});
var pMouseMove = function (e) {
if ($drawBoard.isMouseDown) {
try{ //多点触屏
var touch = e.targetTouches[0];
e = touch;
}
catch(err){
}
// var iX = e.clientX - $drawBoard.offsetLeft + ($win.pageXOffset || $doc.body.scrollLeft || $doc.documentElement.scrollLeft);
// var iY = e.clientY - $drawBoard.offsetTop + ($win.pageYOffset || $doc.body.scrollTop || $doc.documentElement.scrollTop);
var iX = e.layerX || e.offsetX || (e.clientX - $drawBoard.offsetLeft + ($win.pageXOffset || $doc.body.scrollLeft || $doc.documentElement.scrollLeft));
Expand All @@ -793,7 +845,8 @@
x: iX,
y: iY
});
e.preventDefault();
//e.preventDefault();
return false; //兼容触屏
}
}

Expand Down

0 comments on commit a5b29ee

Please sign in to comment.