2021-07-14 23:20:55 +03:00
|
|
|
/** How the history works
|
|
|
|
* - undoStates stores the states that can be undone
|
|
|
|
* - redoStates stores the states that can be redone
|
|
|
|
* - undo() undoes an action and adds it to the redoStates
|
|
|
|
* - redo() redoes an action and adds it to the undoStates
|
|
|
|
* - Each HistoryState must implement an undo() and redo() function
|
|
|
|
* Those functions actually implement the undo and redo mechanism for that action,
|
|
|
|
* so you'll need to save the data you need as attributes in the constructor. For example,
|
|
|
|
* for the HistoryStateAddColour, the added colour is saved so that it can be removed in
|
|
|
|
* undo() or added back in redo().
|
|
|
|
* - Each HistoryState must call saveHistoryState(this) so that it gets added to the stack
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
const History = (() => {
|
|
|
|
|
|
|
|
const undoLogStyle = 'background: #87ff1c; color: black; padding: 5px;';
|
|
|
|
let undoStates = [];
|
|
|
|
let redoStates = [];
|
2021-07-15 23:21:19 +03:00
|
|
|
|
2021-07-20 23:52:51 +03:00
|
|
|
Events.on('click', 'undo-button', undo);
|
|
|
|
Events.on('click', 'redo-button', redo);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//rename to add undo state
|
|
|
|
function saveHistoryState (state) {
|
|
|
|
//get current canvas data and save to undoStates array
|
|
|
|
undoStates.push(state);
|
|
|
|
|
|
|
|
//limit the number of states to settings.numberOfHistoryStates
|
2021-07-26 00:26:32 +03:00
|
|
|
if (undoStates.length > Settings.getCurrSettings().numberOfHistoryStates) {
|
|
|
|
undoStates = undoStates.splice(-Settings.getCurrSettings().numberOfHistoryStates, Settings.getCurrSettings().numberOfHistoryStates);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//there is now definitely at least 1 undo state, so the button shouldnt be disabled
|
|
|
|
document.getElementById('undo-button').classList.remove('disabled');
|
|
|
|
|
|
|
|
//there should be no redoStates after an undoState is saved
|
|
|
|
redoStates = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
function undo () {
|
2022-02-23 19:16:23 +03:00
|
|
|
////console.log("undoing");
|
2021-07-15 18:10:07 +03:00
|
|
|
undoOrRedo('undo');
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function redo () {
|
2022-02-23 19:16:23 +03:00
|
|
|
////console.log("redoing");
|
2021-07-15 18:10:07 +03:00
|
|
|
undoOrRedo('redo');
|
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
function undoOrRedo(mode) {
|
|
|
|
if (redoStates.length <= 0 && mode == 'redo') return;
|
|
|
|
if (undoStates.length <= 0 && mode == 'undo') return;
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
// Enable button
|
|
|
|
document.getElementById(mode + '-button').classList.remove('disabled');
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
if (mode == 'undo') {
|
|
|
|
const undoState = undoStates.pop();
|
|
|
|
redoStates.push(undoState);
|
|
|
|
undoState.undo();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const redoState = redoStates.pop();
|
|
|
|
undoStates.push(redoState);
|
2021-07-14 23:20:55 +03:00
|
|
|
redoState.redo();
|
|
|
|
}
|
2021-07-15 18:10:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
// if theres none left, disable the option
|
|
|
|
if (redoStates.length == 0) document.getElementById('redo-button').classList.add('disabled');
|
|
|
|
if (undoStates.length == 0) document.getElementById('undo-button').classList.add('disabled');
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
redo,
|
|
|
|
undo,
|
|
|
|
saveHistoryState
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
class HistoryState {
|
|
|
|
constructor() {
|
|
|
|
History.saveHistoryState(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResizeSprite (xRatio, yRatio, algo, oldData) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.xRatio = xRatio;
|
|
|
|
this.yRatio = yRatio;
|
|
|
|
this.algo = algo;
|
|
|
|
this.oldData = oldData;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
let layerIndex = 0;
|
|
|
|
|
2021-12-06 22:12:57 +03:00
|
|
|
currFile.currentAlgo = algo;
|
|
|
|
currFile.resizeSprite(null, [1 / this.xRatio, 1 / this.yRatio]);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
// Also putting the old data
|
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].context.putImageData(this.oldData[layerIndex], 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
layerIndex++;
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers[i].updateLayerPreview();
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
2021-12-06 22:12:57 +03:00
|
|
|
currFile.currentAlgo = algo;
|
|
|
|
currFile.resizeSprite(null, [this.xRatio, this.yRatio]);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
ResizeCanvas (newSize, oldSize, imageDatas, trim) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.oldSize = oldSize;
|
|
|
|
this.newSize = newSize;
|
|
|
|
this.imageDatas = imageDatas;
|
|
|
|
this.trim = trim;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
let dataIndex = 0;
|
|
|
|
// Resizing the canvas
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.resizeCanvas(null, oldSize, null, false);
|
2021-07-14 23:20:55 +03:00
|
|
|
// Putting the image datas
|
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].context.putImageData(this.imageDatas[dataIndex], 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
dataIndex++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
if (!this.trim) {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.resizeCanvas(null, newSize, null, false);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.trimCanvas(null, false);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
FlattenVisible(flattened) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.nFlattened = flattened;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
for (let i=0; i<this.nFlattened; i++) {
|
|
|
|
undo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
for (let i=0; i<this.nFlattened; i++) {
|
|
|
|
redo();
|
|
|
|
}
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
FlattenTwoVisibles(belowImageData, afterAbove, layerIndex, aboveLayer, belowLayer) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.aboveLayer = aboveLayer;
|
|
|
|
this.belowLayer = belowLayer;
|
|
|
|
this.belowImageData = belowImageData;
|
|
|
|
|
|
|
|
this.undo = function() {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(aboveLayer.canvas);
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().insertBefore(aboveLayer.menuEntry, afterAbove);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
belowLayer.context.clearRect(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
belowLayer.context.putImageData(this.belowImageData, 0, 0);
|
|
|
|
belowLayer.updateLayerPreview();
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(layerIndex, 0, aboveLayer);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
2021-07-22 23:42:41 +03:00
|
|
|
LayerList.mergeLayers(belowLayer.context, aboveLayer.context);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
// Deleting the above layer
|
|
|
|
aboveLayer.canvas.remove();
|
|
|
|
aboveLayer.menuEntry.remove();
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(currFile.layers.indexOf(aboveLayer), 1);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
FlattenAll(nFlattened) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.nFlattened = nFlattened;
|
|
|
|
|
|
|
|
this.undo = function() {
|
2022-02-23 19:16:23 +03:00
|
|
|
for (let i=0; i<this.nFlattened; i++) {
|
2021-07-14 23:20:55 +03:00
|
|
|
undo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
2022-02-23 19:16:23 +03:00
|
|
|
for (let i=0; i<this.nFlattened; i++) {
|
2021-07-14 23:20:55 +03:00
|
|
|
redo();
|
|
|
|
}
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
MergeLayer(aboveIndex, aboveLayer, belowData, belowLayer) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.aboveIndex = aboveIndex;
|
|
|
|
this.belowData = belowData;
|
|
|
|
this.aboveLayer = aboveLayer;
|
|
|
|
this.belowLayer = belowLayer;
|
|
|
|
|
|
|
|
this.undo = function() {
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().insertBefore(this.aboveLayer.menuEntry, this.belowLayer.menuEntry);
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(this.aboveLayer.canvas);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
belowLayer.context.clearRect(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
belowLayer.context.putImageData(this.belowData, 0, 0);
|
|
|
|
belowLayer.updateLayerPreview();
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(this.aboveIndex, 0, this.aboveLayer);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
aboveLayer.selectLayer();
|
2021-07-22 23:42:41 +03:00
|
|
|
LayerList.merge(false);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
RenameLayer(oldName, newName, layer) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.edited = layer;
|
|
|
|
this.oldName = oldName;
|
|
|
|
this.newName = newName;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
layer.menuEntry.getElementsByTagName("p")[0].innerHTML = oldName;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
layer.menuEntry.getElementsByTagName("p")[0].innerHTML = newName;
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
DuplicateLayer(addedLayer, copiedLayer) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.addedLayer = addedLayer;
|
|
|
|
this.copiedLayer = copiedLayer;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
addedLayer.selectLayer();
|
2022-02-23 19:16:23 +03:00
|
|
|
if (currFile.layers.length != 4) {//TODO: repent and rebirth lol
|
|
|
|
LayerList.deleteLayer(false);
|
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
copiedLayer.selectLayer();
|
2021-07-22 23:42:41 +03:00
|
|
|
LayerList.duplicateLayer(null, false);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
DeleteLayer(layerData, before, index) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.deleted = layerData;
|
|
|
|
this.before = before;
|
|
|
|
this.index = index;
|
|
|
|
|
|
|
|
this.undo = function() {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(this.deleted.canvas);
|
2021-07-14 23:20:55 +03:00
|
|
|
if (this.before != null) {
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().insertBefore(this.deleted.menuEntry, this.before);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().prepend(this.deleted.menuEntry);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(this.index, 0, this.deleted);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
this.deleted.selectLayer();
|
2022-02-23 19:16:23 +03:00
|
|
|
if (currFile.layers.length != 4) {//TODO: repent and rebirth lol
|
|
|
|
LayerList.deleteLayer(false);
|
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
MoveTwoLayers(layer, oldIndex, newIndex) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.layer = layer;
|
|
|
|
this.oldIndex = oldIndex;
|
|
|
|
this.newIndex = newIndex;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
layer.canvas.style.zIndex = oldIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
layer.canvas.style.zIndex = newIndex;
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
MoveLayer(afterToDrop, toDrop, staticc, nMoved) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.beforeToDrop = afterToDrop;
|
|
|
|
this.toDrop = toDrop;
|
|
|
|
|
|
|
|
this.undo = function() {
|
|
|
|
toDrop.menuEntry.remove();
|
|
|
|
|
|
|
|
if (afterToDrop != null) {
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().insertBefore(toDrop.menuEntry, afterToDrop)
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().append(toDrop.menuEntry);
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (let i=0; i<nMoved; i++) {
|
|
|
|
undo();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
|
|
|
moveLayers(toDrop.menuEntry.id, staticc.menuEntry.id, true);
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
2021-07-15 18:10:07 +03:00
|
|
|
AddLayer(layerData, index) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.added = layerData;
|
|
|
|
this.index = index;
|
|
|
|
|
|
|
|
this.undo = function() {
|
2022-02-23 19:16:23 +03:00
|
|
|
if (currFile.layers.length > this.index + 1) {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers[this.index + 1].selectLayer();
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
else {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers[this.index - 1].selectLayer();
|
2021-07-14 23:20:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.added.canvas.remove();
|
|
|
|
this.added.menuEntry.remove();
|
|
|
|
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.layers.splice(index, 1);
|
2021-07-14 23:20:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function() {
|
2021-12-06 19:37:43 +03:00
|
|
|
currFile.canvasView.append(this.added.canvas);
|
2021-07-23 16:15:17 +03:00
|
|
|
LayerList.getLayerListEntries().prepend(this.added.menuEntry);
|
2021-07-14 23:20:55 +03:00
|
|
|
layers.splice(this.index, 0, this.added);
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//prototype for undoing canvas changes
|
2021-07-15 18:10:07 +03:00
|
|
|
EditCanvas() {
|
2021-12-06 19:37:43 +03:00
|
|
|
this.canvasState = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
this.layerID = currFile.currentLayer.id;
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
this.undo = function () {
|
2021-07-22 23:42:41 +03:00
|
|
|
var stateLayer = LayerList.getLayerByID(this.layerID);
|
2021-12-06 19:37:43 +03:00
|
|
|
var currentCanvas = stateLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
stateLayer.context.putImageData(this.canvasState, 0, 0);
|
|
|
|
|
|
|
|
this.canvasState = currentCanvas;
|
|
|
|
|
|
|
|
stateLayer.updateLayerPreview();
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function () {
|
2021-07-22 23:42:41 +03:00
|
|
|
var stateLayer = LayerList.getLayerByID(this.layerID);
|
2021-12-06 19:37:43 +03:00
|
|
|
var currentCanvas = stateLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
stateLayer.context.putImageData(this.canvasState, 0, 0);
|
|
|
|
|
|
|
|
this.canvasState = currentCanvas;
|
|
|
|
|
|
|
|
stateLayer.updateLayerPreview();
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//prototype for undoing added colors
|
2021-07-15 18:10:07 +03:00
|
|
|
AddColor(colorValue) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.colorValue = colorValue;
|
|
|
|
|
|
|
|
this.undo = function () {
|
|
|
|
ColorModule.deleteColor(this.colorValue);
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function () {
|
|
|
|
ColorModule.addColor(this.colorValue);
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//prototype for undoing deleted colors
|
2021-07-15 18:10:07 +03:00
|
|
|
DeleteColor(colorValue) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.colorValue = colorValue;
|
2021-12-06 19:37:43 +03:00
|
|
|
this.canvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
this.undo = function () {
|
2021-12-06 19:37:43 +03:00
|
|
|
var currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
currFile.currentLayer.context.putImageData(this.canvas, 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
ColorModule.addColor(this.colorValue);
|
|
|
|
|
|
|
|
this.canvas = currentCanvas;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function () {
|
2021-12-06 19:37:43 +03:00
|
|
|
var currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
currFile.currentLayer.context.putImageData(this.canvas, 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
ColorModule.deleteColor(this.colorValue);
|
|
|
|
|
|
|
|
this.canvas = currentCanvas;
|
|
|
|
};
|
2021-07-15 18:10:07 +03:00
|
|
|
}
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//prototype for undoing colors edits
|
2021-07-15 18:10:07 +03:00
|
|
|
EditColor(newColorValue, oldColorValue) {
|
2021-07-14 23:20:55 +03:00
|
|
|
this.newColorValue = newColorValue;
|
|
|
|
this.oldColorValue = oldColorValue;
|
2021-12-06 19:37:43 +03:00
|
|
|
this.canvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
this.undo = function () {
|
2021-12-06 19:37:43 +03:00
|
|
|
let currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
currFile.currentLayer.context.putImageData(this.canvas, 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//find new color in palette and change it back to old color
|
2021-07-22 17:40:58 +03:00
|
|
|
let colors = document.getElementsByClassName('color-button');
|
|
|
|
for (let i = 0; i < colors.length; i++) {
|
2022-02-23 19:16:23 +03:00
|
|
|
//////console.log(newColorValue, '==', colors[i].jscolor.toString());
|
2021-07-14 23:20:55 +03:00
|
|
|
if (newColorValue == colors[i].jscolor.toString()) {
|
|
|
|
colors[i].jscolor.fromString(oldColorValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.canvas = currentCanvas;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.redo = function () {
|
2021-12-06 19:37:43 +03:00
|
|
|
let currentCanvas = currFile.currentLayer.context.getImageData(0, 0, currFile.canvasSize[0], currFile.canvasSize[1]);
|
|
|
|
currFile.currentLayer.context.putImageData(this.canvas, 0, 0);
|
2021-07-14 23:20:55 +03:00
|
|
|
|
|
|
|
//find old color in palette and change it back to new color
|
2021-07-22 17:40:58 +03:00
|
|
|
let colors = document.getElementsByClassName('color-button');
|
|
|
|
for (let i = 0; i < colors.length; i++) {
|
2022-02-23 19:16:23 +03:00
|
|
|
//////console.log(oldColorValue, '==', colors[i].jscolor.toString());
|
2021-07-14 23:20:55 +03:00
|
|
|
if (oldColorValue == colors[i].jscolor.toString()) {
|
|
|
|
colors[i].jscolor.fromString(newColorValue);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.canvas = currentCanvas;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|