Fix img resize issues, add redo/undo buttons

This commit is contained in:
JeLuF 2022-12-17 00:29:54 +01:00
parent 7eb29fa91b
commit 341c810bbb
2 changed files with 30 additions and 4 deletions

View File

@ -136,6 +136,10 @@
background: var(--background-color3); background: var(--background-color3);
} }
.editor-controls-right .image-editor-button {
margin-bottom: 4px;
}
#init_image_button_inpaint .input-toggle { #init_image_button_inpaint .input-toggle {
position: absolute; position: absolute;
left: 16px; left: 16px;

View File

@ -105,7 +105,26 @@ const IMAGE_EDITOR_ACTIONS = [
icon: "fa-solid fa-xmark", icon: "fa-solid fa-xmark",
handler: (editor) => { handler: (editor) => {
editor.ctx_current.clearRect(0, 0, editor.width, editor.height) editor.ctx_current.clearRect(0, 0, editor.width, editor.height)
} },
trackHistory: true
},
{
id: "undo",
name: "Undo",
icon: "fa-solid fa-rotate-left",
handler: (editor) => {
editor.history.undo()
},
trackHistory: false
},
{
id: "redo",
name: "Redo",
icon: "fa-solid fa-rotate-right",
handler: (editor) => {
editor.history.redo()
},
trackHistory: false
} }
] ]
@ -436,13 +455,14 @@ class ImageEditor {
return return
} }
var max_size = Math.min(parseInt(window.innerWidth * 0.9), width, 768)
if (width > height) { if (width > height) {
var max_size = Math.min(parseInt(window.innerWidth * 0.9), width, 768)
var multiplier = max_size / width var multiplier = max_size / width
width = (multiplier * width).toFixed() width = (multiplier * width).toFixed()
height = (multiplier * height).toFixed() height = (multiplier * height).toFixed()
} }
else { else {
var max_size = Math.min(parseInt(window.innerHeight * 0.9), height, 768)
var multiplier = max_size / height var multiplier = max_size / height
width = (multiplier * width).toFixed() width = (multiplier * width).toFixed()
height = (multiplier * height).toFixed() height = (multiplier * height).toFixed()
@ -525,7 +545,9 @@ class ImageEditor {
} }
runAction(action_id) { runAction(action_id) {
var action = IMAGE_EDITOR_ACTIONS.find(a => a.id == action_id) var action = IMAGE_EDITOR_ACTIONS.find(a => a.id == action_id)
if (action.trackHistory) {
this.history.pushAction(action_id) this.history.pushAction(action_id)
}
action.handler(this) action.handler(this)
} }
setBrush(layer = null, options = null) { setBrush(layer = null, options = null) {