Skip to content

Commit 1db0fc7

Browse files
committed
New: Custom mouse wheel shortcuts
1 parent b8fe639 commit 1db0fc7

11 files changed

Lines changed: 370 additions & 129 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2121
- OPDS support [`b72f32f`](https://github.com/ollm/OpenComic/commit/b72f32f2445b90f13f5e2cc45865c2c17a72af82)
2222
- Button to enable/disable full screen from the more options menu [`5d2ac36`](https://github.com/ollm/OpenComic/commit/5d2ac367c61da97d04cd67526470fb7885c1b3bf)
2323
- Show package versions in About OpenComic [`888d9ba`](https://github.com/ollm/OpenComic/commit/888d9ba2e23241b1868b6a360e7bca1a0bef9586)
24+
- Custom mouse wheel shortcuts
2425

2526
##### 🐛 Bug Fixes
2627

scripts/app.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,62 @@ function _encodeSrcURI(path)
263263
return /^blob/.test(path) ? path : encodeSrcURI(path);
264264
}
265265

266+
var transitionPrev = {};
267+
268+
// This need to be improved to smooth transitions
269+
function transition(key, transition = 0)
270+
{
271+
const seconds = transition < 50 ? true : false;
272+
273+
transition = seconds ? transition * 1000 : transition;
274+
let _function = 'ease';
275+
276+
const now = performance.now();
277+
const prev = transitionPrev[key] || 0;
278+
transitionPrev[key] = now;
279+
280+
if(prev && now - prev < transition)
281+
{
282+
transition = now - prev;
283+
_function = 'linear';
284+
}
285+
286+
return {
287+
speed: seconds ? transition / 1000 : transition,
288+
function: _function,
289+
};
290+
}
291+
292+
function scrollTransition(key, transition = 0)
293+
{
294+
const seconds = transition < 50 ? true : false;
295+
transition = transition ? 200 : 0;
296+
297+
let _function = 'cubic-bezier(0.42, 0, 0.58, 1)';
298+
299+
const now = performance.now();
300+
const prev = transitionPrev[key] || 0;
301+
transitionPrev[key] = now;
302+
303+
if(prev && now - prev < transition)
304+
{
305+
transition = now - prev;
306+
if(transition < 80) transition = 80;
307+
308+
_function = 'linear';
309+
}
310+
311+
return {
312+
speed: seconds ? transition / 1000 : transition,
313+
function: _function,
314+
};
315+
}
316+
317+
function scrollAnimation()
318+
{
319+
320+
}
321+
266322
var throttles = {};
267323
var debounces = {};
268324

@@ -338,6 +394,9 @@ module.exports = {
338394
sleep: sleep,
339395
setImmediate: setImmediate,
340396
setThrottle: setThrottle,
397+
transition: transition,
398+
scrollTransition: scrollTransition,
399+
scrollAnimation: scrollAnimation,
341400
shortWindowsPath: _shortWindowsPath,
342401
encodeSrcURI: _encodeSrcURI,
343402
};

scripts/dom/header.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function wheel(event)
2424
}, 160);
2525

2626
$(this).stop(true).animate({scrollLeft: scrollLeft+'px'}, 160, 'linear');
27+
28+
/*this.scrollTo({
29+
top: 0,
30+
left: scrollLeft,
31+
behavior: 'smooth',
32+
});*/
2733
}
2834

2935
async function event()

scripts/migration.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,27 @@ function migrateControllerDeadZone(data)
9090
return data;
9191
}
9292

93+
function migrateMouseWheelEvents(data)
94+
{
95+
if(data.shortcuts.reading.actionsConfigured.length) // Has custom shortcuts
96+
{
97+
const shortcuts = data.shortcuts.reading.shortcuts;
98+
99+
shortcuts['MouseUp'] = data.config.readingTurnPagesWithMouseWheel ? 'prev' : 'zoomIn';
100+
shortcuts['MouseDown'] = data.config.readingTurnPagesWithMouseWheel ? 'next' : 'zoomOut';
101+
shortcuts['Ctrl+MouseUp'] = 'zoomIn';
102+
shortcuts['Ctrl+MouseDown'] = 'zoomOut';
103+
shortcuts['Shift+MouseUp'] = 'zoomUp';
104+
shortcuts['Shift+MouseDown'] = 'zoomDown';
105+
shortcuts['Shift+MouseLeft'] = 'zoomLeft';
106+
shortcuts['Shift+MouseRight'] = 'zoomRight';
107+
shortcuts['Alt+MouseUp'] = 'prev';
108+
shortcuts['Alt+MouseDown'] = 'next';
109+
}
110+
111+
return data;
112+
}
113+
93114
function start(data)
94115
{
95116
let changes = data.config.changes;
@@ -108,6 +129,9 @@ function start(data)
108129
if(changes < 99) // Change controllerDeadZone to gamepadDeadZone
109130
data = migrateControllerDeadZone(data);
110131

132+
if(changes < 103) // Add the new mouse wheel events
133+
data = migrateMouseWheelEvents(data);
134+
111135
data = opds.addNewDefaultCatalogs(data, changes);
112136

113137
return data;

scripts/reading.js

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,7 +1349,7 @@ function goToIndex(index, animation = true, nextPrevious = false, end = false)
13491349
currentZoomIndex = false;
13501350
currentScale = _currentScale;
13511351
reading.applyScale(false, _currentScale, true, _currentScale > 1 ? false : true);
1352-
zoomMove(0, readingDirection ? 99999 : -99999);
1352+
if(animation) zoomMove(0, readingDirection ? 99999 : -99999);
13531353
}
13541354

13551355
//goToImageCL(imagesDistribution[eIndex-1][0].index, animation);
@@ -2287,54 +2287,58 @@ function zoomScrollHeight()
22872287
}
22882288

22892289
// Zoom in
2290-
function zoomIn(animation = true, center = false)
2290+
function zoomIn(animation = true, center = false, delta = 120)
22912291
{
22922292
if(zoomMoveData.active)
22932293
return;
22942294

2295+
const multipler = 0.25 * (delta / 120);
2296+
22952297
if(currentScale < 8)
2296-
currentScale *= 1.25;
2298+
currentScale *= 1 + multipler;
22972299

22982300
applyScale(animation, currentScale, center);
22992301
}
23002302

23012303
// Zoom out
2302-
function zoomOut(animation = true, center = false)
2304+
function zoomOut(animation = true, center = false, delta = 120)
23032305
{
23042306
if(zoomMoveData.active)
23052307
return;
23062308

2309+
const multipler = 0.25 * (delta / 120);
2310+
23072311
if(currentScale > 0.2)
2308-
currentScale /= 1.25;
2312+
currentScale /= 1 + multipler;
23092313

23102314
applyScale(animation, currentScale, center, true);
23112315
}
23122316

2313-
function zoomUp()
2317+
function zoomUp(delta = 20, animation = false)
23142318
{
2315-
zoomMove(0, 20);
2319+
zoomMove(0, delta, animation);
23162320
}
23172321

2318-
function zoomDown()
2322+
function zoomDown(delta = 20, animation = false)
23192323
{
2320-
zoomMove(0, -20);
2324+
zoomMove(0, -delta, animation);
23212325
}
23222326

2323-
function zoomLeft()
2327+
function zoomLeft(delta = 20, animation = false)
23242328
{
2325-
zoomMove(-20, 0);
2329+
zoomMove(-delta, 0, animation);
23262330
}
23272331

2328-
function zoomRight()
2332+
function zoomRight(delta = 20, animation = false)
23292333
{
2330-
zoomMove(20, 0);
2334+
zoomMove(delta, 0, animation);
23312335
}
23322336

2333-
function zoomMove(x = 0, y = 0)
2337+
function zoomMove(x = 0, y = 0, animation = false)
23342338
{
23352339
if(!haveZoom) return;
23362340

2337-
dragZoom(x, y);
2341+
dragZoom(x, y, animation);
23382342
dragZoomEnd(true);
23392343
}
23402344

@@ -2537,9 +2541,10 @@ function notCrossZoomLimits(x, y, scale = false)
25372541
}
25382542

