mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Changed implementation for moving layers
This commit is contained in:
parent
4bd05f184d
commit
a860677488
@ -128,8 +128,8 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.layerdragover {
|
.layerdragover {
|
||||||
border: 2px dashed color(base, foreground, bold);
|
margin-top:5px;
|
||||||
border-top: 2px solid color(base, foreground, bold);
|
border-top: 3px solid color(base, foreground, bold);
|
||||||
}
|
}
|
||||||
|
|
||||||
.layers-menu-entry {
|
.layers-menu-entry {
|
||||||
|
55
js/_layer.js
55
js/_layer.js
@ -157,7 +157,7 @@ class Layer {
|
|||||||
let toDropID = element.dataTransfer.getData('text/html');
|
let toDropID = element.dataTransfer.getData('text/html');
|
||||||
let thisID = this.id;
|
let thisID = this.id;
|
||||||
|
|
||||||
swapLayerEntries(toDropID, thisID);
|
moveLayers(toDropID, thisID);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.classList.remove('layerdragover');
|
this.classList.remove('layerdragover');
|
||||||
@ -461,17 +461,56 @@ function renameLayer(event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Swaps two layer entries in the layer menu
|
// Swaps two layer entries in the layer menu
|
||||||
function swapLayerEntries(id1, id2, saveHistory = true) {
|
function moveLayers(toDropLayer, staticLayer, saveHistory = true) {
|
||||||
let entry1 = document.getElementById(id1);
|
let entry1 = document.getElementById(toDropLayer);
|
||||||
let entry2 = document.getElementById(id2);
|
let entry2 = document.getElementById(staticLayer);
|
||||||
|
|
||||||
let layer1 = getLayerByID(id1);
|
let toDrop = getLayerByID(toDropLayer);
|
||||||
let layer2 = getLayerByID(id2);
|
let static = getLayerByID(staticLayer);
|
||||||
|
let layerCopy = layers;
|
||||||
let tmpZIndex;
|
let tmpZIndex;
|
||||||
|
|
||||||
let after2 = entry2.nextSibling;
|
let after2 = entry2.nextSibling;
|
||||||
let parent = entry1.parentNode;
|
let parent = entry1.parentNode;
|
||||||
|
|
||||||
|
layerCopy.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? 1 : -1);
|
||||||
|
console.log(layerCopy.map(a => a.canvas.style.zIndex));
|
||||||
|
|
||||||
|
let toDropIndex = layerCopy.indexOf(toDrop);
|
||||||
|
let staticIndex = layerCopy.indexOf(static);
|
||||||
|
|
||||||
|
layerList.insertBefore(toDrop.menuEntry, static.menuEntry);
|
||||||
|
|
||||||
|
if (toDropIndex < staticIndex) {
|
||||||
|
console.log("UO");
|
||||||
|
let tmp = toDrop.canvas.style.zIndex;
|
||||||
|
let tmp2;
|
||||||
|
|
||||||
|
for (let i=toDropIndex+1; i<=staticIndex; i++) {
|
||||||
|
tmp2 = layerCopy[i].canvas.style.zIndex;
|
||||||
|
layerCopy[i].canvas.style.zIndex = tmp;
|
||||||
|
tmp = tmp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
toDrop.canvas.style.zIndex = tmp;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// BUG QUI
|
||||||
|
let tmp = toDrop.canvas.style.zIndex;
|
||||||
|
let tmp2;
|
||||||
|
|
||||||
|
for (let i=toDropIndex-1; i>staticIndex; i--) {
|
||||||
|
tmp2 = layerCopy[i].canvas.style.zIndex;
|
||||||
|
layerCopy[i].canvas.style.zIndex = tmp;
|
||||||
|
tmp = tmp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
toDrop.canvas.style.zIndex = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
console.log("id1: " + toDrop + ", id2: " + static);
|
||||||
|
|
||||||
tmpZIndex = layer1.canvas.style.zIndex;
|
tmpZIndex = layer1.canvas.style.zIndex;
|
||||||
layer1.canvas.style.zIndex = layer2.canvas.style.zIndex;
|
layer1.canvas.style.zIndex = layer2.canvas.style.zIndex;
|
||||||
layer2.canvas.style.zIndex = tmpZIndex;
|
layer2.canvas.style.zIndex = tmpZIndex;
|
||||||
@ -488,9 +527,9 @@ function swapLayerEntries(id1, id2, saveHistory = true) {
|
|||||||
} else {
|
} else {
|
||||||
parent.appendChild(entry1);
|
parent.appendChild(entry1);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
if (saveHistory) {
|
if (saveHistory) {
|
||||||
new HistoryStateMoveLayer(id1, id2);
|
new HistoryStateMoveLayer(toDrop, static);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user