2022-12-01 15:10:30 -06:00
|
|
|
const _color_brush_draw_callback = (evn, state) => {
|
|
|
|
const ctx = state.drawLayer.ctx;
|
|
|
|
|
|
|
|
ctx.strokeStyle = state.color;
|
|
|
|
|
2022-12-04 16:35:44 -06:00
|
|
|
ctx.filter =
|
|
|
|
"blur(" +
|
|
|
|
state.brushBlur +
|
|
|
|
"px) opacity(" +
|
|
|
|
state.brushOpacity * 100 +
|
|
|
|
"%)";
|
2022-12-01 15:10:30 -06:00
|
|
|
ctx.lineWidth = state.brushSize;
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(
|
|
|
|
evn.px === undefined ? evn.x : evn.px,
|
|
|
|
evn.py === undefined ? evn.y : evn.py
|
|
|
|
);
|
|
|
|
ctx.lineTo(evn.x, evn.y);
|
|
|
|
ctx.lineJoin = ctx.lineCap = "round";
|
|
|
|
ctx.stroke();
|
2022-12-04 16:35:44 -06:00
|
|
|
ctx.filter = null;
|
2022-12-01 15:10:30 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
const _color_brush_erase_callback = (evn, state, ctx) => {
|
|
|
|
ctx.strokeStyle = "black";
|
|
|
|
|
|
|
|
ctx.lineWidth = state.brushSize;
|
|
|
|
ctx.beginPath();
|
|
|
|
ctx.moveTo(
|
|
|
|
evn.px === undefined ? evn.x : evn.px,
|
|
|
|
evn.py === undefined ? evn.y : evn.py
|
|
|
|
);
|
|
|
|
ctx.lineTo(evn.x, evn.y);
|
|
|
|
ctx.lineJoin = ctx.lineCap = "round";
|
|
|
|
ctx.stroke();
|
|
|
|
};
|
|
|
|
|
|
|
|
const colorBrushTool = () =>
|
|
|
|
toolbar.registerTool(
|
2022-12-18 17:50:40 -06:00
|
|
|
"./res/icons/brush.svg",
|
2022-12-01 15:10:30 -06:00
|
|
|
"Color Brush",
|
|
|
|
(state, opt) => {
|
|
|
|
// Draw new cursor immediately
|
2022-12-16 19:57:28 -06:00
|
|
|
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
2022-12-04 13:22:35 -06:00
|
|
|
state.movecb({
|
|
|
|
...mouse.coords.world.pos,
|
|
|
|
evn: {
|
|
|
|
clientX: mouse.coords.window.pos.x,
|
|
|
|
clientY: mouse.coords.window.pos.y,
|
|
|
|
},
|
|
|
|
});
|
2022-12-03 17:00:10 -06:00
|
|
|
|
|
|
|
// Layer for eyedropper magnifiying glass
|
|
|
|
state.glassLayer = imageCollection.registerLayer(null, {
|
|
|
|
bb: {x: 0, y: 0, w: 100, h: 100},
|
|
|
|
resolution: {w: 7, h: 7},
|
|
|
|
after: maskPaintLayer,
|
|
|
|
});
|
2022-12-03 21:22:29 -06:00
|
|
|
state.glassLayer.hide();
|
2022-12-03 17:00:10 -06:00
|
|
|
state.glassLayer.canvas.style.imageRendering = "pixelated";
|
|
|
|
state.glassLayer.canvas.style.borderRadius = "50%";
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
state.drawLayer = imageCollection.registerLayer(null, {
|
|
|
|
after: imgLayer,
|
2022-12-21 09:07:29 -06:00
|
|
|
category: "display",
|
2022-12-04 14:02:46 -06:00
|
|
|
ctxOptions: {willReadFrequently: true},
|
2022-12-01 15:10:30 -06:00
|
|
|
});
|
2022-12-16 19:57:28 -06:00
|
|
|
state.drawLayer.canvas.style.filter = "opacity(70%)";
|
2022-12-01 15:10:30 -06:00
|
|
|
state.eraseLayer = imageCollection.registerLayer(null, {
|
|
|
|
after: imgLayer,
|
2022-12-21 09:07:29 -06:00
|
|
|
category: "processing",
|
2022-12-04 14:02:46 -06:00
|
|
|
ctxOptions: {willReadFrequently: true},
|
2022-12-01 15:10:30 -06:00
|
|
|
});
|
2022-12-03 21:22:29 -06:00
|
|
|
state.eraseLayer.hide();
|
2022-12-01 15:10:30 -06:00
|
|
|
state.eraseBackup = imageCollection.registerLayer(null, {
|
|
|
|
after: imgLayer,
|
2022-12-21 09:07:29 -06:00
|
|
|
category: "processing",
|
2022-12-01 15:10:30 -06:00
|
|
|
});
|
2022-12-03 21:22:29 -06:00
|
|
|
state.eraseBackup.hide();
|
2022-12-01 15:10:30 -06:00
|
|
|
|
|
|
|
// Start Listeners
|
|
|
|
mouse.listen.world.onmousemove.on(state.movecb);
|
|
|
|
mouse.listen.world.onwheel.on(state.wheelcb);
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
keyboard.listen.onkeydown.on(state.keydowncb);
|
|
|
|
keyboard.listen.onkeyup.on(state.keyupcb);
|
|
|
|
mouse.listen.world.btn.left.onclick.on(state.leftclickcb);
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
mouse.listen.world.btn.left.onpaintstart.on(state.drawstartcb);
|
|
|
|
mouse.listen.world.btn.left.onpaint.on(state.drawcb);
|
|
|
|
mouse.listen.world.btn.left.onpaintend.on(state.drawendcb);
|
|
|
|
|
|
|
|
mouse.listen.world.btn.right.onpaintstart.on(state.erasestartcb);
|
|
|
|
mouse.listen.world.btn.right.onpaint.on(state.erasecb);
|
|
|
|
mouse.listen.world.btn.right.onpaintend.on(state.eraseendcb);
|
|
|
|
|
|
|
|
// Display Color
|
|
|
|
setMask("none");
|
|
|
|
},
|
|
|
|
(state, opt) => {
|
|
|
|
// Clear Listeners
|
|
|
|
mouse.listen.world.onmousemove.clear(state.movecb);
|
|
|
|
mouse.listen.world.onwheel.clear(state.wheelcb);
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
keyboard.listen.onkeydown.clear(state.keydowncb);
|
|
|
|
keyboard.listen.onkeyup.clear(state.keyupcb);
|
|
|
|
mouse.listen.world.btn.left.onclick.clear(state.leftclickcb);
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
mouse.listen.world.btn.left.onpaintstart.clear(state.drawstartcb);
|
|
|
|
mouse.listen.world.btn.left.onpaint.clear(state.drawcb);
|
|
|
|
mouse.listen.world.btn.left.onpaintend.clear(state.drawendcb);
|
|
|
|
|
|
|
|
mouse.listen.world.btn.right.onpaintstart.clear(state.erasestartcb);
|
|
|
|
mouse.listen.world.btn.right.onpaint.clear(state.erasecb);
|
|
|
|
mouse.listen.world.btn.right.onpaintend.clear(state.eraseendcb);
|
|
|
|
|
|
|
|
// Delete layer
|
|
|
|
imageCollection.deleteLayer(state.drawLayer);
|
|
|
|
imageCollection.deleteLayer(state.eraseBackup);
|
|
|
|
imageCollection.deleteLayer(state.eraseLayer);
|
2022-12-03 17:00:10 -06:00
|
|
|
imageCollection.deleteLayer(state.glassLayer);
|
|
|
|
|
|
|
|
// Cancel any eyedropping
|
|
|
|
state.drawing = false;
|
|
|
|
state.disableDropper();
|
2022-12-04 13:22:35 -06:00
|
|
|
|
|
|
|
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
2022-12-01 15:10:30 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
init: (state) => {
|
|
|
|
state.config = {
|
|
|
|
brushScrollSpeed: 1 / 5,
|
|
|
|
minBrushSize: 2,
|
|
|
|
maxBrushSize: 500,
|
|
|
|
minBlur: 0,
|
|
|
|
maxBlur: 30,
|
|
|
|
};
|
|
|
|
|
|
|
|
state.color = "#FFFFFF";
|
|
|
|
state.brushSize = 32;
|
|
|
|
state.brushBlur = 0;
|
2022-12-04 16:35:44 -06:00
|
|
|
state.brushOpacity = 1;
|
2022-12-01 15:10:30 -06:00
|
|
|
state.affectMask = true;
|
2022-12-18 20:35:48 -06:00
|
|
|
state.block_res_change = true;
|
2022-12-01 15:10:30 -06:00
|
|
|
state.setBrushSize = (size) => {
|
|
|
|
state.brushSize = size;
|
|
|
|
state.ctxmenu.brushSizeRange.value = size;
|
|
|
|
state.ctxmenu.brushSizeText.value = size;
|
|
|
|
};
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
state.eyedropper = false;
|
|
|
|
|
|
|
|
state.enableDropper = () => {
|
|
|
|
state.eyedropper = true;
|
|
|
|
state.movecb(lastMouseMoveEvn);
|
2022-12-03 21:22:29 -06:00
|
|
|
state.glassLayer.unhide();
|
2022-12-03 17:00:10 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
state.disableDropper = () => {
|
|
|
|
state.eyedropper = false;
|
|
|
|
state.movecb(lastMouseMoveEvn);
|
2022-12-03 21:22:29 -06:00
|
|
|
state.glassLayer.hide();
|
2022-12-03 17:00:10 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
let lastMouseMoveEvn = {x: 0, y: 0};
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
state.movecb = (evn) => {
|
2022-12-03 17:00:10 -06:00
|
|
|
lastMouseMoveEvn = evn;
|
|
|
|
|
2022-12-04 13:22:35 -06:00
|
|
|
const vcp = {x: evn.evn.clientX, y: evn.evn.clientY};
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
// draw drawing cursor
|
2022-12-08 20:33:51 -06:00
|
|
|
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
2022-12-04 13:22:35 -06:00
|
|
|
|
|
|
|
uiCtx.beginPath();
|
|
|
|
uiCtx.arc(
|
|
|
|
vcp.x,
|
|
|
|
vcp.y,
|
2023-01-09 22:02:19 -06:00
|
|
|
(state.eyedropper ? 50 : state.brushSize / 2) / viewport.zoom,
|
2022-12-04 13:22:35 -06:00
|
|
|
0,
|
|
|
|
2 * Math.PI,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
uiCtx.strokeStyle = "black";
|
|
|
|
uiCtx.stroke();
|
2022-12-03 17:00:10 -06:00
|
|
|
|
2022-12-04 13:22:35 -06:00
|
|
|
// Draw eyedropper cursor and magnifiying glass
|
2022-12-03 17:00:10 -06:00
|
|
|
if (state.eyedropper) {
|
|
|
|
const bb = getBoundingBox(evn.x, evn.y, 7, 7, false);
|
|
|
|
|
2022-12-04 13:22:35 -06:00
|
|
|
const canvas = uil.getVisible(bb, {includeBg: true});
|
2022-12-03 17:00:10 -06:00
|
|
|
state.glassLayer.ctx.clearRect(0, 0, 7, 7);
|
|
|
|
state.glassLayer.ctx.drawImage(canvas, 0, 0);
|
|
|
|
state.glassLayer.moveTo(evn.x - 50, evn.y - 50);
|
|
|
|
} else {
|
2022-12-04 13:22:35 -06:00
|
|
|
uiCtx.beginPath();
|
|
|
|
uiCtx.arc(
|
|
|
|
vcp.x,
|
|
|
|
vcp.y,
|
2023-01-09 22:02:19 -06:00
|
|
|
state.brushSize / (2 * viewport.zoom),
|
2022-12-04 13:22:35 -06:00
|
|
|
0,
|
|
|
|
2 * Math.PI,
|
|
|
|
true
|
|
|
|
);
|
|
|
|
uiCtx.fillStyle = state.color + "50";
|
|
|
|
uiCtx.fill();
|
2022-12-03 17:00:10 -06:00
|
|
|
}
|
2022-12-01 15:10:30 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
state.wheelcb = (evn) => {
|
2022-12-26 22:04:56 -06:00
|
|
|
state.brushSize = state.setBrushSize(
|
|
|
|
state.brushSize -
|
|
|
|
Math.floor(state.config.brushScrollSpeed * evn.delta)
|
|
|
|
);
|
|
|
|
uiCtx.clearRect(0, 0, uiCanvas.width, uiCanvas.height);
|
|
|
|
state.movecb(evn);
|
2022-12-01 15:10:30 -06:00
|
|
|
};
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
/**
|
|
|
|
* These are basically for eyedropper purposes
|
|
|
|
*/
|
|
|
|
|
|
|
|
state.keydowncb = (evn) => {
|
|
|
|
if (lastMouseMoveEvn.target === imageCollection.inputElement)
|
|
|
|
switch (evn.code) {
|
|
|
|
case "ShiftLeft":
|
|
|
|
case "ShiftRight":
|
|
|
|
state.enableDropper();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
state.keyupcb = (evn) => {
|
|
|
|
switch (evn.code) {
|
|
|
|
case "ShiftLeft":
|
|
|
|
case "ShiftRight":
|
2022-12-16 19:57:28 -06:00
|
|
|
if (!keyboard.isPressed(evn.code)) {
|
2022-12-03 17:00:10 -06:00
|
|
|
state.disableDropper();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
state.leftclickcb = (evn) => {
|
|
|
|
if (evn.target === imageCollection.inputElement && state.eyedropper) {
|
|
|
|
const bb = getBoundingBox(evn.x, evn.y, 1, 1, false);
|
2022-12-04 21:26:38 -06:00
|
|
|
const visibleCanvas = uil.getVisible(bb);
|
2022-12-03 17:00:10 -06:00
|
|
|
const dat = visibleCanvas
|
|
|
|
.getContext("2d")
|
|
|
|
.getImageData(0, 0, 1, 1).data;
|
|
|
|
state.setColor(
|
|
|
|
"#" + ((dat[0] << 16) | (dat[1] << 8) | dat[2]).toString(16)
|
|
|
|
);
|
2022-12-03 21:22:29 -06:00
|
|
|
state.disableDropper();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
state.rightclickcb = (evn) => {
|
|
|
|
if (evn.target === imageCollection.inputElement && state.eyedropper) {
|
|
|
|
state.disableDropper();
|
2022-12-03 17:00:10 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we actually paint things
|
|
|
|
*/
|
2022-12-01 15:10:30 -06:00
|
|
|
state.drawstartcb = (evn) => {
|
2022-12-03 17:00:10 -06:00
|
|
|
if (state.eyedropper) return;
|
|
|
|
state.drawing = true;
|
2022-12-01 15:10:30 -06:00
|
|
|
if (state.affectMask) _mask_brush_draw_callback(evn, state);
|
|
|
|
_color_brush_draw_callback(evn, state);
|
|
|
|
};
|
|
|
|
|
|
|
|
state.drawcb = (evn) => {
|
2022-12-03 17:00:10 -06:00
|
|
|
if (state.eyedropper || !state.drawing) return;
|
2022-12-01 15:10:30 -06:00
|
|
|
if (state.affectMask) _mask_brush_draw_callback(evn, state);
|
|
|
|
_color_brush_draw_callback(evn, state);
|
|
|
|
};
|
|
|
|
|
|
|
|
state.drawendcb = (evn) => {
|
2022-12-03 17:00:10 -06:00
|
|
|
if (!state.drawing) return;
|
|
|
|
state.drawing = false;
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
const canvas = state.drawLayer.canvas;
|
|
|
|
const ctx = state.drawLayer.ctx;
|
|
|
|
|
2022-12-16 22:15:27 -06:00
|
|
|
const cropped = cropCanvas(canvas, {border: 10});
|
2022-12-01 15:10:30 -06:00
|
|
|
const bb = cropped.bb;
|
2022-12-16 19:57:28 -06:00
|
|
|
|
2023-01-24 20:37:38 -06:00
|
|
|
commands.runCommand(
|
|
|
|
"drawImage",
|
|
|
|
"Color Brush Draw",
|
|
|
|
{
|
|
|
|
image: cropped.canvas,
|
|
|
|
...bb,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extra: {
|
|
|
|
log: `Color brush drawn at x: ${bb.x}, y: ${bb.y}, width: ${bb.w}, height: ${bb.h}`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2022-12-01 15:10:30 -06:00
|
|
|
|
|
|
|
ctx.clearRect(bb.x, bb.y, bb.w, bb.h);
|
|
|
|
};
|
|
|
|
|
|
|
|
state.erasestartcb = (evn) => {
|
2022-12-03 21:22:29 -06:00
|
|
|
if (state.eyedropper) return;
|
|
|
|
state.erasing = true;
|
2022-12-01 15:10:30 -06:00
|
|
|
if (state.affectMask) _mask_brush_erase_callback(evn, state);
|
|
|
|
|
|
|
|
// Make a backup of the current image to apply erase later
|
|
|
|
const bkpctx = state.eraseBackup.ctx;
|
2022-12-16 19:57:28 -06:00
|
|
|
state.eraseBackup.clear();
|
|
|
|
bkpctx.drawImageRoot(uil.canvas, 0, 0);
|
2022-12-01 15:10:30 -06:00
|
|
|
|
2022-12-04 13:22:35 -06:00
|
|
|
uil.ctx.globalCompositeOperation = "destination-out";
|
|
|
|
_color_brush_erase_callback(evn, state, uil.ctx);
|
|
|
|
uil.ctx.globalCompositeOperation = "source-over";
|
2022-12-01 15:10:30 -06:00
|
|
|
_color_brush_erase_callback(evn, state, state.eraseLayer.ctx);
|
|
|
|
};
|
|
|
|
|
|
|
|
state.erasecb = (evn) => {
|
2022-12-03 21:22:29 -06:00
|
|
|
if (state.eyedropper || !state.erasing) return;
|
2022-12-01 15:10:30 -06:00
|
|
|
if (state.affectMask) _mask_brush_erase_callback(evn, state);
|
2022-12-04 13:22:35 -06:00
|
|
|
uil.ctx.globalCompositeOperation = "destination-out";
|
|
|
|
_color_brush_erase_callback(evn, state, uil.ctx);
|
|
|
|
uil.ctx.globalCompositeOperation = "source-over";
|
2022-12-01 15:10:30 -06:00
|
|
|
_color_brush_erase_callback(evn, state, state.eraseLayer.ctx);
|
|
|
|
};
|
|
|
|
|
|
|
|
state.eraseendcb = (evn) => {
|
2022-12-03 21:22:29 -06:00
|
|
|
if (!state.erasing) return;
|
|
|
|
state.erasing = false;
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
const canvas = state.eraseLayer.canvas;
|
|
|
|
const ctx = state.eraseLayer.ctx;
|
|
|
|
|
|
|
|
const bkpcanvas = state.eraseBackup.canvas;
|
|
|
|
|
|
|
|
const cropped = cropCanvas(canvas, {border: 10});
|
|
|
|
const bb = cropped.bb;
|
|
|
|
|
2022-12-04 16:35:44 -06:00
|
|
|
uil.ctx.filter = null;
|
2022-12-16 19:57:28 -06:00
|
|
|
uil.layer.clear();
|
|
|
|
uil.ctx.drawImageRoot(bkpcanvas, 0, 0);
|
2022-12-01 15:10:30 -06:00
|
|
|
|
2023-01-24 20:37:38 -06:00
|
|
|
commands.runCommand(
|
|
|
|
"eraseImage",
|
|
|
|
"Color Brush Erase",
|
|
|
|
{
|
|
|
|
mask: cropped.canvas,
|
|
|
|
...bb,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extra: {
|
|
|
|
log: `Color brush erase at x: ${bb.x}, y: ${bb.y}, width: ${bb.w}, height: ${bb.h}`,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
2022-12-01 15:10:30 -06:00
|
|
|
|
|
|
|
ctx.clearRect(bb.x, bb.y, bb.w, bb.h);
|
|
|
|
};
|
|
|
|
},
|
|
|
|
populateContextMenu: (menu, state) => {
|
|
|
|
if (!state.ctxmenu) {
|
|
|
|
state.ctxmenu = {};
|
|
|
|
|
|
|
|
// Affects Mask Checkbox
|
2023-01-02 18:12:18 -06:00
|
|
|
const array = document.createElement("div");
|
2022-12-01 15:10:30 -06:00
|
|
|
const affectMaskCheckbox = _toolbar_input.checkbox(
|
|
|
|
state,
|
|
|
|
"affectMask",
|
2023-01-02 18:12:18 -06:00
|
|
|
"Affect Mask",
|
|
|
|
"icon-venetian-mask"
|
|
|
|
).checkbox;
|
|
|
|
array.appendChild(affectMaskCheckbox);
|
2022-12-01 15:10:30 -06:00
|
|
|
|
2023-01-02 18:12:18 -06:00
|
|
|
state.ctxmenu.affectMaskCheckbox = array;
|
2022-12-01 15:10:30 -06:00
|
|
|
|
|
|
|
// Brush size slider
|
|
|
|
const brushSizeSlider = _toolbar_input.slider(
|
|
|
|
state,
|
|
|
|
"brushSize",
|
|
|
|
"Brush Size",
|
2022-12-03 04:50:23 -06:00
|
|
|
{
|
|
|
|
min: state.config.minBrushSize,
|
|
|
|
max: state.config.maxBrushSize,
|
|
|
|
step: 5,
|
|
|
|
textStep: 1,
|
|
|
|
}
|
2022-12-01 15:10:30 -06:00
|
|
|
);
|
|
|
|
state.ctxmenu.brushSizeSlider = brushSizeSlider.slider;
|
|
|
|
state.setBrushSize = brushSizeSlider.setValue;
|
|
|
|
|
2022-12-04 16:35:44 -06:00
|
|
|
// Brush opacity slider
|
|
|
|
const brushOpacitySlider = _toolbar_input.slider(
|
|
|
|
state,
|
|
|
|
"brushOpacity",
|
|
|
|
"Brush Opacity",
|
|
|
|
{
|
|
|
|
min: 0,
|
|
|
|
max: 1,
|
|
|
|
step: 0.05,
|
|
|
|
textStep: 0.001,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
state.ctxmenu.brushOpacitySlider = brushOpacitySlider.slider;
|
|
|
|
|
|
|
|
// Brush blur slider
|
2022-12-01 15:10:30 -06:00
|
|
|
const brushBlurSlider = _toolbar_input.slider(
|
|
|
|
state,
|
|
|
|
"brushBlur",
|
|
|
|
"Brush Blur",
|
2022-12-03 04:50:23 -06:00
|
|
|
{
|
|
|
|
min: state.config.minBlur,
|
|
|
|
max: state.config.maxBlur,
|
|
|
|
step: 1,
|
|
|
|
}
|
2022-12-01 15:10:30 -06:00
|
|
|
);
|
|
|
|
state.ctxmenu.brushBlurSlider = brushBlurSlider.slider;
|
|
|
|
|
|
|
|
// Brush color
|
2022-12-03 17:00:10 -06:00
|
|
|
const brushColorPickerWrapper = document.createElement("div");
|
|
|
|
brushColorPickerWrapper.classList.add(
|
|
|
|
"brush-color-picker",
|
|
|
|
"wrapper"
|
|
|
|
);
|
|
|
|
|
2022-12-01 15:10:30 -06:00
|
|
|
const brushColorPicker = document.createElement("input");
|
2022-12-03 17:00:10 -06:00
|
|
|
brushColorPicker.classList.add("brush-color-picker", "picker");
|
2022-12-01 15:10:30 -06:00
|
|
|
brushColorPicker.type = "color";
|
|
|
|
brushColorPicker.value = state.color;
|
|
|
|
brushColorPicker.addEventListener("input", (evn) => {
|
|
|
|
state.color = evn.target.value;
|
|
|
|
});
|
|
|
|
|
2022-12-03 17:00:10 -06:00
|
|
|
state.setColor = (color) => {
|
|
|
|
brushColorPicker.value = color;
|
|
|
|
state.color = brushColorPicker.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
const brushColorEyeDropper = document.createElement("button");
|
|
|
|
brushColorEyeDropper.classList.add(
|
|
|
|
"brush-color-picker",
|
|
|
|
"eyedropper"
|
|
|
|
);
|
|
|
|
brushColorEyeDropper.addEventListener("click", () => {
|
2022-12-03 21:22:29 -06:00
|
|
|
if (state.eyedropper) state.disableDropper();
|
|
|
|
else state.enableDropper();
|
2022-12-03 17:00:10 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
brushColorPickerWrapper.appendChild(brushColorPicker);
|
|
|
|
brushColorPickerWrapper.appendChild(brushColorEyeDropper);
|
|
|
|
|
|
|
|
state.ctxmenu.brushColorPicker = brushColorPickerWrapper;
|
2022-12-01 15:10:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
menu.appendChild(state.ctxmenu.affectMaskCheckbox);
|
|
|
|
menu.appendChild(state.ctxmenu.brushSizeSlider);
|
2022-12-04 16:35:44 -06:00
|
|
|
menu.appendChild(state.ctxmenu.brushOpacitySlider);
|
2022-12-01 15:10:30 -06:00
|
|
|
menu.appendChild(state.ctxmenu.brushBlurSlider);
|
|
|
|
menu.appendChild(state.ctxmenu.brushColorPicker);
|
|
|
|
},
|
|
|
|
shortcut: "C",
|
|
|
|
}
|
|
|
|
);
|