Add swap width/height

This commit is contained in:
pythongosssss
2023-10-01 10:40:07 +01:00
parent 8b6fc32875
commit 88349f3262
+30
View File
@@ -0,0 +1,30 @@
import { app } from "../../../scripts/app.js";
app.registerExtension({
name: "pysssss.SwapResolution",
async beforeRegisterNodeDef(nodeType, nodeData) {
const inputs = { ...nodeData.input?.required, ...nodeData.input?.optional };
if (inputs.width && inputs.height) {
const origGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions;
nodeType.prototype.getExtraMenuOptions = function (_, options) {
const r = origGetExtraMenuOptions?.apply?.(this, arguments);
options.push(
{
content: "Swap width/height",
callback: () => {
const w = this.widgets.find((w) => w.name === "width");
const h = this.widgets.find((w) => w.name === "height");
const a = w.value;
w.value = h.value;
h.value = a;
app.graph.setDirtyCanvas(true);
},
},
null
);
return r;
};
}
},
});