summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/app.c24
-rw-r--r--src/defs.h6
-rw-r--r--src/prefs.c2
-rw-r--r--src/prefs.h6
-rw-r--r--src/ui/command.h4
-rw-r--r--src/ui/documentwidget.c10
-rw-r--r--src/ui/listwidget.c3
-rw-r--r--src/ui/util.c19
8 files changed, 69 insertions, 5 deletions
diff --git a/src/app.c b/src/app.c
index 1f7abbc4..3ee78ee4 100644
--- a/src/app.c
+++ b/src/app.c
@@ -210,6 +210,8 @@ static iString *serializePrefs_App_(const iApp *d) {
210 appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont); 210 appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont);
211 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent); 211 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
212 appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling); 212 appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling);
213 appendFormat_String(str, "scrollspeed arg:%d type:%d\n", d->prefs.smoothScrollSpeed[keyboard_ScrollType], keyboard_ScrollType);
214 appendFormat_String(str, "scrollspeed arg:%d type:%d\n", d->prefs.smoothScrollSpeed[mouse_ScrollType], mouse_ScrollType);
213 appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling); 215 appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling);
214 appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize); 216 appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize);
215 appendFormat_String(str, "memorysize.set arg:%d\n", d->prefs.maxMemorySize); 217 appendFormat_String(str, "memorysize.set arg:%d\n", d->prefs.maxMemorySize);
@@ -1604,6 +1606,15 @@ static void updatePrefsPinSplitButtons_(iWidget *d, int value) {
1604 } 1606 }
1605} 1607}
1606 1608
1609static void updateScrollSpeedButtons_(iWidget *d, enum iScrollType type, const int value) {
1610 const char *typeStr = (type == mouse_ScrollType ? "mouse" : "keyboard");
1611 for (int i = 0; i <= 40; i++) {
1612 setFlags_Widget(findChild_Widget(d, format_CStr("prefs.scrollspeed.%s.%d", typeStr, i)),
1613 selected_WidgetFlag,
1614 i == value);
1615 }
1616}
1617
1607static void updateDropdownSelection_(iLabelWidget *dropButton, const char *selectedCommand) { 1618static void updateDropdownSelection_(iLabelWidget *dropButton, const char *selectedCommand) {
1608 iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu"); 1619 iWidget *menu = findChild_Widget(as_Widget(dropButton), "menu");
1609 iForEach(ObjectList, i, children_Widget(menu)) { 1620 iForEach(ObjectList, i, children_Widget(menu)) {
@@ -1692,6 +1703,10 @@ static iBool handlePrefsCommands_(iWidget *d, const char *cmd) {
1692 updatePrefsPinSplitButtons_(d, arg_Command(cmd)); 1703 updatePrefsPinSplitButtons_(d, arg_Command(cmd));
1693 return iFalse; 1704 return iFalse;
1694 } 1705 }
1706 else if (equal_Command(cmd, "scrollspeed")) {
1707 updateScrollSpeedButtons_(d, argLabel_Command(cmd, "type"), arg_Command(cmd));
1708 return iFalse;
1709 }
1695 else if (equal_Command(cmd, "doctheme.dark.set")) { 1710 else if (equal_Command(cmd, "doctheme.dark.set")) {
1696 updateColorThemeButton_(findChild_Widget(d, "prefs.doctheme.dark"), arg_Command(cmd)); 1711 updateColorThemeButton_(findChild_Widget(d, "prefs.doctheme.dark"), arg_Command(cmd));
1697 return iFalse; 1712 return iFalse;
@@ -2065,6 +2080,13 @@ iBool handleCommand_App(const char *cmd) {
2065 d->prefs.smoothScrolling = arg_Command(cmd); 2080 d->prefs.smoothScrolling = arg_Command(cmd);
2066 return iTrue; 2081 return iTrue;
2067 } 2082 }
2083 else if (equal_Command(cmd, "scrollspeed")) {
2084 const int type = argLabel_Command(cmd, "type");
2085 if (type == keyboard_ScrollType || type == mouse_ScrollType) {
2086 d->prefs.smoothScrollSpeed[type] = iClamp(arg_Command(cmd), 1, 40);
2087 }
2088 return iTrue;
2089 }
2068 else if (equal_Command(cmd, "decodeurls")) { 2090 else if (equal_Command(cmd, "decodeurls")) {
2069 d->prefs.decodeUserVisibleURLs = arg_Command(cmd); 2091 d->prefs.decodeUserVisibleURLs = arg_Command(cmd);
2070 return iTrue; 2092 return iTrue;
@@ -2501,6 +2523,8 @@ iBool handleCommand_App(const char *cmd) {
2501 setToggle_Widget(findChild_Widget(dlg, "prefs.animate"), d->prefs.uiAnimations); 2523 setToggle_Widget(findChild_Widget(dlg, "prefs.animate"), d->prefs.uiAnimations);
2502 setText_InputWidget(findChild_Widget(dlg, "prefs.userfont"), &d->prefs.symbolFontPath); 2524 setText_InputWidget(findChild_Widget(dlg, "prefs.userfont"), &d->prefs.symbolFontPath);
2503 updatePrefsPinSplitButtons_(dlg, d->prefs.pinSplit); 2525 updatePrefsPinSplitButtons_(dlg, d->prefs.pinSplit);
2526 updateScrollSpeedButtons_(dlg, mouse_ScrollType, d->prefs.smoothScrollSpeed[mouse_ScrollType]);
2527 updateScrollSpeedButtons_(dlg, keyboard_ScrollType, d->prefs.smoothScrollSpeed[keyboard_ScrollType]);
2504 updateDropdownSelection_(findChild_Widget(dlg, "prefs.uilang"), cstr_String(&d->prefs.uiLanguage)); 2528 updateDropdownSelection_(findChild_Widget(dlg, "prefs.uilang"), cstr_String(&d->prefs.uiLanguage));
2505 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize); 2529 setToggle_Widget(findChild_Widget(dlg, "prefs.retainwindow"), d->prefs.retainWindowSize);
2506 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"), 2530 setText_InputWidget(findChild_Widget(dlg, "prefs.uiscale"),
diff --git a/src/defs.h b/src/defs.h
index 3ea28e95..5067cce3 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -41,6 +41,12 @@ enum iFileVersion {
41 latest_FileVersion = 4, 41 latest_FileVersion = 4,
42}; 42};
43 43
44enum iScrollType {
45 keyboard_ScrollType,
46 mouse_ScrollType,
47 max_ScrollType
48};
49
44/* Icons */ 50/* Icons */
45 51
46#define menu_Icon "\U0001d362" 52#define menu_Icon "\U0001d362"
diff --git a/src/prefs.c b/src/prefs.c
index 557c6887..f06aab19 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -41,6 +41,8 @@ void init_Prefs(iPrefs *d) {
41 d->pinSplit = 1; 41 d->pinSplit = 1;
42 d->hoverLink = iFalse; 42 d->hoverLink = iFalse;
43 d->smoothScrolling = iTrue; 43 d->smoothScrolling = iTrue;
44 d->smoothScrollSpeed[keyboard_ScrollType] = 10;
45 d->smoothScrollSpeed[mouse_ScrollType] = 10;
44 d->loadImageInsteadOfScrolling = iFalse; 46 d->loadImageInsteadOfScrolling = iFalse;
45 d->collapsePreOnLoad = iFalse; 47 d->collapsePreOnLoad = iFalse;
46 d->openArchiveIndexPages = iTrue; 48 d->openArchiveIndexPages = iTrue;
diff --git a/src/prefs.h b/src/prefs.h
index c1519459..7de6df5d 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -57,6 +57,7 @@ struct Impl_Prefs {
57 iString downloadDir; 57 iString downloadDir;
58 iBool hoverLink; 58 iBool hoverLink;
59 iBool smoothScrolling; 59 iBool smoothScrolling;
60 int smoothScrollSpeed[max_ScrollType];
60 iBool loadImageInsteadOfScrolling; 61 iBool loadImageInsteadOfScrolling;
61 iBool collapsePreOnLoad; 62 iBool collapsePreOnLoad;
62 iString searchUrl; 63 iString searchUrl;
@@ -91,3 +92,8 @@ struct Impl_Prefs {
91}; 92};
92 93
93iDeclareTypeConstruction(Prefs) 94iDeclareTypeConstruction(Prefs)
95
96iLocalDef float scrollSpeedFactor_Prefs(const iPrefs *d, enum iScrollType type) {
97 iAssert(type >= 0 && type < max_ScrollType);
98 return 10.0f / iMax(1, d->smoothScrollSpeed[type]);
99}
diff --git a/src/ui/command.h b/src/ui/command.h
index 10a29101..8dbaafad 100644
--- a/src/ui/command.h
+++ b/src/ui/command.h
@@ -41,3 +41,7 @@ const iString * string_Command (const char *, const char *label); /* space-
41iRangecc range_Command (const char *, const char *label); /* space-delimited */ 41iRangecc range_Command (const char *, const char *label); /* space-delimited */
42const char * suffixPtr_Command (const char *, const char *label); /* until end-of-command */ 42const char * suffixPtr_Command (const char *, const char *label); /* until end-of-command */
43iString * suffix_Command (const char *, const char *label); /* until end-of-command */ 43iString * suffix_Command (const char *, const char *label); /* until end-of-command */
44
45iLocalDef iBool hasLabel_Command(const char *d, const char *label) {
46 return suffixPtr_Command(d, label) != NULL;
47}
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 38f34c77..b59233c7 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -201,7 +201,9 @@ static void updateSideIconBuf_DocumentWidget_ (const iDocumentWidget *d);
201static void prerender_DocumentWidget_ (iAny *); 201static void prerender_DocumentWidget_ (iAny *);
202static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t); 202static void scrollBegan_DocumentWidget_ (iAnyObject *, int, uint32_t);
203 203
204static const int smoothDuration_DocumentWidget_ = 600; /* milliseconds */ 204static const int smoothDuration_DocumentWidget_(enum iScrollType type) {
205 return 600 /* milliseconds */ * scrollSpeedFactor_Prefs(prefs_App(), type);
206}
205 207
206enum iRequestState { 208enum iRequestState {
207 blank_RequestState, 209 blank_RequestState,
@@ -2913,7 +2915,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2913 const float amount = argLabel_Command(cmd, "full") != 0 ? 1.0f : 0.5f; 2915 const float amount = argLabel_Command(cmd, "full") != 0 ? 1.0f : 0.5f;
2914 smoothScroll_DocumentWidget_(d, 2916 smoothScroll_DocumentWidget_(d,
2915 dir * amount * height_Rect(documentBounds_DocumentWidget_(d)), 2917 dir * amount * height_Rect(documentBounds_DocumentWidget_(d)),
2916 smoothDuration_DocumentWidget_); 2918 smoothDuration_DocumentWidget_(keyboard_ScrollType));
2917 return iTrue; 2919 return iTrue;
2918 } 2920 }
2919 else if (equal_Command(cmd, "scroll.top") && document_App() == d) { 2921 else if (equal_Command(cmd, "scroll.top") && document_App() == d) {
@@ -2942,7 +2944,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2942 } 2944 }
2943 smoothScroll_DocumentWidget_(d, 2945 smoothScroll_DocumentWidget_(d,
2944 3 * lineHeight_Text(paragraph_FontId) * dir, 2946 3 * lineHeight_Text(paragraph_FontId) * dir,
2945 smoothDuration_DocumentWidget_); 2947 smoothDuration_DocumentWidget_(keyboard_ScrollType));
2946 return iTrue; 2948 return iTrue;
2947 } 2949 }
2948 else if (equal_Command(cmd, "document.goto") && document_App() == d) { 2950 else if (equal_Command(cmd, "document.goto") && document_App() == d) {
@@ -3381,7 +3383,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3381 smoothScroll_DocumentWidget_( 3383 smoothScroll_DocumentWidget_(
3382 d, 3384 d,
3383 -3 * amount * lineHeight_Text(paragraph_FontId), 3385 -3 * amount * lineHeight_Text(paragraph_FontId),
3384 smoothDuration_DocumentWidget_ * 3386 smoothDuration_DocumentWidget_(mouse_ScrollType) *
3385 /* accelerated speed for repeated wheelings */ 3387 /* accelerated speed for repeated wheelings */
3386 (!isFinished_SmoothScroll(&d->scrollY) && pos_Anim(&d->scrollY.pos) < 0.25f 3388 (!isFinished_SmoothScroll(&d->scrollY) && pos_Anim(&d->scrollY.pos) < 0.25f
3387 ? 0.5f 3389 ? 0.5f
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index f7c43a93..29aa9d1f 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -347,7 +347,8 @@ static iBool processEvent_ListWidget_(iListWidget *d, const SDL_Event *ev) {
347 else { 347 else {
348 /* Traditional mouse wheel. */ 348 /* Traditional mouse wheel. */
349 amount *= 3 * d->itemHeight; 349 amount *= 3 * d->itemHeight;
350 moveSpan_SmoothScroll(&d->scrollY, amount, 200); 350 moveSpan_SmoothScroll(
351 &d->scrollY, amount, 200 * scrollSpeedFactor_Prefs(prefs_App(), mouse_ScrollType));
351 } 352 }
352 return iTrue; 353 return iTrue;
353 } 354 }
diff --git a/src/ui/util.c b/src/ui/util.c
index d68274ad..220e3a50 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1678,6 +1678,25 @@ iWidget *makePreferences_Widget(void) {
1678 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values); 1678 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values);
1679 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.smoothscroll}"))); 1679 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.smoothscroll}")));
1680 addChild_Widget(values, iClob(makeToggle_Widget("prefs.smoothscroll"))); 1680 addChild_Widget(values, iClob(makeToggle_Widget("prefs.smoothscroll")));
1681 /* Scroll speeds. */ {
1682 for (int type = 0; type < max_ScrollType; type++) {
1683 const char *typeStr = (type == mouse_ScrollType ? "mouse" : "keyboard");
1684 addChild_Widget(headings,
1685 iClob(makeHeading_Widget(type == mouse_ScrollType
1686 ? "${prefs.scrollspeed.mouse}"
1687 : "${prefs.scrollspeed.keyboard}")));
1688 iWidget *scrollSpeed = new_Widget();
1689 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.7", typeStr), "0", format_CStr("scrollspeed arg:7 type:%d", type));
1690 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.10", typeStr), "1", format_CStr("scrollspeed arg:10 type:%d", type));
1691 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.13", typeStr), "2", format_CStr("scrollspeed arg:13 type:%d", type));
1692 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.17", typeStr), "3", format_CStr("scrollspeed arg:17 type:%d", type));
1693 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.23", typeStr), "4", format_CStr("scrollspeed arg:23 type:%d", type));
1694 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.30", typeStr), "5", format_CStr("scrollspeed arg:30 type:%d", type));
1695 addRadioButton_(scrollSpeed, format_CStr("prefs.scrollspeed.%s.40", typeStr), "6", format_CStr("scrollspeed arg:40 type:%d", type));
1696 addChildFlags_Widget(
1697 values, iClob(scrollSpeed), arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag);
1698 }
1699 }
1681 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.imageloadscroll}"))); 1700 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.imageloadscroll}")));
1682 addChild_Widget(values, iClob(makeToggle_Widget("prefs.imageloadscroll"))); 1701 addChild_Widget(values, iClob(makeToggle_Widget("prefs.imageloadscroll")));
1683 if (deviceType_App() == phone_AppDeviceType) { 1702 if (deviceType_App() == phone_AppDeviceType) {