2021-07-22 23:42:41 +03:00
|
|
|
const LayerList = (() => {
|
2021-07-23 16:15:17 +03:00
|
|
|
let layerList = document.getElementById("layers-menu");
|
2022-02-23 19:16:23 +03:00
|
|
|
// let layerListEntry = layerList.firstElementChild;
|
|
|
|
let layerListEntry = document.getElementById("default-layer-list-item");
|
2021-07-23 17:25:15 +03:00
|
|
|
let renamingLayer = false;
|
2021-07-23 16:15:17 +03:00
|
|
|
let dragStartLayer;
|
|
|
|
Events.on("mousedown", layerList, openOptionsMenu);
|
2022-02-27 17:14:42 +03:00
|
|
|
Events.on('click',"add-layer-button", addLayerClick, false);
|
2022-03-23 15:47:57 +03:00
|
|
|
Events.on('click',"add-reference-button", addReferenceClick, false);
|
2022-02-23 19:16:23 +03:00
|
|
|
Events.onCustom("switchedToAdvanced", showLayerList);
|
|
|
|
Events.onCustom("switchedToBasic", hideLayerList);
|
2021-07-23 16:15:17 +03:00
|
|
|
|
|
|
|
new Sortable(layerList, {
|
|
|
|
animation: 100,
|
|
|
|
filter: ".layer-button",
|
|
|
|
draggable: ".layers-menu-entry",
|
|
|
|
onStart: layerDragStart,
|
2022-02-23 19:16:23 +03:00
|
|
|
onEnd: layerDragEnd
|
2021-07-23 16:15:17 +03:00
|
|
|
});
|
2022-02-23 19:16:23 +03:00
|
|
|
function showLayerList() {
|
2021-12-07 14:11:40 +03:00
|
|
|
layerList.style.display = "inline-block";
|
|
|
|
document.getElementById('layer-button').style.display = 'inline-block';
|
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
function hideLayerList() {
|
2021-12-07 14:11:40 +03:00
|
|
|
if (EditorState.documentCreated()) {
|
|
|
|
currFile.currentLayer.selectLayer();
|
|
|
|
flatten(true);
|
|
|
|
}
|
|
|
|
layerList.style.display = "none";
|
|
|
|
document.getElementById('layer-button').style.display = 'none';
|
|
|
|
}
|
2022-03-23 15:47:57 +03:00
|
|
|
function addReferenceClick(id, saveHistory = true, layerName) {
|
|
|
|
addLayer(...arguments);
|
|
|
|
currFile.layers[currFile.layers.length-1].selectLayer();
|
|
|
|
}
|
2022-02-27 17:14:42 +03:00
|
|
|
function addLayerClick(id, saveHistory = true, layerName) {
|
|
|
|
addLayer(...arguments);
|
|
|
|
currFile.layers[currFile.layers.length-1].selectLayer();
|
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
function addLayer(id, saveHistory = true, layerName) {
|
|
|
|
let index = currFile.layers.length;
|
2021-07-22 23:42:41 +03:00
|
|
|
// Creating a new canvas
|
|
|
|
let newCanvas = document.createElement("canvas");
|
|
|
|
// Setting up the new canvas
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(newCanvas);
|
2021-07-22 23:42:41 +03:00
|
|
|
newCanvas.classList.add("drawingCanvas");
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
if (!layerListEntry) return //console.warn('skipping adding layer because no document');
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Clone the default layer
|
|
|
|
let toAppend = layerListEntry.cloneNode(true);
|
2022-02-23 19:16:23 +03:00
|
|
|
toAppend.style.display = "flex";
|
|
|
|
//console.log('toAppend === ',toAppend);
|
2021-07-22 23:42:41 +03:00
|
|
|
// Setting the default name for the layer
|
2022-02-23 19:16:23 +03:00
|
|
|
const _layerName = layerName ?? "Layer " + currFile.layers.length;
|
|
|
|
//console.log('_layerName === ',_layerName);
|
|
|
|
toAppend.getElementsByTagName('p')[0].innerHTML = _layerName;
|
2021-07-22 23:42:41 +03:00
|
|
|
// Removing the selected class
|
|
|
|
toAppend.classList.remove("selected-layer");
|
|
|
|
// Adding the layer to the list
|
|
|
|
Layer.layerCount++;
|
|
|
|
|
|
|
|
// Creating a layer object
|
2021-12-06 19:37:43 +03:00
|
|
|
let newLayer = new Layer(currFile.canvasSize[0], currFile.canvasSize[1], newCanvas, toAppend);
|
|
|
|
newLayer.context.fillStyle = currFile.currentLayer.context.fillStyle;
|
2022-10-24 13:40:34 +03:00
|
|
|
newLayer.context.willReadFrequently = true;
|
2021-12-06 19:37:43 +03:00
|
|
|
newLayer.copyData(currFile.currentLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
// currFile.layers.splice(index, 0, newLayer);
|
|
|
|
currFile.layers.push(newLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Insert it before the Add layer button
|
2022-02-23 19:16:23 +03:00
|
|
|
layerList.insertBefore(toAppend, document.getElementById("add-layer-li"));
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
if (id != null && typeof(id) == "string") {
|
|
|
|
newLayer.setID(id);
|
|
|
|
}
|
|
|
|
// Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history
|
|
|
|
if (saveHistory) {
|
|
|
|
new HistoryState().AddLayer(newLayer, index);
|
2022-02-25 17:49:30 +03:00
|
|
|
if(FileManager.cacheEnabled)FileManager.localStorageSave();
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
2022-02-27 17:14:42 +03:00
|
|
|
|
|
|
|
currFile.layers.forEach((layer, i) => {
|
|
|
|
const _i = currFile.layers.length - i;
|
|
|
|
layer.canvas.style.zIndex = (_i+1) * 10;
|
|
|
|
})
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
return newLayer;
|
|
|
|
}
|
|
|
|
/** Merges topLayer onto belowLayer
|
|
|
|
*
|
|
|
|
* @param {*} belowLayer The layer on the bottom of the layer stack
|
|
|
|
* @param {*} topLayer The layer on the top of the layer stack
|
|
|
|
*/
|
|
|
|
function mergeLayers(belowLayer, topLayer) {
|
|
|
|
// Copying the above content on the layerBelow
|
2021-09-18 23:32:58 +03:00
|
|
|
let belowImageData = belowLayer.getImageData(0, 0, belowLayer.canvas.width, belowLayer.canvas.height);
|
|
|
|
let toMergeImageData = topLayer.getImageData(0, 0, topLayer.canvas.width, topLayer.canvas.height);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
for (let i=0; i<belowImageData.data.length; i+=4) {
|
|
|
|
let currentMovePixel = [
|
|
|
|
toMergeImageData.data[i], toMergeImageData.data[i+1],
|
|
|
|
toMergeImageData.data[i+2], toMergeImageData.data[i+3]
|
|
|
|
];
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
let currentUnderlyingPixel = [ //TODO: I'd be curious to know if this array slows this function down
|
2021-07-22 23:42:41 +03:00
|
|
|
belowImageData.data[i], belowImageData.data[i+1],
|
|
|
|
belowImageData.data[i+2], belowImageData.data[i+3]
|
|
|
|
];
|
|
|
|
|
2021-11-09 00:25:30 +03:00
|
|
|
if (Util.isPixelEmpty(currentMovePixel)) {
|
|
|
|
if (!Util.isPixelEmpty(belowImageData)) {
|
2021-07-22 23:42:41 +03:00
|
|
|
toMergeImageData.data[i] = currentUnderlyingPixel[0];
|
|
|
|
toMergeImageData.data[i+1] = currentUnderlyingPixel[1];
|
|
|
|
toMergeImageData.data[i+2] = currentUnderlyingPixel[2];
|
|
|
|
toMergeImageData.data[i+3] = currentUnderlyingPixel[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Putting the top data into the belowdata
|
|
|
|
belowLayer.putImageData(toMergeImageData, 0, 0);
|
|
|
|
}
|
|
|
|
/** Sets the z indexes of the layers when the user drops the layer in the menu
|
|
|
|
*
|
|
|
|
* @param {*} event
|
|
|
|
*/
|
2022-02-23 19:16:23 +03:00
|
|
|
function layerDragEnd(event) {
|
|
|
|
Events.simulateMouseEvent(window, "mouseup");
|
|
|
|
|
|
|
|
const tempLayerCache = currFile.layers.reduce((r,n,i) => {
|
|
|
|
r[n.id] = n;
|
|
|
|
return r;
|
|
|
|
},{});
|
|
|
|
|
|
|
|
let selectedId;
|
|
|
|
const idArr = [...document.querySelectorAll(".layers-menu-entry")].map(elm => {
|
|
|
|
if([...elm.classList].includes("selected-layer")) {
|
|
|
|
selectedId = elm.id;
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
return elm.id;
|
|
|
|
});
|
|
|
|
let selectedIdx = idArr.indexOf(selectedId);
|
|
|
|
idArr.forEach((id,i)=>{
|
|
|
|
currFile.layers[i] = tempLayerCache[id];
|
|
|
|
currFile.layers[i].isSelected = i===selectedIdx;
|
|
|
|
});
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2022-02-27 17:14:42 +03:00
|
|
|
currFile.layers.forEach((layer, i) => {
|
|
|
|
const _i = currFile.layers.length - i;
|
|
|
|
layer.canvas.style.zIndex = (_i+1) * 10;
|
|
|
|
});
|
2022-02-25 17:49:30 +03:00
|
|
|
if(FileManager.cacheEnabled)FileManager.localStorageSave();
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
}
|
2021-07-22 23:42:41 +03:00
|
|
|
/** Saves the layer that is being moved when the dragging starts
|
|
|
|
*
|
|
|
|
* @param {*} event
|
|
|
|
*/
|
|
|
|
function layerDragStart(event) {
|
|
|
|
dragStartLayer = getLayerByID(layerList.children[event.oldIndex].id);
|
|
|
|
}
|
|
|
|
function getLayerByID(id) {
|
2022-02-23 19:16:23 +03:00
|
|
|
let ret;
|
2021-12-06 19:37:43 +03:00
|
|
|
for (let i=0; i<currFile.layers.length; i++) {
|
|
|
|
if (currFile.layers[i].hasCanvas()) {
|
|
|
|
if (currFile.layers[i].menuEntry.id == id) {
|
2022-02-23 19:16:23 +03:00
|
|
|
ret = currFile.layers[i];
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
return ret ?? null;
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
function getLayerByName(name) {
|
2021-12-06 19:37:43 +03:00
|
|
|
for (let i=0; i<currFile.layers.length; i++) {
|
|
|
|
if (currFile.layers[i].hasCanvas()) {
|
|
|
|
if (currFile.layers[i].menuEntry.getElementsByTagName("p")[0].innerHTML == name) {
|
|
|
|
return currFile.layers[i];
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2021-07-23 17:25:15 +03:00
|
|
|
function startRenamingLayer(event) {
|
2021-12-06 19:37:43 +03:00
|
|
|
let p = currFile.currentLayer.menuEntry.getElementsByTagName("p")[0];
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.currentLayer.oldLayerName = p.innerHTML;
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
p.setAttribute("contenteditable", true);
|
|
|
|
p.classList.add("layer-name-editable");
|
|
|
|
p.focus();
|
|
|
|
Events.simulateInput(65, true, false, false);
|
|
|
|
|
2021-07-23 17:25:15 +03:00
|
|
|
renamingLayer = true;
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
function duplicateLayer(event, saveHistory = true) {
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
let layerIndex = currFile.layers.indexOf(currFile.currentLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Creating a new canvas
|
|
|
|
let newCanvas = document.createElement("canvas");
|
|
|
|
// Setting up the new canvas
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(newCanvas);
|
2021-07-22 23:42:41 +03:00
|
|
|
newCanvas.classList.add("drawingCanvas");
|
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
if (!layerListEntry) return //console.warn('skipping adding layer because no document');
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Clone the default layer
|
2021-12-06 19:37:43 +03:00
|
|
|
let toAppend = currFile.currentLayer.menuEntry.cloneNode(true);
|
2021-07-22 23:42:41 +03:00
|
|
|
// Setting the default name for the layer
|
|
|
|
toAppend.getElementsByTagName('p')[0].innerHTML += " copy";
|
|
|
|
// Removing the selected class
|
|
|
|
toAppend.classList.remove("selected-layer");
|
|
|
|
// Adding the layer to the list
|
|
|
|
Layer.layerCount++;
|
|
|
|
|
|
|
|
// Creating a layer object
|
2021-12-06 19:37:43 +03:00
|
|
|
let newLayer = new Layer(currFile.canvasSize[0], currFile.canvasSize[1], newCanvas, toAppend);
|
|
|
|
newLayer.context.fillStyle = currFile.currentLayer.context.fillStyle;
|
|
|
|
newLayer.copyData(currFile.currentLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(layerIndex, 0, newLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Insert it before the Add layer button
|
2021-12-06 19:37:43 +03:00
|
|
|
layerList.insertBefore(toAppend, currFile.currentLayer.menuEntry);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Copy the layer content
|
2021-12-06 19:37:43 +03:00
|
|
|
newLayer.context.putImageData(currFile.currentLayer.context.getImageData(
|
|
|
|
0, 0, currFile.canvasSize[0], currFile.canvasSize[1]), 0, 0);
|
2021-07-22 23:42:41 +03:00
|
|
|
newLayer.updateLayerPreview();
|
2022-02-27 17:44:16 +03:00
|
|
|
|
|
|
|
LayerList.refreshZ();
|
|
|
|
|
2021-07-22 23:42:41 +03:00
|
|
|
// Basically "if I'm not adding a layer because redo() is telling meto do so", then I can save the history
|
|
|
|
if (saveHistory) {
|
2021-12-06 19:37:43 +03:00
|
|
|
new HistoryState().DuplicateLayer(newLayer, currFile.currentLayer);
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
function clearLayers() {
|
2022-02-27 17:14:42 +03:00
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
currFile.layers.forEach(()=>deleteLayer());
|
|
|
|
//console.log('currFile.layers.length === ',currFile.layers.length);
|
|
|
|
for(let i = 0; i < currFile.layers.length;i++){
|
|
|
|
const layer = currFile.layers[i];
|
|
|
|
//console.log('i === ', i);
|
|
|
|
//console.log('layer === ',layer);
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
}
|
|
|
|
function deleteLayer(saveHistory = true) {
|
|
|
|
//console.log('deleting layer: ', currFile.currentLayer.name, currFile.currentLayer);
|
|
|
|
//console.trace();
|
|
|
|
deleteLayerDirectly(currFile.currentLayer, saveHistory);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Closing the menu
|
2021-07-23 15:49:55 +03:00
|
|
|
closeOptionsMenu();
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
2022-02-23 19:16:23 +03:00
|
|
|
function deleteLayerDirectly(layer, saveHistory = true) {
|
|
|
|
let layerIndex = currFile.layers.indexOf(layer);
|
|
|
|
let toDelete = currFile.layers[layerIndex];
|
|
|
|
let previousSibling = toDelete.menuEntry.previousElementSibling;
|
|
|
|
// Adding the ids to the unused ones
|
|
|
|
Layer.unusedIDs.push(toDelete.id);
|
|
|
|
|
|
|
|
if(layer.isSelected) {
|
|
|
|
// Selecting the nearest layer
|
|
|
|
const nearestLayer = (currFile.layers[layerIndex + 1] ?? currFile.layers[layerIndex - 1]);
|
|
|
|
if(nearestLayer){
|
|
|
|
nearestLayer.selectLayer();
|
|
|
|
//console.log('changing to nearest layer');
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 23:42:41 +03:00
|
|
|
|
2022-02-23 19:16:23 +03:00
|
|
|
// Deleting canvas and entry
|
|
|
|
toDelete.canvas.remove();
|
|
|
|
toDelete.menuEntry.remove();
|
|
|
|
|
|
|
|
// Removing the layer from the list
|
|
|
|
currFile.layers.splice(layerIndex, 1);
|
|
|
|
|
|
|
|
if (saveHistory) {
|
|
|
|
new HistoryState().DeleteLayer(toDelete, previousSibling, layerIndex);
|
|
|
|
}
|
|
|
|
}
|
2021-07-22 23:42:41 +03:00
|
|
|
function merge(saveHistory = true) {
|
|
|
|
// Saving the layer that should be merged
|
2021-12-06 19:37:43 +03:00
|
|
|
let toMerge = currFile.currentLayer;
|
|
|
|
let toMergeIndex = currFile.layers.indexOf(toMerge);
|
2021-07-22 23:42:41 +03:00
|
|
|
// Getting layer below
|
2021-12-06 19:37:43 +03:00
|
|
|
let layerBelow = LayerList.getLayerByID(currFile.currentLayer.menuEntry.nextElementSibling.id);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// If I have something to merge with
|
|
|
|
if (layerBelow != null) {
|
|
|
|
// Selecting that layer
|
|
|
|
layerBelow.selectLayer();
|
|
|
|
|
|
|
|
if (saveHistory) {
|
|
|
|
new HistoryState().MergeLayer(toMergeIndex, toMerge,
|
2021-12-06 19:37:43 +03:00
|
|
|
layerBelow.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]),
|
2021-07-22 23:42:41 +03:00
|
|
|
layerBelow);
|
|
|
|
}
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
LayerList.mergeLayers(currFile.currentLayer.context, toMerge.context);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Deleting the above layer
|
|
|
|
toMerge.canvas.remove();
|
|
|
|
toMerge.menuEntry.remove();
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(toMergeIndex, 1);
|
2021-07-22 23:42:41 +03:00
|
|
|
|
|
|
|
// Updating the layer preview
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.currentLayer.updateLayerPreview();
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function flatten(onlyVisible) {
|
|
|
|
if (!onlyVisible) {
|
|
|
|
// Selecting the first layer
|
|
|
|
let firstLayer = layerList.firstElementChild;
|
|
|
|
let nToFlatten = layerList.childElementCount - 1;
|
|
|
|
LayerList.getLayerByID(firstLayer.id).selectLayer();
|
|
|
|
|
|
|
|
for (let i = 0; i < nToFlatten; i++) {
|
|
|
|
merge();
|
|
|
|
}
|
|
|
|
|
|
|
|
new HistoryState().FlattenAll(nToFlatten);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Getting all the visible layers
|
|
|
|
let visibleLayers = [];
|
|
|
|
let nToFlatten = 0;
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
for (let i=0; i<currFile.layers.length; i++) {
|
|
|
|
if (currFile.layers[i].hasCanvas() && currFile.layers[i].isVisible) {
|
|
|
|
visibleLayers.push(currFile.layers[i]);
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sorting them by z-index
|
|
|
|
visibleLayers.sort((a, b) => (a.canvas.style.zIndex > b.canvas.style.zIndex) ? -1 : 1);
|
|
|
|
// Selecting the last visible layer (the only one that won't get deleted)
|
|
|
|
visibleLayers[visibleLayers.length - 1].selectLayer();
|
|
|
|
|
|
|
|
// Merging all the layer but the last one
|
|
|
|
for (let i=0; i<visibleLayers.length - 1; i++) {
|
|
|
|
nToFlatten++;
|
2021-12-11 12:48:14 +03:00
|
|
|
|
2021-07-22 23:42:41 +03:00
|
|
|
new HistoryState().FlattenTwoVisibles(
|
2021-12-06 19:37:43 +03:00
|
|
|
visibleLayers[i + 1].context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]),
|
2021-07-22 23:42:41 +03:00
|
|
|
visibleLayers[i].menuEntry.nextElementSibling,
|
2021-12-11 12:48:14 +03:00
|
|
|
currFile.layers.indexOf(visibleLayers[i]),
|
2021-07-22 23:42:41 +03:00
|
|
|
visibleLayers[i], visibleLayers[i + 1]
|
|
|
|
);
|
|
|
|
|
|
|
|
LayerList.mergeLayers(visibleLayers[i + 1].context, visibleLayers[i].context);
|
|
|
|
|
|
|
|
// Deleting the above layer
|
|
|
|
visibleLayers[i].canvas.remove();
|
|
|
|
visibleLayers[i].menuEntry.remove();
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(currFile.layers.indexOf(visibleLayers[i]), 1);
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
new HistoryState().FlattenVisible(nToFlatten);
|
|
|
|
// Updating the layer preview
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.currentLayer.updateLayerPreview();
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 15:49:55 +03:00
|
|
|
function openOptionsMenu(event) {
|
|
|
|
if (event.which == 3) {
|
|
|
|
let selectedId;
|
|
|
|
let target = event.target;
|
|
|
|
|
|
|
|
while (target != null && target.classList != null && !target.classList.contains("layers-menu-entry")) {
|
|
|
|
target = target.parentElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectedId = target.id;
|
|
|
|
|
|
|
|
Layer.layerOptions.style.visibility = "visible";
|
|
|
|
Layer.layerOptions.style.top = "0";
|
|
|
|
Layer.layerOptions.style.marginTop = "" + (event.clientY - 25) + "px";
|
|
|
|
|
2021-12-11 14:48:12 +03:00
|
|
|
getLayerByID(selectedId).selectLayer(false);
|
2021-07-23 15:49:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function closeOptionsMenu(event) {
|
|
|
|
Layer.layerOptions.style.visibility = "hidden";
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.currentLayer.rename();
|
2021-07-23 17:25:15 +03:00
|
|
|
renamingLayer = false;
|
2021-07-23 15:49:55 +03:00
|
|
|
}
|
2021-07-23 16:15:17 +03:00
|
|
|
function getLayerListEntries() {
|
|
|
|
return layerList;
|
|
|
|
}
|
2021-07-23 17:25:15 +03:00
|
|
|
function isRenamingLayer() {
|
|
|
|
return renamingLayer;
|
|
|
|
}
|
2022-02-27 17:44:16 +03:00
|
|
|
function refreshZ() {
|
|
|
|
try{
|
|
|
|
let selectedZIndex = 0;
|
|
|
|
let maxZ = 0;
|
|
|
|
currFile.layers.forEach((layer, i) => {
|
|
|
|
const _i = currFile.layers.length - i;
|
|
|
|
let z = (_i+1) * 10;
|
|
|
|
if(maxZ < z)maxZ = z;
|
|
|
|
layer.canvas.style.zIndex = z;
|
|
|
|
if(layer.isSelected){
|
|
|
|
selectedZIndex = z;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
currFile.checkerBoard.canvas.style.zIndex = 1;
|
|
|
|
currFile.pixelGrid.canvas.style.zIndex = 2;
|
|
|
|
currFile.TMPLayer.canvas.style.zIndex = selectedZIndex + 1;
|
|
|
|
currFile.VFXLayer.canvas.style.zIndex = maxZ + 10;
|
|
|
|
}catch(e){}
|
|
|
|
}
|
2021-07-22 23:42:41 +03:00
|
|
|
return {
|
2022-02-27 17:44:16 +03:00
|
|
|
refreshZ,
|
2021-07-22 23:42:41 +03:00
|
|
|
addLayer,
|
|
|
|
mergeLayers,
|
|
|
|
getLayerByID,
|
|
|
|
getLayerByName,
|
2021-07-23 17:25:15 +03:00
|
|
|
renameLayer: startRenamingLayer,
|
2021-07-22 23:42:41 +03:00
|
|
|
duplicateLayer,
|
2022-02-23 19:16:23 +03:00
|
|
|
clearLayers,
|
2021-07-22 23:42:41 +03:00
|
|
|
deleteLayer,
|
2022-02-23 19:16:23 +03:00
|
|
|
deleteLayerDirectly,
|
2021-07-22 23:42:41 +03:00
|
|
|
merge,
|
2021-07-23 15:49:55 +03:00
|
|
|
flatten,
|
2021-07-23 16:15:17 +03:00
|
|
|
closeOptionsMenu,
|
2021-07-23 17:25:15 +03:00
|
|
|
getLayerListEntries,
|
|
|
|
isRenamingLayer
|
2021-07-22 23:42:41 +03:00
|
|
|
}
|
|
|
|
})();
|