some general fixes
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com> Former-commit-id: 4434e218c4f67ac3c63c3a5b645013588a7ce770
This commit is contained in:
parent
8419f52f43
commit
db73982df2
2 changed files with 47 additions and 35 deletions
|
@ -87,6 +87,12 @@ const selectTransformTool = () =>
|
||||||
y: Math.min(y1, y2),
|
y: Math.min(y1, y2),
|
||||||
w: Math.abs(x1 - x2),
|
w: Math.abs(x1 - x2),
|
||||||
h: Math.abs(y1 - y2),
|
h: Math.abs(y1 - y2),
|
||||||
|
updateOriginal() {
|
||||||
|
this.original.x = this.x;
|
||||||
|
this.original.y = this.y;
|
||||||
|
this.original.w = this.w;
|
||||||
|
this.original.h = this.h;
|
||||||
|
},
|
||||||
contains(x, y) {
|
contains(x, y) {
|
||||||
return (
|
return (
|
||||||
this.x <= x &&
|
this.x <= x &&
|
||||||
|
@ -171,13 +177,14 @@ const selectTransformTool = () =>
|
||||||
|
|
||||||
// Update scale
|
// Update scale
|
||||||
if (state.scaling) {
|
if (state.scaling) {
|
||||||
state.scaling.scaleTo(x, y);
|
state.scaling.scaleTo(x, y, state.keepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update position
|
// Update position
|
||||||
if (state.moving) {
|
if (state.moving) {
|
||||||
state.selected.x = x - state.moving.offset.x;
|
state.selected.x = x - state.moving.offset.x;
|
||||||
state.selected.y = y - state.moving.offset.y;
|
state.selected.y = y - state.moving.offset.y;
|
||||||
|
state.selected.updateOriginal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw dragging box
|
// Draw dragging box
|
||||||
|
@ -271,6 +278,7 @@ const selectTransformTool = () =>
|
||||||
|
|
||||||
state.clickcb = (evn) => {
|
state.clickcb = (evn) => {
|
||||||
if (evn.target.id === "overlayCanvas") {
|
if (evn.target.id === "overlayCanvas") {
|
||||||
|
if (state.selected) {
|
||||||
imgCtx.drawImage(
|
imgCtx.drawImage(
|
||||||
state.selected.image,
|
state.selected.image,
|
||||||
state.original.x,
|
state.original.x,
|
||||||
|
@ -291,6 +299,7 @@ const selectTransformTool = () =>
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
state.dragstartcb = (evn) => {
|
state.dragstartcb = (evn) => {
|
||||||
if (evn.target.id === "overlayCanvas") {
|
if (evn.target.id === "overlayCanvas") {
|
||||||
|
@ -330,6 +339,7 @@ const selectTransformTool = () =>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.scaling) {
|
if (state.scaling) {
|
||||||
|
state.selected.updateOriginal();
|
||||||
state.scaling = null;
|
state.scaling = null;
|
||||||
} else if (state.moving) {
|
} else if (state.moving) {
|
||||||
state.moving = null;
|
state.moving = null;
|
||||||
|
@ -419,17 +429,7 @@ const selectTransformTool = () =>
|
||||||
const ctx = state.clipboard.copy.getContext("2d");
|
const ctx = state.clipboard.copy.getContext("2d");
|
||||||
|
|
||||||
ctx.clearRect(0, 0, state.selected.w, state.selected.h);
|
ctx.clearRect(0, 0, state.selected.w, state.selected.h);
|
||||||
ctx.drawImage(
|
ctx.drawImage(state.selected.image, 0, 0);
|
||||||
imgCanvas,
|
|
||||||
state.selected.x,
|
|
||||||
state.selected.y,
|
|
||||||
state.selected.w,
|
|
||||||
state.selected.h,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
state.selected.w,
|
|
||||||
state.selected.h
|
|
||||||
);
|
|
||||||
|
|
||||||
// Because firefox needs manual activation of the feature
|
// Because firefox needs manual activation of the feature
|
||||||
if (state.useClipboard) {
|
if (state.useClipboard) {
|
||||||
|
|
|
@ -13,11 +13,13 @@ const stampTool = () =>
|
||||||
|
|
||||||
// For calls from other tools to paste image
|
// For calls from other tools to paste image
|
||||||
if (opt && opt.image) {
|
if (opt && opt.image) {
|
||||||
state.selected = state.addResource(
|
const resource = state.addResource(
|
||||||
opt.name || "Clipboard",
|
opt.name || "Clipboard",
|
||||||
opt.image,
|
opt.image,
|
||||||
opt.temporary === undefined ? true : opt.temporary
|
opt.temporary === undefined ? true : opt.temporary
|
||||||
);
|
);
|
||||||
|
state.selected = resource;
|
||||||
|
document.getElementById(`resource-${resource.id}`).click();
|
||||||
state.ctxmenu.uploadButton.disabled = true;
|
state.ctxmenu.uploadButton.disabled = true;
|
||||||
state.back = opt.back || null;
|
state.back = opt.back || null;
|
||||||
toolbar.lock();
|
toolbar.lock();
|
||||||
|
@ -33,6 +35,12 @@ const stampTool = () =>
|
||||||
// Clear Listeners
|
// Clear Listeners
|
||||||
mouse.listen.canvas.onmousemove.clear(state.movecb);
|
mouse.listen.canvas.onmousemove.clear(state.movecb);
|
||||||
mouse.listen.canvas.left.onclick.clear(state.drawcb);
|
mouse.listen.canvas.left.onclick.clear(state.drawcb);
|
||||||
|
|
||||||
|
// Deselect
|
||||||
|
state.selected = null;
|
||||||
|
Array.from(state.ctxmenu.resourceList.children).forEach((child) => {
|
||||||
|
child.classList.remove("selected");
|
||||||
|
});
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: (state) => {
|
init: (state) => {
|
||||||
|
@ -50,6 +58,7 @@ const stampTool = () =>
|
||||||
resourceWrapper.classList.add("resource");
|
resourceWrapper.classList.add("resource");
|
||||||
|
|
||||||
resourceWrapper.addEventListener("click", () => {
|
resourceWrapper.addEventListener("click", () => {
|
||||||
|
if (state.ctxmenu.uploadButton.disabled) return;
|
||||||
state.selected = resource;
|
state.selected = resource;
|
||||||
Array.from(state.ctxmenu.resourceList.children).forEach(
|
Array.from(state.ctxmenu.resourceList.children).forEach(
|
||||||
(child) => {
|
(child) => {
|
||||||
|
@ -76,10 +85,13 @@ const stampTool = () =>
|
||||||
|
|
||||||
if (elements.length > state.resources.length)
|
if (elements.length > state.resources.length)
|
||||||
elements.forEach((element) => {
|
elements.forEach((element) => {
|
||||||
for (let resource in state.resources) {
|
let remove = true;
|
||||||
if (element.id.endsWith(resource.id)) return;
|
state.resources.some((resource) => {
|
||||||
}
|
console.debug(element.id, resource.id);
|
||||||
state.ctxmenu.resourceList.removeChild(element);
|
if (element.id.endsWith(resource.id)) remove = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (remove) state.ctxmenu.resourceList.removeChild(element);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue