Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
Victor Seiji Hariki 2023-02-19 10:14:38 -03:00
parent 2598cb9c41
commit fe0095421a
7 changed files with 71 additions and 8 deletions

View file

@ -151,18 +151,24 @@ const toolbar = {
* Premade inputs for populating the context menus * Premade inputs for populating the context menus
*/ */
const _toolbar_input = { const _toolbar_input = {
checkbox: (state, dataKey, text, classes, cb = null) => { checkbox: (state, lsKey, dataKey, text, classes, cb = null) => {
if (state[dataKey] === undefined) state[dataKey] = false; if (state[dataKey] === undefined) state[dataKey] = false;
const savedValueStr = lsKey && localStorage.getItem(lsKey);
const savedValue = savedValueStr && JSON.parse(savedValueStr);
const checkbox = document.createElement("input"); const checkbox = document.createElement("input");
checkbox.type = "checkbox"; checkbox.type = "checkbox";
checkbox.classList.add("oo-checkbox", "ui", "inline-icon"); checkbox.classList.add("oo-checkbox", "ui", "inline-icon");
if (savedValue !== null) state[dataKey] = checkbox.checked = savedValue;
if (typeof classes === "string") classes = [classes]; if (typeof classes === "string") classes = [classes];
if (classes) checkbox.classList.add(...classes); if (classes) checkbox.classList.add(...classes);
checkbox.checked = state[dataKey]; checkbox.checked = state[dataKey];
checkbox.onchange = () => { checkbox.onchange = () => {
if (lsKey) localStorage.setItem(lsKey, JSON.stringify(checkbox.checked));
state[dataKey] = checkbox.checked; state[dataKey] = checkbox.checked;
cb && cb(); cb && cb();
}; };
@ -185,15 +191,19 @@ const _toolbar_input = {
}; };
}, },
slider: (state, dataKey, text, options = {}) => { slider: (state, lsKey, dataKey, text, options = {}) => {
defaultOpt(options, {min: 0, max: 1, step: 0.1, textStep: null, cb: null}); defaultOpt(options, {min: 0, max: 1, step: 0.1, textStep: null, cb: null});
const slider = document.createElement("div"); const slider = document.createElement("div");
const savedValueStr = lsKey && localStorage.getItem(lsKey);
const savedValue = savedValueStr && JSON.parse(savedValueStr);
const value = createSlider(text, slider, { const value = createSlider(text, slider, {
min: options.min, min: options.min,
max: options.max, max: options.max,
step: options.step, step: options.step,
valuecb: (v) => { valuecb: (v) => {
if (lsKey) localStorage.setItem(lsKey, JSON.stringify(v));
state[dataKey] = v; state[dataKey] = v;
options.cb && options.cb(v); options.cb && options.cb(v);
}, },
@ -201,6 +211,8 @@ const _toolbar_input = {
textStep: options.textStep, textStep: options.textStep,
}); });
if (savedValue !== null) value.value = savedValue;
return { return {
slider, slider,
rawSlider: value, rawSlider: value,
@ -213,12 +225,16 @@ const _toolbar_input = {
selectlist: ( selectlist: (
state, state,
lsKey,
dataKey, dataKey,
text, text,
options = {value, text}, options = {value, text},
defaultOptionValue, defaultOptionValue,
cb = null cb = null
) => { ) => {
const savedValueStr = lsKey && localStorage.getItem(lsKey);
const savedValue = savedValueStr && JSON.parse(savedValueStr);
const selectlist = document.createElement("select"); const selectlist = document.createElement("select");
selectlist.classList.add("bareselector"); selectlist.classList.add("bareselector");
Object.entries(options).forEach((opt) => { Object.entries(options).forEach((opt) => {
@ -228,7 +244,13 @@ const _toolbar_input = {
selectlist.options.add(option); selectlist.options.add(option);
}); });
selectlist.selectedIndex = defaultOptionValue; selectlist.selectedIndex = defaultOptionValue;
if (savedValue !== null)
state[dataKey] = selectlist.selectedIndex = savedValue;
selectlist.onchange = () => { selectlist.onchange = () => {
if (lsKey)
localStorage.setItem(lsKey, JSON.stringify(selectlist.selectedIndex));
state[dataKey] = selectlist.selectedIndex; state[dataKey] = selectlist.selectedIndex;
cb && cb(); cb && cb();
}; };

View file

@ -373,6 +373,7 @@ const colorBrushTool = () =>
const array = document.createElement("div"); const array = document.createElement("div");
const affectMaskCheckbox = _toolbar_input.checkbox( const affectMaskCheckbox = _toolbar_input.checkbox(
state, state,
"openoutpaint/colorbrush-affectmask",
"affectMask", "affectMask",
"Affect Mask", "Affect Mask",
"icon-venetian-mask" "icon-venetian-mask"
@ -384,6 +385,7 @@ const colorBrushTool = () =>
// Brush size slider // Brush size slider
const brushSizeSlider = _toolbar_input.slider( const brushSizeSlider = _toolbar_input.slider(
state, state,
"openoutpaint/colorbrush-brushsize",
"brushSize", "brushSize",
"Brush Size", "Brush Size",
{ {
@ -399,6 +401,7 @@ const colorBrushTool = () =>
// Brush opacity slider // Brush opacity slider
const brushOpacitySlider = _toolbar_input.slider( const brushOpacitySlider = _toolbar_input.slider(
state, state,
"openoutpaint/colorbrush-brushopacity",
"brushOpacity", "brushOpacity",
"Brush Opacity", "Brush Opacity",
{ {
@ -413,6 +416,7 @@ const colorBrushTool = () =>
// Brush blur slider // Brush blur slider
const brushBlurSlider = _toolbar_input.slider( const brushBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/colorbrush-brushblur",
"brushBlur", "brushBlur",
"Brush Blur", "Brush Blur",
{ {

View file

@ -1600,6 +1600,7 @@ const dreamTool = () =>
// Cursor Size Slider // Cursor Size Slider
const cursorSizeSlider = _toolbar_input.slider( const cursorSizeSlider = _toolbar_input.slider(
state, state,
"openoutpaint/dream-cursorsize",
"cursorSize", "cursorSize",
"Cursor Size", "Cursor Size",
{ {
@ -1632,6 +1633,7 @@ const dreamTool = () =>
// Snap to Grid Checkbox // Snap to Grid Checkbox
state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox( state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/dream-snaptogrid",
"snapToGrid", "snapToGrid",
"Snap To Grid", "Snap To Grid",
"icon-grid" "icon-grid"
@ -1640,6 +1642,7 @@ const dreamTool = () =>
// Invert Mask Checkbox // Invert Mask Checkbox
state.ctxmenu.invertMaskLabel = _toolbar_input.checkbox( state.ctxmenu.invertMaskLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/dream-invertmask",
"invertMask", "invertMask",
"Invert Mask", "Invert Mask",
["icon-venetian-mask", "invert-mask-checkbox"], ["icon-venetian-mask", "invert-mask-checkbox"],
@ -1651,6 +1654,7 @@ const dreamTool = () =>
// Keep Masked Content Checkbox // Keep Masked Content Checkbox
state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox( state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/dream-keepunmasked",
"keepUnmasked", "keepUnmasked",
"Keep Unmasked", "Keep Unmasked",
"icon-pin", "icon-pin",
@ -1674,6 +1678,7 @@ const dreamTool = () =>
// Keep Masked Content Blur Slider // Keep Masked Content Blur Slider
state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider( state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/dream-keepunmaskedblur",
"keepUnmaskedBlur", "keepUnmaskedBlur",
"Keep Unmasked Blur", "Keep Unmasked Blur",
{ {
@ -1693,6 +1698,7 @@ const dreamTool = () =>
// outpaint fill type select list // outpaint fill type select list
state.ctxmenu.outpaintTypeSelect = _toolbar_input.selectlist( state.ctxmenu.outpaintTypeSelect = _toolbar_input.selectlist(
state, state,
"openoutpaint/dream-outpainttype",
"outpainting_fill", "outpainting_fill",
"Outpaint Type", "Outpaint Type",
{ {
@ -1710,6 +1716,7 @@ const dreamTool = () =>
// Preserve Brushed Masks Checkbox // Preserve Brushed Masks Checkbox
state.ctxmenu.preserveMasksLabel = _toolbar_input.checkbox( state.ctxmenu.preserveMasksLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/dream-preservemasks",
"preserveMasks", "preserveMasks",
"Preserve Brushed Masks", "Preserve Brushed Masks",
"icon-paintbrush" "icon-paintbrush"
@ -1718,6 +1725,7 @@ const dreamTool = () =>
// Overmasking Slider // Overmasking Slider
state.ctxmenu.overMaskPxLabel = _toolbar_input.slider( state.ctxmenu.overMaskPxLabel = _toolbar_input.slider(
state, state,
"openoutpaint/dream-overmaskpx",
"overMaskPx", "overMaskPx",
"Overmask px", "Overmask px",
{ {
@ -1731,6 +1739,7 @@ const dreamTool = () =>
// Eager generation Slider // Eager generation Slider
state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider( state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider(
state, state,
"openoutpaint/dream-eagergeneratecount",
"eagerGenerateCount", "eagerGenerateCount",
"Generate-ahead count", "Generate-ahead count",
{ {
@ -2148,6 +2157,7 @@ const img2imgTool = () =>
// Cursor Size Slider // Cursor Size Slider
const cursorSizeSlider = _toolbar_input.slider( const cursorSizeSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-cursorsize",
"cursorSize", "cursorSize",
"Cursor Size", "Cursor Size",
{ {
@ -2177,6 +2187,7 @@ const img2imgTool = () =>
// Snap To Grid Checkbox // Snap To Grid Checkbox
state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox( state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-snaptogrid",
"snapToGrid", "snapToGrid",
"Snap To Grid", "Snap To Grid",
"icon-grid" "icon-grid"
@ -2185,6 +2196,7 @@ const img2imgTool = () =>
// Invert Mask Checkbox // Invert Mask Checkbox
state.ctxmenu.invertMaskLabel = _toolbar_input.checkbox( state.ctxmenu.invertMaskLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-invertmask",
"invertMask", "invertMask",
"Invert Mask", "Invert Mask",
["icon-venetian-mask", "invert-mask-checkbox"], ["icon-venetian-mask", "invert-mask-checkbox"],
@ -2196,6 +2208,7 @@ const img2imgTool = () =>
// Keep Masked Content Checkbox // Keep Masked Content Checkbox
state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox( state.ctxmenu.keepUnmaskedLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-keepunmasked",
"keepUnmasked", "keepUnmasked",
"Keep Unmasked", "Keep Unmasked",
"icon-pin", "icon-pin",
@ -2219,6 +2232,7 @@ const img2imgTool = () =>
// Keep Masked Content Blur Slider // Keep Masked Content Blur Slider
state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider( state.ctxmenu.keepUnmaskedBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-unmaskedblur",
"keepUnmaskedBlur", "keepUnmaskedBlur",
"Keep Unmasked Blur", "Keep Unmasked Blur",
{ {
@ -2238,6 +2252,7 @@ const img2imgTool = () =>
// Preserve Brushed Masks Checkbox // Preserve Brushed Masks Checkbox
state.ctxmenu.preserveMasksLabel = _toolbar_input.checkbox( state.ctxmenu.preserveMasksLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-preservemasks",
"preserveMasks", "preserveMasks",
"Preserve Brushed Masks", "Preserve Brushed Masks",
"icon-paintbrush" "icon-paintbrush"
@ -2246,6 +2261,7 @@ const img2imgTool = () =>
// Inpaint Full Resolution Checkbox // Inpaint Full Resolution Checkbox
state.ctxmenu.fullResolutionLabel = _toolbar_input.checkbox( state.ctxmenu.fullResolutionLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-fullresolution",
"fullResolution", "fullResolution",
"Inpaint Full Resolution", "Inpaint Full Resolution",
"icon-expand" "icon-expand"
@ -2254,6 +2270,7 @@ const img2imgTool = () =>
// Denoising Strength Slider // Denoising Strength Slider
state.ctxmenu.denoisingStrengthSlider = _toolbar_input.slider( state.ctxmenu.denoisingStrengthSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-denoisingstrength",
"denoisingStrength", "denoisingStrength",
"Denoising Strength", "Denoising Strength",
{ {
@ -2267,6 +2284,7 @@ const img2imgTool = () =>
// Border Mask Gradient Checkbox // Border Mask Gradient Checkbox
state.ctxmenu.borderMaskGradientCheckbox = _toolbar_input.checkbox( state.ctxmenu.borderMaskGradientCheckbox = _toolbar_input.checkbox(
state, state,
"openoutpaint/img2img-gradient",
"gradient", "gradient",
"Border Mask Gradient", "Border Mask Gradient",
"icon-box-select" "icon-box-select"
@ -2275,6 +2293,7 @@ const img2imgTool = () =>
// Border Mask Size Slider // Border Mask Size Slider
state.ctxmenu.borderMaskSlider = _toolbar_input.slider( state.ctxmenu.borderMaskSlider = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-keepbordersize",
"keepBorderSize", "keepBorderSize",
"Keep Border Size", "Keep Border Size",
{ {
@ -2288,6 +2307,7 @@ const img2imgTool = () =>
// inpaint fill type select list // inpaint fill type select list
state.ctxmenu.inpaintTypeSelect = _toolbar_input.selectlist( state.ctxmenu.inpaintTypeSelect = _toolbar_input.selectlist(
state, state,
"openoutpaint/img2img-inpaintingtype",
"inpainting_fill", "inpainting_fill",
"Inpaint Type", "Inpaint Type",
{ {
@ -2305,6 +2325,7 @@ const img2imgTool = () =>
// Eager generation Slider // Eager generation Slider
state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider( state.ctxmenu.eagerGenerateCountLabel = _toolbar_input.slider(
state, state,
"openoutpaint/img2img-eagergeneratecount",
"eagerGenerateCount", "eagerGenerateCount",
"Generate-ahead count", "Generate-ahead count",
{ {

View file

@ -80,6 +80,7 @@ const interrogateTool = () =>
// Cursor Size Slider // Cursor Size Slider
const cursorSizeSlider = _toolbar_input.slider( const cursorSizeSlider = _toolbar_input.slider(
state, state,
"openoutpaint/interrogate-cursorsize",
"cursorSize", "cursorSize",
"Cursor Size", "Cursor Size",
{ {
@ -96,6 +97,7 @@ const interrogateTool = () =>
// Snap to Grid Checkbox // Snap to Grid Checkbox
state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox( state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/interrogate-snaptogrid",
"snapToGrid", "snapToGrid",
"Snap To Grid", "Snap To Grid",
"icon-grid" "icon-grid"

View file

@ -186,6 +186,7 @@ const maskBrushTool = () =>
// Brush size slider // Brush size slider
const brushSizeSlider = _toolbar_input.slider( const brushSizeSlider = _toolbar_input.slider(
state, state,
"openoutpaint/maskbrush-brushsize",
"brushSize", "brushSize",
"Brush Size", "Brush Size",
{ {
@ -206,6 +207,7 @@ const maskBrushTool = () =>
// Brush opacity slider // Brush opacity slider
const brushOpacitySlider = _toolbar_input.slider( const brushOpacitySlider = _toolbar_input.slider(
state, state,
"openoutpaint/maskbrush-brushopacity",
"brushOpacity", "brushOpacity",
"Brush Opacity", "Brush Opacity",
{ {
@ -220,6 +222,7 @@ const maskBrushTool = () =>
// Brush blur slider // Brush blur slider
const brushBlurSlider = _toolbar_input.slider( const brushBlurSlider = _toolbar_input.slider(
state, state,
"openoutpaint/maskbrush-brushblur",
"brushBlur", "brushBlur",
"Brush Blur", "Brush Blur",
{ {

View file

@ -652,6 +652,7 @@ const selectTransformTool = () =>
// Snap To Grid Checkbox // Snap To Grid Checkbox
state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox( state.ctxmenu.snapToGridLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/select-snaptogrid",
"snapToGrid", "snapToGrid",
"Snap To Grid", "Snap To Grid",
"icon-grid" "icon-grid"
@ -660,6 +661,7 @@ const selectTransformTool = () =>
// Keep Aspect Ratio // Keep Aspect Ratio
state.ctxmenu.keepAspectRatioLabel = _toolbar_input.checkbox( state.ctxmenu.keepAspectRatioLabel = _toolbar_input.checkbox(
state, state,
"openoutpaint/select-keepaspectratio",
"keepAspectRatio", "keepAspectRatio",
"Keep Aspect Ratio", "Keep Aspect Ratio",
"icon-maximize" "icon-maximize"
@ -668,6 +670,7 @@ const selectTransformTool = () =>
// Use Clipboard // Use Clipboard
const clipboardCheckbox = _toolbar_input.checkbox( const clipboardCheckbox = _toolbar_input.checkbox(
state, state,
"openoutpaint/select-useclipboard",
"useClipboard", "useClipboard",
"Use clipboard", "Use clipboard",
"icon-clipboard-list" "icon-clipboard-list"
@ -679,6 +682,7 @@ const selectTransformTool = () =>
// Selection Peek Opacity // Selection Peek Opacity
state.ctxmenu.selectionPeekOpacitySlider = _toolbar_input.slider( state.ctxmenu.selectionPeekOpacitySlider = _toolbar_input.slider(
state, state,
"openoutpaint/select-peekopacity",
"selectionPeekOpacity", "selectionPeekOpacity",
"Peek Opacity", "Peek Opacity",
{ {

View file

@ -495,6 +495,7 @@ const stampTool = () =>
array.appendChild( array.appendChild(
_toolbar_input.checkbox( _toolbar_input.checkbox(
state, state,
"openoutpaint/stamp-snaptogrid",
"snapToGrid", "snapToGrid",
"Snap To Grid", "Snap To Grid",
"icon-grid" "icon-grid"
@ -515,12 +516,18 @@ const stampTool = () =>
state.ctxmenu.buttonArray = array; state.ctxmenu.buttonArray = array;
// Scale Slider // Scale Slider
const scaleSlider = _toolbar_input.slider(state, "scale", "Scale", { const scaleSlider = _toolbar_input.slider(
state,
null,
"scale",
"Scale",
{
min: 0.01, min: 0.01,
max: 10, max: 10,
step: 0.1, step: 0.1,
textStep: 0.001, textStep: 0.001,
}); }
);
state.ctxmenu.scaleSlider = scaleSlider.slider; state.ctxmenu.scaleSlider = scaleSlider.slider;
state.setScale = scaleSlider.setValue; state.setScale = scaleSlider.setValue;