A web-based drawing app
git clone git://soophie.de/outline
212
canvas.draw_crop(state);213
canvas.get_canvas().style.cursor = 'default';214
}215
let data = create_capture(0, 0, window.innerWidth, window.innerHeight);215
let data = canvas.create_capture(0, 0, window.innerWidth, window.innerHeight, 60);216
if(data) {217
node.download.download = `outline-${uuid()}.png`;218
node.download.href = data;
581
delta.y *= -1;582
}583
if(delta.x != 0 && delta.y != 0) {584
let data = create_capture(x, y, delta.x, delta.y);584
let data = canvas.create_capture(x, y, delta.x, delta.y);585
if(data) {586
node.download.download = `outline-${uuid()}.png`;587
node.download.href = data;
797
}798
}, 1000);799
}801
function create_capture(x, y, width, height) {802
let cache = document.createElement('canvas');803
let c = cache.getContext('2d');804
canvas.scale_canvas(cache, c, width, height);805
c.translate(-x, -y);806
c.fillStyle = 'white';807
c.fillRect(0, 0, window.innerWidth, window.innerHeight);808
c.drawImage(canvas.get_canvas(), 0, 0);809
node.download.download = 'test.png';810
let data = cache.toDataURL() || null;811
cache.remove();812
return data;813
}
83
function scale_canvas(canvas, g, size, height) {84
if(DEVICE_PIXEL_RATIO !== backing_store_ratio) {85
canvas.width = size * ratio;86
canvas.height = height || size * ratio;86
canvas.height = (height || size) * ratio;87
canvas.style.width = size + 'px';88
canvas.style.height = height || size + 'px';88
canvas.style.height = (height || size) + 'px';89
}90
else {91
canvas.width = size;
285
return canvas.toDataURL();286
}288
function create_capture(x, y, width, height, offset) {289
if(!offset) {290
offset = 0;291
}292
let cache = document.createElement('canvas');293
let c = cache.getContext('2d');294
scale_canvas(cache, c, width * ratio, (height - offset) * ratio);295
c.translate(-x * ratio, -(y * ratio + offset));296
c.fillStyle = 'white';297
c.fillRect(0, 0, window.innerWidth * ratio, window.innerHeight * ratio);298
c.drawImage(canvas, 0, 0 - offset);299
let data = cache.toDataURL() || null;300
cache.remove();301
return data;302
}304
export default {305
init,306
get_canvas,
317
draw_crop,318
clear_cursor,319
set_data,304
get_data320
get_data,321
create_capture322
};