Merge pull request #668 from JeLuF/imgedit

Fix img resize issues, add redo/undo buttons
This commit is contained in:
cmdr2 2022-12-17 09:50:07 +05:30 committed by GitHub
commit aea70e3dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
@ -208,4 +212,4 @@
} }
.image-editor-popup h4 { .image-editor-popup h4 {
text-align: left; text-align: left;
} }

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)
this.history.pushAction(action_id) if (action.trackHistory) {
this.history.pushAction(action_id)
}
action.handler(this) action.handler(this)
} }
setBrush(layer = null, options = null) { setBrush(layer = null, options = null) {