diff options
author | missionfloyd <missionfloyd@users.noreply.github.com> | 2023-05-06 04:48:27 +0000 |
---|---|---|
committer | missionfloyd <missionfloyd@users.noreply.github.com> | 2023-05-06 04:48:27 +0000 |
commit | a46c23b10f972ee235e282e7d79de2e9e7a91d68 (patch) | |
tree | d92c8ed74268ddae7b712005d05fc2a8f8af2ffd | |
parent | 5ab7f213bec2f816f9c5644becb32eb72c8ffb89 (diff) | |
download | stable-diffusion-webui-gfx803-a46c23b10f972ee235e282e7d79de2e9e7a91d68.tar.gz stable-diffusion-webui-gfx803-a46c23b10f972ee235e282e7d79de2e9e7a91d68.tar.bz2 stable-diffusion-webui-gfx803-a46c23b10f972ee235e282e7d79de2e9e7a91d68.zip |
Make gamepad navigation optional
-rw-r--r-- | javascript/imageviewerGamepad.js | 61 | ||||
-rw-r--r-- | modules/shared.py | 1 |
2 files changed, 30 insertions, 32 deletions
diff --git a/javascript/imageviewerGamepad.js b/javascript/imageviewerGamepad.js index 29bd7140..db932bca 100644 --- a/javascript/imageviewerGamepad.js +++ b/javascript/imageviewerGamepad.js @@ -1,36 +1,33 @@ - let delay = 350//ms - window.addEventListener('gamepadconnected', (e) => { - console.log("Gamepad connected!") - const gamepad = e.gamepad; - setInterval(() => { - const xValue = gamepad.axes[0].toFixed(2); - if (xValue < -0.3) { - modalPrevImage(e); - } else if (xValue > 0.3) { - modalNextImage(e); - } - - }, delay); - }); - - - /* - Primarily for vr controller type pointer devices. - I use the wheel event because there's currently no way to do it properly with web xr. - */ - - let isScrolling = false; - window.addEventListener('wheel', (e) => { - if (isScrolling) return; - isScrolling = true; - - if (e.deltaX <= -0.6) { +const delay = 250//ms +window.addEventListener('gamepadconnected', (e) => { + setInterval(() => { + if (!opts.js_modal_lightbox_gamepad) return; + const gamepad = navigator.getGamepads()[0]; + const xValue = gamepad.axes[0]; + if (xValue < -0.3) { modalPrevImage(e); - } else if (e.deltaX >= 0.6) { + } else if (xValue > 0.3) { modalNextImage(e); } + }, delay); +}); + +/* +Primarily for vr controller type pointer devices. +I use the wheel event because there's currently no way to do it properly with web xr. + */ +let isScrolling = false; +window.addEventListener('wheel', (e) => { + if (!opts.js_modal_lightbox_gamepad || isScrolling) return; + isScrolling = true; + + if (e.deltaX <= -0.6) { + modalPrevImage(e); + } else if (e.deltaX >= 0.6) { + modalNextImage(e); + } - setTimeout(() => { - isScrolling = false; - }, delay); - });
\ No newline at end of file + setTimeout(() => { + isScrolling = false; + }, delay); +}); diff --git a/modules/shared.py b/modules/shared.py index 6a2b3c2b..977ff16b 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -399,6 +399,7 @@ options_templates.update(options_section(('ui', "User interface"), { "font": OptionInfo("", "Font for image grids that have text"),
"js_modal_lightbox": OptionInfo(True, "Enable full page image viewer"),
"js_modal_lightbox_initially_zoomed": OptionInfo(True, "Show images zoomed in by default in full page image viewer"),
+ "js_modal_lightbox_gamepad": OptionInfo(True, "Navagete image viewer with gamepad"),
"show_progress_in_title": OptionInfo(True, "Show generation progress in window title."),
"samplers_in_dropdown": OptionInfo(True, "Use dropdown for sampler selection instead of radio group"),
"dimensions_and_batch_together": OptionInfo(True, "Show Width/Height and Batch sliders in same row"),
|