25392543
// Drag zoom
2540-
function dragZoom(x, y)
2544+
function dragZoom(x, y, animation = false)
25412545
{
2542-
let withLimits = notCrossZoomLimits(scalePrevData.tranX2 + x, scalePrevData.tranY2 + y);
2546+
const transition = animation ? app.scrollTransition('dragZoom', _config.readingViewSpeed) : 0;
2547+
const withLimits = notCrossZoomLimits(scalePrevData.tranX2 + x, scalePrevData.tranY2 + y);
25432548

25442549
const diff = {
25452550
x: (scalePrevData.tranX2 + x) - withLimits.x,
@@ -2549,15 +2554,15 @@ function dragZoom(x, y)
25492554
x = withLimits.x;
25502555
y = withLimits.y;
25512556

2552-
let contentRight = template._contentRight();
2557+
const contentRight = template._contentRight();
25532558

25542559
if(config.readingGlobalZoom && readingViewIs('scroll'))
25552560
{
25562561
scalePrevData.tranX = zoomMoveData.tranX = x;
25572562
zoomMoveData.tranY = scalePrevData.tranY;
25582563

25592564
dom.this(contentRight).find('.reading-body > div').css({
2560-
transition: 'transform 0s, z-index 0s',
2565+
transition: 'transform '+transition.speed+'s '+transition.function+', z-index 0s',
25612566
transform: 'translateX('+app.roundDPR(x)+'px) translateY('+app.roundDPR(scalePrevData.tranY)+'px) scale('+scalePrevData.scale+')',
25622567
transformOrigin: 'top center',
25632568
});
@@ -2568,7 +2573,7 @@ function dragZoom(x, y)
25682573
zoomMoveData.tranY = y;
25692574

25702575
dom.this(contentRight).find('.image-position'+currentZoomIndex, true).css({
2571-
transition: 'transform 0s, z-index 0s',
2576+
transition: 'transform '+transition.speed+'s '+transition.function+', z-index 0s',
25722577
transform: 'translateX('+app.roundDPR(x)+'px) translateY('+app.roundDPR(y)+'px) scale('+scalePrevData.scale+')',
25732578
transformOrigin: 'center center',
25742579
});
@@ -4894,33 +4899,14 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
48944899
});
48954900
onLoadPromise = {promise: promise, resolve: resolve};
48964901

4897-
template.contentRight().on('mousewheel', function(e) {
4902+
template.contentRight().on('mousewheel', function(event) {
48984903

48994904
if(onReading && isLoaded)
49004905
{
4901-
if(config.readingTurnPagesWithMouseWheel && !e.originalEvent.ctrlKey && !readingViewIs('scroll'))
4902-
{
4903-
e.preventDefault();
4904-
4905-
if(e.originalEvent.wheelDelta / 120 > 0)
4906-
reading.goPrev();
4907-
else
4908-
reading.goNext();
4909-
}
4910-
else if(e.originalEvent.ctrlKey || !readingViewIs('scroll'))
4911-
{
4912-
e.preventDefault();
4906+
const oEvent = event.originalEvent;
49134907

4914-
if(e.originalEvent.wheelDelta / 120 > 0)
4915-
reading.zoomIn();
4916-
else
4917-
reading.zoomOut();
4918-
}
4919-
else
4920-
{
4921-
if(reading.scrollNextOrPrevComic(e.originalEvent.wheelDelta / 120 > 0, true))
4922-
e.preventDefault();
4923-
}
4908+
if(readingViewIs('scroll') && !oEvent.altKey && !oEvent.metaKey && !oEvent.ctrlKey && !oEvent.shiftKey && reading.scrollNextOrPrevComic(oEvent.wheelDelta / 120 > 0, true))
4909+
event.preventDefault();
49244910
}
49254911

49264912
});

scripts/settings.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ function changeShortcut(action, current, This)
652652

653653
generateShortcutsTable(gamepad.currentHighlightItem());
654654

655+
events.events();
656+
655657
setTimeout(function(){recording = false}, 100);
656658

657659
});
@@ -662,6 +664,8 @@ function removeShortcut(action, current)
662664
shortcuts.change('reading', action, current, '');
663665

664666
generateShortcutsTable(gamepad.currentHighlightItem());
667+
668+
events.events();
665669
}
666670

667671
function changeButton(action, current, This)

0 commit comments

Comments
 (0)