Skip to content

Commit

Permalink
temporarily draw the linear bits for responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
ezl committed Aug 29, 2013
1 parent f68559a commit 674eb14
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions jquery.signaturepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,17 @@ function SignaturePad (selector, options) {
if (newYOffset)
newY += newYOffset

if (settings.drawLinearSegments === true) {
canvasContext.beginPath()
canvasContext.moveTo(previous.x, previous.y)
canvasContext.lineTo(newX, newY)
canvasContext.lineCap = settings.penCap
canvasContext.stroke()
canvasContext.closePath()
}
// We always draw the linear bits
canvasContext.beginPath()
canvasContext.moveTo(previous.x, previous.y)
canvasContext.lineTo(newX, newY)
canvasContext.lineCap = settings.penCap
canvasContext.stroke()
canvasContext.closePath()


// But if we want beziers, we erase the straight lines
// As soon as we have enough points to draw a bezier over it
if (settings.drawBezierCurves === true) {
strokePoints.push({'lx': newX, 'ly': newY,
'mx': previous.x, 'my': previous.y});
Expand All @@ -228,11 +230,28 @@ function SignaturePad (selector, options) {
var maxCacheLength = 4 * settings.bezierSkip;

if (strokePoints.length >= maxCacheLength) {
// "Erase" the linear part that we drew and replace it with the bezier
var retrace = output.slice(output.length - maxCacheLength + 2, output.length);

canvasContext.strokeStyle = settings.bgColour;
for (i in retrace) {
var point = retrace[i];
canvasContext.beginPath()
canvasContext.moveTo(point.mx, point.my)
canvasContext.lineTo(point.lx, point.ly)
canvasContext.lineCap = settings.penCap
canvasContext.stroke()
canvasContext.closePath()
}
canvasContext.strokeStyle = settings.penColour
strokePath(strokePoints, canvasContext);
strokePoints = strokePoints.slice(maxCacheLength - 1, maxCacheLength);
}
}


// does javascript support negative indexing at all?

output.push({
'lx' : newX
, 'ly' : newY
Expand Down

0 comments on commit 674eb14

Please sign in to comment.