Paste Tool

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

OWOP.tool.addToolObject(new OWOP.tool.class('paste', OWOP.cursors.

paste,
OWOP.fx.player.RECT_SELECT_ALIGNED(1), false, function(tool){
tool.setEvent('mousedown', (mouse, event) => {
if(event.button === 1) return;
let fileinp = document.createElement('input');
fileinp.type = 'file';
fileinp.accept = 'image/*';
fileinp.click();
let c = document.createElement('canvas');
let ctx = c.getContext('2d');
fileinp.addEventListener('change', () => {
if(fileinp.files.length === 0) return;
const file = fileinp.files[0];
let img = new Image;
img.onload = () => {
c.height = img.height;
c.width = img.width ;
ctx.fillStyle = "#fff";
ctx.fillRect(0, 0, img.width, img.height);
ctx.drawImage(img, 0, 0);
paste(ctx.getImageData(0, 0, img.width, img.height), [mouse.tileX,
mouse.tileY]);
URL.revokeObjectURL(img.src);
};
img.src = URL.createObjectURL(file);
});
});
let paste = (imgdata, pos) => {
for(let y = 0; y < imgdata.height; ++y){
for(let x = 0; x < imgdata.width; ++x){
const idx = (x + y*imgdata.width) << 2;
const color = [
imgdata.data[idx],
imgdata.data[idx+1],
imgdata.data[idx+2]
];
pixqueue.unshift({pos: [x+pos[0], y+pos[1]], color: color});
}
}
};
}));

You might also like