Canvas: Adjust brush size by area

This commit is contained in:
w-e-w 2024-10-31 20:03:27 +09:00
parent 957888a100
commit 4e808fbef4
2 changed files with 19 additions and 8 deletions

View File

@ -470,11 +470,20 @@ onUiLoaded(async() => {
if (!withoutValue) { if (!withoutValue) {
const maxValue = const maxValue =
parseFloat(input.getAttribute("max")) || 100; parseFloat(input.getAttribute("max")) || 100;
if (opts.canvas_hotkey_brush_scale === "Radius") {
const changeAmount = maxValue * (percentage / 100); const changeAmount = maxValue * (percentage / 100);
const newValue = const newValue =
parseFloat(input.value) + parseFloat(input.value) +
(deltaY > 0 ? -changeAmount : changeAmount); (deltaY > 0 ? -changeAmount : changeAmount);
input.value = Math.min(Math.max(newValue, 0), maxValue); input.value = Math.min(Math.max(newValue, 0), maxValue);
} else {
const brush_factor = deltaY > 0 ? 1 - opts.canvas_hotkey_brush_factor : 1 + opts.canvas_hotkey_brush_factor
const currentRadius = parseFloat(input.value);
const currentArea = currentRadius ** 2;
const newArea = currentArea * brush_factor;
const newValue = Math.sqrt(newArea);
input.value = Math.min(Math.max(newValue, 0), maxValue);
}
input.dispatchEvent(new Event("change")); input.dispatchEvent(new Event("change"));
} }
} }

View File

@ -14,4 +14,6 @@ shared.options_templates.update(shared.options_section(('canvas_hotkey', "Canvas
"canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"), "canvas_auto_expand": shared.OptionInfo(True, "Automatically expands an image that does not fit completely in the canvas area, similar to manually pressing the S and R buttons"),
"canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"), "canvas_blur_prompt": shared.OptionInfo(False, "Take the focus off the prompt when working with a canvas"),
"canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom", "Adjust brush size", "Hotkey enlarge brush", "Hotkey shrink brush", "Moving canvas", "Fullscreen", "Reset Zoom", "Overlap"]}), "canvas_disabled_functions": shared.OptionInfo(["Overlap"], "Disable function that you don't use", gr.CheckboxGroup, {"choices": ["Zoom", "Adjust brush size", "Hotkey enlarge brush", "Hotkey shrink brush", "Moving canvas", "Fullscreen", "Reset Zoom", "Overlap"]}),
"canvas_hotkey_brush_scale": shared.OptionInfo("Radius", "Brush scale", gr.Radio, {"choices": ["Radius", "Area"]}),
"canvas_hotkey_brush_factor": shared.OptionInfo(0.1, "Brush factor", gr.Slider, {"minimum": 0, "maximum": 2, "step": 0.01})
})) }))