diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-11 16:04:04 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-11 16:04:04 +0300 |
commit | 35cd31e58751b72d69bb9ece02241d31b449d8a1 (patch) | |
tree | 88e349046014b88db998fc2e83b6aa40a0efd17b /src/ui/documentwidget.c | |
parent | 2166620cdb5cbdd58c4b865d834bf41758094642 (diff) |
DocumentWidget: Smooth mouse wheel scrolling
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index f5672c42..b7b40aca 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -789,9 +789,15 @@ static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) { | |||
789 | refresh_Widget(as_Widget(d)); | 789 | refresh_Widget(as_Widget(d)); |
790 | } | 790 | } |
791 | 791 | ||
792 | static iBool isSmoothScrolling_DocumentWidget_(const iDocumentWidget *d) { | ||
793 | return d->smoothScroll != 0; | ||
794 | } | ||
795 | |||
792 | static void doScroll_DocumentWidget_(iAny *ptr) { | 796 | static void doScroll_DocumentWidget_(iAny *ptr) { |
793 | iDocumentWidget *d = ptr; | 797 | iDocumentWidget *d = ptr; |
794 | if (!d->smoothScroll) return; /* was cancelled */ | 798 | if (!isSmoothScrolling_DocumentWidget_(d)) { |
799 | return; /* was cancelled */ | ||
800 | } | ||
795 | const double elapsed = (double) elapsedSinceLastTicker_App() / 1000.0; | 801 | const double elapsed = (double) elapsedSinceLastTicker_App() / 1000.0; |
796 | int delta = d->smoothSpeed * elapsed * iSign(d->smoothScroll); | 802 | int delta = d->smoothSpeed * elapsed * iSign(d->smoothScroll); |
797 | if (iAbs(d->smoothScroll) <= iAbs(delta)) { | 803 | if (iAbs(d->smoothScroll) <= iAbs(delta)) { |
@@ -804,7 +810,7 @@ static void doScroll_DocumentWidget_(iAny *ptr) { | |||
804 | } | 810 | } |
805 | scroll_DocumentWidget_(d, delta); | 811 | scroll_DocumentWidget_(d, delta); |
806 | d->smoothScroll -= delta; | 812 | d->smoothScroll -= delta; |
807 | if (d->smoothScroll != 0) { | 813 | if (isSmoothScrolling_DocumentWidget_(d)) { |
808 | addTicker_App(doScroll_DocumentWidget_, d); | 814 | addTicker_App(doScroll_DocumentWidget_, d); |
809 | } | 815 | } |
810 | } | 816 | } |
@@ -1420,7 +1426,11 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1420 | postCommandf_App("zoom.delta arg:%d", ev->wheel.y > 0 ? 10 : -10); | 1426 | postCommandf_App("zoom.delta arg:%d", ev->wheel.y > 0 ? 10 : -10); |
1421 | return iTrue; | 1427 | return iTrue; |
1422 | } | 1428 | } |
1423 | scroll_DocumentWidget_(d, -3 * ev->wheel.y * lineHeight_Text(default_FontId)); | 1429 | smoothScroll_DocumentWidget_( |
1430 | d, | ||
1431 | -3 * ev->wheel.y * lineHeight_Text(default_FontId), | ||
1432 | gap_UI * smoothSpeed_DocumentWidget_ + | ||
1433 | (isSmoothScrolling_DocumentWidget_(d) ? d->smoothSpeed : 0)); | ||
1424 | #endif | 1434 | #endif |
1425 | d->noHoverWhileScrolling = iTrue; | 1435 | d->noHoverWhileScrolling = iTrue; |
1426 | return iTrue; | 1436 | return iTrue; |