sync should now work a bit better; #116

Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2022-12-29 02:39:32 -03:00
parent a628c45717
commit a95906dc8a
6 changed files with 41 additions and 44 deletions

View file

@ -313,7 +313,7 @@
</div>
<!-- Basics -->
<script src="js/global.js?v=af78871" type="text/javascript"></script>
<script src="js/global.js?v=3da0b2e" type="text/javascript"></script>
<!-- Base Libs -->
<script src="js/lib/util.js?v=1ae75ef" type="text/javascript"></script>
@ -322,8 +322,8 @@
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
<script src="js/lib/commands.js?v=00464cb" type="text/javascript"></script>
<script src="js/lib/toolbar.js?v=b4eb003" type="text/javascript"></script>
<script src="js/lib/ui.js?v=ab99160" type="text/javascript"></script>
<script src="js/lib/toolbar.js?v=8a08072" type="text/javascript"></script>
<script src="js/lib/ui.js?v=8481b85" type="text/javascript"></script>
<script
src="js/initalize/layers.populate.js?v=c81f0a5"
@ -334,7 +334,7 @@
<!-- Content -->
<script src="js/prompt.js?v=7a1c68c" type="text/javascript"></script>
<script src="js/index.js?v=3feb99d" type="text/javascript"></script>
<script src="js/index.js?v=dd80c92" type="text/javascript"></script>
<script
src="js/ui/floating/history.js?v=fc92d14"
@ -348,7 +348,7 @@
src="js/ui/tool/generic.js?v=e45f721"
type="text/javascript"></script>
<script src="js/ui/tool/dream.js?v=8656e01" type="text/javascript"></script>
<script src="js/ui/tool/dream.js?v=230e42e" type="text/javascript"></script>
<script
src="js/ui/tool/maskbrush.js?v=1e8a893"
type="text/javascript"></script>

View file

@ -20,6 +20,9 @@ const global = {
// If there is a selected input
hasActiveInput: false,
// If cursor size sync is enabled
syncCursorSize: false,
// If debugging is enabled
_debug: false,
set debug(v) {

View file

@ -555,7 +555,10 @@ const resSlider = makeSlider(
stableDiffusionData.width = stableDiffusionData.height = v;
stableDiffusionData.firstphase_width =
stableDiffusionData.firstphase_height = v / 2;
informCursorSizeSlider();
toolbar.currentTool &&
toolbar.currentTool.redraw &&
toolbar.currentTool.redraw();
}
);
makeSlider(
@ -629,16 +632,10 @@ function changeRestoreFaces() {
}
function changeSyncCursorSize() {
stableDiffusionData.sync_cursor_size = Boolean(
global.syncCursorSize = Boolean(
document.getElementById("cbxSyncCursorSize").checked
); //is this horribly hacky, putting it in SD data instead of making a gross global var?
localStorage.setItem(
"openoutpaint/sync_cursor_size",
stableDiffusionData.sync_cursor_size
);
if (stableDiffusionData.sync_cursor_size) {
resSlider.value = stableDiffusionData.width;
}
localStorage.setItem("openoutpaint/sync_cursor_size", global.syncCursorSize);
}
function changeSmoothRendering() {
@ -1042,9 +1039,6 @@ imageCollection.element.addEventListener(
"wheel",
(evn) => {
evn.preventDefault();
if (!evn.ctrlKey) {
_resolution_onwheel(evn);
}
},
{passive: false}
);
@ -1062,25 +1056,3 @@ function resetToDefaults() {
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.block_res_change
) {
toolbar._current_tool.state.ignorePrevious = true; //so hacky
resSlider.value =
stableDiffusionData.width - (128 * evn.deltaY) / Math.abs(evn.deltaY);
}
};

View file

@ -181,6 +181,7 @@ const _toolbar_input = {
return {
slider,
rawSlider: value,
setValue(v) {
value.value = v;
return value.value;

View file

@ -74,7 +74,7 @@ function makeDraggable(element) {
* @param {number} option.defaultValue The default value of the slider
* @param {number} [options.textStep=step] The step size for the slider text and setvalue \
* (usually finer, and an integer divisor of step size)
* @returns {{value: number}} A reference to the value of the slider
* @returns {{value: number, onchange: Observer<{value: number}>}} A reference to the value of the slider
*/
function createSlider(name, wrapper, options = {}) {
defaultOpt(options, {
@ -124,6 +124,10 @@ function createSlider(name, wrapper, options = {}) {
underEl.appendChild(bar);
underEl.appendChild(document.createElement("div"));
// Change observer
/** @type {Observer<{value: number}>} */
const onchange = new Observer();
// Set value
const setValue = (val) => {
phantomTextRange.value = val;
@ -133,6 +137,7 @@ function createSlider(name, wrapper, options = {}) {
}%`;
textEl.value = `${name}: ${value}`;
options.valuecb && options.valuecb(value);
onchange.emit({value: val});
};
setValue(options.defaultValue);
@ -184,6 +189,7 @@ function createSlider(name, wrapper, options = {}) {
});
return {
onchange,
set value(val) {
setValue(val);
},

View file

@ -1391,14 +1391,24 @@ const dreamTool = () =>
step: 128,
textStep: 2,
cb: () => {
if (stableDiffusionData.sync_cursor_size) {
state.ignorePrevious = true;
if (
global.syncCursorSize &&
resSlider.value !== state.cursorSize
) {
resSlider.value = state.cursorSize;
}
state.redraw();
},
}
);
resSlider.onchange.on(({value}) => {
if (global.syncCursorSize && value !== state.cursorSize) {
cursorSizeSlider.rawSlider.value = value;
}
});
state.setCursorSize = cursorSizeSlider.setValue;
state.ctxmenu.cursorSizeSlider = cursorSizeSlider.slider;
@ -1876,14 +1886,19 @@ const img2imgTool = () =>
step: 128,
textStep: 2,
cb: () => {
if (stableDiffusionData.sync_cursor_size) {
state.ignorePrevious = true;
if (global.syncCursorSize) {
resSlider.value = state.cursorSize;
}
},
}
);
resSlider.onchange.on(({value}) => {
if (global.syncCursorSize && value !== state.cursorSize) {
cursorSizeSlider.rawSlider.value = value;
}
});
state.setCursorSize = cursorSizeSlider.setValue;
state.ctxmenu.cursorSizeSlider = cursorSizeSlider.slider;