right-click erase, ensure webUI is running on startup

This commit is contained in:
tim h 2022-11-19 11:17:47 -06:00
parent ce26af81c4
commit dc472d49c3
2 changed files with 268 additions and 244 deletions

View file

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>openOutpaint 0.0.5</title> <title>openOutpaint 0.0.5.1</title>
<link href="css/index.css" rel="stylesheet" /> <link href="css/index.css" rel="stylesheet" />
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">
</head> </head>
@ -132,7 +132,7 @@
<input type="file" id="preloadImage" onchange="preloadImage()" accept="image/*" /><br /> <input type="file" id="preloadImage" onchange="preloadImage()" accept="image/*" /><br />
<button onclick="downloadCanvas()">dl canvas</button> <button onclick="downloadCanvas()">dl canvas</button>
</div> </div>
<div id="canvasHolder" class="canvasHolder"> <div id="canvasHolder" class="canvasHolder" oncontextmenu="return false;">
<canvas id="backgroundCanvas" class="mainCanvases backgroundCanvas" width="2560" height="1440" <canvas id="backgroundCanvas" class="mainCanvases backgroundCanvas" width="2560" height="1440"
style="z-index: 0;"> style="z-index: 0;">
<!-- gray grid bg canvas --> <!-- gray grid bg canvas -->

View file

@ -112,6 +112,7 @@ const bgCanvas = document.getElementById("backgroundCanvas"); // gray bg grid
const bgCtx = bgCanvas.getContext("2d"); const bgCtx = bgCanvas.getContext("2d");
function startup() { function startup() {
checkIfWebuiIsRunning();
loadSettings(); loadSettings();
drawBackground(); drawBackground();
changeScaleFactor(); changeScaleFactor();
@ -396,6 +397,7 @@ function mouseMove(evt) {
function mouseDown(evt) { function mouseDown(evt) {
const rect = ovCanvas.getBoundingClientRect() const rect = ovCanvas.getBoundingClientRect()
if (evt.button == 0) { // left click
if (placingArbitraryImage) { if (placingArbitraryImage) {
var nextBox = {}; var nextBox = {};
nextBox.x = evt.clientX - ((basePixelCount * scaleFactor) / 2) - rect.left; //origin is middle of the frame nextBox.x = evt.clientX - ((basePixelCount * scaleFactor) / 2) - rect.left; //origin is middle of the frame
@ -419,9 +421,19 @@ function mouseDown(evt) {
nextBox.h = basePixelCount * scaleFactor; nextBox.h = basePixelCount * scaleFactor;
drawTargets.push(nextBox); drawTargets.push(nextBox);
} }
} else if (evt.button == 2 && !paintMode) { // right click, also gotta make sure mask blob isn't being used as it's visually inconsistent with behavior of erased region
// erase the canvas underneath the cursor,
ctx = imgCanvas.getContext('2d');
if (snapToGrid) {
ctx.clearRect(canvasX + snap(canvasX) - ((basePixelCount * scaleFactor) / 2), canvasY + snap(canvasY) - ((basePixelCount * scaleFactor) / 2), basePixelCount * scaleFactor, basePixelCount * scaleFactor);
} else {
ctx.clearRect(canvasX - ((basePixelCount * scaleFactor) / 2), canvasY - ((basePixelCount * scaleFactor) / 2), basePixelCount * scaleFactor, basePixelCount * scaleFactor);
}
}
} }
function mouseUp(evt) { function mouseUp(evt) {
if (evt.button == 0) { // left click
if (placingArbitraryImage) { if (placingArbitraryImage) {
//TODO DO SOMETHING //TODO DO SOMETHING
// jeez i REALLY need to refactor tons of this to not be duplicated all over, that's definitely my next chore after figuring out that razza frazza overmask fade // jeez i REALLY need to refactor tons of this to not be duplicated all over, that's definitely my next chore after figuring out that razza frazza overmask fade
@ -681,6 +693,7 @@ function mouseUp(evt) {
dream(drawIt.x, drawIt.y, stableDiffusionData); dream(drawIt.x, drawIt.y, stableDiffusionData);
} }
} }
}
} }
function changeScaleFactor() { function changeScaleFactor() {
@ -857,6 +870,17 @@ function cropCanvas(sourceCanvas) {
return cutCanvas; return cutCanvas;
} }
function checkIfWebuiIsRunning() {
var url = document.getElementById("host").value + "/startup-events"
fetch(url).then(response => {
if (response.status == 200) {
console.log("webui is running");
}
}).catch(error => {
alert("WebUI doesnt seem to be running, please start it and try again\nCheck console for additional info\n" + error);
});
}
function loadSettings() { function loadSettings() {
// set default values if not set DEFAULTS // set default values if not set DEFAULTS
var _sampler = localStorage.getItem("sampler") == null ? "DDIM" : localStorage.getItem("sampler"); var _sampler = localStorage.getItem("sampler") == null ? "DDIM" : localStorage.getItem("sampler");