Merge pull request #123 from zero01101/testing

An easy fix for mouse wheel scrolling
This commit is contained in:
tim h 2022-12-26 16:49:56 -06:00 committed by GitHub
commit 8fbc42744e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 9 deletions

View file

@ -320,6 +320,9 @@
src="js/initalize/layers.populate.js"
type="text/javascript"></script>
<!-- Configuration -->
<script src="js/config.js" type="text/javascript"></script>
<!-- Content -->
<script src="js/global.js" type="text/javascript"></script>
<script src="js/prompt.js" type="text/javascript"></script>

12
js/config.js Normal file
View file

@ -0,0 +1,12 @@
/**
* 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 = makeReadOnly(
{
// Scroll Tick Limit (How much must scroll to reach next tick)
wheelTickSize: 50,
},
"config"
);

View file

@ -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({

View file

@ -1083,18 +1083,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
}
}
};

View file

@ -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,