From 3d298473b7126776614bf8df1424e3ac7041d6be Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Sun, 25 Dec 2022 23:29:03 -0300 Subject: [PATCH 1/3] An easy fix for mouse wheel scrolling Relates to #116 Signed-off-by: Victor Seiji Hariki --- index.html | 3 +++ js/config.js | 9 +++++++++ js/lib/input.js | 6 ++++++ js/ui/tool/dream.js | 25 ++++++++++++++++++------- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 js/config.js diff --git a/index.html b/index.html index 15c6f03..ee432aa 100644 --- a/index.html +++ b/index.html @@ -317,6 +317,9 @@ src="js/initalize/layers.populate.js" type="text/javascript"> + + + diff --git a/js/config.js b/js/config.js new file mode 100644 index 0000000..631c318 --- /dev/null +++ b/js/config.js @@ -0,0 +1,9 @@ +/** + * This is a file for static unchanging global configurations. + * + * Do NOT confuse with settings, which are modifiable by either the settings menu, or in the application itself. + */ +const config = { + // Scroll Tick Limit (How much must scroll to reach next tick) + wheelTickSize: 50, +}; diff --git a/js/lib/input.js b/js/lib/input.js index 4a469e3..bf67dfd 100644 --- a/js/lib/input.js +++ b/js/lib/input.js @@ -440,6 +440,12 @@ window.addEventListener( window.addEventListener( "wheel", (evn) => { + // For firefox, we need to read a delta before deltaMode to force a PIXEL deltaMode read. + // If we read deltaMode before a delta read, deltaMode will be LINE. + // ref: https://bugzilla.mozilla.org/show_bug.cgi?id=1392460 + let _discard = evn.deltaY; + _discard = evn.deltaMode; + mouse._contexts.forEach(({name, target, validate}) => { if (!target || (target === evn.target && (!validate || validate(evn)))) { mouse.listen[name].onwheel.emit({ diff --git a/js/ui/tool/dream.js b/js/ui/tool/dream.js index fa19b1a..b36a076 100644 --- a/js/ui/tool/dream.js +++ b/js/ui/tool/dream.js @@ -1053,18 +1053,29 @@ const dream_img2img_callback = (bb, resolution, state) => { /** * Generic wheel handler */ +let _dream_wheel_accum = 0; const _dream_onwheel = (evn, state) => { if (!evn.evn.ctrlKey) { - // Seems mouse wheel scroll is very different between different browsers. - // Will use scroll as just an event to go to the next cursor snap position instead. - // - // TODO: Someone that has a smooth scrolling mouse should verify if this works with them. + if (evn.mode !== WheelEvent.DOM_DELTA_PIXEL) { + // We don't really handle non-pixel scrolling + return; + } - const v = state.cursorSize - 128 * (evn.delta / Math.abs(evn.delta)); + // A simple but (I hope) effective fix for mouse wheel behavior + _dream_wheel_accum += evn.delta; - state.cursorSize = state.setCursorSize(v + snap(v, 0, 128)); - state.mousemovecb(evn); + if (Math.abs(_dream_wheel_accum) > config.wheelTickSize) { + // Snap to next or previous position + const v = + state.cursorSize - + 128 * (_dream_wheel_accum / Math.abs(_dream_wheel_accum)); + + state.cursorSize = state.setCursorSize(v + snap(v, 0, 128)); + state.mousemovecb(evn); + + _dream_wheel_accum = 0; // Zero accumulation + } } }; From aa3ec73b4520cfb723bd4fed3b2445587faa2e82 Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Sun, 25 Dec 2022 23:39:04 -0300 Subject: [PATCH 2/3] make config readonly Signed-off-by: Victor Seiji Hariki --- js/config.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/js/config.js b/js/config.js index 631c318..6120e78 100644 --- a/js/config.js +++ b/js/config.js @@ -3,7 +3,10 @@ * * Do NOT confuse with settings, which are modifiable by either the settings menu, or in the application itself. */ -const config = { - // Scroll Tick Limit (How much must scroll to reach next tick) - wheelTickSize: 50, -}; +const config = makeReadOnly( + { + // Scroll Tick Limit (How much must scroll to reach next tick) + wheelTickSize: 50, + }, + "config" +); From 100829298ced8dab2aa1020e80866b16856e8d5d Mon Sep 17 00:00:00 2001 From: Victor Seiji Hariki Date: Mon, 26 Dec 2022 10:35:33 -0300 Subject: [PATCH 3/3] fixes #124 System clipboard paste was not working correctly Signed-off-by: Victor Seiji Hariki --- js/ui/tool/select.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/js/ui/tool/select.js b/js/ui/tool/select.js index 5fd2cd5..c62cf14 100644 --- a/js/ui/tool/select.js +++ b/js/ui/tool/select.js @@ -592,11 +592,12 @@ const selectTransformTool = () => for (const item of items) { for (const type of item.types) { if (type.startsWith("image/")) { - item.getType(type).then((blob) => { + item.getType(type).then(async (blob) => { // Converts blob to image const url = window.URL || window.webkitURL; const image = document.createElement("img"); - image.src = url.createObjectURL(file); + image.src = url.createObjectURL(blob); + await image.decode(); tools.stamp.enable({ image, back: tools.selecttransform.enable,