mirror of https://github.com/luileito/jsketch.git
Improved drawing performance
This commit is contained in:
parent
1a2328cc9f
commit
7ede4879fd
|
|
@ -474,14 +474,16 @@
|
||||||
// Exit early if interactivity is disabled.
|
// Exit early if interactivity is disabled.
|
||||||
if (!options.interactive) return;
|
if (!options.interactive) return;
|
||||||
|
|
||||||
data.sketch.isDrawing = true;
|
|
||||||
|
|
||||||
var p = getMousePos(e);
|
var p = getMousePos(e);
|
||||||
|
|
||||||
// Mark visually 1st point of stroke.
|
// Mark visually 1st point of stroke.
|
||||||
if (options.graphics.firstPointSize > 0) {
|
if (options.graphics.firstPointSize > 0) {
|
||||||
data.sketch.beginFill(options.graphics.fillStyle).fillCircle(p.x, p.y, options.graphics.firstPointSize).endFill();
|
data.sketch.beginFill(options.graphics.fillStyle).fillCircle(p.x, p.y, options.graphics.firstPointSize).endFill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.sketch.isDrawing = true;
|
||||||
|
data.sketch.beginPath();
|
||||||
|
|
||||||
// Ensure that coords is properly initialized.
|
// Ensure that coords is properly initialized.
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
if (!coords) coords = [];
|
if (!coords) coords = [];
|
||||||
|
|
@ -515,7 +517,7 @@
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
var last = coords[coords.length - 1];
|
var last = coords[coords.length - 1];
|
||||||
if (last) {
|
if (last) {
|
||||||
var brush = data.sketch.beginPath();
|
var brush = data.sketch;
|
||||||
if (data.sketch.isDrawing) {
|
if (data.sketch.isDrawing) {
|
||||||
// Style for regular, pendown strokes.
|
// Style for regular, pendown strokes.
|
||||||
brush.lineStyle(options.graphics.strokeStyle, options.graphics.lineWidth);
|
brush.lineStyle(options.graphics.strokeStyle, options.graphics.lineWidth);
|
||||||
|
|
@ -523,7 +525,7 @@
|
||||||
// Style for penup strokes.
|
// Style for penup strokes.
|
||||||
brush.lineStyle(options.mouseupMovements.strokeStyle || '#DDD', options.mouseupMovements.lineWidth || 1);
|
brush.lineStyle(options.mouseupMovements.strokeStyle || '#DDD', options.mouseupMovements.lineWidth || 1);
|
||||||
}
|
}
|
||||||
brush.line(last[0], last[1], p.x, p.y).stroke().closePath();
|
brush.line(last[0], last[1], p.x, p.y).stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMousePos(idx, data, p);
|
saveMousePos(idx, data, p);
|
||||||
|
|
@ -545,6 +547,7 @@
|
||||||
if (!options.interactive) return;
|
if (!options.interactive) return;
|
||||||
|
|
||||||
data.sketch.isDrawing = false;
|
data.sketch.isDrawing = false;
|
||||||
|
data.sketch.closePath();
|
||||||
|
|
||||||
data.strokes.push(data.coords[idx]);
|
data.strokes.push(data.coords[idx]);
|
||||||
data.coords[idx] = [];
|
data.coords[idx] = [];
|
||||||
|
|
|
||||||
|
|
@ -467,14 +467,16 @@
|
||||||
// Exit early if interactivity is disabled.
|
// Exit early if interactivity is disabled.
|
||||||
if (!options.interactive) return;
|
if (!options.interactive) return;
|
||||||
|
|
||||||
data.sketch.isDrawing = true;
|
|
||||||
|
|
||||||
var p = getMousePos(e);
|
var p = getMousePos(e);
|
||||||
|
|
||||||
// Mark visually 1st point of stroke.
|
// Mark visually 1st point of stroke.
|
||||||
if (options.graphics.firstPointSize > 0) {
|
if (options.graphics.firstPointSize > 0) {
|
||||||
data.sketch.beginFill(options.graphics.fillStyle).fillCircle(p.x, p.y, options.graphics.firstPointSize).endFill();
|
data.sketch.beginFill(options.graphics.fillStyle).fillCircle(p.x, p.y, options.graphics.firstPointSize).endFill();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data.sketch.isDrawing = true;
|
||||||
|
data.sketch.beginPath();
|
||||||
|
|
||||||
// Ensure that coords is properly initialized.
|
// Ensure that coords is properly initialized.
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
if (!coords) coords = [];
|
if (!coords) coords = [];
|
||||||
|
|
@ -508,7 +510,7 @@
|
||||||
var coords = data.coords[idx];
|
var coords = data.coords[idx];
|
||||||
var last = coords[coords.length - 1];
|
var last = coords[coords.length - 1];
|
||||||
if (last) {
|
if (last) {
|
||||||
var brush = data.sketch.beginPath();
|
var brush = data.sketch;
|
||||||
if (data.sketch.isDrawing) {
|
if (data.sketch.isDrawing) {
|
||||||
// Style for regular, pendown strokes.
|
// Style for regular, pendown strokes.
|
||||||
brush.lineStyle(options.graphics.strokeStyle, options.graphics.lineWidth);
|
brush.lineStyle(options.graphics.strokeStyle, options.graphics.lineWidth);
|
||||||
|
|
@ -516,7 +518,7 @@
|
||||||
// Style for penup strokes.
|
// Style for penup strokes.
|
||||||
brush.lineStyle(options.mouseupMovements.strokeStyle || '#DDD', options.mouseupMovements.lineWidth || 1);
|
brush.lineStyle(options.mouseupMovements.strokeStyle || '#DDD', options.mouseupMovements.lineWidth || 1);
|
||||||
}
|
}
|
||||||
brush.line(last[0], last[1], p.x, p.y).stroke().closePath();
|
brush.line(last[0], last[1], p.x, p.y).stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
saveMousePos(idx, data, p);
|
saveMousePos(idx, data, p);
|
||||||
|
|
@ -538,6 +540,7 @@
|
||||||
if (!options.interactive) return;
|
if (!options.interactive) return;
|
||||||
|
|
||||||
data.sketch.isDrawing = false;
|
data.sketch.isDrawing = false;
|
||||||
|
data.sketch.closePath();
|
||||||
|
|
||||||
data.strokes.push(data.coords[idx]);
|
data.strokes.push(data.coords[idx]);
|
||||||
data.coords[idx] = [];
|
data.coords[idx] = [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue