Merge pull request #98 from zero01101/i90

i think this should fix issue 90 - optional resolution/reticle sync
This commit is contained in:
Victor Seiji Hariki 2022-12-13 11:08:38 -03:00 committed by GitHub
commit 35afbfa766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 7 deletions

View file

@ -99,6 +99,13 @@
<br /> <br />
<input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" /> <input type="checkbox" id="cbxHRFix" onchange="changeHiResFix()" />
<label for="cbxHRFix">Auto txt2img HRfix</label> <label for="cbxHRFix">Auto txt2img HRfix</label>
<br />
<input
type="checkbox"
id="cbxSyncCursorSize"
onchange="changeSyncCursorSize()" />
<label for="cbxSyncCursorSize">Sync cursor size</label>
<br />
<div id="resolution"></div> <div id="resolution"></div>
<div id="steps"></div> <div id="steps"></div>
<div id="cfgScale"></div> <div id="cfgScale"></div>

View file

@ -101,6 +101,7 @@ function startup() {
changeSmoothRendering(); changeSmoothRendering();
changeSeed(); changeSeed();
changeHiResFix(); changeHiResFix();
changeSyncCursorSize();
} }
/** /**
@ -448,19 +449,20 @@ const upscalerAutoComplete = createAutoComplete(
document.getElementById("upscaler-ac-select") document.getElementById("upscaler-ac-select")
); );
makeSlider( const resSlider = makeSlider(
"Resolution", "Resolution",
document.getElementById("resolution"), document.getElementById("resolution"),
"resolution", "resolution",
64, 128,
1024, 2048,
64, 128,
512, 512,
2, 2,
(v) => { (v) => {
stableDiffusionData.width = stableDiffusionData.height = v; stableDiffusionData.width = stableDiffusionData.height = v;
stableDiffusionData.firstphase_width = stableDiffusionData.firstphase_width =
stableDiffusionData.firstphase_height = v / 2; stableDiffusionData.firstphase_height = v / 2;
informCursorSizeSlider();
} }
); );
makeSlider( makeSlider(
@ -522,6 +524,20 @@ function changeHiResFix() {
); );
localStorage.setItem("enable_hr", stableDiffusionData.enable_hr); localStorage.setItem("enable_hr", stableDiffusionData.enable_hr);
} }
function changeSyncCursorSize() {
stableDiffusionData.sync_cursor_size = Boolean(
document.getElementById("cbxSyncCursorSize").checked
); //is this horribly hacky, putting it in SD data instead of making a gross global var?
localStorage.setItem(
"sync_cursor_size",
stableDiffusionData.sync_cursor_size
);
if (stableDiffusionData.sync_cursor_size) {
resSlider.value = stableDiffusionData.width;
}
}
function changeSmoothRendering() { function changeSmoothRendering() {
const layers = document.getElementById("layer-render"); const layers = document.getElementById("layer-render");
if (document.getElementById("cbxSmooth").checked) { if (document.getElementById("cbxSmooth").checked) {
@ -893,17 +909,27 @@ function loadSettings() {
? false ? false
: localStorage.getItem("enable_hr") : localStorage.getItem("enable_hr")
); );
var _sync_cursor_size = Boolean(
localStorage.getItem("sync_cursor_size") == (null || "false")
? false
: localStorage.getItem("sync_cursor_size")
);
// set the values into the UI // set the values into the UI
document.getElementById("maskBlur").value = Number(_mask_blur); document.getElementById("maskBlur").value = Number(_mask_blur);
document.getElementById("seed").value = Number(_seed); document.getElementById("seed").value = Number(_seed);
document.getElementById("cbxHRFix").checked = Boolean(_enable_hr); document.getElementById("cbxHRFix").checked = Boolean(_enable_hr);
document.getElementById("cbxSyncCursorSize").checked =
Boolean(_sync_cursor_size);
} }
imageCollection.element.addEventListener( imageCollection.element.addEventListener(
"wheel", "wheel",
(evn) => { (evn) => {
evn.preventDefault(); evn.preventDefault();
if (!evn.ctrlKey) {
_resolution_onwheel(evn);
}
}, },
{passive: false} {passive: false}
); );
@ -921,3 +947,22 @@ function resetToDefaults() {
localStorage.clear(); localStorage.clear();
} }
} }
function informCursorSizeSlider() {
if (stableDiffusionData.sync_cursor_size) {
if (toolbar._current_tool) {
if (!toolbar._current_tool.state.ignorePrevious) {
toolbar._current_tool.state.setCursorSize(stableDiffusionData.width);
}
toolbar._current_tool.state.ignorePrevious = false;
}
}
}
const _resolution_onwheel = (evn) => {
if (stableDiffusionData.sync_cursor_size) {
toolbar._current_tool.state.ignorePrevious = true; //so hacky
resSlider.value =
stableDiffusionData.width - (128 * evn.deltaY) / Math.abs(evn.deltaY);
}
};

View file

@ -935,6 +935,11 @@ const dreamTool = () =>
// Display Mask // Display Mask
setMask(state.invertMask ? "hold" : "clear"); setMask(state.invertMask ? "hold" : "clear");
// update cursor size if matching is enabled
if (stableDiffusionData.sync_cursor_size) {
state.setCursorSize(stableDiffusionData.width);
}
}, },
(state, opt) => { (state, opt) => {
// Clear Listeners // Clear Listeners
@ -955,7 +960,6 @@ const dreamTool = () =>
}; };
state.cursorSize = 512; state.cursorSize = 512;
state.snapToGrid = true; state.snapToGrid = true;
state.invertMask = false; state.invertMask = false;
state.overMaskPx = 0; state.overMaskPx = 0;
@ -1003,10 +1007,16 @@ const dreamTool = () =>
"cursorSize", "cursorSize",
"Cursor Size", "Cursor Size",
{ {
min: 0, min: 128,
max: 2048, max: 2048,
step: 128, step: 128,
textStep: 2, textStep: 2,
cb: () => {
if (stableDiffusionData.sync_cursor_size) {
state.ignorePrevious = true;
resSlider.value = state.cursorSize;
}
},
} }
); );
@ -1074,6 +1084,11 @@ const img2imgTool = () =>
// Display Mask // Display Mask
setMask(state.invertMask ? "hold" : "clear"); setMask(state.invertMask ? "hold" : "clear");
// update cursor size if matching is enabled
if (stableDiffusionData.sync_cursor_size) {
state.setCursorSize(stableDiffusionData.width);
}
}, },
(state, opt) => { (state, opt) => {
// Clear Listeners // Clear Listeners
@ -1244,10 +1259,16 @@ const img2imgTool = () =>
"cursorSize", "cursorSize",
"Cursor Size", "Cursor Size",
{ {
min: 0, min: 128,
max: 2048, max: 2048,
step: 128, step: 128,
textStep: 2, textStep: 2,
cb: () => {
if (stableDiffusionData.sync_cursor_size) {
state.ignorePrevious = true;
resSlider.value = state.cursorSize;
}
},
} }
); );