Merge pull request #75 from zero01101/testing

Some general fixes
This commit is contained in:
Victor Seiji Hariki 2022-12-07 23:36:28 -03:00 committed by GitHub
commit 0b5b0188e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 142 additions and 48 deletions

View file

@ -264,6 +264,7 @@ async function testHostConnection() {
setConnectionStatus("online"); setConnectionStatus("online");
// Load data as soon as connection is first stablished // Load data as soon as connection is first stablished
if (firstTimeOnline) { if (firstTimeOnline) {
getConfig();
getStyles(); getStyles();
getSamplers(); getSamplers();
getUpscalers(); getUpscalers();
@ -688,6 +689,65 @@ function changeModel() {
}); });
} }
async function getConfig() {
var url = document.getElementById("host").value + "/sdapi/v1/options";
let message =
"The following options for the AUTOMATIC1111's webui are not recommended to use with this software:";
try {
const response = await fetch(url);
const data = await response.json();
let wrong = false;
// Check if img2img color correction is disabled and inpainting mask weight is set to one
// TODO: API Seems bugged for retrieving inpainting mask weight - returning 0 for all values different than 1.0
if (data.img2img_color_correction) {
message += "\n - Image to Image Color Correction: false recommended";
wrong = true;
}
if (data.inpainting_mask_weight < 1.0) {
message += `\n - Inpainting Conditioning Mask Strength: 1.0 recommended`;
wrong = true;
}
message += "\n\nShould these values be changed to the recommended ones?";
if (!wrong) {
console.info("[index] WebUI Settings set as recommended.");
return;
}
console.info(
"[index] WebUI Settings not set as recommended. Prompting for changing settings automatically."
);
if (!confirm(message)) return;
try {
await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
img2img_color_correction: false,
inpainting_mask_weight: 1.0,
}),
});
} catch (e) {
console.warn("[index] Failed to fetch WebUI Configuration");
console.warn(e);
}
} catch (e) {
console.warn("[index] Failed to fetch WebUI Configuration");
console.warn(e);
}
}
async function getStyles() { async function getStyles() {
/** @type {HTMLSelectElement} */ /** @type {HTMLSelectElement} */
var styleSelect = document.getElementById("styleSelect"); var styleSelect = document.getElementById("styleSelect");

View file

@ -59,8 +59,14 @@ mouse.registerContext(
"world", "world",
(evn, ctx) => { (evn, ctx) => {
// Fix because in chrome layerX and layerY simply doesnt work // Fix because in chrome layerX and layerY simply doesnt work
/** @type {HTMLDivElement} */ ctx.coords.prev.x = ctx.coords.pos.x;
const target = evn.target; ctx.coords.prev.y = ctx.coords.pos.y;
if (evn.layerX !== evn.clientX || evn.layerY !== evn.clientY) {
ctx.coords.pos.x = evn.layerX;
ctx.coords.pos.y = evn.layerY;
return;
}
// Get element bounding rect // Get element bounding rect
const bb = imageCollection.element.getBoundingClientRect(); const bb = imageCollection.element.getBoundingClientRect();
@ -78,10 +84,8 @@ mouse.registerContext(
const layerY = ((y - bb.top) / bb.height) * h; const layerY = ((y - bb.top) / bb.height) * h;
// //
ctx.coords.prev.x = ctx.coords.pos.x; ctx.coords.pos.x = Math.round(layerX);
ctx.coords.prev.y = ctx.coords.pos.y; ctx.coords.pos.y = Math.round(layerY);
ctx.coords.pos.x = layerX;
ctx.coords.pos.y = layerY;
}, },
{target: imageCollection.inputElement} {target: imageCollection.inputElement}
); );

View file

@ -1,6 +1,28 @@
document.querySelectorAll(".floating-window").forEach((w) => { document.querySelectorAll(".floating-window").forEach(
/**
* Runs for each floating window
*
* @param {HTMLDivElement} w
*/
(w) => {
makeDraggable(w); makeDraggable(w);
}); w.addEventListener(
"wheel",
(e) => {
e.stopPropagation();
},
{passive: false}
);
w.addEventListener(
"click",
(e) => {
e.stopPropagation();
},
{passive: false}
);
}
);
var coll = document.getElementsByClassName("collapsible"); var coll = document.getElementsByClassName("collapsible");
for (var i = 0; i < coll.length; i++) { for (var i = 0; i < coll.length; i++) {

View file

@ -168,14 +168,17 @@ function createSlider(name, wrapper, options = {}) {
mouse.listen.window.btn.left.ondrag.on((evn) => { mouse.listen.window.btn.left.ondrag.on((evn) => {
if (evn.initialTarget === overEl) { if (evn.initialTarget === overEl) {
phantomRange.value = Math.max( const newv = Math.max(
options.min, options.min,
Math.min( Math.min(
options.max, options.max,
(evn.evn.layerX / wrapper.offsetWidth) * (options.max - options.min) + ((evn.evn.clientX - evn.initialTarget.getBoundingClientRect().left) /
wrapper.offsetWidth) *
(options.max - options.min) +
options.min options.min
) )
); );
phantomRange.value = newv;
setValue(parseFloat(phantomRange.value)); setValue(parseFloat(phantomRange.value));
} }
}); });

View file

@ -180,14 +180,15 @@ function getBoundingBox(cx, cy, w, h, gridSnap = null, offset = 0) {
offs.x = snap(cx, offset, gridSnap); offs.x = snap(cx, offset, gridSnap);
offs.y = snap(cy, offset, gridSnap); offs.y = snap(cy, offset, gridSnap);
} }
box.x = offs.x + cx;
box.y = offs.y + cy; box.x = Math.round(offs.x + cx);
box.y = Math.round(offs.y + cy);
return { return {
x: Math.floor(box.x - w / 2), x: Math.floor(box.x - w / 2),
y: Math.floor(box.y - h / 2), y: Math.floor(box.y - h / 2),
w, w: Math.round(w),
h, h: Math.round(h),
}; };
} }

View file

@ -37,7 +37,7 @@ const _color_brush_erase_callback = (evn, state, ctx) => {
const colorBrushTool = () => const colorBrushTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/brush.svg", "/res/icons/brush.svg",
"Color Brush", "Color Brush",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately

View file

@ -806,9 +806,13 @@ const _reticle_draw = (evn, state, tool, style = {}) => {
const _dream_onwheel = (evn, state) => { const _dream_onwheel = (evn, state) => {
if (!evn.evn.ctrlKey) { if (!evn.evn.ctrlKey) {
const v = // Seems mouse wheel scroll is very different between different browsers.
state.cursorSize - // Will use scroll as just an event to go to the next cursor snap position instead.
Math.floor(state.config.cursorSizeScrollSpeed * evn.delta); //
// TODO: Someone that has a smooth scrolling mouse should verify if this works with them.
const v = state.cursorSize - 128 * (evn.delta / Math.abs(evn.delta));
state.cursorSize = state.setCursorSize(v + snap(v, 0, 128)); state.cursorSize = state.setCursorSize(v + snap(v, 0, 128));
state.mousemovecb(evn); state.mousemovecb(evn);
} }
@ -819,7 +823,7 @@ const _dream_onwheel = (evn, state) => {
*/ */
const dreamTool = () => const dreamTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/image-plus.svg", "/res/icons/image-plus.svg",
"Dream", "Dream",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately
@ -940,7 +944,7 @@ const dreamTool = () =>
{ {
min: 0, min: 0,
max: 64, max: 64,
step: 5, step: 4,
textStep: 1, textStep: 1,
} }
).slider; ).slider;
@ -959,7 +963,7 @@ const dreamTool = () =>
const img2imgTool = () => const img2imgTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/image.svg", "/res/icons/image.svg",
"Img2Img", "Img2Img",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately

View file

@ -1,6 +1,6 @@
const interrogateTool = () => const interrogateTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/microscope.svg", "/res/icons/microscope.svg",
"Interrogate", "Interrogate",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately
@ -48,8 +48,16 @@ const interrogateTool = () =>
reticleStyle: "#AFAF", reticleStyle: "#AFAF",
}); });
}; };
state.redraw = () => {
state.mousemovecb({
x: mouse.coords.world.pos.x,
y: mouse.coords.world.pos.y,
});
};
state.wheelcb = (evn) => { state.wheelcb = (evn) => {
_interrogate_onwheel(evn, state); _dream_onwheel(evn, state);
}; };
state.interrogatecb = (evn) => { state.interrogatecb = (evn) => {
@ -91,20 +99,6 @@ const interrogateTool = () =>
} }
); );
/**
* Generic wheel handler
*/
const _interrogate_onwheel = (evn, state) => {
if (!evn.evn.ctrlKey) {
const v =
state.cursorSize -
Math.floor(state.config.cursorSizeScrollSpeed * evn.delta);
state.cursorSize = state.setCursorSize(v + snap(v, 0, 128));
state.mousemovecb(evn);
}
};
const interrogate_callback = async (evn, state) => { const interrogate_callback = async (evn, state) => {
const bb = getBoundingBox( const bb = getBoundingBox(
evn.x, evn.x,

View file

@ -61,7 +61,7 @@ const _mask_brush_erase_callback = (evn, state, opacity = 100) => {
const maskBrushTool = () => const maskBrushTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/paintbrush.svg", "/res/icons/paintbrush.svg",
"Mask Brush", "Mask Brush",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately

View file

@ -1,6 +1,6 @@
const selectTransformTool = () => const selectTransformTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/box-select.svg", "/res/icons/box-select.svg",
"Select Image", "Select Image",
(state, opt) => { (state, opt) => {
// Draw new cursor immediately // Draw new cursor immediately
@ -101,6 +101,10 @@ const selectTransformTool = () =>
// Selection bounding box object. Has some witchery to deal with handles. // Selection bounding box object. Has some witchery to deal with handles.
const selectionBB = (x1, y1, x2, y2) => { const selectionBB = (x1, y1, x2, y2) => {
x1 = Math.round(x1);
y1 = Math.round(y1);
x2 = Math.round(x2);
y2 = Math.round(y2);
return { return {
original: { original: {
x: Math.min(x1, x2), x: Math.min(x1, x2),
@ -213,8 +217,8 @@ const selectTransformTool = () =>
// Update position // Update position
if (state.moving) { if (state.moving) {
state.selected.x = x - state.moving.offset.x; state.selected.x = Math.round(x - state.moving.offset.x);
state.selected.y = y - state.moving.offset.y; state.selected.y = Math.round(y - state.moving.offset.y);
state.selected.updateOriginal(); state.selected.updateOriginal();
} }
@ -350,11 +354,13 @@ const selectTransformTool = () =>
"Image Transform Erase", "Image Transform Erase",
state.original state.original
); );
commands.runCommand( commands.runCommand("drawImage", "Image Transform Draw", {
"drawImage", image: state.selected.image,
"Image Transform Draw", x: Math.round(state.selected.x),
state.selected y: Math.round(state.selected.y),
); w: Math.round(state.selected.w),
h: Math.round(state.selected.h),
});
state.original = null; state.original = null;
state.selected = null; state.selected = null;

View file

@ -1,6 +1,6 @@
const stampTool = () => const stampTool = () =>
toolbar.registerTool( toolbar.registerTool(
"res/icons/file-up.svg", "/res/icons/file-up.svg",
"Stamp Image", "Stamp Image",
(state, opt) => { (state, opt) => {
state.loaded = true; state.loaded = true;